MagickCore  6.7.4
pixel-private.h
Go to the documentation of this file.
00001 /*
00002   Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization
00003   dedicated to making software imaging solutions freely available.
00004   
00005   You may not use this file except in compliance with the License.
00006   obtain a copy of the License at
00007   
00008     http://www.imagemagick.org/script/license.php
00009   
00010   Unless required by applicable law or agreed to in writing, software
00011   distributed under the License is distributed on an "AS IS" BASIS,
00012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013   See the License for the specific language governing permissions and
00014   limitations under the License.
00015 
00016   MagickCore image pixel private methods.
00017 */
00018 #ifndef _MAGICKCORE_PIXEL_PRIVATE_H
00019 #define _MAGICKCORE_PIXEL_PRIVATE_H
00020 
00021 #if defined(__cplusplus) || defined(c_plusplus)
00022 extern "C" {
00023 #endif
00024 
00025 #include <magick/exception-private.h>
00026 #include <magick/image.h>
00027 #include <magick/color.h>
00028 #include <magick/image-private.h>
00029 #include <magick/quantum-private.h>
00030 
00031 static inline MagickPixelInfo *CloneMagickPixelInfo(
00032   const MagickPixelInfo *pixel)
00033 {
00034   MagickPixelInfo
00035     *clone_pixel;
00036 
00037   clone_pixel=(MagickPixelInfo *) AcquireMemory(sizeof(*clone_pixel));
00038   if (clone_pixel == (MagickPixelInfo *) NULL)
00039     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
00040   *clone_pixel=(*pixel);
00041   return(clone_pixel);
00042 }
00043 
00044 static inline MagickBooleanType IsGrayPixel(const PixelInfo *pixel)
00045 {
00046 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00047   if ((GetPixelRed(pixel) == GetPixelGreen(pixel)) && 
00048       (GetPixelGreen(pixel) == GetPixelBlue(pixel)))
00049     return(MagickTrue);
00050 #else
00051   {
00052     double
00053       alpha,
00054       beta;
00055 
00056     alpha=GetPixelRed(pixel)-GetPixelGreen(pixel);
00057     beta=GetPixelGreen(pixel)-GetPixelBlue(pixel);
00058     if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
00059       return(MagickTrue);
00060   }
00061 #endif
00062   return(MagickFalse);
00063 }
00064 
00065 static inline MagickBooleanType IsMonochromePixel(const PixelInfo *pixel)
00066 {
00067 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00068   if (((GetPixelRed(pixel) == 0) ||
00069        (GetPixelRed(pixel) == (Quantum) QuantumRange)) &&
00070       (GetPixelRed(pixel) == GetPixelGreen(pixel)) &&
00071       (GetPixelGreen(pixel) == GetPixelBlue(pixel)))
00072     return(MagickTrue);
00073 #else
00074   {
00075     double
00076       alpha,
00077       beta;
00078 
00079     alpha=GetPixelRed(pixel)-GetPixelGreen(pixel);
00080     beta=GetPixelGreen(pixel)-GetPixelBlue(pixel);
00081     if (((fabs(GetPixelRed(pixel)) <= MagickEpsilon) ||
00082          (fabs(GetPixelRed(pixel)-QuantumRange) <= MagickEpsilon)) &&
00083         (fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
00084       return(MagickTrue);
00085     }
00086 #endif
00087   return(MagickFalse);
00088 }
00089 
00090 static inline void GetPixelInfo(const Image *image,
00091   const MagickPixelInfo *pixel,PixelInfo *color,IndexPacket *index)
00092 {
00093   SetPixelRed(color,ClampToQuantum(pixel->red));
00094   SetPixelGreen(color,ClampToQuantum(pixel->green));
00095   SetPixelBlue(color,ClampToQuantum(pixel->blue));
00096   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
00097     SetPixelAlpha(color,ClampToQuantum(pixel->alpha));
00098   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
00099     SetPixelBlack(index,ClampToQuantum(pixel->black));
00100   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
00101     SetPixelIndex(index,ClampToQuantum(pixel->index));
00102 }
00103 
00104 #if defined(__cplusplus) || defined(c_plusplus)
00105 }
00106 #endif
00107 
00108 #endif