00001 /* 00002 Copyright 1999-2010 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 color methods. 00017 */ 00018 #ifndef _MAGICKCORE_COLOR_PRIVATE_H 00019 #define _MAGICKCORE_COLOR_PRIVATE_H 00020 00021 #if defined(__cplusplus) || defined(c_plusplus) 00022 extern "C" { 00023 #endif 00024 00025 #include <magick/image.h> 00026 #include <magick/color.h> 00027 #include <magick/exception-private.h> 00028 00029 static inline MagickBooleanType IsColorEqual(const PixelPacket *p, 00030 const PixelPacket *q) 00031 { 00032 if (p->red != q->red) 00033 return(MagickFalse); 00034 if (p->green != q->green) 00035 return(MagickFalse); 00036 if (p->blue != q->blue) 00037 return(MagickFalse); 00038 if (p->opacity != q->opacity) 00039 return(MagickFalse); 00040 return(MagickTrue); 00041 } 00042 00043 static inline IndexPacket ConstrainColormapIndex(Image *image, 00044 const unsigned long index) 00045 { 00046 if (index >= image->colors) 00047 { 00048 (void) ThrowMagickException(&image->exception,GetMagickModule(), 00049 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename); 00050 return((IndexPacket) 0); 00051 } 00052 return((IndexPacket) index); 00053 } 00054 00055 static inline MagickBooleanType IsGray(const PixelPacket *pixel) 00056 { 00057 if (pixel->red != pixel->green) 00058 return(MagickFalse); 00059 if (pixel->green != pixel->blue) 00060 return(MagickFalse); 00061 return(MagickTrue); 00062 } 00063 00064 static inline MagickBooleanType IsMagickColorEqual(const MagickPixelPacket *p, 00065 const MagickPixelPacket *q) 00066 { 00067 if ((p->matte != MagickFalse) && (q->matte == MagickFalse) && 00068 (p->opacity != OpaqueOpacity)) 00069 return(MagickFalse); 00070 if ((q->matte != MagickFalse) && (p->matte == MagickFalse) && 00071 (q->opacity != OpaqueOpacity)) 00072 return(MagickFalse); 00073 if ((p->matte != MagickFalse) && (q->matte != MagickFalse)) 00074 { 00075 if (p->opacity != q->opacity) 00076 return(MagickFalse); 00077 if (p->opacity == TransparentOpacity) 00078 return(MagickTrue); 00079 } 00080 if (p->red != q->red) 00081 return(MagickFalse); 00082 if (p->green != q->green) 00083 return(MagickFalse); 00084 if (p->blue != q->blue) 00085 return(MagickFalse); 00086 if ((p->colorspace == CMYKColorspace) && (p->index != q->index)) 00087 return(MagickFalse); 00088 return(MagickTrue); 00089 } 00090 00091 static inline MagickBooleanType IsMagickGray(const MagickPixelPacket *pixel) 00092 { 00093 if (pixel->colorspace != RGBColorspace) 00094 return(MagickFalse); 00095 if (pixel->red != pixel->green) 00096 return(MagickFalse); 00097 if (pixel->green != pixel->blue) 00098 return(MagickFalse); 00099 return(MagickTrue); 00100 } 00101 00102 static inline MagickRealType MagickPixelIntensity( 00103 const MagickPixelPacket *pixel) 00104 { 00105 MagickRealType 00106 intensity; 00107 00108 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue; 00109 return(intensity); 00110 } 00111 00112 static inline Quantum MagickPixelIntensityToQuantum( 00113 const MagickPixelPacket *pixel) 00114 { 00115 #if !defined(MAGICKCORE_HDRI_SUPPORT) 00116 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue+0.5)); 00117 #else 00118 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue)); 00119 #endif 00120 } 00121 00122 static inline MagickRealType MagickPixelLuminance( 00123 const MagickPixelPacket *pixel) 00124 { 00125 MagickRealType 00126 luminance; 00127 00128 luminance=0.21267*pixel->red+0.71516*pixel->green+0.07217*pixel->blue; 00129 return(luminance); 00130 } 00131 00132 static inline MagickRealType PixelIntensity(const PixelPacket *pixel) 00133 { 00134 MagickRealType 00135 intensity; 00136 00137 intensity=(MagickRealType) (0.299*pixel->red+0.587*pixel->green+0.114* 00138 pixel->blue); 00139 return(intensity); 00140 } 00141 00142 static inline Quantum PixelIntensityToQuantum(const PixelPacket *pixel) 00143 { 00144 #if !defined(MAGICKCORE_HDRI_SUPPORT) 00145 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue+0.5)); 00146 #else 00147 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue)); 00148 #endif 00149 } 00150 00151 #if defined(__cplusplus) || defined(c_plusplus) 00152 } 00153 #endif 00154 00155 #endif