1
0
Fork 0

crtc: Add identity gamma LUT helpers

One to create a identity LUT of a certain size, one to check if a LUT
represents identity.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3552>
This commit is contained in:
Sebastian Wick 2024-01-29 20:56:42 +01:00 committed by Marge Bot
parent 6876b51875
commit a55e2e5af2
2 changed files with 47 additions and 0 deletions

View file

@ -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)
{

View file

@ -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);