]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/gem-private.h
https://github.com/ImageMagick/ImageMagick/issues/539
[imagemagick] / MagickCore / gem-private.h
index d6ad13d71d8fa348233718f333b4472e05a2c379..9010ee6f22f14b3dd945184befea6fcb64867d44 100644 (file)
@@ -1,11 +1,11 @@
 /*
-  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization
+  Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization
   dedicated to making software imaging solutions freely available.
   
   You may not use this file except in compliance with the License.
   obtain a copy of the License at
   
-    http://www.imagemagick.org/script/license.php
+    https://www.imagemagick.org/script/license.php
   
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
 
   MagickCore private graphic gems methods.
 */
-#ifndef _MAGICKCORE_GEM_PRIVATE_H
-#define _MAGICKCORE_GEM_PRIVATE_H
+#ifndef MAGICKCORE_GEM_PRIVATE_H
+#define MAGICKCORE_GEM_PRIVATE_H
+
+#include "MagickCore/pixel-accessor.h"
 
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {
 #endif
 
-#include "MagickCore/pixel-private.h"
-
 #define D65X  0.950456
 #define D65Y  1.0
 #define D65Z  1.088754
@@ -84,9 +84,9 @@ static inline void ConvertLabToXYZ(const double L,const double a,const double b,
   assert(X != (double *) NULL);
   assert(Y != (double *) NULL);
   assert(Z != (double *) NULL);
-  y=(100.0*L+16.0)/116.0;
-  x=y+255.0*(a-0.5)/500.0;
-  z=y-255.0*(b-0.5)/200.0;
+  y=(L+16.0)/116.0;
+  x=y+a/500.0;
+  z=y-b/200.0;
   if ((x*x*x) > CIEEpsilon)
     x=(x*x*x);
   else
@@ -94,7 +94,7 @@ static inline void ConvertLabToXYZ(const double L,const double a,const double b,
   if ((y*y*y) > CIEEpsilon)
     y=(y*y*y);
   else
-    y=(100.0*L)/CIEK;
+    y=L/CIEK;
   if ((z*z*z) > CIEEpsilon)
     z=(z*z*z);
   else
@@ -110,16 +110,15 @@ static inline void ConvertLuvToXYZ(const double L,const double u,const double v,
   assert(X != (double *) NULL);
   assert(Y != (double *) NULL);
   assert(Z != (double *) NULL);
-  if ((100.0*L) > (CIEK*CIEEpsilon))
-    *Y=(double) pow(((100.0*L)+16.0)/116.0,3.0);
+  if (L > (CIEK*CIEEpsilon))
+    *Y=(double) pow((L+16.0)/116.0,3.0);
   else
-    *Y=(100.0*L)/CIEK;
-  *X=((*Y*((39.0*(100.0*L)/((262.0*v-140.0)+13.0*(100.0*L)*(9.0*D65Y/
-    (D65X+15.0*D65Y+3.0*D65Z))))-5.0))+5.0*(*Y))/((((52.0f*(100.0*L)/
-    ((354.0*u-134.0)+13.0*(100.0*L)*(4.0*D65X/(D65X+15.0*D65Y+3.0*
-    D65Z))))-1.0)/3.0)-(-1.0/3.0));
-  *Z=(*X*(((52.0f*(100.0*L)/((354.0*u-134.0)+13.0*(100.0*L)*(4.0*D65X/
-    (D65X+15.0*D65Y+3.0*D65Z))))-1.0)/3.0))-5.0*(*Y);
+    *Y=L/CIEK;
+  *X=((*Y*((39.0*L/(v+13.0*L*(9.0*D65Y/(D65X+15.0*D65Y+3.0*D65Z))))-5.0))+
+    5.0*(*Y))/((((52.0*L/(u+13.0*L*(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z))))-1.0)/
+    3.0)-(-1.0/3.0));
+  *Z=(*X*(((52.0*L/(u+13.0*L*(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z))))-1.0)/3.0))-
+    5.0*(*Y);
 }
 
 static inline void ConvertRGBToXYZ(const double red,const double green,
@@ -136,12 +135,12 @@ static inline void ConvertRGBToXYZ(const double red,const double green,
   assert(X != (double *) NULL);
   assert(Y != (double *) NULL);
   assert(Z != (double *) NULL);
-  r=QuantumScale*red;
-  g=QuantumScale*green;
-  b=QuantumScale*blue;
-  *X=0.41239558896741421610*r+0.35758343076371481710*g+0.18049264738170157350*b;
-  *Y=0.21258623078559555160*r+0.71517030370341084990*g+0.07220049864333622685*b;
-  *Z=0.01929721549174694484*r+0.11918386458084853180*g+0.95049712513157976600*b;
+  r=QuantumScale*DecodePixelGamma(red);
+  g=QuantumScale*DecodePixelGamma(green);
+  b=QuantumScale*DecodePixelGamma(blue);
+  *X=0.4124564*r+0.3575761*g+0.1804375*b;
+  *Y=0.2126729*r+0.7151522*g+0.0721750*b;
+  *Z=0.0193339*r+0.1191920*g+0.9503041*b;
 }
 
 static inline void ConvertXYZToLab(const double X,const double Y,const double Z,
@@ -151,6 +150,7 @@ static inline void ConvertXYZToLab(const double X,const double Y,const double Z,
     x,
     y,
     z;
+
   assert(L != (double *) NULL);
   assert(a != (double *) NULL);
   assert(b != (double *) NULL);
@@ -192,7 +192,7 @@ static inline void ConvertXYZToLuv(const double X,const double Y,const double Z,
   *v=(*v+140.0)/262.0;
 }
 
-static inline void ConvertXYZToRGB(const double x,const double y,const double z,
+static inline void ConvertXYZToRGB(const double X,const double Y,const double Z,
   double *red,double *green,double *blue)
 {
   double
@@ -200,21 +200,17 @@ static inline void ConvertXYZToRGB(const double x,const double y,const double z,
     g,
     r;
 
-  /*
-    Convert XYZ to RGB colorspace.
-  */
   assert(red != (double *) NULL);
   assert(green != (double *) NULL);
   assert(blue != (double *) NULL);
-  r=3.2406*x-1.5372*y-0.4986*z;
-  g=(-0.9689*x+1.8758*y+0.0415*z);
-  b=0.0557*x-0.2040*y+1.0570*z;
-  *red=QuantumRange*r;
-  *green=QuantumRange*g;
-  *blue=QuantumRange*b;
+  r=3.2404542*X-1.5371385*Y-0.4985314*Z;
+  g=(-0.9692660)*X+1.8760108*Y+0.0415560*Z;
+  b=0.0556434*X-0.2040259*Y+1.0572252*Z;
+  *red=EncodePixelGamma(QuantumRange*r);
+  *green=EncodePixelGamma(QuantumRange*g);
+  *blue=EncodePixelGamma(QuantumRange*b);
 }
 
-
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif