blob: 9fda19485f917489074fdf28019b9e8e700876f2 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
cristy16af1cb2009-12-11 21:38:29 +00002 Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization
cristy3ed852e2009-09-05 21:47:34 +00003 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
cristy8cd5b312010-01-07 01:10:24 +000037 clone_pixel=(MagickPixelPacket *) AcquireAlignedMemory(1,
38 sizeof(*clone_pixel));
cristy3ed852e2009-09-05 21:47:34 +000039 if (clone_pixel == (MagickPixelPacket *) NULL)
40 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
41 *clone_pixel=(*pixel);
42 return(clone_pixel);
43}
44
45static 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
58static 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
74static 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
cristyddd82202009-11-03 20:14:50 +000087static 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
cristy3ed852e2009-09-05 21:47:34 +000097static inline void SetPixelPacket(const Image *image,
98 const MagickPixelPacket *pixel,PixelPacket *color,IndexPacket *index)
99{
cristyce70c172010-01-07 17:15:30 +0000100 color->red=ClampToQuantum(pixel->red);
101 color->green=ClampToQuantum(pixel->green);
102 color->blue=ClampToQuantum(pixel->blue);
103 color->opacity=ClampToQuantum(pixel->opacity);
cristy3ed852e2009-09-05 21:47:34 +0000104 if (((image->colorspace == CMYKColorspace) ||
105 (image->storage_class == PseudoClass)) &&
106 (index != (const IndexPacket *) NULL))
cristyce70c172010-01-07 17:15:30 +0000107 *index=ClampToQuantum(pixel->index);
cristy3ed852e2009-09-05 21:47:34 +0000108}
109
110#if defined(__cplusplus) || defined(c_plusplus)
111}
112#endif
113
114#endif