[Intel-gfx] [PATCH 1/2] drm: Add color management LUT validation helpers
Matt Roper
matthew.d.roper at intel.com
Wed Dec 12 01:05:50 UTC 2018
Some hardware may place additional restrictions on the gamma/degamma
curves described by our LUT properties. E.g., that a gamma curve never
decreases or that the red/green/blue channels of a LUT's entries must be
equal. Let's add a couple helpers that drivers can use to test that a
userspace-provided LUT doesn't violate hardware requirements.
Cc: Uma Shankar <uma.shankar at intel.com>
Cc: Swati Sharma <swati2.sharma at intel.com>
Signed-off-by: Matt Roper <matthew.d.roper at intel.com>
---
drivers/gpu/drm/drm_color_mgmt.c | 53 ++++++++++++++++++++++++++++++++++++++++
include/drm/drm_color_mgmt.h | 3 +++
2 files changed, 56 insertions(+)
diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_mgmt.c
index 07dcf47daafe..41e617e34c10 100644
--- a/drivers/gpu/drm/drm_color_mgmt.c
+++ b/drivers/gpu/drm/drm_color_mgmt.c
@@ -462,3 +462,56 @@ int drm_plane_create_color_properties(struct drm_plane *plane,
return 0;
}
EXPORT_SYMBOL(drm_plane_create_color_properties);
+
+/**
+ * drm_color_lut_has_equal_channels - check LUT for equal r/g/b values
+ * @lut: property blob containing LUT to check
+ *
+ * Helper to check whether the entries of a LUT all have equal values for the
+ * red, green, and blue channels. Some hardware can only be programmed
+ * with a single value per LUT entry, which is assumed to apply to all
+ * three color components.
+ */
+bool drm_color_lut_has_equal_channels(struct drm_property_blob *lut)
+{
+ struct drm_color_lut *entry;
+ int i;
+
+ if (!lut)
+ return true;
+
+ entry = lut->data;
+ for (i = 0; i < drm_color_lut_size(lut); i++)
+ if (entry[i].red != entry[i].blue ||
+ entry[i].red != entry[i].green)
+ return false;
+
+ return true;
+}
+EXPORT_SYMBOL(drm_color_lut_has_equal_channels);
+
+/**
+ * drm_color_lut_is_increasing - check that LUT is always flat/increasing
+ * @lut: LUT to check
+ *
+ * Helper to check whether the entries of a LUT are always flat or increasing
+ * (never decreasing).
+ */
+bool drm_color_lut_is_increasing(struct drm_property_blob *lut)
+{
+ struct drm_color_lut *entry;
+ int i;
+
+ if (!lut)
+ return true;
+
+ entry = lut->data;
+ for (i = 1; i < drm_color_lut_size(lut); i++)
+ if (entry[i].red < entry[i-1].red ||
+ entry[i].green < entry[i-1].green ||
+ entry[i].blue < entry[i-1].blue)
+ return false;
+
+ return true;
+}
+EXPORT_SYMBOL(drm_color_lut_is_increasing);
diff --git a/include/drm/drm_color_mgmt.h b/include/drm/drm_color_mgmt.h
index 90ef9996d9a4..6c38f5477e29 100644
--- a/include/drm/drm_color_mgmt.h
+++ b/include/drm/drm_color_mgmt.h
@@ -69,4 +69,7 @@ int drm_plane_create_color_properties(struct drm_plane *plane,
u32 supported_ranges,
enum drm_color_encoding default_encoding,
enum drm_color_range default_range);
+
+bool drm_color_lut_has_equal_channels(struct drm_property_blob *lut);
+bool drm_color_lut_is_increasing(struct drm_property_blob *lut);
#endif
--
2.14.4
More information about the Intel-gfx
mailing list