]> granicus.if.org Git - imagemagick/blob - magick/pixel-private.h
(no commit message)
[imagemagick] / magick / pixel-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 pixel private methods.
17 */
18 #ifndef _MAGICKCORE_PIXEL_PRIVATE_H
19 #define _MAGICKCORE_PIXEL_PRIVATE_H
20
21 #if defined(__cplusplus) || defined(c_plusplus)
22 extern "C" {
23 #endif
24
25 #include <magick/exception-private.h>
26 #include <magick/image.h>
27 #include <magick/color.h>
28 #include <magick/image-private.h>
29 #include <magick/quantum-private.h>
30
31 static inline MagickPixelPacket *CloneMagickPixelPacket(
32   const MagickPixelPacket *pixel)
33 {
34   MagickPixelPacket
35     *clone_pixel;
36
37   clone_pixel=(MagickPixelPacket *) AcquireAlignedMemory(1,
38     sizeof(*clone_pixel));
39   if (clone_pixel == (MagickPixelPacket *) NULL)
40     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
41   *clone_pixel=(*pixel);
42   return(clone_pixel);
43 }
44
45 static inline MagickBooleanType IsGrayPixel(const PixelPacket *pixel)
46 {
47 #if !defined(MAGICKCORE_HDRI_SUPPORT)
48   if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
49     return(MagickTrue);
50 #else
51   if ((fabs(pixel->red-pixel->green) <= MagickEpsilon) &&
52       (fabs(pixel->green-pixel->blue) <= MagickEpsilon))
53     return(MagickTrue);
54 #endif
55   return(MagickFalse);
56 }
57
58 static inline MagickBooleanType IsMonochromePixel(const PixelPacket *pixel)
59 {
60 #if !defined(MAGICKCORE_HDRI_SUPPORT)
61   if (((pixel->red == 0) || (pixel->red == (Quantum) QuantumRange)) &&
62       (pixel->red == pixel->green) && (pixel->green == pixel->blue))
63     return(MagickTrue);
64 #else
65   if (((fabs(pixel->red) <= MagickEpsilon) ||
66        (fabs(pixel->red-QuantumRange) <= MagickEpsilon)) &&
67       (fabs(pixel->red-pixel->green) <= MagickEpsilon) &&
68       (fabs(pixel->green-pixel->blue) <= MagickEpsilon))
69     return(MagickTrue);
70 #endif
71   return(MagickFalse);
72 }
73
74 static inline void SetMagickPixelPacket(const Image *image,
75   const PixelPacket *color,const IndexPacket *index,MagickPixelPacket *pixel)
76 {
77   pixel->red=(MagickRealType) color->red;
78   pixel->green=(MagickRealType) color->green;
79   pixel->blue=(MagickRealType) color->blue;
80   pixel->opacity=(MagickRealType) color->opacity;
81   if (((image->colorspace == CMYKColorspace) ||
82        (image->storage_class == PseudoClass)) &&
83       (index != (const IndexPacket *) NULL))
84     pixel->index=(MagickRealType) *index;
85 }
86
87 static inline void SetMagickPixelPacketBias(const Image *image,
88   MagickPixelPacket *pixel)
89 {
90   pixel->red=image->bias;
91   pixel->green=image->bias;
92   pixel->blue=image->bias;
93   pixel->opacity=image->bias;
94   pixel->index=image->bias;
95 }
96
97 static inline void SetPixelPacket(const Image *image,
98   const MagickPixelPacket *pixel,PixelPacket *color,IndexPacket *index)
99 {
100   color->red=ClampToQuantum(pixel->red);
101   color->green=ClampToQuantum(pixel->green);
102   color->blue=ClampToQuantum(pixel->blue);
103   color->opacity=ClampToQuantum(pixel->opacity);
104   if (((image->colorspace == CMYKColorspace) ||
105        (image->storage_class == PseudoClass)) &&
106       (index != (const IndexPacket *) NULL))
107     *index=ClampToQuantum(pixel->index);
108 }
109
110 #if defined(__cplusplus) || defined(c_plusplus)
111 }
112 #endif
113
114 #endif