00001 /* 00002 Copyright 1999-2009 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 MagickBooleanType IsGray(const PixelPacket *pixel) 00038 { 00039 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue)) 00040 return(MagickTrue); 00041 return(MagickFalse); 00042 } 00043 00044 static inline MagickBooleanType IsMagickColorEqual(const MagickPixelPacket *p, 00045 const MagickPixelPacket *q) 00046 { 00047 #if !defined(MAGICKCORE_HDRI_SUPPORT) 00048 if ((p->matte != MagickFalse) && (q->matte == MagickFalse) && 00049 (p->opacity != OpaqueOpacity)) 00050 return(MagickFalse); 00051 if ((q->matte != MagickFalse) && (p->matte == MagickFalse) && 00052 (q->opacity != OpaqueOpacity)) 00053 return(MagickFalse); 00054 if ((p->matte != MagickFalse) && (q->matte != MagickFalse)) 00055 { 00056 if (p->opacity != q->opacity) 00057 return(MagickFalse); 00058 if (p->opacity == TransparentOpacity) 00059 return(MagickTrue); 00060 } 00061 if (p->red != q->red) 00062 return(MagickFalse); 00063 if (p->green != q->green) 00064 return(MagickFalse); 00065 if (p->blue != q->blue) 00066 return(MagickFalse); 00067 if ((p->colorspace == CMYKColorspace) && (p->index != q->index)) 00068 return(MagickFalse); 00069 #else 00070 if ((p->matte != MagickFalse) && (q->matte == MagickFalse) && 00071 (fabs(p->opacity-OpaqueOpacity) > 0.5)) 00072 return(MagickFalse); 00073 if ((q->matte != MagickFalse) && (p->matte == MagickFalse) && 00074 (fabs(q->opacity-OpaqueOpacity)) > 0.5) 00075 return(MagickFalse); 00076 if ((p->matte != MagickFalse) && (q->matte != MagickFalse)) 00077 { 00078 if (fabs(p->opacity-q->opacity) > 0.5) 00079 return(MagickFalse); 00080 if (fabs(p->opacity-TransparentOpacity) <= 0.5) 00081 return(MagickTrue); 00082 } 00083 if (fabs(p->red-q->red) > 0.5) 00084 return(MagickFalse); 00085 if (fabs(p->green-q->green) > 0.5) 00086 return(MagickFalse); 00087 if (fabs(p->blue-q->blue) > 0.5) 00088 return(MagickFalse); 00089 if ((p->colorspace == CMYKColorspace) && (fabs(p->index-q->index) > 0.5)) 00090 return(MagickFalse); 00091 #endif 00092 return(MagickTrue); 00093 } 00094 00095 static inline MagickBooleanType IsMagickGray(const MagickPixelPacket *pixel) 00096 { 00097 if (pixel->colorspace != RGBColorspace) 00098 return(MagickFalse); 00099 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue)) 00100 return(MagickTrue); 00101 return(MagickFalse); 00102 } 00103 00104 static inline MagickRealType MagickPixelIntensity( 00105 const MagickPixelPacket *pixel) 00106 { 00107 MagickRealType 00108 intensity; 00109 00110 intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue; 00111 return(intensity); 00112 } 00113 00114 static inline Quantum MagickPixelIntensityToQuantum( 00115 const MagickPixelPacket *pixel) 00116 { 00117 #if !defined(MAGICKCORE_HDRI_SUPPORT) 00118 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue+0.5)); 00119 #else 00120 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue)); 00121 #endif 00122 } 00123 00124 static inline MagickRealType MagickPixelLuminance( 00125 const MagickPixelPacket *pixel) 00126 { 00127 MagickRealType 00128 luminance; 00129 00130 luminance=0.21267*pixel->red+0.71516*pixel->green+0.07217*pixel->blue; 00131 return(luminance); 00132 } 00133 00134 static inline MagickRealType PixelIntensity(const PixelPacket *pixel) 00135 { 00136 MagickRealType 00137 intensity; 00138 00139 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue)) 00140 return((MagickRealType) pixel->red); 00141 intensity=(MagickRealType) (0.299*pixel->red+0.587*pixel->green+0.114* 00142 pixel->blue); 00143 return(intensity); 00144 } 00145 00146 static inline Quantum PixelIntensityToQuantum(const PixelPacket *pixel) 00147 { 00148 #if !defined(MAGICKCORE_HDRI_SUPPORT) 00149 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue)) 00150 return(pixel->red); 00151 #if (MAGICKCORE_QUANTUM_DEPTH <= 16) 00152 return((Quantum) ((306U*(unsigned int) pixel->red+ 00153 601U*(unsigned int) pixel->green+117U*(unsigned int) pixel->blue) >> 10U)); 00154 #else 00155 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue+0.5)); 00156 #endif 00157 #else 00158 if ((fabs(pixel->red-pixel->green) <= MagickEpsilon) && 00159 (fabs(pixel->green-pixel->blue) <= MagickEpsilon)) 00160 return((Quantum) pixel->red); 00161 return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue)); 00162 #endif 00163 } 00164 00165 #if defined(__cplusplus) || defined(c_plusplus) 00166 } 00167 #endif 00168 00169 #endif
1.6.1