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 748187 - Change kappa and epsilon calculations, modify H range code
Change kappa and epsilon calculations, modify H range code
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: 2015-04-20 14:42 UTC by Elle Stone
Modified: 2015-05-21 13:31 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to modify the kappa/epsilon code and add to the H code (1.34 KB, patch)
2015-04-20 14:42 UTC, Elle Stone
none Details | Review
revised patch with hopefully correct H code (1.34 KB, patch)
2015-04-20 15:57 UTC, Elle Stone
none Details | Review
patch without the added H code (15.74 KB, patch)
2015-04-20 17:29 UTC, Elle Stone
none Details | Review
patch without the diagnostic printf statements (1.32 KB, patch)
2015-04-21 17:53 UTC, Elle Stone
none Details | Review

Description Elle Stone 2015-04-20 14:42:09 UTC
Created attachment 302003 [details] [review]
patch to modify the kappa/epsilon code and add to the H code

Thomas Manni's LAB/LCH code uses the equations rather than the simplified calculated values for kappa and epsilon. I misinterpreted Lindbloom to mean use the simplified values rather than the equations, so that's what I put in CIE.c. But upon re-reading Lindbloom, in fact the right thing to do is use the equations. So this patch changes kappa and epsilon to be calculated. See http://brucelindbloom.com/index.html?LContinuity.html

Also Manni's code has two parts for bringing the H value within range, which seems to make sense. So I added the second part to the CIE.c code.

Manni uses #define statements for the calculations for kappa and epsilon. As these calculations are used in two different functions in CIE.c, should they be made into #define statements in CIE.c?
Comment 1 Massimo 2015-04-20 15:27:45 UTC
Comment on attachment 302003 [details] [review]
patch to modify the kappa/epsilon code and add to the H code

   if (*to_H < 0.0)
     *to_H += 360;
 
+  else if (*to_H < 0.0)

At first sight this else if seems useless
Comment 2 Elle Stone 2015-04-20 15:36:57 UTC
FWIW, the Lindbloom page does list both cases:
http://brucelindbloom.com/index.html?Eqn_Lab_to_LCH.html
"If H < 0°, add 360° to it.
If H ≥ 360°, subtract 360° from it."
Comment 3 Massimo 2015-04-20 15:50:08 UTC
(In reply to Elle Stone from comment #2)
> FWIW, the Lindbloom page does list both cases:
> http://brucelindbloom.com/index.html?Eqn_Lab_to_LCH.html
> "If H < 0°, add 360° to it.
> If H ≥ 360°, subtract 360° from it."

well but both if are for the < 0 case and so only
the first is possibly executed
Comment 4 Elle Stone 2015-04-20 15:57:16 UTC
Created attachment 302008 [details] [review]
revised patch with hopefully correct H code

Sorry! I didn't look at the second lines of code closely enough. Try this patch.
Comment 5 Massimo 2015-04-20 16:42:36 UTC
(In reply to Elle Stone from comment #4)
> Created attachment 302008 [details] [review] [review]
> revised patch with hopefully correct H code
> 
> Sorry! I didn't look at the second lines of code closely enough. Try this
> patch.

I thought it was sanitizing a user input, but

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

it is only acting on the return value of atan2 which is
always between -PI and PI so *to_H cannot be greater than 2*PI
(360°) and so that check was probably not there on purpose
Comment 6 Elle Stone 2015-04-20 17:29:33 UTC
Created attachment 302016 [details] [review]
patch without the added H code

Try this patch. The H range-correcting code that was originally in CIE.c really is needed. I removed the new lines as not needed.
Comment 7 Massimo 2015-04-21 17:40:57 UTC
Review of attachment 302016 [details] [review]:

extensions/CIE.c | 258 ++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 159 insertions(+), 99 deletions(-)

that patch seems to do much more than I expected.
Among other things it has diagnostic printf and 
indentation changes that suggest it is not the
patch intended.

Anyway if you think that kappa and epsilon should be
computed as in the comments after their initialization
that's fine for me.
Comment 8 Elle Stone 2015-04-21 17:53:48 UTC
Created attachment 302091 [details] [review]
patch without the diagnostic printf statements

Massimo, sorry, many apologies, I made the commit using the wrong CIE.c file. This one doesn't have the printf statements.
Comment 9 Massimo 2015-05-20 18:34:23 UTC
(In reply to Elle Stone from comment #0)
> 
> Manni uses #define statements for the calculations for kappa and epsilon. As
> these calculations are used in two different functions in CIE.c, should they
> be made into #define statements in CIE.c?

It is a matter of style, they could be made into #define statements
or two static const global variables (foreseeing possible multiple uses
with a common definition and so only one place to correct in case of typos)
but for two uses it is good to keep as they are in your last patch.
Comment 10 Elle Stone 2015-05-21 10:50:48 UTC
This patch fixed the epsilon and kappa code to use the equations, and also resolved the "style" in favor of #define statements: https://bugzilla.gnome.org/show_bug.cgi?id=749628

So this bug report can be closed.
Comment 11 Øyvind Kolås (pippin) 2015-05-21 13:31:59 UTC
commit 3b14d5b08cce705eb84ea788d4259f99eab7602f
Author: Thomas Manni <thomas.manni@free.fr>
Date:   Thu May 21 01:33:54 2015 +0200

    CIE: minor cleanups
    
    Use macros for kappa, epsilon and D50 reference white in all places
    Remove duplicated comments

commit f4cc927054d4e3554734456ebc14b2fdc2c895b6
Author: Thomas Manni <thomas.manni@free.fr>
Date:   Wed May 20 12:12:35 2015 +0200

    CIE: new conversions to/from "CIE Lab alpha float" and "RGBA float"