MagickCore  7.0.10
gem-private.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2020 ImageMagick Studio LLC, a non-profit organization
3  dedicated to making software imaging solutions freely available.
4 
5  You may not use this file except in compliance with the License. You may
6  obtain a copy of the License at
7 
8  https://imagemagick.org/script/license.php
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  MagickCore private graphic gems methods.
17 */
18 #ifndef MAGICKCORE_GEM_PRIVATE_H
19 #define MAGICKCORE_GEM_PRIVATE_H
20 
23 
24 #if defined(__cplusplus) || defined(c_plusplus)
25 extern "C" {
26 #endif
27 
28 #define D65X 0.950456
29 #define D65Y 1.0
30 #define D65Z 1.088754
31 #define CIEEpsilon (216.0/24389.0)
32 #define CIEK (24389.0/27.0)
33 
34 extern MagickPrivate double
36  const double);
37 
38 extern MagickPrivate size_t
39  GetOptimalKernelWidth(const double,const double),
40  GetOptimalKernelWidth1D(const double,const double),
41  GetOptimalKernelWidth2D(const double,const double);
42 
43 extern MagickPrivate void
44  ConvertHCLToRGB(const double,const double,const double,double *,double *,
45  double *),
46  ConvertHCLpToRGB(const double,const double,const double,double *,double *,
47  double *),
48  ConvertHSBToRGB(const double,const double,const double,double *,double *,
49  double *),
50  ConvertHSIToRGB(const double,const double,const double,double *,double *,
51  double *),
52  ConvertHSVToRGB(const double,const double,const double,double *,double *,
53  double *),
54  ConvertHWBToRGB(const double,const double,const double,double *,double *,
55  double *),
56  ConvertLCHabToRGB(const double,const double,const double,double *,double *,
57  double *),
58  ConvertLCHuvToRGB(const double,const double,const double,double *,double *,
59  double *),
60  ConvertRGBToHCL(const double,const double,const double,double *,double *,
61  double *),
62  ConvertRGBToHCLp(const double,const double,const double,double *,double *,
63  double *),
64  ConvertRGBToHSB(const double,const double,const double,double *,double *,
65  double *),
66  ConvertRGBToHSI(const double,const double,const double,double *,double *,
67  double *),
68  ConvertRGBToHSV(const double,const double,const double,double *,double *,
69  double *),
70  ConvertRGBToHWB(const double,const double,const double,double *,double *,
71  double *),
72  ConvertRGBToLab(const double,const double,const double,double *,double *,
73  double *),
74  ConvertRGBToLCHab(const double,const double,const double,double *,double *,
75  double *),
76  ConvertRGBToLCHuv(const double,const double,const double,double *,double *,
77  double *);
78 
79 static inline void ConvertLabToXYZ(const double L,const double a,const double b,
80  double *X,double *Y,double *Z)
81 {
82  double
83  x,
84  y,
85  z;
86 
87  assert(X != (double *) NULL);
88  assert(Y != (double *) NULL);
89  assert(Z != (double *) NULL);
90  y=(L+16.0)/116.0;
91  x=y+a/500.0;
92  z=y-b/200.0;
93  if ((x*x*x) > CIEEpsilon)
94  x=(x*x*x);
95  else
96  x=(116.0*x-16.0)/CIEK;
97  if ((y*y*y) > CIEEpsilon)
98  y=(y*y*y);
99  else
100  y=L/CIEK;
101  if ((z*z*z) > CIEEpsilon)
102  z=(z*z*z);
103  else
104  z=(116.0*z-16.0)/CIEK;
105  *X=D65X*x;
106  *Y=D65Y*y;
107  *Z=D65Z*z;
108 }
109 
110 static inline void ConvertLuvToXYZ(const double L,const double u,const double v,
111  double *X,double *Y,double *Z)
112 {
113  double
114  gamma;
115 
116  assert(X != (double *) NULL);
117  assert(Y != (double *) NULL);
118  assert(Z != (double *) NULL);
119  if (L > (CIEK*CIEEpsilon))
120  *Y=(double) pow((L+16.0)/116.0,3.0);
121  else
122  *Y=L/CIEK;
123  gamma=PerceptibleReciprocal((((52.0*L/(u+13.0*L*(4.0*D65X/(D65X+15.0*D65Y+
124  3.0*D65Z))))-1.0)/3.0)-(-1.0/3.0));
125  *X=gamma*((*Y*((39.0*L/(v+13.0*L*(9.0*D65Y/(D65X+15.0*D65Y+3.0*D65Z))))-5.0))+
126  5.0*(*Y));
127  *Z=(*X*(((52.0*L/(u+13.0*L*(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z))))-1.0)/3.0))-
128  5.0*(*Y);
129 }
130 
131 static inline void ConvertRGBToXYZ(const double red,const double green,
132  const double blue,double *X,double *Y,double *Z)
133 {
134  double
135  b,
136  g,
137  r;
138 
139  /*
140  Convert RGB to XYZ colorspace.
141  */
142  assert(X != (double *) NULL);
143  assert(Y != (double *) NULL);
144  assert(Z != (double *) NULL);
148  *X=0.4124564*r+0.3575761*g+0.1804375*b;
149  *Y=0.2126729*r+0.7151522*g+0.0721750*b;
150  *Z=0.0193339*r+0.1191920*g+0.9503041*b;
151 }
152 
153 static inline void ConvertXYZToLab(const double X,const double Y,const double Z,
154  double *L,double *a,double *b)
155 {
156  double
157  x,
158  y,
159  z;
160 
161  assert(L != (double *) NULL);
162  assert(a != (double *) NULL);
163  assert(b != (double *) NULL);
164  if ((X/D65X) > CIEEpsilon)
165  x=pow(X/D65X,1.0/3.0);
166  else
167  x=(CIEK*X/D65X+16.0)/116.0;
168  if ((Y/D65Y) > CIEEpsilon)
169  y=pow(Y/D65Y,1.0/3.0);
170  else
171  y=(CIEK*Y/D65Y+16.0)/116.0;
172  if ((Z/D65Z) > CIEEpsilon)
173  z=pow(Z/D65Z,1.0/3.0);
174  else
175  z=(CIEK*Z/D65Z+16.0)/116.0;
176  *L=((116.0*y)-16.0)/100.0;
177  *a=(500.0*(x-y))/255.0+0.5;
178  *b=(200.0*(y-z))/255.0+0.5;
179 }
180 
181 static inline void ConvertXYZToLuv(const double X,const double Y,const double Z,
182  double *L,double *u,double *v)
183 {
184  double
185  alpha;
186 
187  assert(L != (double *) NULL);
188  assert(u != (double *) NULL);
189  assert(v != (double *) NULL);
190  if ((Y/D65Y) > CIEEpsilon)
191  *L=(double) (116.0*pow(Y/D65Y,1.0/3.0)-16.0);
192  else
193  *L=CIEK*(Y/D65Y);
194  alpha=PerceptibleReciprocal(X+15.0*Y+3.0*Z);
195  *u=13.0*(*L)*((4.0*alpha*X)-(4.0*D65X/(D65X+15.0*D65Y+3.0*D65Z)));
196  *v=13.0*(*L)*((9.0*alpha*Y)-(9.0*D65Y/(D65X+15.0*D65Y+3.0*D65Z)));
197  *L/=100.0;
198  *u=(*u+134.0)/354.0;
199  *v=(*v+140.0)/262.0;
200 }
201 
202 static inline void ConvertXYZToRGB(const double X,const double Y,const double Z,
203  double *red,double *green,double *blue)
204 {
205  double
206  b,
207  g,
208  r;
209 
210  assert(red != (double *) NULL);
211  assert(green != (double *) NULL);
212  assert(blue != (double *) NULL);
213  r=3.2404542*X-1.5371385*Y-0.4985314*Z;
214  g=(-0.9692660)*X+1.8760108*Y+0.0415560*Z;
215  b=0.0556434*X-0.2040259*Y+1.0572252*Z;
217  *green=EncodePixelGamma(QuantumRange*g);
219 }
220 
221 #if defined(__cplusplus) || defined(c_plusplus)
222 }
223 #endif
224 
225 #endif
MagickExport MagickRealType EncodePixelGamma(const MagickRealType pixel)
Definition: pixel.c:446
#define D65X
Definition: gem-private.h:28
MagickPrivate void ConvertLCHabToRGB(const double, const double, const double, double *, double *, double *)
MagickPrivate void ConvertHSIToRGB(const double, const double, const double, double *, double *, double *)
#define CIEK
Definition: gem-private.h:32
#define CIEEpsilon
Definition: gem-private.h:31
MagickPrivate double GenerateDifferentialNoise(RandomInfo *, const Quantum, const NoiseType, const double)
Definition: gem.c:1494
#define D65Z
Definition: gem-private.h:30
MagickPrivate size_t GetOptimalKernelWidth1D(const double, const double)
NoiseType
#define D65Y
Definition: gem-private.h:29
MagickPrivate void ConvertRGBToHSB(const double, const double, const double, double *, double *, double *)
MagickExport MagickRealType DecodePixelGamma(const MagickRealType pixel)
Definition: pixel.c:319
static double PerceptibleReciprocal(const double x)
MagickPrivate size_t GetOptimalKernelWidth2D(const double, const double)
Definition: gem.c:1674
MagickPrivate void ConvertLCHuvToRGB(const double, const double, const double, double *, double *, double *)
static void ConvertLuvToXYZ(const double L, const double u, const double v, double *X, double *Y, double *Z)
Definition: gem-private.h:110
MagickPrivate void ConvertRGBToHSV(const double, const double, const double, double *, double *, double *)
static void ConvertXYZToLuv(const double X, const double Y, const double Z, double *L, double *u, double *v)
Definition: gem-private.h:181
MagickPrivate void ConvertRGBToHSI(const double, const double, const double, double *, double *, double *)
#define QuantumScale
Definition: magick-type.h:119
MagickPrivate void ConvertHWBToRGB(const double, const double, const double, double *, double *, double *)
static void ConvertXYZToLab(const double X, const double Y, const double Z, double *L, double *a, double *b)
Definition: gem-private.h:153
static void ConvertRGBToXYZ(const double red, const double green, const double blue, double *X, double *Y, double *Z)
Definition: gem-private.h:131
unsigned short Quantum
Definition: magick-type.h:86
MagickPrivate void ConvertRGBToLab(const double, const double, const double, double *, double *, double *)
MagickPrivate void ConvertHSVToRGB(const double, const double, const double, double *, double *, double *)
static void ConvertLabToXYZ(const double L, const double a, const double b, double *X, double *Y, double *Z)
Definition: gem-private.h:79
MagickPrivate size_t GetOptimalKernelWidth(const double, const double)
MagickPrivate void ConvertHCLToRGB(const double, const double, const double, double *, double *, double *)
MagickPrivate void ConvertRGBToHWB(const double, const double, const double, double *, double *, double *)
MagickPrivate void ConvertHCLpToRGB(const double, const double, const double, double *, double *, double *)
static void ConvertXYZToRGB(const double X, const double Y, const double Z, double *red, double *green, double *blue)
Definition: gem-private.h:202
MagickPrivate void ConvertRGBToLCHab(const double, const double, const double, double *, double *, double *)
#define MagickPrivate
MagickPrivate void ConvertHSBToRGB(const double, const double, const double, double *, double *, double *)
MagickPrivate void ConvertRGBToHCL(const double, const double, const double, double *, double *, double *)
MagickPrivate void ConvertRGBToLCHuv(const double, const double, const double, double *, double *, double *)
Definition: gem.c:1414
#define QuantumRange
Definition: magick-type.h:87
MagickPrivate void ConvertRGBToHCLp(const double, const double, const double, double *, double *, double *)