| 1 | /* |
|---|
| 2 | Copyright 1999-2012 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 ((GetPixelRed(pixel) == GetPixelGreen(pixel)) && |
|---|
| 49 | (GetPixelGreen(pixel) == GetPixelBlue(pixel))) |
|---|
| 50 | return(MagickTrue); |
|---|
| 51 | #else |
|---|
| 52 | { |
|---|
| 53 | double |
|---|
| 54 | alpha, |
|---|
| 55 | beta; |
|---|
| 56 | |
|---|
| 57 | alpha=GetPixelRed(pixel)-GetPixelGreen(pixel); |
|---|
| 58 | beta=GetPixelGreen(pixel)-GetPixelBlue(pixel); |
|---|
| 59 | if ((fabs((double) 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 (((GetPixelRed(pixel) == 0) || |
|---|
| 70 | (GetPixelRed(pixel) == (Quantum) QuantumRange)) && |
|---|
| 71 | (GetPixelRed(pixel) == GetPixelGreen(pixel)) && |
|---|
| 72 | (GetPixelGreen(pixel) == GetPixelBlue(pixel))) |
|---|
| 73 | return(MagickTrue); |
|---|
| 74 | #else |
|---|
| 75 | { |
|---|
| 76 | double |
|---|
| 77 | alpha, |
|---|
| 78 | beta; |
|---|
| 79 | |
|---|
| 80 | alpha=GetPixelRed(pixel)-GetPixelGreen(pixel); |
|---|
| 81 | beta=GetPixelGreen(pixel)-GetPixelBlue(pixel); |
|---|
| 82 | if (((fabs(GetPixelRed(pixel)) <= MagickEpsilon) || |
|---|
| 83 | (fabs(GetPixelRed(pixel)-QuantumRange) <= MagickEpsilon)) && |
|---|
| 84 | (fabs((double) 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) GetPixelRed(color); |
|---|
| 95 | pixel->green=(MagickRealType) GetPixelGreen(color); |
|---|
| 96 | pixel->blue=(MagickRealType) GetPixelBlue(color); |
|---|
| 97 | pixel->opacity=(MagickRealType) GetPixelOpacity(color); |
|---|
| 98 | if ((image->colorspace == CMYKColorspace) && |
|---|
| 99 | (index != (const IndexPacket *) NULL)) |
|---|
| 100 | pixel->index=(MagickRealType) GetPixelIndex(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 | SetPixelRed(color,ClampToQuantum(pixel->red)); |
|---|
| 120 | SetPixelGreen(color,ClampToQuantum(pixel->green)); |
|---|
| 121 | SetPixelBlue(color,ClampToQuantum(pixel->blue)); |
|---|
| 122 | SetPixelOpacity(color,ClampToQuantum(pixel->opacity)); |
|---|
| 123 | if ((image->colorspace == CMYKColorspace) || |
|---|
| 124 | (image->storage_class == PseudoClass)) |
|---|
| 125 | SetPixelIndex(index,ClampToQuantum(pixel->index)); |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | #if defined(__cplusplus) || defined(c_plusplus) |
|---|
| 129 | } |
|---|
| 130 | #endif |
|---|
| 131 | |
|---|
| 132 | #endif |
|---|