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) && (p->green == q->green) && (p->blue == q->blue)) 00033 return(MagickTrue); 00034 return(MagickFalse); 00035 } 00036 00037 static inline IndexPacket ConstrainColormapIndex(Image *image, 00038 const unsigned long index) 00039 { 00040 if (index < image->colors) 00041 return((IndexPacket) index); 00042 (void) ThrowMagickException(&image->exception,GetMagickModule(), 00043 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename); 00044 return((IndexPacket) 0); 00045 } 00046 00047 static inline MagickBooleanType IsGray(const PixelPacket *pixel) 00048 { 00049 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue)) 00050 return(MagickTrue); 00051 return(MagickFalse); 00052 } 00053 00054 static inline MagickBooleanType IsMagickColorEqual(const MagickPixelPacket *p, 00055 const MagickPixelPacket *q) 00056 { 00057 if ((p->matte != MagickFalse) && (q->matte == MagickFalse) && 00058 (p->opacity != OpaqueOpacity)) 00059 return(MagickFalse); 00060 if ((q->matte != MagickFalse) && (p->matte == MagickFalse) && 00061 (q->opacity != OpaqueOpacity)) 00062 return(MagickFalse); 00063 if ((p->matte != MagickFalse) && (q->matte != MagickFalse)) 00064 { 00065 if (p->opacity != q->opacity) 00066 return(MagickFalse); 00067 if (p->opacity == TransparentOpacity) 00068 return(MagickTrue); 00069 } 00070 if (p->red != q->red) 00071 return(MagickFalse); 00072 if (p->green != q->green) 00073 return(MagickFalse); 00074 if (p->blue != q->blue) 00075 return(MagickFalse); 00076 if ((p->colorspace == CMYKColorspace) && (p->index != q->index)) 00077 return(MagickFalse); 00078 return(MagickTrue); 00079 } 00080 00081 static inline MagickBooleanType IsMagickGray(const MagickPixelPacket *pixel) 00082 { 00083 if (pixel->colorspace != RGBColorspace) 00084 return(MagickFalse); 00085 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue)) 00086 return(MagickTrue); 00087 return(MagickFalse); 00088 } 00089 00090 static inline MagickRealType MagickPixelIntensity( 00091 const MagickPixelPacket *pixel) 00092 { 00093 MagickRealType 00094 intensity; 00095 00096 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue; 00097 return(intensity); 00098 } 00099 00100 static inline Quantum MagickPixelIntensityToQuantum( 00101 const MagickPixelPacket *pixel) 00102 { 00103 #if !defined(MAGICKCORE_HDRI_SUPPORT) 00104 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue+0.5)); 00105 #else 00106 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue)); 00107 #endif 00108 } 00109 00110 static inline MagickRealType MagickPixelLuminance( 00111 const MagickPixelPacket *pixel) 00112 { 00113 MagickRealType 00114 luminance; 00115 00116 luminance=0.21267*pixel->red+0.71516*pixel->green+0.07217*pixel->blue; 00117 return(luminance); 00118 } 00119 00120 static inline MagickRealType PixelIntensity(const PixelPacket *pixel) 00121 { 00122 MagickRealType 00123 intensity; 00124 00125 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue)) 00126 return((MagickRealType) pixel->red); 00127 intensity=(MagickRealType) (0.299*pixel->red+0.587*pixel->green+0.114* 00128 pixel->blue); 00129 return(intensity); 00130 } 00131 00132 static inline Quantum PixelIntensityToQuantum(const PixelPacket *pixel) 00133 { 00134 #if !defined(MAGICKCORE_HDRI_SUPPORT) 00135 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue)) 00136 return(pixel->red); 00137 #if (MAGICKCORE_QUANTUM_DEPTH <= 16) 00138 return((Quantum) ((306U*(unsigned int) pixel->red+ 00139 601U*(unsigned int) pixel->green+117U*(unsigned int) pixel->blue) >> 10U)); 00140 #else 00141 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue+0.5)); 00142 #endif 00143 #else 00144 if ((fabs(pixel->red-pixel->green) <= MagickEpsilon) && 00145 (fabs(pixel->green-pixel->blue) <= MagickEpsilon)) 00146 return((Quantum) pixel->red); 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