Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 09:01:36

0001 /*
0002   Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization
0003   dedicated to making software imaging solutions freely available.
0004 
0005   You may not use this file except in compliance with the License.  You may
0006   obtain a copy of the License at
0007 
0008     https://imagemagick.org/script/license.php
0009 
0010   Unless required by applicable law or agreed to in writing, software
0011   distributed under the License is distributed on an "AS IS" BASIS,
0012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013   See the License for the specific language governing permissions and
0014   limitations under the License.
0015 
0016   MagickCore pixel accessor methods.
0017 */
0018 #ifndef MAGICKCORE_PIXEL_ACCESSOR_H
0019 #define MAGICKCORE_PIXEL_ACCESSOR_H
0020 
0021 #include "MagickCore/cache.h"
0022 #include "MagickCore/cache-view.h"
0023 #include "MagickCore/color.h"
0024 #include "MagickCore/colorspace.h"
0025 #include "MagickCore/gem.h"
0026 #include "MagickCore/image.h"
0027 #include "MagickCore/memory_.h"
0028 
0029 #if defined(__cplusplus) || defined(c_plusplus)
0030 extern "C" {
0031 #endif
0032 
0033 #undef index
0034 
0035 static inline Quantum ClampPixel(const MagickRealType pixel)
0036 {
0037   if (pixel < 0.0)
0038     return((Quantum) 0);
0039   if (pixel >= (MagickRealType) QuantumRange)
0040     return((Quantum) QuantumRange);
0041 #if !defined(MAGICKCORE_HDRI_SUPPORT)
0042   return((Quantum) (pixel+0.5f));
0043 #else
0044   return((Quantum) pixel);
0045 #endif
0046 }
0047 
0048 static inline Quantum GetPixela(const Image *magick_restrict image,
0049   const Quantum *magick_restrict pixel)
0050 {
0051   return(pixel[image->channel_map[aPixelChannel].offset]);
0052 }
0053 
0054 static inline Quantum GetPixelAlpha(const Image *magick_restrict image,
0055   const Quantum *magick_restrict pixel)
0056 {
0057   if (image->channel_map[AlphaPixelChannel].traits == UndefinedPixelTrait)
0058     return(OpaqueAlpha);
0059   return(pixel[image->channel_map[AlphaPixelChannel].offset]);
0060 }
0061 
0062 static inline PixelTrait GetPixelAlphaTraits(const Image *magick_restrict image)
0063 {
0064   return(image->channel_map[AlphaPixelChannel].traits);
0065 }
0066 
0067 static inline Quantum GetPixelb(const Image *magick_restrict image,
0068   const Quantum *magick_restrict pixel)
0069 {
0070   return(pixel[image->channel_map[bPixelChannel].offset]);
0071 }
0072 
0073 static inline Quantum GetPixelBlack(const Image *magick_restrict image,
0074   const Quantum *magick_restrict pixel)
0075 {
0076   if (image->channel_map[BlackPixelChannel].traits == UndefinedPixelTrait)
0077     return((Quantum) 0);
0078   return(pixel[image->channel_map[BlackPixelChannel].offset]);
0079 }
0080 
0081 static inline PixelTrait GetPixelBlackTraits(const Image *magick_restrict image)
0082 {
0083   return(image->channel_map[BlackPixelChannel].traits);
0084 }
0085 
0086 static inline Quantum GetPixelBlue(const Image *magick_restrict image,
0087   const Quantum *magick_restrict pixel)
0088 {
0089   return(pixel[image->channel_map[BluePixelChannel].offset]);
0090 }
0091 
0092 static inline PixelTrait GetPixelBlueTraits(const Image *magick_restrict image)
0093 {
0094   return(image->channel_map[BluePixelChannel].traits);
0095 }
0096 
0097 static inline Quantum GetPixelCb(const Image *magick_restrict image,
0098   const Quantum *magick_restrict pixel)
0099 {
0100   return(pixel[image->channel_map[CbPixelChannel].offset]);
0101 }
0102 
0103 static inline PixelTrait GetPixelCbTraits(const Image *magick_restrict image)
0104 {
0105   return(image->channel_map[CbPixelChannel].traits);
0106 }
0107 
0108 static inline Quantum GetPixelChannel(const Image *magick_restrict image,
0109   const PixelChannel channel,const Quantum *magick_restrict pixel)
0110 {
0111   if ((size_t) channel >= MaxPixelChannels)
0112     return((Quantum) 0);
0113   if (image->channel_map[channel].traits == UndefinedPixelTrait)
0114     return((Quantum) 0);
0115   return(pixel[image->channel_map[channel].offset]);
0116 }
0117 
0118 static inline PixelChannel GetPixelChannelChannel(
0119   const Image *magick_restrict image,const ssize_t offset)
0120 {
0121   if ((offset < 0) || (offset >= MaxPixelChannels))
0122     return(UndefinedPixelChannel);
0123   return(image->channel_map[offset].channel);
0124 }
0125 
0126 static inline ssize_t GetPixelChannelOffset(const Image *magick_restrict image,
0127   const PixelChannel channel)
0128 {
0129   return(image->channel_map[channel].offset);
0130 }
0131 
0132 static inline PixelTrait GetPixelChannelTraits(
0133   const Image *magick_restrict image,const PixelChannel channel)
0134 {
0135   if ((size_t) channel >= MaxPixelChannels)
0136     return(UndefinedPixelTrait);
0137   return(image->channel_map[channel].traits);
0138 }
0139 
0140 static inline size_t GetPixelChannels(const Image *magick_restrict image)
0141 {
0142   return(image->number_channels);
0143 }
0144 
0145 static inline Quantum GetPixelCompositeMask(
0146   const Image *magick_restrict image,const Quantum *magick_restrict pixel)
0147 {
0148   if (image->channel_map[CompositeMaskPixelChannel].traits == UndefinedPixelTrait)
0149     return((Quantum) QuantumRange);
0150   return(pixel[image->channel_map[CompositeMaskPixelChannel].offset]);
0151 }
0152 
0153 static inline PixelTrait GetPixelCompositeMaskTraits(
0154   const Image *magick_restrict image)
0155 {
0156   return(image->channel_map[CompositeMaskPixelChannel].traits);
0157 }
0158 
0159 static inline Quantum GetPixelCr(const Image *magick_restrict image,
0160   const Quantum *magick_restrict pixel)
0161 {
0162   return(pixel[image->channel_map[CrPixelChannel].offset]);
0163 }
0164 
0165 static inline PixelTrait GetPixelCrTraits(const Image *magick_restrict image)
0166 {
0167   return(image->channel_map[CrPixelChannel].traits);
0168 }
0169 
0170 static inline Quantum GetPixelCyan(const Image *magick_restrict image,
0171   const Quantum *magick_restrict pixel)
0172 {
0173   return(pixel[image->channel_map[CyanPixelChannel].offset]);
0174 }
0175 
0176 static inline PixelTrait GetPixelCyanTraits(const Image *magick_restrict image)
0177 {
0178   return(image->channel_map[CyanPixelChannel].traits);
0179 }
0180 
0181 static inline Quantum GetPixelGray(const Image *magick_restrict image,
0182   const Quantum *magick_restrict pixel)
0183 {
0184   return(pixel[image->channel_map[GrayPixelChannel].offset]);
0185 }
0186 
0187 static inline PixelTrait GetPixelGrayTraits(const Image *magick_restrict image)
0188 {
0189   return(image->channel_map[GrayPixelChannel].traits);
0190 }
0191 
0192 static inline Quantum GetPixelGreen(const Image *magick_restrict image,
0193   const Quantum *magick_restrict pixel)
0194 {
0195   return(pixel[image->channel_map[GreenPixelChannel].offset]);
0196 }
0197 
0198 static inline PixelTrait GetPixelGreenTraits(const Image *magick_restrict image)
0199 {
0200   return(image->channel_map[GreenPixelChannel].traits);
0201 }
0202 
0203 static inline Quantum GetPixelIndex(const Image *magick_restrict image,
0204   const Quantum *magick_restrict pixel)
0205 {
0206   if (image->channel_map[IndexPixelChannel].traits == UndefinedPixelTrait)
0207     return((Quantum) 0);
0208   return(pixel[image->channel_map[IndexPixelChannel].offset]);
0209 }
0210 
0211 static inline PixelTrait GetPixelIndexTraits(const Image *magick_restrict image)
0212 {
0213   return(image->channel_map[IndexPixelChannel].traits);
0214 }
0215 
0216 static inline MagickRealType GetPixelInfoChannel(
0217   const PixelInfo *magick_restrict pixel_info,const PixelChannel channel)
0218 {
0219   switch (channel)
0220   {
0221     case RedPixelChannel: return(pixel_info->red);
0222     case GreenPixelChannel: return(pixel_info->green);
0223     case BluePixelChannel: return(pixel_info->blue);
0224     case BlackPixelChannel:
0225     {
0226       if (pixel_info->colorspace != CMYKColorspace)
0227         return(0.0);
0228       return(pixel_info->black);
0229     }
0230     case AlphaPixelChannel:
0231     {
0232       if (pixel_info->alpha_trait == UndefinedPixelTrait)
0233         return(OpaqueAlpha);
0234       return(pixel_info->alpha);
0235     }
0236     case IndexPixelChannel: return(pixel_info->index);
0237     default: break;
0238   }
0239   return((MagickRealType) 0.0);
0240 }
0241 
0242 static inline double PerceptibleReciprocal(const double x)
0243 {
0244   double
0245     sign;
0246 
0247   /*
0248     Return 1/x where x is perceptible (not unlimited or infinitesimal).
0249   */
0250   sign=x < 0.0 ? -1.0 : 1.0;
0251   if ((sign*x) >= MagickEpsilon)
0252     return(1.0/x);
0253   return(sign/MagickEpsilon);
0254 }
0255 
0256 static inline MagickRealType GetPixelInfoLuma(
0257   const PixelInfo *magick_restrict pixel)
0258 {
0259   MagickRealType
0260     intensity;
0261 
0262   if (pixel->colorspace == sRGBColorspace)
0263     {
0264       intensity=(MagickRealType) (0.212656*pixel->red+0.715158*pixel->green+
0265         0.072186*pixel->blue);
0266       return(intensity);
0267     }
0268   intensity=(MagickRealType) (0.212656*EncodePixelGamma(pixel->red)+
0269     0.715158*EncodePixelGamma(pixel->green)+
0270     0.072186*EncodePixelGamma(pixel->blue));
0271   return(intensity);
0272 }
0273 
0274 static inline MagickRealType GetPixelInfoLuminance(
0275   const PixelInfo *magick_restrict pixel)
0276 {
0277   MagickRealType
0278     intensity;
0279 
0280   if (pixel->colorspace != sRGBColorspace)
0281     {
0282       intensity=(MagickRealType) (0.212656*pixel->red+0.715158*pixel->green+
0283         0.072186*pixel->blue);
0284       return(intensity);
0285     }
0286   intensity=(MagickRealType) (0.212656*DecodePixelGamma(pixel->red)+
0287     0.715158*DecodePixelGamma(pixel->green)+
0288     0.072186*DecodePixelGamma(pixel->blue));
0289   return(intensity);
0290 }
0291 
0292 static inline Quantum GetPixelL(const Image *magick_restrict image,
0293   const Quantum *magick_restrict pixel)
0294 {
0295   return(pixel[image->channel_map[LPixelChannel].offset]);
0296 }
0297 
0298 static inline ssize_t GetPixelLabel(const Image *magick_restrict image,
0299   const Quantum *magick_restrict pixel)
0300 {
0301   return((ssize_t) pixel[image->channel_map[LabelPixelChannel].offset]);
0302 }
0303 
0304 static inline MagickRealType GetPixelLuma(
0305   const Image *magick_restrict image,const Quantum *magick_restrict pixel)
0306 {
0307   MagickRealType
0308     intensity;
0309 
0310   intensity=
0311     0.212656*(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]+
0312     0.715158*(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]+
0313     0.072186*(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
0314   return(intensity);
0315 }
0316 
0317 static inline MagickRealType GetPixelLuminance(
0318   const Image *magick_restrict image,const Quantum *magick_restrict pixel)
0319 {
0320   MagickRealType
0321     intensity;
0322 
0323   if (image->colorspace != sRGBColorspace)
0324     {
0325       intensity=
0326         0.212656*(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]+
0327         0.715158*(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]+
0328         0.072186*(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
0329       return(intensity);
0330     }
0331   intensity=(MagickRealType) (0.212656*DecodePixelGamma((MagickRealType)
0332     pixel[image->channel_map[RedPixelChannel].offset])+0.715158*
0333     DecodePixelGamma((MagickRealType)
0334     pixel[image->channel_map[GreenPixelChannel].offset])+0.072186*
0335     DecodePixelGamma((MagickRealType)
0336     pixel[image->channel_map[BluePixelChannel].offset]));
0337   return(intensity);
0338 }
0339 
0340 static inline Quantum GetPixelMagenta(const Image *magick_restrict image,
0341   const Quantum *magick_restrict pixel)
0342 {
0343   return(pixel[image->channel_map[MagentaPixelChannel].offset]);
0344 }
0345 
0346 static inline PixelTrait GetPixelMagentaTraits(
0347   const Image *magick_restrict image)
0348 {
0349   return(image->channel_map[MagentaPixelChannel].traits);
0350 }
0351 
0352 static inline Quantum GetPixelMeta(const Image *magick_restrict image,
0353   const Quantum *magick_restrict pixel)
0354 {
0355   if (image->channel_map[MetaPixelChannels].traits == UndefinedPixelTrait)
0356     return(OpaqueAlpha);
0357   return(pixel[image->channel_map[MetaPixelChannels].offset]);
0358 }
0359 
0360 static inline PixelTrait GetPixelMetaTraits(const Image *magick_restrict image)
0361 {
0362   return(image->channel_map[MetaPixelChannels].traits);
0363 }
0364 
0365 static inline Quantum GetPixelReadMask(const Image *magick_restrict image,
0366   const Quantum *magick_restrict pixel)
0367 {
0368   if (image->channel_map[ReadMaskPixelChannel].traits == UndefinedPixelTrait)
0369     return((Quantum) QuantumRange);
0370   return(pixel[image->channel_map[ReadMaskPixelChannel].offset]);
0371 }
0372 
0373 static inline void GetPixelInfoRGBA(const Quantum red,const Quantum green,
0374   const Quantum blue,const Quantum alpha,PixelInfo *magick_restrict pixel)
0375 {
0376   GetPixelInfo((Image *) NULL,pixel);
0377   pixel->red=red;
0378   pixel->green=green;
0379   pixel->blue=blue;
0380   pixel->alpha=alpha;
0381 }
0382 
0383 static inline Quantum GetPixelWriteMask(
0384   const Image *magick_restrict image,const Quantum *magick_restrict pixel)
0385 {
0386   if (image->channel_map[WriteMaskPixelChannel].traits == UndefinedPixelTrait)
0387     return((Quantum) QuantumRange);
0388   return(pixel[image->channel_map[WriteMaskPixelChannel].offset]);
0389 }
0390 
0391 static inline PixelTrait GetPixelReadMaskTraits(
0392   const Image *magick_restrict image)
0393 {
0394   return(image->channel_map[ReadMaskPixelChannel].traits);
0395 }
0396 
0397 static inline size_t GetPixelMetaChannels(const Image *magick_restrict image)
0398 {
0399   return(image->number_meta_channels);
0400 }
0401 
0402 static inline size_t GetPixelMetacontentExtent(
0403   const Image *magick_restrict image)
0404 {
0405   return(image->metacontent_extent);
0406 }
0407 
0408 static inline Quantum GetPixelOpacity(const Image *magick_restrict image,
0409   const Quantum *magick_restrict pixel)
0410 {
0411   if (image->channel_map[AlphaPixelChannel].traits != BlendPixelTrait)
0412     return(QuantumRange-OpaqueAlpha);
0413   return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
0414 }
0415 
0416 static inline Quantum GetPixelRed(const Image *magick_restrict image,
0417   const Quantum *magick_restrict pixel)
0418 {
0419   return(pixel[image->channel_map[RedPixelChannel].offset]);
0420 }
0421 
0422 static inline PixelTrait GetPixelRedTraits(const Image *magick_restrict image)
0423 {
0424   return(image->channel_map[RedPixelChannel].traits);
0425 }
0426 
0427 static inline void GetPixelInfoPixel(const Image *magick_restrict image,
0428   const Quantum *magick_restrict pixel,PixelInfo *magick_restrict pixel_info)
0429 {
0430   (void) ResetMagickMemory(pixel_info,0,sizeof(*pixel_info));
0431   pixel_info->storage_class=DirectClass;
0432   pixel_info->colorspace=sRGBColorspace;
0433   pixel_info->depth=MAGICKCORE_QUANTUM_DEPTH;
0434   pixel_info->alpha_trait=UndefinedPixelTrait;
0435   pixel_info->alpha=(MagickRealType) OpaqueAlpha;
0436   if (image != (Image *) NULL)
0437     {
0438       pixel_info->storage_class=image->storage_class;
0439       pixel_info->colorspace=image->colorspace;
0440       pixel_info->fuzz=image->fuzz;
0441       pixel_info->depth=image->depth;
0442       pixel_info->alpha_trait=image->alpha_trait;
0443       if (pixel != (Quantum *) NULL)
0444         {
0445           pixel_info->red=(MagickRealType)
0446             pixel[image->channel_map[RedPixelChannel].offset];
0447           pixel_info->green=(MagickRealType)
0448             pixel[image->channel_map[GreenPixelChannel].offset];
0449           pixel_info->blue=(MagickRealType)
0450             pixel[image->channel_map[BluePixelChannel].offset];
0451           if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
0452             pixel_info->black=(MagickRealType)
0453               pixel[image->channel_map[BlackPixelChannel].offset];
0454           if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
0455             pixel_info->alpha=(MagickRealType)
0456               pixel[image->channel_map[AlphaPixelChannel].offset];
0457           if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
0458             pixel_info->index=(MagickRealType)
0459               pixel[image->channel_map[IndexPixelChannel].offset];
0460         }
0461     }
0462 }
0463 
0464 static inline PixelTrait GetPixelTraits(const Image *magick_restrict image,
0465   const PixelChannel channel)
0466 {
0467   if ((size_t) channel >= MaxPixelChannels)
0468     return(UndefinedPixelTrait);
0469   return(image->channel_map[channel].traits);
0470 }
0471 
0472 static inline PixelTrait GetPixelWriteMaskTraits(
0473   const Image *magick_restrict image)
0474 {
0475   return(image->channel_map[WriteMaskPixelChannel].traits);
0476 }
0477 
0478 static inline Quantum GetPixelY(const Image *magick_restrict image,
0479   const Quantum *magick_restrict pixel)
0480 {
0481   return(pixel[image->channel_map[YPixelChannel].offset]);
0482 }
0483 
0484 static inline PixelTrait GetPixelYTraits(const Image *magick_restrict image)
0485 {
0486   return(image->channel_map[YPixelChannel].traits);
0487 }
0488 
0489 static inline Quantum GetPixelYellow(const Image *magick_restrict image,
0490   const Quantum *magick_restrict pixel)
0491 {
0492   return(pixel[image->channel_map[YellowPixelChannel].offset]);
0493 }
0494 
0495 static inline PixelTrait GetPixelYellowTraits(
0496   const Image *magick_restrict image)
0497 {
0498   return(image->channel_map[YellowPixelChannel].traits);
0499 }
0500 
0501 static inline MagickRealType AbsolutePixelValue(const MagickRealType x)
0502 {
0503   return(x < 0.0 ? -x : x);
0504 }
0505 
0506 static inline MagickBooleanType IsPixelAtDepth(const Quantum pixel,
0507   const QuantumAny range)
0508 {
0509   Quantum
0510     quantum;
0511 
0512   if (range == 0)
0513     return(MagickTrue);
0514 #if !defined(MAGICKCORE_HDRI_SUPPORT)
0515   quantum=(Quantum) (((double) QuantumRange*((QuantumAny) (((double) range*
0516     pixel)/(double) QuantumRange+0.5)))/(double) range+0.5);
0517 #else
0518   quantum=(Quantum) (((double) QuantumRange*((QuantumAny) (((double) range*
0519     (double) pixel)/(double) QuantumRange+0.5)))/(double) range);
0520 #endif
0521   return(pixel == quantum ? MagickTrue : MagickFalse);
0522 }
0523 
0524 static inline MagickBooleanType IsPixelEquivalent(
0525   const Image *magick_restrict image,const Quantum *magick_restrict p,
0526   const PixelInfo *magick_restrict q)
0527 {
0528   MagickRealType
0529     alpha,
0530     beta,
0531     color;
0532 
0533   color=(MagickRealType) p[image->channel_map[AlphaPixelChannel].offset];
0534   alpha=image->alpha_trait == UndefinedPixelTrait ? (MagickRealType)
0535     OpaqueAlpha : color;
0536   beta=q->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
0537     q->alpha;
0538   if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
0539     return(MagickFalse);
0540   if ((AbsolutePixelValue(alpha-(MagickRealType) TransparentAlpha) < MagickEpsilon) ||
0541       (AbsolutePixelValue(beta-(MagickRealType) TransparentAlpha) < MagickEpsilon))
0542     return(MagickTrue);  /* no color component if pixel is transparent */
0543   color=(MagickRealType) p[image->channel_map[RedPixelChannel].offset];
0544   if (AbsolutePixelValue(color-q->red) >= MagickEpsilon)
0545     return(MagickFalse);
0546   color=(MagickRealType) p[image->channel_map[GreenPixelChannel].offset];
0547   if (AbsolutePixelValue(color-q->green) >= MagickEpsilon)
0548     return(MagickFalse);
0549   color=(MagickRealType) p[image->channel_map[BluePixelChannel].offset];
0550   if (AbsolutePixelValue(color-q->blue) >= MagickEpsilon)
0551     return(MagickFalse);
0552   if (image->colorspace == CMYKColorspace)
0553     {
0554       color=(MagickRealType) p[image->channel_map[BlackPixelChannel].offset];
0555       if (AbsolutePixelValue(color-q->black) >= MagickEpsilon)
0556         return(MagickFalse);
0557     }
0558   return(MagickTrue);
0559 }
0560 
0561 static inline MagickBooleanType IsPixelGray(const Image *magick_restrict image,
0562   const Quantum *magick_restrict pixel)
0563 {
0564   MagickRealType
0565     green_blue,
0566     red_green;
0567 
0568   red_green=
0569     (MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
0570     (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
0571   green_blue=
0572     (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]-
0573     (MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
0574   if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
0575       (AbsolutePixelValue(green_blue) < MagickEpsilon))
0576     return(MagickTrue);
0577   return(MagickFalse);
0578 }
0579 
0580 static inline MagickBooleanType IsPixelInfoEquivalent(
0581   const PixelInfo *magick_restrict p,const PixelInfo *magick_restrict q)
0582 {
0583   MagickRealType
0584     alpha,
0585     beta;
0586 
0587   alpha=p->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
0588     p->alpha;
0589   beta=q->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
0590     q->alpha;
0591   if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
0592     return(MagickFalse);
0593   if ((AbsolutePixelValue(alpha-(MagickRealType) TransparentAlpha) < MagickEpsilon) ||
0594       (AbsolutePixelValue(beta-(MagickRealType) TransparentAlpha) < MagickEpsilon))
0595     return(MagickTrue);  /* no color component if pixel is transparent */
0596   if (AbsolutePixelValue(p->red-q->red) >= MagickEpsilon)
0597     return(MagickFalse);
0598   if (AbsolutePixelValue(p->green-q->green) >= MagickEpsilon)
0599     return(MagickFalse);
0600   if (AbsolutePixelValue(p->blue-q->blue) >= MagickEpsilon)
0601     return(MagickFalse);
0602   if (p->colorspace == CMYKColorspace)
0603     {
0604       if (AbsolutePixelValue(p->black-q->black) >= MagickEpsilon)
0605         return(MagickFalse);
0606     }
0607   return(MagickTrue);
0608 }
0609 
0610 static inline MagickBooleanType IsPixelMonochrome(
0611   const Image *magick_restrict image,const Quantum *magick_restrict pixel)
0612 {
0613   MagickRealType
0614     green_blue,
0615     red,
0616     red_green;
0617 
0618   red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
0619   if ((AbsolutePixelValue(red) >= MagickEpsilon) &&
0620       (AbsolutePixelValue(red-(MagickRealType) QuantumRange) >= MagickEpsilon))
0621     return(MagickFalse);
0622   red_green=
0623     (MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
0624     (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
0625   green_blue=
0626     (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]-
0627     (MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
0628   if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
0629       (AbsolutePixelValue(green_blue) < MagickEpsilon))
0630     return(MagickTrue);
0631   return(MagickFalse);
0632 }
0633 
0634 static inline MagickBooleanType IsPixelInfoGray(
0635   const PixelInfo *magick_restrict pixel)
0636 {
0637   if ((AbsolutePixelValue(pixel->red-pixel->green) < MagickEpsilon) &&
0638       (AbsolutePixelValue(pixel->green-pixel->blue) < MagickEpsilon))
0639     return(MagickTrue);
0640   return(MagickFalse);
0641 }
0642 
0643 static inline MagickBooleanType IsPixelInfoMonochrome(
0644   const PixelInfo *magick_restrict pixel_info)
0645 {
0646   MagickRealType
0647     green_blue,
0648     red_green;
0649 
0650   if ((AbsolutePixelValue(pixel_info->red) >= MagickEpsilon) ||
0651       (AbsolutePixelValue(pixel_info->red-(MagickRealType) QuantumRange) >= MagickEpsilon))
0652     return(MagickFalse);
0653   red_green=pixel_info->red-pixel_info->green;
0654   green_blue=pixel_info->green-pixel_info->blue;
0655   if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
0656       (AbsolutePixelValue(green_blue) < MagickEpsilon))
0657     return(MagickTrue);
0658   return(MagickFalse);
0659 }
0660 
0661 static inline void SetPixela(const Image *magick_restrict image,
0662   const Quantum a,Quantum *magick_restrict pixel)
0663 {
0664   if (image->channel_map[aPixelChannel].traits != UndefinedPixelTrait)
0665     pixel[image->channel_map[aPixelChannel].offset]=a;
0666 }
0667 
0668 static inline void SetPixelAlpha(const Image *magick_restrict image,
0669   const Quantum alpha,Quantum *magick_restrict pixel)
0670 {
0671   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
0672     pixel[image->channel_map[AlphaPixelChannel].offset]=alpha;
0673 }
0674 
0675 static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
0676 {
0677   image->channel_map[AlphaPixelChannel].traits=traits;
0678 }
0679 
0680 static inline void SetPixelb(const Image *magick_restrict image,
0681   const Quantum b,Quantum *magick_restrict pixel)
0682 {
0683   if (image->channel_map[bPixelChannel].traits != UndefinedPixelTrait)
0684     pixel[image->channel_map[bPixelChannel].offset]=b;
0685 }
0686 
0687 static inline void SetPixelBackgroundColor(const Image *magick_restrict image,
0688   Quantum *magick_restrict pixel)
0689 {
0690   ssize_t
0691     i;
0692 
0693   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
0694     pixel[i]=(Quantum) 0;
0695   pixel[image->channel_map[RedPixelChannel].offset]=
0696     ClampToQuantum(image->background_color.red);
0697   pixel[image->channel_map[GreenPixelChannel].offset]=
0698     ClampToQuantum(image->background_color.green);
0699   pixel[image->channel_map[BluePixelChannel].offset]=
0700     ClampToQuantum(image->background_color.blue);
0701   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
0702     pixel[image->channel_map[BlackPixelChannel].offset]=
0703       ClampToQuantum(image->background_color.black);
0704   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
0705     pixel[image->channel_map[AlphaPixelChannel].offset]=
0706       image->background_color.alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
0707       ClampToQuantum(image->background_color.alpha);
0708 }
0709 
0710 static inline void SetPixelBackgoundColor(const Image *magick_restrict image,
0711   Quantum *magick_restrict pixel) magick_attribute((deprecated));
0712 
0713 static inline void SetPixelBackgoundColor(const Image *magick_restrict image,
0714   Quantum *magick_restrict pixel)
0715 {
0716   SetPixelBackgroundColor(image,pixel);
0717 }
0718 
0719 static inline void SetPixelBlack(const Image *magick_restrict image,
0720   const Quantum black,Quantum *magick_restrict pixel)
0721 {
0722   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
0723     pixel[image->channel_map[BlackPixelChannel].offset]=black;
0724 }
0725 
0726 static inline void SetPixelBlackTraits(Image *image,const PixelTrait traits)
0727 {
0728   image->channel_map[BlackPixelChannel].traits=traits;
0729 }
0730 
0731 static inline void SetPixelBlue(const Image *magick_restrict image,
0732   const Quantum blue,Quantum *magick_restrict pixel)
0733 {
0734   pixel[image->channel_map[BluePixelChannel].offset]=blue;
0735 }
0736 
0737 static inline void SetPixelBlueTraits(Image *image,const PixelTrait traits)
0738 {
0739   image->channel_map[BluePixelChannel].traits=traits;
0740 }
0741 
0742 static inline void SetPixelCb(const Image *magick_restrict image,
0743   const Quantum cb,Quantum *magick_restrict pixel)
0744 {
0745   pixel[image->channel_map[CbPixelChannel].offset]=cb;
0746 }
0747 
0748 static inline void SetPixelCbTraits(Image *image,const PixelTrait traits)
0749 {
0750   image->channel_map[CbPixelChannel].traits=traits;
0751 }
0752 
0753 static inline void SetPixelChannel(const Image *magick_restrict image,
0754   const PixelChannel channel,const Quantum quantum,
0755   Quantum *magick_restrict pixel)
0756 {
0757   if ((size_t) channel >= MaxPixelChannels)
0758     return;
0759   if (image->channel_map[channel].traits != UndefinedPixelTrait)
0760     pixel[image->channel_map[channel].offset]=quantum;
0761 }
0762 
0763 static inline void SetPixelChannelAttributes(
0764   const Image *magick_restrict image,const PixelChannel channel,
0765   const PixelTrait traits,const ssize_t offset)
0766 {
0767   if ((offset < 0) || (offset >= MaxPixelChannels))
0768     return;
0769   if ((size_t) channel >= MaxPixelChannels)
0770     return;
0771   image->channel_map[offset].channel=channel;
0772   image->channel_map[channel].offset=offset;
0773   image->channel_map[channel].traits=traits;
0774 }
0775 
0776 static inline void SetPixelChannelChannel(const Image *magick_restrict image,
0777   const PixelChannel channel,const ssize_t offset)
0778 {
0779   if ((offset < 0) || (offset >= MaxPixelChannels))
0780     return;
0781   if ((size_t) channel >= MaxPixelChannels)
0782     return;
0783   image->channel_map[offset].channel=channel;
0784   image->channel_map[channel].offset=offset;
0785 }
0786 
0787 static inline void SetPixelChannels(Image *image,const size_t number_channels)
0788 {
0789   image->number_channels=number_channels;
0790 }
0791 
0792 static inline void SetPixelChannelTraits(Image *image,
0793   const PixelChannel channel,const PixelTrait traits)
0794 {
0795   if ((size_t) channel >= MaxPixelChannels)
0796     return;
0797   image->channel_map[channel].traits=traits;
0798 }
0799 
0800 static inline void SetPixelCompositeMask(const Image *magick_restrict image,
0801   const Quantum mask,Quantum *magick_restrict pixel)
0802 {
0803   if (image->channel_map[CompositeMaskPixelChannel].traits != UndefinedPixelTrait)
0804     pixel[image->channel_map[CompositeMaskPixelChannel].offset]=mask;
0805 }
0806 
0807 static inline void SetPixelCr(const Image *magick_restrict image,
0808   const Quantum cr,Quantum *magick_restrict pixel)
0809 {
0810   pixel[image->channel_map[CrPixelChannel].offset]=cr;
0811 }
0812 
0813 static inline void SetPixelCrTraits(Image *image,const PixelTrait traits)
0814 {
0815   image->channel_map[CrPixelChannel].traits=traits;
0816 }
0817 
0818 static inline void SetPixelCyan(const Image *magick_restrict image,
0819   const Quantum cyan,Quantum *magick_restrict pixel)
0820 {
0821   pixel[image->channel_map[CyanPixelChannel].offset]=cyan;
0822 }
0823 
0824 static inline void SetPixelGray(const Image *magick_restrict image,
0825   const Quantum gray,Quantum *magick_restrict pixel)
0826 {
0827   pixel[image->channel_map[GrayPixelChannel].offset]=gray;
0828 }
0829 
0830 static inline void SetPixelGrayTraits(Image *image,const PixelTrait traits)
0831 {
0832   image->channel_map[GrayPixelChannel].traits=traits;
0833 }
0834 
0835 static inline void SetPixelGreen(const Image *magick_restrict image,
0836   const Quantum green,Quantum *magick_restrict pixel)
0837 {
0838   pixel[image->channel_map[GreenPixelChannel].offset]=green;
0839 }
0840 
0841 static inline void SetPixelGreenTraits(Image *image,const PixelTrait traits)
0842 {
0843   image->channel_map[GreenPixelChannel].traits=traits;
0844 }
0845 
0846 static inline void SetPixelIndex(const Image *magick_restrict image,
0847   const Quantum index,Quantum *magick_restrict pixel)
0848 {
0849   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
0850     pixel[image->channel_map[IndexPixelChannel].offset]=index;
0851 }
0852 
0853 static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
0854 {
0855   image->channel_map[IndexPixelChannel].traits=traits;
0856 }
0857 
0858 static inline void SetPixelViaPixelInfo(const Image *magick_restrict image,
0859   const PixelInfo *magick_restrict pixel_info,Quantum *magick_restrict pixel)
0860 {
0861   pixel[image->channel_map[RedPixelChannel].offset]=
0862     ClampToQuantum(pixel_info->red);
0863   pixel[image->channel_map[GreenPixelChannel].offset]=
0864     ClampToQuantum(pixel_info->green);
0865   pixel[image->channel_map[BluePixelChannel].offset]=
0866     ClampToQuantum(pixel_info->blue);
0867   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
0868     pixel[image->channel_map[BlackPixelChannel].offset]=
0869       ClampToQuantum(pixel_info->black);
0870   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
0871     pixel[image->channel_map[AlphaPixelChannel].offset]=
0872       pixel_info->alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
0873       ClampToQuantum(pixel_info->alpha);
0874 }
0875 
0876 static inline void SetPixelL(const Image *magick_restrict image,const Quantum L,
0877   Quantum *magick_restrict pixel)
0878 {
0879   if (image->channel_map[LPixelChannel].traits != UndefinedPixelTrait)
0880     pixel[image->channel_map[LPixelChannel].offset]=L;
0881 }
0882 
0883 static inline void SetPixelMagenta(const Image *magick_restrict image,
0884   const Quantum magenta,Quantum *magick_restrict pixel)
0885 {
0886   pixel[image->channel_map[MagentaPixelChannel].offset]=magenta;
0887 }
0888 
0889 static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
0890 {
0891   image->channel_map[MagentaPixelChannel].traits=traits;
0892 }
0893 
0894 static inline void SetPixelMeta(const Image *magick_restrict image,
0895   const Quantum red,Quantum *magick_restrict pixel)
0896 {
0897   pixel[image->channel_map[MetaPixelChannels].offset]=red;
0898 }
0899 
0900 static inline void SetPixelMetaTraits(Image *image,const PixelTrait traits)
0901 {
0902   image->channel_map[MetaPixelChannels].traits=traits;
0903 }
0904 
0905 static inline void SetPixelReadMask(const Image *magick_restrict image,
0906   const Quantum mask,Quantum *magick_restrict pixel)
0907 {
0908   if (image->channel_map[ReadMaskPixelChannel].traits != UndefinedPixelTrait)
0909     pixel[image->channel_map[ReadMaskPixelChannel].offset]=mask;
0910 }
0911 
0912 static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
0913 {
0914   image->metacontent_extent=extent;
0915 }
0916 
0917 static inline void SetPixelOpacity(const Image *magick_restrict image,
0918   const Quantum alpha,Quantum *magick_restrict pixel)
0919 {
0920   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
0921     pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
0922 }
0923 
0924 static inline void SetPixelRed(const Image *magick_restrict image,
0925   const Quantum red,Quantum *magick_restrict pixel)
0926 {
0927   pixel[image->channel_map[RedPixelChannel].offset]=red;
0928 }
0929 
0930 static inline void SetPixelRedTraits(Image *image,const PixelTrait traits)
0931 {
0932   image->channel_map[RedPixelChannel].traits=traits;
0933 }
0934 
0935 static inline void SetPixelWriteMask(const Image *magick_restrict image,
0936   const Quantum mask,Quantum *magick_restrict pixel)
0937 {
0938   if (image->channel_map[WriteMaskPixelChannel].traits != UndefinedPixelTrait)
0939     pixel[image->channel_map[WriteMaskPixelChannel].offset]=mask;
0940 }
0941 
0942 static inline void SetPixelYellow(const Image *magick_restrict image,
0943   const Quantum yellow,Quantum *magick_restrict pixel)
0944 {
0945   pixel[image->channel_map[YellowPixelChannel].offset]=yellow;
0946 }
0947 
0948 static inline void SetPixelYellowTraits(Image *image,const PixelTrait traits)
0949 {
0950   image->channel_map[YellowPixelChannel].traits=traits;
0951 }
0952 
0953 static inline void SetPixelY(const Image *magick_restrict image,
0954   const Quantum y,Quantum *magick_restrict pixel)
0955 {
0956   pixel[image->channel_map[YPixelChannel].offset]=y;
0957 }
0958 
0959 static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
0960 {
0961   image->channel_map[YPixelChannel].traits=traits;
0962 }
0963 
0964 #if defined(__cplusplus) || defined(c_plusplus)
0965 }
0966 #endif
0967 
0968 #endif