color-private.h

Go to the documentation of this file.
00001 /*
00002   Copyright 1999-2020 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.  You may
00006   obtain a copy of the License at
00007 
00008     https://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 #include "magick/image.h"
00022 #include "magick/image-private.h"
00023 #include "magick/color.h"
00024 #include "magick/colorspace-private.h"
00025 #include "magick/exception-private.h"
00026 #include "magick/pixel-accessor.h"
00027 
00028 #if defined(__cplusplus) || defined(c_plusplus)
00029 extern "C" {
00030 #endif
00031 
00032 extern MagickPrivate MagickBooleanType
00033   IsIntensitySimilar(const Image *,const PixelPacket *,const PixelPacket *);
00034 
00035 static inline double GetFuzzyColorDistance(const Image *p,const Image *q)
00036 {
00037   double
00038     fuzz;
00039 
00040   fuzz=(double) MagickMax(MagickMax(p->fuzz,q->fuzz),(MagickRealType)
00041     MagickSQ1_2);
00042   return(fuzz*fuzz);
00043 }
00044 
00045 static inline MagickBooleanType IsColorEqual(const PixelPacket *p,
00046   const PixelPacket *q)
00047 {
00048   MagickRealType
00049     blue,
00050     green,
00051     red;
00052 
00053   red=(MagickRealType) p->red;
00054   green=(MagickRealType) p->green;
00055   blue=(MagickRealType) p->blue;
00056   if ((AbsolutePixelValue(red-q->red) < MagickEpsilon) &&
00057       (AbsolutePixelValue(green-q->green) < MagickEpsilon) &&
00058       (AbsolutePixelValue(blue-q->blue) < MagickEpsilon))
00059     return(MagickTrue);
00060   return(MagickFalse);
00061 }
00062 
00063 static inline MagickBooleanType IsMagickColorEqual(const MagickPixelPacket *p,
00064   const MagickPixelPacket *q)
00065 {
00066   MagickRealType
00067     alpha,
00068     beta;
00069 
00070   alpha=p->matte == MagickFalse ? OpaqueOpacity : p->opacity;
00071   beta=q->matte == MagickFalse ? OpaqueOpacity : q->opacity;
00072   if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
00073     return(MagickFalse);
00074   if ((AbsolutePixelValue(alpha-TransparentOpacity) < MagickEpsilon) ||
00075       (AbsolutePixelValue(beta-TransparentOpacity) < MagickEpsilon))
00076     return(MagickTrue);  /* no color component if pixel is transparent */
00077   if (AbsolutePixelValue(p->red-q->red) >= MagickEpsilon)
00078     return(MagickFalse);
00079   if (AbsolutePixelValue(p->green-q->green) >= MagickEpsilon)
00080     return(MagickFalse);
00081   if (AbsolutePixelValue(p->blue-q->blue) >= MagickEpsilon)
00082     return(MagickFalse);
00083   if (p->colorspace == CMYKColorspace)
00084     {
00085       if (AbsolutePixelValue(p->index-q->index) >= MagickEpsilon)
00086         return(MagickFalse);
00087     }
00088   return(MagickTrue);
00089 }
00090 
00091 static inline MagickBooleanType IsMagickGray(const MagickPixelPacket *pixel)
00092 {
00093   if (IssRGBCompatibleColorspace(pixel->colorspace) == MagickFalse)
00094     return(MagickFalse);
00095   if ((AbsolutePixelValue(pixel->red-pixel->green) < MagickEpsilon) &&
00096       (AbsolutePixelValue(pixel->green-pixel->blue) < MagickEpsilon))
00097     return(MagickTrue);
00098   return(MagickFalse);
00099 }
00100 
00101 static inline MagickRealType MagickPixelIntensity(
00102   const MagickPixelPacket *pixel)
00103 {
00104   if (IsGrayColorspace(pixel->colorspace) != MagickFalse)
00105     return(pixel->red);
00106   return(0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue);
00107 }
00108 
00109 static inline Quantum MagickPixelIntensityToQuantum(
00110   const MagickPixelPacket *pixel)
00111 {
00112   if (IsGrayColorspace(pixel->colorspace) != MagickFalse)
00113     return(ClampToQuantum(pixel->red));
00114   return(ClampToQuantum(0.212656*pixel->red+0.715158*pixel->green+
00115     0.072186*pixel->blue));
00116 }
00117 
00118 static inline MagickRealType MagickPixelLuma(const MagickPixelPacket *pixel)
00119 {
00120   MagickRealType
00121     blue,
00122     green,
00123     red;
00124 
00125   if (IsGrayColorspace(pixel->colorspace) != MagickFalse)
00126     return(pixel->red);
00127   if (pixel->colorspace == sRGBColorspace)
00128     return(0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue);
00129   red=EncodePixelGamma(pixel->red);
00130   green=EncodePixelGamma(pixel->green);
00131   blue=EncodePixelGamma(pixel->blue);
00132   return(0.212656*red+0.715158*green+0.072186*blue);
00133 }
00134 
00135 static inline MagickRealType MagickPixelLuminance(
00136   const MagickPixelPacket *pixel)
00137 {
00138   MagickRealType
00139     blue,
00140     green,
00141     red;
00142 
00143   if (IsGrayColorspace(pixel->colorspace) != MagickFalse)
00144     return(pixel->red);
00145   if (pixel->colorspace != sRGBColorspace)
00146     return(0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue);
00147   red=DecodePixelGamma(pixel->red);
00148   green=DecodePixelGamma(pixel->green);
00149   blue=DecodePixelGamma(pixel->blue);
00150   return(0.212656*red+0.715158*green+0.072186*blue);
00151 }
00152 
00153 #if defined(__cplusplus) || defined(c_plusplus)
00154 }
00155 #endif
00156 
00157 #endif

Generated on 2 Dec 2019 for MagickCore by  doxygen 1.6.1