2 Copyright 1999-2009 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 IndexPacket ConstrainColormapIndex(Image *image,
38 const unsigned long index)
40 if (index < image->colors)
41 return((IndexPacket) index);
42 (void) ThrowMagickException(&image->exception,GetMagickModule(),
43 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
44 return((IndexPacket) 0);
47 static inline MagickBooleanType IsGray(const PixelPacket *pixel)
49 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
54 static inline MagickBooleanType IsMagickColorEqual(const MagickPixelPacket *p,
55 const MagickPixelPacket *q)
57 if ((p->matte != MagickFalse) && (q->matte == MagickFalse) &&
58 (p->opacity != OpaqueOpacity))
60 if ((q->matte != MagickFalse) && (p->matte == MagickFalse) &&
61 (q->opacity != OpaqueOpacity))
63 if ((p->matte != MagickFalse) && (q->matte != MagickFalse))
65 if (p->opacity != q->opacity)
67 if (p->opacity == TransparentOpacity)
72 if (p->green != q->green)
74 if (p->blue != q->blue)
76 if ((p->colorspace == CMYKColorspace) && (p->index != q->index))
81 static inline MagickBooleanType IsMagickGray(const MagickPixelPacket *pixel)
83 if (pixel->colorspace != RGBColorspace)
85 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
90 static inline MagickRealType MagickPixelIntensity(
91 const MagickPixelPacket *pixel)
96 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue;
100 static inline Quantum MagickPixelIntensityToQuantum(
101 const MagickPixelPacket *pixel)
103 #if !defined(MAGICKCORE_HDRI_SUPPORT)
104 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue+0.5));
106 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue));
110 static inline MagickRealType MagickPixelLuminance(
111 const MagickPixelPacket *pixel)
116 luminance=0.21267*pixel->red+0.71516*pixel->green+0.07217*pixel->blue;
120 static inline MagickRealType PixelIntensity(const PixelPacket *pixel)
125 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
126 return((MagickRealType) pixel->red);
127 intensity=(MagickRealType) (0.299*pixel->red+0.587*pixel->green+0.114*
132 static inline Quantum PixelIntensityToQuantum(const PixelPacket *pixel)
134 #if !defined(MAGICKCORE_HDRI_SUPPORT)
135 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
137 #if (MAGICKCORE_QUANTUM_DEPTH <= 16)
138 return((Quantum) ((306U*(unsigned int) pixel->red+
139 601U*(unsigned int) pixel->green+117U*(unsigned int) pixel->blue) >> 10U));
141 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue+0.5));
144 if ((fabs(pixel->red-pixel->green) <= MagickEpsilon) &&
145 (fabs(pixel->green-pixel->blue) <= MagickEpsilon))
146 return((Quantum) pixel->red);
147 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue));
151 #if defined(__cplusplus) || defined(c_plusplus)