]> granicus.if.org Git - imagemagick/blob - MagickCore/pixel-private.h
(no commit message)
[imagemagick] / MagickCore / 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 MagickPixelInfo *CloneMagickPixelInfo(
32   const MagickPixelInfo *pixel)
33 {
34   MagickPixelInfo
35     *clone_pixel;
36
37   clone_pixel=(MagickPixelInfo *) AcquireMemory(sizeof(*clone_pixel));
38   if (clone_pixel == (MagickPixelInfo *) NULL)
39     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
40   *clone_pixel=(*pixel);
41   return(clone_pixel);
42 }
43
44 static inline MagickBooleanType IsGrayPixel(const PixelInfo *pixel)
45 {
46 #if !defined(MAGICKCORE_HDRI_SUPPORT)
47   if ((GetPixelRed(pixel) == GetPixelGreen(pixel)) && 
48       (GetPixelGreen(pixel) == GetPixelBlue(pixel)))
49     return(MagickTrue);
50 #else
51   {
52     double
53       alpha,
54       beta;
55
56     alpha=GetPixelRed(pixel)-GetPixelGreen(pixel);
57     beta=GetPixelGreen(pixel)-GetPixelBlue(pixel);
58     if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
59       return(MagickTrue);
60   }
61 #endif
62   return(MagickFalse);
63 }
64
65 static inline MagickBooleanType IsMonochromePixel(const PixelInfo *pixel)
66 {
67 #if !defined(MAGICKCORE_HDRI_SUPPORT)
68   if (((GetPixelRed(pixel) == 0) ||
69        (GetPixelRed(pixel) == (Quantum) QuantumRange)) &&
70       (GetPixelRed(pixel) == GetPixelGreen(pixel)) &&
71       (GetPixelGreen(pixel) == GetPixelBlue(pixel)))
72     return(MagickTrue);
73 #else
74   {
75     double
76       alpha,
77       beta;
78
79     alpha=GetPixelRed(pixel)-GetPixelGreen(pixel);
80     beta=GetPixelGreen(pixel)-GetPixelBlue(pixel);
81     if (((fabs(GetPixelRed(pixel)) <= MagickEpsilon) ||
82          (fabs(GetPixelRed(pixel)-QuantumRange) <= MagickEpsilon)) &&
83         (fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
84       return(MagickTrue);
85     }
86 #endif
87   return(MagickFalse);
88 }
89
90 static inline void GetPixelInfo(const Image *image,
91   const MagickPixelInfo *pixel,PixelInfo *color,IndexPacket *index)
92 {
93   SetPixelRed(color,ClampToQuantum(pixel->red));
94   SetPixelGreen(color,ClampToQuantum(pixel->green));
95   SetPixelBlue(color,ClampToQuantum(pixel->blue));
96   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
97     SetPixelAlpha(color,ClampToQuantum(pixel->alpha));
98   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
99     SetPixelBlack(index,ClampToQuantum(pixel->black));
100   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
101     SetPixelIndex(index,ClampToQuantum(pixel->index));
102 }
103
104 #if defined(__cplusplus) || defined(c_plusplus)
105 }
106 #endif
107
108 #endif