MagickCore  6.9.13-8
Convert, Edit, Or Compose Bitmap Images
colorspace-private.h
1 /*
2  Copyright 1999 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 image colorspace private methods.
17 */
18 #ifndef MAGICKCORE_COLORSPACE_PRIVATE_H
19 #define MAGICKCORE_COLORSPACE_PRIVATE_H
20 
21 #include "magick/image.h"
22 #include "magick/image-private.h"
23 #include "magick/pixel.h"
24 #include "magick/pixel-accessor.h"
25 
26 #if defined(__cplusplus) || defined(c_plusplus)
27 extern "C" {
28 #endif
29 
30 static inline void ConvertCMYKToRGB(MagickPixelPacket *pixel)
31 {
32  pixel->red=(((double) QuantumRange-(QuantumScale*pixel->red*((double)
33  QuantumRange-pixel->index)+pixel->index)));
34  pixel->green=(((double) QuantumRange-(QuantumScale*pixel->green*((double)
35  QuantumRange-pixel->index)+pixel->index)));
36  pixel->blue=(((double) QuantumRange-(QuantumScale*pixel->blue*((double)
37  QuantumRange-pixel->index)+pixel->index)));
38 }
39 
40 static inline void ConvertRGBToCMYK(MagickPixelPacket *pixel)
41 {
42  MagickRealType
43  black,
44  blue,
45  cyan,
46  green,
47  magenta,
48  red,
49  yellow;
50 
51  if (pixel->colorspace != sRGBColorspace)
52  {
53  red=QuantumScale*pixel->red;
54  green=QuantumScale*pixel->green;
55  blue=QuantumScale*pixel->blue;
56  }
57  else
58  {
59  red=QuantumScale*DecodePixelGamma(pixel->red);
60  green=QuantumScale*DecodePixelGamma(pixel->green);
61  blue=QuantumScale*DecodePixelGamma(pixel->blue);
62  }
63  if ((fabs((double) red) < MagickEpsilon) &&
64  (fabs((double) green) < MagickEpsilon) &&
65  (fabs((double) blue) < MagickEpsilon))
66  {
67  pixel->index=(MagickRealType) QuantumRange;
68  return;
69  }
70  cyan=(MagickRealType) (1.0-red);
71  magenta=(MagickRealType) (1.0-green);
72  yellow=(MagickRealType) (1.0-blue);
73  black=cyan;
74  if (magenta < black)
75  black=magenta;
76  if (yellow < black)
77  black=yellow;
78  cyan=(MagickRealType) (PerceptibleReciprocal(1.0-black)*(cyan-black));
79  magenta=(MagickRealType) (PerceptibleReciprocal(1.0-black)*(magenta-black));
80  yellow=(MagickRealType) (PerceptibleReciprocal(1.0-black)*(yellow-black));
81  pixel->colorspace=CMYKColorspace;
82  pixel->red=(double) QuantumRange*cyan;
83  pixel->green=(double) QuantumRange*magenta;
84  pixel->blue=(double) QuantumRange*yellow;
85  pixel->index=(double) QuantumRange*black;
86 }
87 
88 static inline MagickBooleanType IsCMYKColorspace(
89  const ColorspaceType colorspace)
90 {
91  if (colorspace == CMYKColorspace)
92  return(MagickTrue);
93  return(MagickFalse);
94 }
95 
96 static inline MagickBooleanType IsGrayColorspace(
97  const ColorspaceType colorspace)
98 {
99  if ((colorspace == LinearGRAYColorspace) || (colorspace == GRAYColorspace) ||
100  (colorspace == Rec601LumaColorspace) ||
101  (colorspace == Rec709LumaColorspace))
102  return(MagickTrue);
103  return(MagickFalse);
104 }
105 
106 static inline MagickBooleanType IsHueCompatibleColorspace(
107  const ColorspaceType colorspace)
108 {
109  if ((colorspace == HCLColorspace) || (colorspace == HCLpColorspace) ||
110  (colorspace == HSBColorspace) || (colorspace == HSIColorspace) ||
111  (colorspace == HSLColorspace) || (colorspace == HSVColorspace))
112  return(MagickTrue);
113  return(MagickFalse);
114 }
115 
116 static inline MagickBooleanType IsLabCompatibleColorspace(
117  const ColorspaceType colorspace)
118 {
119  if ((colorspace == LabColorspace) || (colorspace == LCHColorspace) ||
120  (colorspace == LCHabColorspace) || (colorspace == LCHuvColorspace))
121  return(MagickTrue);
122  return(MagickFalse);
123 }
124 
125 static inline MagickBooleanType IsRGBColorspace(const ColorspaceType colorspace)
126 {
127  if ((colorspace == RGBColorspace) || (colorspace == scRGBColorspace) ||
128  (colorspace == LinearGRAYColorspace))
129  return(MagickTrue);
130  return(MagickFalse);
131 }
132 
133 static inline MagickBooleanType IssRGBColorspace(
134  const ColorspaceType colorspace)
135 {
136  if ((colorspace == sRGBColorspace) || (colorspace == TransparentColorspace))
137  return(MagickTrue);
138  return(MagickFalse);
139 }
140 
141 static inline MagickBooleanType IssRGBCompatibleColorspace(
142  const ColorspaceType colorspace)
143 {
144  if ((colorspace == sRGBColorspace) || (colorspace == RGBColorspace) ||
145  (colorspace == scRGBColorspace) ||
146  (colorspace == TransparentColorspace) || (colorspace == GRAYColorspace) ||
147  (colorspace == LinearGRAYColorspace))
148  return(MagickTrue);
149  return(MagickFalse);
150 }
151 
152 static inline MagickBooleanType IsYCbCrCompatibleColorspace(
153  const ColorspaceType colorspace)
154 {
155  if ((colorspace == YCbCrColorspace) ||
156  (colorspace == Rec709YCbCrColorspace) ||
157  (colorspace == Rec601YCbCrColorspace))
158  return(MagickTrue);
159  return(MagickFalse);
160 }
161 
162 #if defined(__cplusplus) || defined(c_plusplus)
163 }
164 #endif
165 
166 #endif