Re: [Gegl-developer] [Gimp-developer] babl roadmap



In the current babl/GEGL/GIMP code base, I counted five files that contain functions that require a conversion from RGB to XYZ:

1. gimp/plug-ins/common/decompose.c
2. gimp/plug-ins/common/compose.c
3. gimp/app/core/gimpimage-convert-type.c
4. gegl/operations/common/image-compare.c
5. gegl/operations/common/noise-cie-lch.c

These five files use the babl file: babl/extensions/CIE.c

The babl/extensions/CIE.c code calculates the "sRGB to XYZ" matrix "M", starting from the D65 unadapted sRGB color space red, green, blue, and white xy values.

Calculating "M" from xy values is a fairly complicated process. Study the equations on http://brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html and make sure to read note 2, which says "Be careful that reference whites are used consistently. For example, sRGB is defined relative to a D65 reference white and ICC profiles are defined relative to a D50 reference white. Mismatched reference whites must be accounted for elsewhere, typically by using a chromatic adaptation algorithm."

In an ICC profile D50-adapted color-managed workflow, you don't use the unadapted D65 sRGB "M" (that the babl code calculates) to get from sRGB to XYZ.

In an ICC profile color-managed workflow, you don't need to calculate the D50-adapted "M" for a matrix RGB working space, because you can read "M" directly from the ICC profile colorants.

There are two ways to fix the "conversion to XYZ" code in babl/extensions/CIE.c:

1. babl/extensions/CIE.c can be rewritten to use D50-adapted "M" retrieved directly from the UserRGB ICC profile colorants. Then convert to XYZ.

2. Or else you can use "sRGB as PCS", which allows you to rewrite the code in babl/extensions/CIE.c to use hard-coded D50-adapted sRGB "M". In this case:

i. Upon opening an image, first retrieve "M" from UserRGB (call this matrix "A"). ii. Then retrieve "M" from sRGB and calculate the inverse (call this matrix "C").
iii. Then calculate "C*A" and store this information in memory as "D".
iv. Then convert from UserRGB to unbounded sRGB using the matrix "D".
v. Then convert from unbounded sRGB to XYZ using the hard-coded D50-adapted sRGB M.

In an ICC profile color-managed workflow, sRGB is just another ICC working space profile. It doesn't need special treatment.

The right way to fix the babl conversion to XYZ is to rewrite babl/extensions/CIE.c to use "M" taken from the UserRGB ICC profile colorants. And forget about "sRGB as PCS".

There may be a problem somewhere in the GIMP code for which "sRGB as PCS" might be a solution. Converting to XYZ is not one of those problems.

Kind regards,
Elle Stone
--
http://ninedegreesbelow.com
Color management and free/libre photography


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]