blob: 7925eb98f9807b2334771d7df443a274a7b3ebc2 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2 Copyright 1999-2009 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)
22extern "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
31static inline MagickPixelPacket *CloneMagickPixelPacket(
32 const MagickPixelPacket *pixel)
33{
34 MagickPixelPacket
35 *clone_pixel;
36
37 clone_pixel=(MagickPixelPacket *) AcquireMagickMemory(sizeof(*clone_pixel));
38 if (clone_pixel == (MagickPixelPacket *) NULL)
39 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
40 *clone_pixel=(*pixel);
41 return(clone_pixel);
42}
43
44static inline MagickBooleanType IsGrayPixel(const PixelPacket *pixel)
45{
46#if !defined(MAGICKCORE_HDRI_SUPPORT)
47 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
48 return(MagickTrue);
49#else
50 if ((fabs(pixel->red-pixel->green) <= MagickEpsilon) &&
51 (fabs(pixel->green-pixel->blue) <= MagickEpsilon))
52 return(MagickTrue);
53#endif
54 return(MagickFalse);
55}
56
57static inline MagickBooleanType IsMonochromePixel(const PixelPacket *pixel)
58{
59#if !defined(MAGICKCORE_HDRI_SUPPORT)
60 if (((pixel->red == 0) || (pixel->red == (Quantum) QuantumRange)) &&
61 (pixel->red == pixel->green) && (pixel->green == pixel->blue))
62 return(MagickTrue);
63#else
64 if (((fabs(pixel->red) <= MagickEpsilon) ||
65 (fabs(pixel->red-QuantumRange) <= MagickEpsilon)) &&
66 (fabs(pixel->red-pixel->green) <= MagickEpsilon) &&
67 (fabs(pixel->green-pixel->blue) <= MagickEpsilon))
68 return(MagickTrue);
69#endif
70 return(MagickFalse);
71}
72
73static inline void SetMagickPixelPacket(const Image *image,
74 const PixelPacket *color,const IndexPacket *index,MagickPixelPacket *pixel)
75{
76 pixel->red=(MagickRealType) color->red;
77 pixel->green=(MagickRealType) color->green;
78 pixel->blue=(MagickRealType) color->blue;
79 pixel->opacity=(MagickRealType) color->opacity;
80 if (((image->colorspace == CMYKColorspace) ||
81 (image->storage_class == PseudoClass)) &&
82 (index != (const IndexPacket *) NULL))
83 pixel->index=(MagickRealType) *index;
84}
85
cristyddd82202009-11-03 20:14:50 +000086static inline void SetMagickPixelPacketBias(const Image *image,
87 MagickPixelPacket *pixel)
88{
89 pixel->red=image->bias;
90 pixel->green=image->bias;
91 pixel->blue=image->bias;
92 pixel->opacity=image->bias;
93 pixel->index=image->bias;
94}
95
cristy3ed852e2009-09-05 21:47:34 +000096static inline void SetPixelPacket(const Image *image,
97 const MagickPixelPacket *pixel,PixelPacket *color,IndexPacket *index)
98{
99 color->red=RoundToQuantum(pixel->red);
100 color->green=RoundToQuantum(pixel->green);
101 color->blue=RoundToQuantum(pixel->blue);
102 color->opacity=RoundToQuantum(pixel->opacity);
103 if (((image->colorspace == CMYKColorspace) ||
104 (image->storage_class == PseudoClass)) &&
105 (index != (const IndexPacket *) NULL))
106 *index=RoundToQuantum(pixel->index);
107}
108
109#if defined(__cplusplus) || defined(c_plusplus)
110}
111#endif
112
113#endif