diff --git a/src/backends/meta-crtc.c b/src/backends/meta-crtc.c index 7235df263..646a508b9 100644 --- a/src/backends/meta-crtc.c +++ b/src/backends/meta-crtc.c @@ -219,6 +219,48 @@ meta_gamma_lut_new_sized (int size) return gamma; } +MetaGammaLut * +meta_gamma_lut_new_identity (int size) +{ + MetaGammaLut *lut = meta_gamma_lut_new_sized (size); + int i; + + if (size < 2) + return lut; + + for (i = 0; i < size; i++) + { + double value = (i / (double) (size - 1)); + + lut->red[i] = value * UINT16_MAX; + lut->green[i] = value * UINT16_MAX; + lut->blue[i] = value * UINT16_MAX; + } + + return lut; +} + +gboolean +meta_gamma_lut_is_identity (const MetaGammaLut *lut) +{ + int i; + + if (!lut) + return TRUE; + + for (i = 0; i < lut->size; i++) + { + uint16_t value = (i / (double) (lut->size - 1)) * UINT16_MAX; + + if (ABS (lut->red[i] - value) > 1 || + ABS (lut->green[i] - value) > 1 || + ABS (lut->blue[i] - value) > 1) + return FALSE; + } + + return TRUE; +} + MetaGammaLut * meta_gamma_lut_copy (const MetaGammaLut *gamma) { diff --git a/src/backends/meta-crtc.h b/src/backends/meta-crtc.h index 8e4e00f68..0b1eb8b67 100644 --- a/src/backends/meta-crtc.h +++ b/src/backends/meta-crtc.h @@ -110,8 +110,13 @@ MetaGammaLut * meta_gamma_lut_new (int size, const uint16_t *green, const uint16_t *blue); +META_EXPORT_TEST MetaGammaLut * meta_gamma_lut_new_sized (int size); +MetaGammaLut *meta_gamma_lut_new_identity (int size); + +gboolean meta_gamma_lut_is_identity (const MetaGammaLut *lut); + META_EXPORT_TEST MetaGammaLut * meta_gamma_lut_copy (const MetaGammaLut *gamma);