2 Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
5 You may not use this file except in compliance with the License.
6 obtain a copy of the License at
8 http://www.imagemagick.org/script/license.php
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.
16 MagickCore image color methods.
18 #ifndef _MAGICKCORE_COLOR_PRIVATE_H
19 #define _MAGICKCORE_COLOR_PRIVATE_H
21 #if defined(__cplusplus) || defined(c_plusplus)
25 #include <magick/image.h>
26 #include <magick/color.h>
27 #include <magick/exception-private.h>
29 static inline MagickBooleanType IsColorEqual(const PixelPacket *p,
32 if ((p->red == q->red) && (p->green == q->green) && (p->blue == q->blue))
37 static inline MagickBooleanType IsGray(const PixelPacket *pixel)
39 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
44 static inline MagickBooleanType IsMagickColorEqual(const MagickPixelPacket *p,
45 const MagickPixelPacket *q)
47 #if !defined(MAGICKCORE_HDRI_SUPPORT)
48 if ((p->matte != MagickFalse) && (q->matte == MagickFalse) &&
49 (p->opacity != OpaqueOpacity))
51 if ((q->matte != MagickFalse) && (p->matte == MagickFalse) &&
52 (q->opacity != OpaqueOpacity))
54 if ((p->matte != MagickFalse) && (q->matte != MagickFalse))
56 if (p->opacity != q->opacity)
58 if (p->opacity == TransparentOpacity)
63 if (p->green != q->green)
65 if (p->blue != q->blue)
67 if ((p->colorspace == CMYKColorspace) && (p->index != q->index))
70 if ((p->matte != MagickFalse) && (q->matte == MagickFalse) &&
71 (fabs(p->opacity-OpaqueOpacity) > 0.5))
73 if ((q->matte != MagickFalse) && (p->matte == MagickFalse) &&
74 (fabs(q->opacity-OpaqueOpacity)) > 0.5)
76 if ((p->matte != MagickFalse) && (q->matte != MagickFalse))
78 if (fabs(p->opacity-q->opacity) > 0.5)
80 if (fabs(p->opacity-TransparentOpacity) <= 0.5)
83 if (fabs(p->red-q->red) > 0.5)
85 if (fabs(p->green-q->green) > 0.5)
87 if (fabs(p->blue-q->blue) > 0.5)
89 if ((p->colorspace == CMYKColorspace) && (fabs(p->index-q->index) > 0.5))
95 static inline MagickBooleanType IsMagickGray(const MagickPixelPacket *pixel)
97 if (pixel->colorspace != RGBColorspace)
99 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
104 static inline MagickRealType MagickPixelIntensity(
105 const MagickPixelPacket *pixel)
107 return((MagickRealType) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue));
110 static inline Quantum MagickPixelIntensityToQuantum(
111 const MagickPixelPacket *pixel)
113 #if !defined(MAGICKCORE_HDRI_SUPPORT)
114 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue+0.5));
116 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue));
120 static inline MagickRealType MagickPixelLuminance(
121 const MagickPixelPacket *pixel)
126 luminance=0.21267*pixel->red+0.71516*pixel->green+0.07217*pixel->blue;
130 static inline MagickRealType PixelIntensity(const PixelPacket *pixel)
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*
142 static inline Quantum PixelIntensityToQuantum(const PixelPacket *pixel)
144 #if !defined(MAGICKCORE_HDRI_SUPPORT)
145 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
147 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue+0.5));
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));
156 #if defined(__cplusplus) || defined(c_plusplus)