Thread: [Lcms-user] Unexpected gray to RGB result
An ICC-based CMM for color management
Brought to you by:
mm2
From: Ralf J. <ral...@gm...> - 2022-11-26 22:12:24
|
I try to use lcms2 to convert gray to RGB, but the output differs considerably. So I double-checked with jpgicc gray-inverted-profile-linear.jpg gray-rgb-linear.jpg but the result is the same: Unexpected saturation of dark gray areas to pitch black. As reference of the expected outcome, please take a look at gray-chromium.png to see how Chromium renders gray-inverted-profile-linear.jpg. Firefox and GIMP look just the same. Am I missing something? I am grateful for any advice! Ralf PS I hope the list accepts attachments. If not please advice how to send the images in question. |
From: <mar...@li...> - 2022-11-27 00:27:38
|
Hi, The embedded profile is wrong. It claims to be V4 and perceptual, but fails to scale on perceptual black. See https://color.org/specification/ICC.1-2022-05.pdf "6.3.4.3 PCS encodings for white and black" "Perceptual transforms developed to meet ICC specifications prior to version 4.0 frequently use zero to represent the black point, and thus do not conform to this specification." Other CMM may choose to reject the profile, lcms uses it, despite it is wrong. Regards Marti Maria The LittleCMS Project https://www.littlecms.com -----Original Message----- From: Ralf Junker <ral...@gm...> Sent: Saturday, November 26, 2022 11:13 PM To: lcm...@li... Subject: [Lcms-user] Unexpected gray to RGB result I try to use lcms2 to convert gray to RGB, but the output differs considerably. So I double-checked with jpgicc gray-inverted-profile-linear.jpg gray-rgb-linear.jpg but the result is the same: Unexpected saturation of dark gray areas to pitch black. As reference of the expected outcome, please take a look at gray-chromium.png to see how Chromium renders gray-inverted-profile-linear.jpg. Firefox and GIMP look just the same. Am I missing something? I am grateful for any advice! Ralf PS I hope the list accepts attachments. If not please advice how to send the images in question. |
From: Ralf J. <ral...@gm...> - 2022-11-27 08:40:42
|
Thanks for the fast answer! > The embedded profile is wrong. It claims to be V4 and perceptual, > but fails to scale on perceptual black. Here is the C code that generated the profile: int main() { const cmsCIExyY *whitepoint = cmsD50_xyY(); int i; cmsUInt16Number values[256]; cmsToneCurve *tonecurve; cmsHPROFILE profile; for(i = 0; i < 256; i++) { values[i] = (255 - i) * 65535 / 255; } tonecurve = cmsBuildTabulatedToneCurve16 (0, 256, values); profile = cmsCreateGrayProfile(whitepoint, tonecurve); cmsSaveProfileToFile(profile, "gray-inverted.icc"); } The goal is a profile which swaps blacks and whites, dark grays and white grays, to create an inverted, negative grayscale. The profile's purpose is testing image rendering software with color correction using lcms2. I found WhackedRGB.icc for color images, but nothing for grayscale. > Other CMM may choose to reject the profile, lcms uses it, despite it > is wrong. My bad, I take your point. Please note that the profile somehow works with Chromium, Firefox and Gimp which all show whites on the left and blacks on the right of the image. And they all show it identically. Viewers which do not apply the profile show blacks on the left and whites on the right. > See https://color.org/specification/ICC.1-2022-05.pdf > > "6.3.4.3 PCS encodings for white and black" Unfortunately, I am unable translate this technical specification into lcms2 code. Could you suggest a function or a chapter in the documentation? I found nothing obviously related, I'm afraid. Grateful, Ralf |
From: <mar...@li...> - 2022-11-27 20:23:02
|
Hello, I was puzzled because I remember I added an algorithm to detect those bad profiles and hot-fix them. Upon reviewing the code, the algorithm was there but it failed on your profile! So, you hit the rare case of gray profile + wrong V4 encoding + apparent black point higher than L* > 50 + inverted curves. All that was confusing the black point compensation part that was supposed to fix the issue. Thank you very much to help in finding a very elusive bug. Now it is fixed by https://github.com/mm2/Little-CMS/commit/caab4c07e60022a0f776b543eaa30785e2b b42ed Best regards Marti Maria The LittleCMS Project https://www.littlecms.com -----Original Message----- From: Ralf Junker <ral...@gm...> Sent: Sunday, November 27, 2022 9:41 AM To: lcm...@li... Subject: Re: [Lcms-user] Unexpected gray to RGB result Thanks for the fast answer! > The embedded profile is wrong. It claims to be V4 and perceptual, but > fails to scale on perceptual black. Here is the C code that generated the profile: int main() { const cmsCIExyY *whitepoint = cmsD50_xyY(); int i; cmsUInt16Number values[256]; cmsToneCurve *tonecurve; cmsHPROFILE profile; for(i = 0; i < 256; i++) { values[i] = (255 - i) * 65535 / 255; } tonecurve = cmsBuildTabulatedToneCurve16 (0, 256, values); profile = cmsCreateGrayProfile(whitepoint, tonecurve); cmsSaveProfileToFile(profile, "gray-inverted.icc"); } The goal is a profile which swaps blacks and whites, dark grays and white grays, to create an inverted, negative grayscale. The profile's purpose is testing image rendering software with color correction using lcms2. I found WhackedRGB.icc for color images, but nothing for grayscale. > Other CMM may choose to reject the profile, lcms uses it, despite it > is wrong. My bad, I take your point. Please note that the profile somehow works with Chromium, Firefox and Gimp which all show whites on the left and blacks on the right of the image. And they all show it identically. Viewers which do not apply the profile show blacks on the left and whites on the right. > See https://color.org/specification/ICC.1-2022-05.pdf > > "6.3.4.3 PCS encodings for white and black" Unfortunately, I am unable translate this technical specification into lcms2 code. Could you suggest a function or a chapter in the documentation? I found nothing obviously related, I'm afraid. Grateful, Ralf _______________________________________________ Lcms-user mailing list Lcm...@li... https://lists.sourceforge.net/lists/listinfo/lcms-user |
From: Ralf J. <ral...@gm...> - 2022-11-29 09:34:31
|
On 27.11.2022 17:44, mar...@li... wrote: > Now it is fixed by > https://github.com/mm2/Little-CMS/commit/caab4c07e60022a0f776b543eaa30785e2bb42ed Thanks for the fix. I confirm it works well. lcms2 now generates visually identically image to Chromium, Firefox, and Gimp. One more question, if I may: You wrote that the fix is in the "algorithm to detect those bad profiles". What corrections would be needed to generate a good profile in the first place? Ralf |
From: <mar...@li...> - 2022-11-29 20:17:14
|
Hi, Thanks for checking. > One more question, if I may: You wrote that the fix is in the "algorithm to detect those bad profiles". What corrections would be needed to generate a good profile in the first place? ICC spec expects a "good" V4 perceptual profile to return "perceptual black" on darkest colorant (gray=0). This is around Lab=(3.14, 0, 0) or XYZ=( 0.3357, 0.3479, 0.2869). You profile was trying to trick the CMM by returning Lab=(100, 0, 0) on the darkest colorant. And made it crazy. Now it detects this and let you to take full control. Regards Marti Maria The LittleCMS Project https://www.littlecms.com -----Original Message----- From: Ralf Junker <ral...@gm...> Sent: Tuesday, November 29, 2022 10:35 AM To: lcm...@li... Subject: Re: [Lcms-user] Unexpected gray to RGB result On 27.11.2022 17:44, mar...@li... wrote: > Now it is fixed by > https://github.com/mm2/Little-CMS/commit/caab4c07e60022a0f776b543eaa30 > 785e2bb42ed Thanks for the fix. I confirm it works well. lcms2 now generates visually identically image to Chromium, Firefox, and Gimp. One more question, if I may: You wrote that the fix is in the "algorithm to detect those bad profiles". What corrections would be needed to generate a good profile in the first place? Ralf _______________________________________________ Lcms-user mailing list Lcm...@li... https://lists.sourceforge.net/lists/listinfo/lcms-user |
From: Ralf J. <ral...@gm...> - 2022-11-30 10:00:14
|
On 29.11.2022 20:00, mar...@li... wrote: > ICC spec expects a "good" V4 perceptual profile to return "perceptual black" > on darkest colorant (gray=0). This is around Lab=(3.14, 0, 0) or XYZ=( > 0.3357, 0.3479, 0.2869). Thanks for explaining! As I am trying to make sense of it, I notice that the XYZ numbers you cited are off by two digits. According to ICC.1:2022, chapter 6.3.4.3, they should be: > XYZ values for the PCS perceptual black point (X = 0,003357, Y = 0,003479, Z = 0,002869) I further noticed that lcms2.h uses slightly different values: // V4 perceptual black #define cmsPERCEPTUAL_BLACK_X 0.00336 #define cmsPERCEPTUAL_BLACK_Y 0.0034731 #define cmsPERCEPTUAL_BLACK_Z 0.00287 https://github.com/mm2/Little-CMS/blob/caab4c07e60022a0f776b543eaa30785e2bb42ed/include/lcms2.h#L280-L283 I also noticed that src/cmscam02.c contains the floating-point literal 3.141592654 three times, all of which could probably be replaced by M_PI for clarity, simplicity and accuracy. Ralf |
From: Robin W. <rob...@ar...> - 2022-11-30 10:52:01
|
On 30/11/2022 10:01, Ralf Junker wrote: > https://github.com/mm2/Little-CMS/blob/caab4c07e60022a0f776b543eaa30785e2bb42ed/include/lcms2.h#L280-L283 > > I also noticed that src/cmscam02.c contains the floating-point literal > 3.141592654 three times, all of which could probably be replaced by M_PI > for clarity, simplicity and accuracy. This would also guard us against the possibility of PI changing in future. Robin |
From: <mar...@li...> - 2022-11-30 19:27:42
|
Hello, >As I am trying to make sense of it, I notice that the XYZ numbers you cited are off by two digits. According to ICC.1:2022, chapter 6.3.4.3, they should be: >> XYZ values for the PCS perceptual black point (X = 0,003357, Y = 0,003479, Z = 0,002869) ICC PCS uses XYZ values divided by 100, so Y in white point is represented by 1.0 instead of 100. Is just a matter of encoding. Regards Marti Maria The LittleCMS Project https://www.littlecms.com -----Original Message----- From: Ralf Junker <ral...@gm...> Sent: Wednesday, November 30, 2022 11:01 AM To: lcm...@li... Subject: Re: [Lcms-user] Unexpected gray to RGB result On 29.11.2022 20:00, mar...@li... wrote: > ICC spec expects a "good" V4 perceptual profile to return "perceptual black" > on darkest colorant (gray=0). This is around Lab=(3.14, 0, 0) or XYZ=( > 0.3357, 0.3479, 0.2869). Thanks for explaining! As I am trying to make sense of it, I notice that the XYZ numbers you cited are off by two digits. According to ICC.1:2022, chapter 6.3.4.3, they should be: > XYZ values for the PCS perceptual black point (X = 0,003357, Y = 0,003479, Z = 0,002869) I further noticed that lcms2.h uses slightly different values: // V4 perceptual black #define cmsPERCEPTUAL_BLACK_X 0.00336 #define cmsPERCEPTUAL_BLACK_Y 0.0034731 #define cmsPERCEPTUAL_BLACK_Z 0.00287 https://github.com/mm2/Little-CMS/blob/caab4c07e60022a0f776b543eaa30785e2bb4 2ed/include/lcms2.h#L280-L283 I also noticed that src/cmscam02.c contains the floating-point literal 3.141592654 three times, all of which could probably be replaced by M_PI for clarity, simplicity and accuracy. Ralf _______________________________________________ Lcms-user mailing list Lcm...@li... https://lists.sourceforge.net/lists/listinfo/lcms-user |