GNOME Bugzilla – Bug 736701
LCMS2 rounding errors cause problems with certain GIMP blend modes
Last modified: 2016-09-15 10:58:21 UTC
Created attachment 286238 [details] linear gamma sRGB profile to assign to the gradient before converting to GIMP's sRGB at floating point precision LCMS2 produces rounding errors evident at 16-bit and higher integer and floating point precisions. The errors involve converting channel values that are zero or near zero. Details are here: http://sourceforge.net/p/lcms/mailman/message/32834352/ At floating point precision these errors affect certain GIMP blend modes and also any editing operation that involves multiply or divide. The problem is that at floating point precision the rounding errors are randomly slightly positive and slightly negative. To illustrate: 1. At 32-bit floating point precision draw a gradient from red to black, don't use dithering, so the Green and Blue channel values are all zero. 2. Assign a linear gamma sRGB profile or even a V2 sRGB profile from disk. Make a copy of the layer and put the Layer mode to Burn or to Divide. Results are as expected. 3. Now convert to the GIMP built-in sRGB profile. A bunch of negative channel values are produced by the conversion and results of the blend mode are outrageously wrong. One solution might be to clip the results of any ICC profile conversion done at floating point precision, as soon as the profile conversion is done. Or modify all blend modes and editing operations that involve divide or multiply so input channel values are clipped to the range 0.0 to 1.0. Here's are links to two images showing the problem with burn and divide blend modes: http://ninedegreesbelow.com/bug-reports/red-to-black-burn.jpg http://ninedegreesbelow.com/bug-reports/red-to-black-divide.jpg For both examples, the top row is the original gradient, the bottom row shows what the result should look like, and the middle row shows what happens when the image has negative Green and Blue channel values resulting from the ICC profile conversion rounding errors. At 16-bit integer and 32-bit integer precision, there are still rounding errors, but at least the errors are all positive. I attached a linear gamma sRGB profile for testing purposes.
With release of lcms 2.7, above problem has been fixed. Conversions using lcms 2.6 produced spurious wrong and negative channel values, resulting in problems for burn and divide blend mode. Conversions using lcms 2.7 produce correct results. So this bug report can be closed and perhaps >=lcms 2.7 should be made a requirement.
This sounds like a good idea. We will do that once lcms 2.7 is in debian testing (which is our agreed-upon metric for "we can depend on it"). Setting milestone so we don't forget.
Fixed in master. Elle, is there anything else to do in order to use the fixes, such as passing new flags to lcms? If so, please reopen... commit 0ce364ee4dd2200e6607a4575af0cc657600afc9 Author: Michael Natterer <mitch@gimp.org> Date: Thu Sep 15 12:52:20 2016 +0200 configure.ac, app: require liblcms2 >= 2.7 and add an lcms2 runtime version check to app/sanity.c Fixes: Bug 736701 - LCMS2 rounding errors cause problems with certain GIMP blend modes app/Makefile.am | 2 ++ app/sanity.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 2 +- 3 files changed, 56 insertions(+), 1 deletion(-)