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 789695 - CIE: Make RGB to Lab fast paths accurate; add conversion from "RGBA float" to "CIE Lab float"
CIE: Make RGB to Lab fast paths accurate; add conversion from "RGBA float" to...
Status: RESOLVED FIXED
Product: GEGL
Classification: Other
Component: babl
git master
Other All
: Normal normal
: ---
Assigned To: Default Gegl Component Owner
Default Gegl Component Owner
Depends on:
Blocks:
 
 
Reported: 2017-10-31 09:57 UTC by Debarshi Ray
Modified: 2017-11-07 09:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
CIE: Add conversion from "RGBA float" to "CIE Lab float" (2.67 KB, patch)
2017-10-31 10:00 UTC, Debarshi Ray
committed Details | Review
CIE: Use cbrt instead of pow for the reference XYZ to LAB conversion (1.33 KB, patch)
2017-10-31 10:01 UTC, Debarshi Ray
committed Details | Review
CIE: Make the RGB to Lab fast paths as accurate as the reference (3.75 KB, patch)
2017-10-31 10:01 UTC, Debarshi Ray
committed Details | Review
CIE: Make the RGB to Lab fast paths work with non-sRGB primaries (5.44 KB, patch)
2017-10-31 11:21 UTC, Debarshi Ray
committed Details | Review

Description Debarshi Ray 2017-10-31 09:57:53 UTC
The RGB to Lab fast paths in extensions/CIE.c need a BABL_TOLERANCE of 0.000006 on an Intel i7 CPU. Even though the fast paths are pretty naive, they do make a substantial difference in some cases. For example this one:

commit b4535d6efc205c790c8263ba3f9568f9b442027d
Author: Debarshi Ray <debarshir@gnome.org>
Date:   Sat Jan 9 19:41:29 2016 +0100

    CIE: Add conversion from "RGB float" to "CIE Lab float" and vice versa
    
    Conversions from "RGB float" to "CIE Lab float" are 10 times slower
    without this. One use case is passing a "RGB float" buffer to a
    saturation operation that works in the "CIE Lab" colour space.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=760310

This inaccuracy is caused by the fast paths using slightly different matrices than the reference matrices in the Babl space to convert from RGB to XYZ.
Comment 1 Debarshi Ray 2017-10-31 10:00:58 UTC
Created attachment 362608 [details] [review]
CIE: Add conversion from "RGBA float" to "CIE Lab float"
Comment 2 Debarshi Ray 2017-10-31 10:01:24 UTC
Created attachment 362609 [details] [review]
CIE: Use cbrt instead of pow for the reference XYZ to LAB conversion
Comment 3 Debarshi Ray 2017-10-31 10:01:49 UTC
Created attachment 362610 [details] [review]
CIE: Make the RGB to Lab fast paths as accurate as the reference
Comment 4 Øyvind Kolås (pippin) 2017-10-31 10:11:16 UTC
Just for completeness of the bug, as mentioned on IRC - the XYZ <-> RGB conversions should no longer be using constants, but values taken from babl_space, since we now support more than just sRGB primaries.
Comment 5 Debarshi Ray 2017-10-31 11:21:32 UTC
Created attachment 362617 [details] [review]
CIE: Make the RGB to Lab fast paths work with non-sRGB primaries
Comment 6 Øyvind Kolås (pippin) 2017-10-31 12:17:10 UTC
All patches pushed, thanks for clearing out these warnings about missing fast paths =)

commit 72a074df6545fcb35b82ecc2636864afecaa9294
Author: Debarshi Ray <debarshir@gnome.org>
Date:   Tue Oct 31 12:20:45 2017 +0100

    CIE: Make the RGB to Lab fast paths work with non-sRGB primaries
    
    The older constants were tied to sRGB primaries. Using the matrices
    from the Babl space removes this restriction.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=789695

commit e17807f235557d5d7b5d2dff3e4c96a7386d5d36
Author: Debarshi Ray <debarshir@gnome.org>
Date:   Tue Oct 31 09:43:53 2017 +0100

    CIE: Make the RGB to Lab fast paths as accurate as the reference
    
    The matrices used by the fast paths to convert from RGB to XYZ didn't
    exactly match the reference matrices in the Babl space. This caused a
    measurable error in their output.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=789695

commit ab883c55fa74dfaeb27d488f0bd5de53fd1b1afb
Author: Debarshi Ray <debarshir@gnome.org>
Date:   Tue Oct 31 09:36:39 2017 +0100

    CIE: Use cbrt instead of pow for the reference XYZ to LAB conversion
    
    The fast-paths use an inlining-friendly version of cbrt(3). Using
    something similar removes superficial differences between the two
    conversion paths. It's not like the C library's cbrt(3) will perform
    any worse than its own pow(3).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=789695

commit ea00661dd8986b9a1380c9c500122dec8ca5a0db
Author: Debarshi Ray <debarshir@gnome.org>
Date:   Sun Oct 29 13:52:26 2017 +0100

    CIE: Add conversion from "RGBA float" to "CIE Lab float"
    
    Conversions from "RaGaBaA float" to "CIE Lab float", as seen when
    using gegl:shadows-highlights" go via:
      "RaGaBaA float" to "RGBA float"
      "RGBA float"    to "RGB float"
      "RGB float"     to "CIE Lab float"
    
    A direct conversion from "RaGaBaA float" to "CIE Lab float" in simple
    C is hindered by the need to check every pixel's alpha value to avoid
    dividing by zero. The pipeline stalls make it lose out to the look-up
    table and SIMD based conversions to unassociated alpha.
    
    However, we can trivially cut out the second step and still reduce
    some memory traffic.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=789695
Comment 7 Massimo 2017-11-03 10:37:47 UTC
(In reply to Øyvind Kolås (pippin) from comment #6)
> All patches pushed, thanks for clearing out these warnings about missing
> fast paths =)
> 

At least these 2 need the same adjustment 

https://git.gnome.org/browse/babl/tree/extensions/CIE.c#n750

https://git.gnome.org/browse/babl/tree/extensions/CIE.c#n784
Comment 8 Debarshi Ray 2017-11-03 10:51:16 UTC
(In reply to Massimo from comment #7)
> (In reply to Øyvind Kolås (pippin) from comment #6)
> > All patches pushed, thanks for clearing out these warnings about missing
> > fast paths =)
> > 
> 
> At least these 2 need the same adjustment 
> 
> https://git.gnome.org/browse/babl/tree/extensions/CIE.c#n750
> 
> https://git.gnome.org/browse/babl/tree/extensions/CIE.c#n784

Yes, as I mentioned on IRC, I have only looked at the RGB to Lab conversions and not the other way round. I'll do that once I have some tests to see what Lab to RGB fast-paths are missing, etc.. One small step at a time. :P
Comment 9 Debarshi Ray 2017-11-07 09:41:24 UTC
(In reply to Debarshi Ray from comment #8)
> (In reply to Massimo from comment #7)
> > (In reply to Øyvind Kolås (pippin) from comment #6)
> > > All patches pushed, thanks for clearing out these warnings about missing
> > > fast paths =)
> > > 
> > 
> > At least these 2 need the same adjustment 
> > 
> > https://git.gnome.org/browse/babl/tree/extensions/CIE.c#n750
> > 
> > https://git.gnome.org/browse/babl/tree/extensions/CIE.c#n784
> 
> Yes, as I mentioned on IRC, I have only looked at the RGB to Lab conversions
> and not the other way round. I'll do that once I have some tests to see what
> Lab to RGB fast-paths are missing, etc.. One small step at a time. :P

Going to attach some patches against bug 790011