[Mesa-dev] [PATCH 31/32] intel/isl: Add a helper for determining if a color is 0/1

Jason Ekstrand jason at jlekstrand.net
Wed Jul 19 21:01:57 UTC 2017


---
 src/intel/isl/isl.c | 27 +++++++++++++++++++++++++++
 src/intel/isl/isl.h |  3 +++
 2 files changed, 30 insertions(+)

diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c
index 12ffe3b..2976e32 100644
--- a/src/intel/isl/isl.c
+++ b/src/intel/isl/isl.c
@@ -259,6 +259,33 @@ isl_tiling_get_info(enum isl_tiling tiling,
    };
 }
 
+bool
+isl_color_value_is_zero_one(union isl_color_value value,
+                            enum isl_format format)
+{
+   const struct isl_format_layout *fmtl = isl_format_get_layout(format);
+
+#define RETURN_FALSE_IF_NOT_0_1(c, i, field) \
+   if (fmtl->channels.c.bits && value.field[i] != 0 && value.field[i] != 1) \
+      return false
+
+   if (isl_format_has_int_channel(format)) {
+      RETURN_FALSE_IF_NOT_0_1(r, 0, u32);
+      RETURN_FALSE_IF_NOT_0_1(g, 1, u32);
+      RETURN_FALSE_IF_NOT_0_1(b, 2, u32);
+      RETURN_FALSE_IF_NOT_0_1(a, 3, u32);
+   } else {
+      RETURN_FALSE_IF_NOT_0_1(r, 0, f32);
+      RETURN_FALSE_IF_NOT_0_1(g, 1, f32);
+      RETURN_FALSE_IF_NOT_0_1(b, 2, f32);
+      RETURN_FALSE_IF_NOT_0_1(a, 3, f32);
+   }
+
+#undef RETURN_FALSE_IF_NOT_0_1
+
+   return true;
+}
+
 /**
  * @param[out] tiling is set only on success
  */
diff --git a/src/intel/isl/isl.h b/src/intel/isl/isl.h
index bc68e58..b2f5d39 100644
--- a/src/intel/isl/isl.h
+++ b/src/intel/isl/isl.h
@@ -1630,6 +1630,9 @@ isl_extent4d(uint32_t width, uint32_t height, uint32_t depth,
    return e;
 }
 
+bool isl_color_value_is_zero_one(union isl_color_value value,
+                                 enum isl_format format);
+
 #define isl_surf_init(dev, surf, ...) \
    isl_surf_init_s((dev), (surf), \
                    &(struct isl_surf_init_info) {  __VA_ARGS__ });
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list