core, libgimpcolor: CMKY & HSL to float

Continuing 32d64ab1, this converts the
few instances of CMYK and HSL/A double
to float to match babl's precision.
This commit is contained in:
Alx Sa 2024-04-23 13:38:59 +00:00
parent bffe62d43e
commit 47aabfc93a
3 changed files with 22 additions and 17 deletions

View File

@ -572,13 +572,13 @@ gimp_palette_load_aco (GimpContext *context,
}
else if (color_space == 2) /* CMYK */
{
gdouble cmyk[4] = { 1.0 - ((gdouble) w) / 65536.0,
1.0 - ((gdouble) x) / 65536.0,
1.0 - ((gdouble) y) / 65536.0,
1.0 - ((gdouble) z) / 65536.0 };
float cmyk[4] = { 1.0f - ((gfloat) w) / 65536.0f,
1.0f - ((gfloat) x) / 65536.0f,
1.0f - ((gfloat) y) / 65536.0f,
1.0f - ((gfloat) z) / 65536.0f };
/* No color space information in the format. */
gegl_color_set_pixel (color, babl_format ("CMYK double"), cmyk);
gegl_color_set_pixel (color, babl_format ("CMYK float"), cmyk);
color_ok = TRUE;
}
else if (color_space == 7) /* CIE Lab */
@ -605,12 +605,12 @@ gimp_palette_load_aco (GimpContext *context,
* implementation in GIMP so it's hard to know the origin behind it.
* Where does it come from?
*/
gdouble cmyk[4] = { 1.0 - ((gdouble) w) / 10000.0,
1.0 - ((gdouble) x) / 10000.0,
1.0 - ((gdouble) y) / 10000.0,
1.0 - ((gdouble) z) / 10000.0 };
gfloat cmyk[4] = { 1.0f - ((gfloat) w) / 10000.0,
1.0f - ((gfloat) x) / 10000.0,
1.0f - ((gfloat) y) / 10000.0,
1.0f - ((gfloat) z) / 10000.0 };
gegl_color_set_pixel (color, babl_format ("CMYK double"), cmyk);
gegl_color_set_pixel (color, babl_format ("CMYK float"), cmyk);
color_ok = TRUE;
}
else

View File

@ -554,10 +554,15 @@ gimp_color_parse_css_numeric (const gchar *css)
color = gegl_color_new (NULL);
if (hsl)
{
gfloat values_f[4];
for (i = 0; i < (alpha ? 4 : 3); i++)
values_f[i] = (gfloat) values[i];
if (alpha)
gegl_color_set_pixel (color, babl_format ("HSLA double"), values);
gegl_color_set_pixel (color, babl_format ("HSLA float"), values_f);
else
gegl_color_set_pixel (color, babl_format ("HSL double"), values);
gegl_color_set_pixel (color, babl_format ("HSL float"), values_f);
}
else
{

View File

@ -235,9 +235,9 @@ gimp_color_is_out_of_self_gamut (GeglColor *color)
model == babl_model ("cmyk") ||
model == babl_model ("cmykA"))
{
gdouble cmyk[4];
gfloat cmyk[4];
gegl_color_get_pixel (color, babl_format_with_space ("CMYK double", space), cmyk);
gegl_color_get_pixel (color, babl_format_with_space ("CMYK float", space), cmyk);
oog = ((cmyk[0] < 0.0 && -cmyk[0] > CHANNEL_EPSILON) ||
(cmyk[0] > 1.0 && cmyk[0] - 1.0 > CHANNEL_EPSILON) ||
(cmyk[1] < 0.0 && -cmyk[1] > CHANNEL_EPSILON) ||
@ -303,16 +303,16 @@ gimp_color_is_out_of_gamut (GeglColor *color,
else if (babl_space_is_cmyk (space))
{
GeglColor *c = gegl_color_new (NULL);
gdouble cmyk[4];
gfloat cmyk[4];
/* CMYK conversion always produces colors in [0; 1] range. What we want
* to check is whether the source and converted colors are the same in
* Lab space.
*/
gegl_color_get_pixel (color,
babl_format_with_space ("CMYK double", space),
babl_format_with_space ("CMYK float", space),
cmyk);
gegl_color_set_pixel (c, babl_format_with_space ("CMYK double", space), cmyk);
gegl_color_set_pixel (c, babl_format_with_space ("CMYK float", space), cmyk);
is_out_of_gamut = (! gimp_color_is_perceptually_identical (color, c));
g_object_unref (c);
}