]> granicus.if.org Git - imagemagick/blob - MagickCore/colorspace-private.h
Fixed detection of Ghostscript location.
[imagemagick] / MagickCore / colorspace-private.h
1 /*
2   Copyright 1999-2014 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.
6   obtain a copy of the License at
7   
8     http://www.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"
22 #include "MagickCore/image-private.h"
23 #include "MagickCore/pixel.h"
24 #include "MagickCore/pixel-accessor.h"
25
26 #if defined(__cplusplus) || defined(c_plusplus)
27 extern "C" {
28 #endif
29
30 static inline void ConvertRGBToCMYK(PixelInfo *pixel)
31 {
32   MagickRealType
33     black,
34     blue,
35     cyan,
36     green,
37     magenta,
38     red,
39     yellow;
40                                                                                 
41   if (pixel->colorspace != sRGBColorspace)
42     {
43       red=QuantumScale*pixel->red;
44       green=QuantumScale*pixel->green;
45       blue=QuantumScale*pixel->blue;
46     }
47   else
48     {
49       red=DecodePixelGamma(pixel->red);
50       green=DecodePixelGamma(pixel->green);
51       blue=DecodePixelGamma(pixel->blue);
52     }
53   if ((fabs(red) < MagickEpsilon) && (fabs(green) < MagickEpsilon) &&
54       (fabs(blue) < MagickEpsilon))
55     {
56       pixel->black=(MagickRealType) QuantumRange;
57       return;
58     }
59   cyan=(MagickRealType) (1.0-red);
60   magenta=(MagickRealType) (1.0-green);
61   yellow=(MagickRealType) (1.0-blue);
62   black=cyan;
63   if (magenta < black)
64     black=magenta;
65   if (yellow < black)
66     black=yellow;
67   cyan=(MagickRealType) ((cyan-black)/(1.0-black));
68   magenta=(MagickRealType) ((magenta-black)/(1.0-black));
69   yellow=(MagickRealType) ((yellow-black)/(1.0-black));
70   pixel->colorspace=CMYKColorspace;
71   pixel->red=QuantumRange*cyan;
72   pixel->green=QuantumRange*magenta;
73   pixel->blue=QuantumRange*yellow;
74   pixel->black=QuantumRange*black;
75 }
76
77 static inline MagickBooleanType IsCMYKColorspace(
78   const ColorspaceType colorspace)
79 {
80   if (colorspace == CMYKColorspace)
81     return(MagickTrue);
82   return(MagickFalse);
83 }
84
85 static inline MagickBooleanType IsGrayColorspace(
86   const ColorspaceType colorspace)
87 {
88   if (colorspace == GRAYColorspace)
89     return(MagickTrue);
90   return(MagickFalse);
91 }
92
93 static inline MagickBooleanType IsRGBColorspace(const ColorspaceType colorspace)
94 {
95   if ((colorspace == RGBColorspace) || (colorspace == scRGBColorspace))
96     return(MagickTrue);
97   return(MagickFalse);
98 }
99
100 static inline MagickBooleanType IssRGBColorspace(
101   const ColorspaceType colorspace)
102 {
103   if ((colorspace == sRGBColorspace) || (colorspace == TransparentColorspace))
104     return(MagickTrue);
105   return(MagickFalse);
106 }
107
108 static inline MagickBooleanType IssRGBCompatibleColorspace(
109   const ColorspaceType colorspace)
110 {
111   if ((colorspace == sRGBColorspace) || (colorspace == RGBColorspace) ||
112       (colorspace == scRGBColorspace) || 
113       (IsGrayColorspace(colorspace) != MagickFalse))
114     return(MagickTrue);
115   return(MagickFalse);
116 }
117
118 #if defined(__cplusplus) || defined(c_plusplus)
119 }
120 #endif
121
122 #endif