]> granicus.if.org Git - imagemagick/blob - magick/colorspace-private.h
(no commit message)
[imagemagick] / magick / colorspace-private.h
1 /*
2   Copyright 1999-2010 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 #if defined(__cplusplus) || defined(c_plusplus)
22 extern "C" {
23 #endif
24
25 #include <magick/pixel.h>
26
27 static inline MagickBooleanType IsGrayColorspace(
28   const ColorspaceType colorspace)
29 {
30   if ((colorspace == GRAYColorspace) || (colorspace == Rec601LumaColorspace) || 
31       (colorspace == Rec709LumaColorspace))
32     return(MagickTrue);
33   return(MagickFalse);
34 }
35
36 static inline void ConvertRGBToCMYK(MagickPixelPacket *pixel)
37 {
38   MagickRealType
39     black,
40     cyan,
41     magenta,
42     yellow;
43                                                                                 
44   cyan=(MagickRealType) (QuantumRange-pixel->red);
45   magenta=(MagickRealType) (QuantumRange-pixel->green);
46   yellow=(MagickRealType) (QuantumRange-pixel->blue);
47   black=(MagickRealType) QuantumRange;
48   if (cyan < black)
49     black=cyan;
50   if (magenta < black)
51     black=magenta;
52   if (yellow < black)
53     black=yellow;
54   if (black == QuantumRange)
55     {
56       cyan=0.0;
57       magenta=0.0;
58       yellow=0.0;
59     }
60   else
61     {
62       cyan=(MagickRealType) (QuantumRange*(cyan-black)/
63         (QuantumRange-black));
64       magenta=(MagickRealType) (QuantumRange*(magenta-black)/
65         (QuantumRange-black));
66       yellow=(MagickRealType) (QuantumRange*(yellow-black)/
67         (QuantumRange-black));
68     }
69   pixel->colorspace=CMYKColorspace;
70   pixel->red=cyan;
71   pixel->green=magenta;
72   pixel->blue=yellow;
73   pixel->index=black;
74 }
75
76 #if defined(__cplusplus) || defined(c_plusplus)
77 }
78 #endif
79
80 #endif