cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
cristy | 16af1cb | 2009-12-11 21:38:29 +0000 | [diff] [blame^] | 2 | Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 *) AcquireMagickMemory(sizeof(*clone_pixel)); |
| 38 | if (clone_pixel == (MagickPixelPacket *) NULL) |
| 39 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 40 | *clone_pixel=(*pixel); |
| 41 | return(clone_pixel); |
| 42 | } |
| 43 | |
| 44 | static 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 | |
| 57 | static 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 | |
| 73 | static 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 | |
cristy | ddd8220 | 2009-11-03 20:14:50 +0000 | [diff] [blame] | 86 | static 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 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 96 | static 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 |