]> granicus.if.org Git - imagemagick/blob - magick/pixel-private.h
(no commit message)
[imagemagick] / magick / pixel-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 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 ((GetRedPixelComponent(pixel) == GetGreenPixelComponent(pixel)) && 
49       (GetGreenPixelComponent(pixel) == GetBluePixelComponent(pixel)))
50     return(MagickTrue);
51 #else
52   {
53     double
54       alpha,
55       beta;
56
57     alpha=GetRedPixelComponent(pixel)-GetGreenPixelComponent(pixel);
58     beta=GetGreenPixelComponent(pixel)-GetBluePixelComponent(pixel);
59     if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
60       return(MagickTrue);
61   }
62 #endif
63   return(MagickFalse);
64 }
65
66 static inline MagickBooleanType IsMonochromePixel(const PixelPacket *pixel)
67 {
68 #if !defined(MAGICKCORE_HDRI_SUPPORT)
69   if (((GetRedPixelComponent(pixel) == 0) ||
70        (GetRedPixelComponent(pixel) == (Quantum) QuantumRange)) &&
71       (GetRedPixelComponent(pixel) == GetGreenPixelComponent(pixel)) &&
72       (GetGreenPixelComponent(pixel) == GetBluePixelComponent(pixel)))
73     return(MagickTrue);
74 #else
75   {
76     double
77       alpha,
78       beta;
79
80     alpha=GetRedPixelComponent(pixel)-GetGreenPixelComponent(pixel);
81     beta=GetGreenPixelComponent(pixel)-GetBluePixelComponent(pixel);
82     if (((fabs(GetRedPixelComponent(pixel)) <= MagickEpsilon) ||
83          (fabs(GetRedPixelComponent(pixel)-QuantumRange) <= MagickEpsilon)) &&
84         (fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
85       return(MagickTrue);
86     }
87 #endif
88   return(MagickFalse);
89 }
90
91 static inline void SetMagickPixelPacket(const Image *image,
92   const PixelPacket *color,const IndexPacket *index,MagickPixelPacket *pixel)
93 {
94   pixel->red=(MagickRealType) GetRedPixelComponent(color);
95   pixel->green=(MagickRealType) GetGreenPixelComponent(color);
96   pixel->blue=(MagickRealType) GetBluePixelComponent(color);
97   pixel->opacity=(MagickRealType) GetOpacityPixelComponent(color);
98   if ((image->colorspace == CMYKColorspace) &&
99       (index != (const IndexPacket *) NULL))
100     pixel->index=(MagickRealType) GetIndexPixelComponent(index);
101 }
102
103 static inline void SetMagickPixelPacketBias(const Image *image,
104   MagickPixelPacket *pixel)
105 {
106   /*
107     Obsoleted by MorphologyApply().
108   */
109   pixel->red=image->bias;
110   pixel->green=image->bias;
111   pixel->blue=image->bias;
112   pixel->opacity=image->bias;
113   pixel->index=image->bias;
114 }
115
116 static inline void SetPixelPacket(const Image *image,
117   const MagickPixelPacket *pixel,PixelPacket *color,IndexPacket *index)
118 {
119   SetRedPixelComponent(color,ClampToQuantum(pixel->red));
120   SetGreenPixelComponent(color,ClampToQuantum(pixel->green));
121   SetBluePixelComponent(color,ClampToQuantum(pixel->blue));
122   SetOpacityPixelComponent(color,ClampToQuantum(pixel->opacity));
123   if ((image->colorspace == CMYKColorspace) ||
124       (image->storage_class == PseudoClass))
125     SetIndexPixelComponent(index,ClampToQuantum(pixel->index));
126 }
127
128 #if defined(__cplusplus) || defined(c_plusplus)
129 }
130 #endif
131
132 #endif