]> granicus.if.org Git - imagemagick/blob - magick/color-private.h
Minor
[imagemagick] / magick / color-private.h
1 /*
2   Copyright 1999-2011 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 color methods.
17 */
18 #ifndef _MAGICKCORE_COLOR_PRIVATE_H
19 #define _MAGICKCORE_COLOR_PRIVATE_H
20
21 #if defined(__cplusplus) || defined(c_plusplus)
22 extern "C" {
23 #endif
24
25 #include <magick/image.h>
26 #include <magick/color.h>
27 #include <magick/exception-private.h>
28
29 static inline MagickBooleanType IsColorEqual(const PixelPacket *p,
30   const PixelPacket *q)
31 {
32   if ((p->red == q->red) && (p->green == q->green) && (p->blue == q->blue))
33     return(MagickTrue);
34   return(MagickFalse);
35 }
36
37 static inline MagickBooleanType IsGray(const PixelPacket *pixel)
38 {
39   if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
40     return(MagickTrue);
41   return(MagickFalse);
42 }
43
44 static inline MagickBooleanType IsMagickColorEqual(const MagickPixelPacket *p,
45   const MagickPixelPacket *q)
46 {
47 #if !defined(MAGICKCORE_HDRI_SUPPORT)
48   if ((p->matte != MagickFalse) && (q->matte == MagickFalse) &&
49       (p->opacity != OpaqueOpacity))
50     return(MagickFalse);
51   if ((q->matte != MagickFalse) && (p->matte == MagickFalse) &&
52       (q->opacity != OpaqueOpacity))
53     return(MagickFalse);
54   if ((p->matte != MagickFalse) && (q->matte != MagickFalse))
55     {
56       if (p->opacity != q->opacity)
57         return(MagickFalse);
58       if (p->opacity == TransparentOpacity)
59         return(MagickTrue);
60     }
61   if (p->red != q->red)
62     return(MagickFalse);
63   if (p->green != q->green)
64     return(MagickFalse);
65   if (p->blue != q->blue)
66     return(MagickFalse);
67   if ((p->colorspace == CMYKColorspace) && (p->index != q->index))
68     return(MagickFalse);
69 #else
70   if ((p->matte != MagickFalse) && (q->matte == MagickFalse) &&
71       (fabs(p->opacity-OpaqueOpacity) > 0.5))
72     return(MagickFalse);
73   if ((q->matte != MagickFalse) && (p->matte == MagickFalse) &&
74       (fabs(q->opacity-OpaqueOpacity)) > 0.5)
75     return(MagickFalse);
76   if ((p->matte != MagickFalse) && (q->matte != MagickFalse))
77     {
78       if (fabs(p->opacity-q->opacity) > 0.5)
79         return(MagickFalse);
80       if (fabs(p->opacity-TransparentOpacity) <= 0.5)
81         return(MagickTrue);
82     }
83   if (fabs(p->red-q->red) > 0.5)
84     return(MagickFalse);
85   if (fabs(p->green-q->green) > 0.5)
86     return(MagickFalse);
87   if (fabs(p->blue-q->blue) > 0.5)
88     return(MagickFalse);
89   if ((p->colorspace == CMYKColorspace) && (fabs(p->index-q->index) > 0.5))
90     return(MagickFalse);
91 #endif
92   return(MagickTrue);
93 }
94
95 static inline MagickBooleanType IsMagickGray(const MagickPixelPacket *pixel)
96 {
97   if (pixel->colorspace != RGBColorspace)
98     return(MagickFalse);
99   if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
100     return(MagickTrue);
101   return(MagickFalse);
102 }
103
104 static inline MagickRealType MagickPixelIntensity(
105   const MagickPixelPacket *pixel)
106 {
107   return(0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue);
108 }
109
110 static inline Quantum MagickPixelIntensityToQuantum(
111   const MagickPixelPacket *pixel)
112 {
113 #if !defined(MAGICKCORE_HDRI_SUPPORT)
114   return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue+0.5));
115 #else
116   return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue));
117 #endif
118 }
119
120 static inline MagickRealType MagickPixelLuminance(
121   const MagickPixelPacket *pixel)
122 {
123   MagickRealType
124     luminance;
125
126   luminance=0.21267*pixel->red+0.71516*pixel->green+0.07217*pixel->blue;
127   return(luminance);
128 }
129
130 static inline MagickRealType PixelIntensity(const PixelPacket *pixel)
131 {
132   MagickRealType
133     intensity;
134
135   if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
136     return((MagickRealType) pixel->red);
137   intensity=(MagickRealType) (0.299*pixel->red+0.587*pixel->green+0.114*
138     pixel->blue);
139   return(intensity);
140 }
141
142 static inline Quantum PixelIntensityToQuantum(const PixelPacket *pixel)
143 {
144 #if !defined(MAGICKCORE_HDRI_SUPPORT)
145   if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
146     return(pixel->red);
147   return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue+0.5));
148 #else
149   if ((fabs(pixel->red-pixel->green) <= MagickEpsilon) &&
150       (fabs(pixel->green-pixel->blue) <= MagickEpsilon))
151     return((Quantum) pixel->red);
152   return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue));
153 #endif
154 }
155
156 #if defined(__cplusplus) || defined(c_plusplus)
157 }
158 #endif
159
160 #endif