After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 736701 - LCMS2 rounding errors cause problems with certain GIMP blend modes
LCMS2 rounding errors cause problems with certain GIMP blend modes
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: General
git master
Other All
: Normal normal
: 2.10
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2014-09-15 21:54 UTC by Elle Stone
Modified: 2016-09-15 10:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
linear gamma sRGB profile to assign to the gradient before converting to GIMP's sRGB at floating point precision (864 bytes, application/vnd.iccprofile)
2014-09-15 21:54 UTC, Elle Stone
Details

Description Elle Stone 2014-09-15 21:54:29 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.
Comment 1 Elle Stone 2015-02-07 19:40:34 UTC
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.
Comment 2 Michael Natterer 2015-02-07 23:03:41 UTC
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.
Comment 3 Michael Natterer 2016-09-15 10:58:21 UTC
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(-)