MagickCore  7.1.0
colorspace-private.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2021 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 "MagickCore/image.h"
23 #include "MagickCore/pixel.h"
25 
26 #if defined(__cplusplus) || defined(c_plusplus)
27 extern "C" {
28 #endif
29 
30 static inline void ConvertCMYKToRGB(PixelInfo *pixel)
31 {
32  pixel->red=((QuantumRange-(QuantumScale*pixel->red*(QuantumRange-
33  pixel->black)+pixel->black)));
35  pixel->black)+pixel->black)));
37  pixel->black)+pixel->black)));
38 }
39 
40 static inline void ConvertRGBToCMYK(PixelInfo *pixel)
41 {
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  {
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));
82  pixel->red=QuantumRange*cyan;
83  pixel->green=QuantumRange*magenta;
84  pixel->blue=QuantumRange*yellow;
85  pixel->black=QuantumRange*black;
86 }
87 
89  const ColorspaceType colorspace)
90 {
91  if (colorspace == CMYKColorspace)
92  return(MagickTrue);
93  return(MagickFalse);
94 }
95 
97  const ColorspaceType colorspace)
98 {
99  if ((colorspace == LinearGRAYColorspace) || (colorspace == GRAYColorspace))
100  return(MagickTrue);
101  return(MagickFalse);
102 }
103 
104 static inline MagickBooleanType IsGrayImageType(const ImageType type)
105 {
106  if ((type == GrayscaleType) || (type == GrayscaleAlphaType) ||
107  (type == BilevelType))
108  return(MagickTrue);
109  return(MagickFalse);
110 }
111 
113  const ColorspaceType colorspace)
114 {
115  if ((colorspace == HCLColorspace) || (colorspace == HCLpColorspace) ||
116  (colorspace == HSBColorspace) || (colorspace == HSIColorspace) ||
117  (colorspace == HSLColorspace) || (colorspace == HSVColorspace))
118  return(MagickTrue);
119  return(MagickFalse);
120 }
121 
122 static inline MagickBooleanType IsRGBColorspace(const ColorspaceType colorspace)
123 {
124  if ((colorspace == RGBColorspace) || (colorspace == scRGBColorspace) ||
125  (colorspace == LinearGRAYColorspace))
126  return(MagickTrue);
127  return(MagickFalse);
128 }
129 
131  const ColorspaceType colorspace)
132 {
133  if ((colorspace == sRGBColorspace) || (colorspace == TransparentColorspace))
134  return(MagickTrue);
135  return(MagickFalse);
136 }
137 
139  const ColorspaceType colorspace)
140 {
141  if ((colorspace == sRGBColorspace) || (colorspace == RGBColorspace) ||
142  (colorspace == Adobe98Colorspace) || (colorspace == ProPhotoColorspace) ||
143  (colorspace == DisplayP3Colorspace) || (colorspace == scRGBColorspace) ||
144  (colorspace == TransparentColorspace) || (colorspace == GRAYColorspace) ||
145  (colorspace == LinearGRAYColorspace))
146  return(MagickTrue);
147  return(MagickFalse);
148 }
149 
151  const ColorspaceType colorspace)
152 {
153  if ((colorspace == YCbCrColorspace) ||
154  (colorspace == Rec709YCbCrColorspace) ||
155  (colorspace == Rec601YCbCrColorspace))
156  return(MagickTrue);
157  return(MagickFalse);
158 }
159 
160 #if defined(__cplusplus) || defined(c_plusplus)
161 }
162 #endif
163 
164 #endif
MagickDoubleType MagickRealType
Definition: magick-type.h:124
MagickRealType red
Definition: pixel.h:193
static MagickBooleanType IsRGBColorspace(const ColorspaceType colorspace)
static MagickBooleanType IsGrayColorspace(const ColorspaceType colorspace)
#define MagickEpsilon
Definition: magick-type.h:114
static MagickBooleanType IsGrayImageType(const ImageType type)
MagickExport MagickRealType DecodePixelGamma(const MagickRealType pixel)
Definition: pixel.c:319
static MagickBooleanType IsCMYKColorspace(const ColorspaceType colorspace)
static MagickBooleanType IsHueCompatibleColorspace(const ColorspaceType colorspace)
MagickBooleanType
Definition: magick-type.h:165
static double PerceptibleReciprocal(const double x)
static MagickBooleanType IssRGBCompatibleColorspace(const ColorspaceType colorspace)
MagickRealType blue
Definition: pixel.h:193
static MagickBooleanType IssRGBColorspace(const ColorspaceType colorspace)
static void ConvertRGBToCMYK(PixelInfo *pixel)
#define QuantumScale
Definition: magick-type.h:119
MagickRealType black
Definition: pixel.h:193
ColorspaceType
Definition: colorspace.h:25
MagickRealType green
Definition: pixel.h:193
ImageType
Definition: image.h:48
ColorspaceType colorspace
Definition: pixel.h:178
static MagickBooleanType IsYCbCrCompatibleColorspace(const ColorspaceType colorspace)
static void ConvertCMYKToRGB(PixelInfo *pixel)
#define QuantumRange
Definition: magick-type.h:87