2 Copyright 1999-2010 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)
110 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue;
114 static inline Quantum MagickPixelIntensityToQuantum(
115 const MagickPixelPacket *pixel)
117 #if !defined(MAGICKCORE_HDRI_SUPPORT)
118 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue+0.5));
120 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue));
124 static inline MagickRealType MagickPixelLuminance(
125 const MagickPixelPacket *pixel)
130 luminance=0.21267*pixel->red+0.71516*pixel->green+0.07217*pixel->blue;
134 static inline MagickRealType PixelIntensity(const PixelPacket *pixel)
139 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
140 return((MagickRealType) pixel->red);
141 intensity=(MagickRealType) (0.299*pixel->red+0.587*pixel->green+0.114*
146 static inline Quantum PixelIntensityToQuantum(const PixelPacket *pixel)
148 #if !defined(MAGICKCORE_HDRI_SUPPORT)
149 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
151 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue+0.5));
153 if ((fabs(pixel->red-pixel->green) <= MagickEpsilon) &&
154 (fabs(pixel->green-pixel->blue) <= MagickEpsilon))
155 return((Quantum) pixel->red);
156 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue));
160 #if defined(__cplusplus) || defined(c_plusplus)