From e551de23121a4d5be88f8e47a56ae206b40d8068 Mon Sep 17 00:00:00 2001 From: Jehan Date: Sat, 18 Jan 2025 21:32:22 +0100 Subject: [PATCH] libgimpcolor: GIMP built-in sRGB profiles now generated by babl. Though it also seems like a next step towards babl-managed color management, the first reason is that LittleCMS adds a creation timestamp. Looking up upstream code, it looks like there is no way to override this value (Icc->Created is only set at creation and none of the time tags seem to touch this). Unfortunately it makes our built-in sRGB profiles non-reproducible binaries (which for instance is a problem in gimp-date#7). --- libgimpcolor/gimpcolorprofile.c | 154 +++++++------------------------- 1 file changed, 32 insertions(+), 122 deletions(-) diff --git a/libgimpcolor/gimpcolorprofile.c b/libgimpcolor/gimpcolorprofile.c index 82e1238f6d3..9e4f8ec7940 100644 --- a/libgimpcolor/gimpcolorprofile.c +++ b/libgimpcolor/gimpcolorprofile.c @@ -1044,63 +1044,6 @@ gimp_color_profile_new_linear_from_color_profile (GimpColorProfile *profile) return gimp_color_profile_new_from_color_profile (profile, TRUE); } -static cmsHPROFILE * -gimp_color_profile_new_rgb_srgb_internal (void) -{ - cmsHPROFILE profile; - - /* white point is D65 from the sRGB specs */ - cmsCIExyY whitepoint = { 0.3127, 0.3290, 1.0 }; - - /* primaries are ITU‐R BT.709‐5 (xYY), which are also the primaries - * from the sRGB specs, modified to properly account for hexadecimal - * quantization during the profile making process. - */ - cmsCIExyYTRIPLE primaries = - { - /* R { 0.6400, 0.3300, 1.0 }, */ - /* G { 0.3000, 0.6000, 1.0 }, */ - /* B { 0.1500, 0.0600, 1.0 } */ - /* R */ { 0.639998686, 0.330010138, 1.0 }, - /* G */ { 0.300003784, 0.600003357, 1.0 }, - /* B */ { 0.150002046, 0.059997204, 1.0 } - }; - - cmsFloat64Number srgb_parameters[5] = - { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 }; - - cmsToneCurve *curve[3]; - - /* sRGB curve */ - curve[0] = curve[1] = curve[2] = cmsBuildParametricToneCurve (NULL, 4, - srgb_parameters); - - profile = cmsCreateRGBProfile (&whitepoint, &primaries, curve); - - cmsFreeToneCurve (curve[0]); - - gimp_color_profile_set_tag (profile, cmsSigProfileDescriptionTag, - "GIMP built-in sRGB"); - gimp_color_profile_set_tag (profile, cmsSigDeviceMfgDescTag, - "GIMP"); - gimp_color_profile_set_tag (profile, cmsSigDeviceModelDescTag, - "sRGB"); - gimp_color_profile_set_tag (profile, cmsSigCopyrightTag, - "Public Domain"); - - /* The following line produces a V2 profile with a point curve TRC. - * Profiles with point curve TRCs can't be used in LCMS2 unbounded - * mode ICC profile conversions. A V2 profile might be appropriate - * for embedding in sRGB images saved to disk, if the image is to be - * opened by an image editing application that doesn't understand V4 - * profiles. - * - * cmsSetProfileVersion (srgb_profile, 2.1); - */ - - return profile; -} - /** * gimp_color_profile_new_rgb_srgb: * @@ -1137,64 +1080,26 @@ gimp_color_profile_new_rgb_srgb (void) { static GimpColorProfile *profile = NULL; - const guint8 *data; - gsize length = 0; - if (G_UNLIKELY (profile == NULL)) { - cmsHPROFILE lcms_profile = gimp_color_profile_new_rgb_srgb_internal (); - - profile = gimp_color_profile_new_from_lcms_profile (lcms_profile, NULL); - - cmsCloseProfile (lcms_profile); + const char *data; + int length; + + data = babl_space_get_icc (babl_space ("sRGB"), &length); + profile = gimp_color_profile_new_from_icc_profile ((const guint8 *) data, + (gsize) length, NULL); + + gimp_color_profile_set_tag (profile->lcms_profile, cmsSigProfileDescriptionTag, + "GIMP built-in sRGB"); + gimp_color_profile_set_tag (profile->lcms_profile, cmsSigDeviceMfgDescTag, + "GIMP"); + gimp_color_profile_set_tag (profile->lcms_profile, cmsSigDeviceModelDescTag, + "sRGB"); + gimp_color_profile_set_tag (profile->lcms_profile, cmsSigCopyrightTag, + "Public Domain"); } - data = gimp_color_profile_get_icc_profile (profile, &length); - - return gimp_color_profile_new_from_icc_profile (data, length, NULL); -} - -static cmsHPROFILE -gimp_color_profile_new_rgb_srgb_linear_internal (void) -{ - cmsHPROFILE profile; - - /* white point is D65 from the sRGB specs */ - cmsCIExyY whitepoint = { 0.3127, 0.3290, 1.0 }; - - /* primaries are ITU‐R BT.709‐5 (xYY), which are also the primaries - * from the sRGB specs, modified to properly account for hexadecimal - * quantization during the profile making process. - */ - cmsCIExyYTRIPLE primaries = - { - /* R { 0.6400, 0.3300, 1.0 }, */ - /* G { 0.3000, 0.6000, 1.0 }, */ - /* B { 0.1500, 0.0600, 1.0 } */ - /* R */ { 0.639998686, 0.330010138, 1.0 }, - /* G */ { 0.300003784, 0.600003357, 1.0 }, - /* B */ { 0.150002046, 0.059997204, 1.0 } - }; - - cmsToneCurve *curve[3]; - - /* linear light */ - curve[0] = curve[1] = curve[2] = cmsBuildGamma (NULL, 1.0); - - profile = cmsCreateRGBProfile (&whitepoint, &primaries, curve); - - cmsFreeToneCurve (curve[0]); - - gimp_color_profile_set_tag (profile, cmsSigProfileDescriptionTag, - "GIMP built-in Linear sRGB"); - gimp_color_profile_set_tag (profile, cmsSigDeviceMfgDescTag, - "GIMP"); - gimp_color_profile_set_tag (profile, cmsSigDeviceModelDescTag, - "Linear sRGB"); - gimp_color_profile_set_tag (profile, cmsSigCopyrightTag, - "Public Domain"); - - return profile; + return gimp_color_profile_new_from_lcms_profile (profile->lcms_profile, NULL); } /** @@ -1212,21 +1117,26 @@ gimp_color_profile_new_rgb_srgb_linear (void) { static GimpColorProfile *profile = NULL; - const guint8 *data; - gsize length = 0; - if (G_UNLIKELY (profile == NULL)) { - cmsHPROFILE lcms_profile = gimp_color_profile_new_rgb_srgb_linear_internal (); - - profile = gimp_color_profile_new_from_lcms_profile (lcms_profile, NULL); - - cmsCloseProfile (lcms_profile); + const char *data; + int length; + + data = babl_space_get_icc (babl_space ("scRGB"), &length); + profile = gimp_color_profile_new_from_icc_profile ((const guint8 *) data, + (gsize) length, NULL); + + gimp_color_profile_set_tag (profile->lcms_profile, cmsSigProfileDescriptionTag, + "GIMP built-in Linear sRGB"); + gimp_color_profile_set_tag (profile->lcms_profile, cmsSigDeviceMfgDescTag, + "GIMP"); + gimp_color_profile_set_tag (profile->lcms_profile, cmsSigDeviceModelDescTag, + "Linear sRGB"); + gimp_color_profile_set_tag (profile->lcms_profile, cmsSigCopyrightTag, + "Public Domain"); } - data = gimp_color_profile_get_icc_profile (profile, &length); - - return gimp_color_profile_new_from_icc_profile (data, length, NULL); + return gimp_color_profile_new_from_lcms_profile (profile->lcms_profile, NULL); } static cmsHPROFILE * -- GitLab