Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:23

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.0f)
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: return((MagickRealType) 0.0);
0238   }
0239 }
0240 
0241 static inline double PerceptibleReciprocal(const double x)
0242 {
0243   double
0244     sign;
0245 
0246   /*
0247     Return 1/x where x is perceptible (not unlimited or infinitesimal).
0248   */
0249   sign=x < 0.0 ? -1.0 : 1.0;
0250   if ((sign*x) >= MagickEpsilon)
0251     return(1.0/x);
0252   return(sign/MagickEpsilon);
0253 }
0254 
0255 static inline MagickRealType GetPixelInfoLuma(
0256   const PixelInfo *magick_restrict pixel)
0257 {
0258   MagickRealType
0259     intensity;
0260 
0261   if (pixel->colorspace == sRGBColorspace)
0262     {
0263       intensity=(MagickRealType) (0.212656f*pixel->red+0.715158f*pixel->green+
0264         0.072186f*pixel->blue);
0265       return(intensity);
0266     }
0267   intensity=(MagickRealType) (0.212656f*EncodePixelGamma(pixel->red)+
0268     0.715158f*EncodePixelGamma(pixel->green)+
0269     0.072186f*EncodePixelGamma(pixel->blue));
0270   return(intensity);
0271 }
0272 
0273 static inline MagickRealType GetPixelInfoLuminance(
0274   const PixelInfo *magick_restrict pixel)
0275 {
0276   MagickRealType
0277     intensity;
0278 
0279   if (pixel->colorspace != sRGBColorspace)
0280     {
0281       intensity=(MagickRealType) (0.212656f*pixel->red+0.715158f*pixel->green+
0282         0.072186f*pixel->blue);
0283       return(intensity);
0284     }
0285   intensity=(MagickRealType) (0.212656f*DecodePixelGamma(pixel->red)+
0286     0.715158f*DecodePixelGamma(pixel->green)+
0287     0.072186f*DecodePixelGamma(pixel->blue));
0288   return(intensity);
0289 }
0290 
0291 static inline Quantum GetPixelL(const Image *magick_restrict image,
0292   const Quantum *magick_restrict pixel)
0293 {
0294   return(pixel[image->channel_map[LPixelChannel].offset]);
0295 }
0296 
0297 static inline ssize_t GetPixelLabel(const Image *magick_restrict image,
0298   const Quantum *magick_restrict pixel)
0299 {
0300   return((ssize_t) pixel[image->channel_map[LabelPixelChannel].offset]);
0301 }
0302 
0303 static inline MagickRealType GetPixelLuma(
0304   const Image *magick_restrict image,const Quantum *magick_restrict pixel)
0305 {
0306   MagickRealType
0307     intensity;
0308 
0309   intensity=
0310     0.212656f*(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]+
0311     0.715158f*(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]+
0312     0.072186f*(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
0313   return(intensity);
0314 }
0315 
0316 static inline MagickRealType GetPixelLuminance(
0317   const Image *magick_restrict image,const Quantum *magick_restrict pixel)
0318 {
0319   MagickRealType
0320     intensity;
0321 
0322   if (image->colorspace != sRGBColorspace)
0323     {
0324       intensity=
0325         0.212656f*(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]+
0326         0.715158f*(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]+
0327         0.072186f*(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
0328       return(intensity);
0329     }
0330   intensity=(MagickRealType) (0.212656f*DecodePixelGamma((MagickRealType)
0331     pixel[image->channel_map[RedPixelChannel].offset])+0.715158f*
0332     DecodePixelGamma((MagickRealType)
0333     pixel[image->channel_map[GreenPixelChannel].offset])+0.072186f*
0334     DecodePixelGamma((MagickRealType)
0335     pixel[image->channel_map[BluePixelChannel].offset]));
0336   return(intensity);
0337 }
0338 
0339 static inline Quantum GetPixelMagenta(const Image *magick_restrict image,
0340   const Quantum *magick_restrict pixel)
0341 {
0342   return(pixel[image->channel_map[MagentaPixelChannel].offset]);
0343 }
0344 
0345 static inline PixelTrait GetPixelMagentaTraits(
0346   const Image *magick_restrict image)
0347 {
0348   return(image->channel_map[MagentaPixelChannel].traits);
0349 }
0350 
0351 static inline Quantum GetPixelMeta(const Image *magick_restrict image,
0352   const Quantum *magick_restrict pixel)
0353 {
0354   if (image->channel_map[MetaPixelChannels].traits == UndefinedPixelTrait)
0355     return(OpaqueAlpha);
0356   return(pixel[image->channel_map[MetaPixelChannels].offset]);
0357 }
0358 
0359 static inline PixelTrait GetPixelMetaTraits(const Image *magick_restrict image)
0360 {
0361   return(image->channel_map[MetaPixelChannels].traits);
0362 }
0363 
0364 static inline Quantum GetPixelReadMask(const Image *magick_restrict image,
0365   const Quantum *magick_restrict pixel)
0366 {
0367   if (image->channel_map[ReadMaskPixelChannel].traits == UndefinedPixelTrait)
0368     return((Quantum) QuantumRange);
0369   return(pixel[image->channel_map[ReadMaskPixelChannel].offset]);
0370 }
0371 
0372 static inline void GetPixelInfoRGBA(const Quantum red,const Quantum green,
0373   const Quantum blue,const Quantum alpha,PixelInfo *magick_restrict pixel)
0374 {
0375   GetPixelInfo((Image *) NULL,pixel);
0376   pixel->red=red;
0377   pixel->green=green;
0378   pixel->blue=blue;
0379   pixel->alpha=alpha;
0380 }
0381 
0382 static inline Quantum GetPixelWriteMask(
0383   const Image *magick_restrict image,const Quantum *magick_restrict pixel)
0384 {
0385   if (image->channel_map[WriteMaskPixelChannel].traits == UndefinedPixelTrait)
0386     return((Quantum) QuantumRange);
0387   return(pixel[image->channel_map[WriteMaskPixelChannel].offset]);
0388 }
0389 
0390 static inline PixelTrait GetPixelReadMaskTraits(
0391   const Image *magick_restrict image)
0392 {
0393   return(image->channel_map[ReadMaskPixelChannel].traits);
0394 }
0395 
0396 static inline size_t GetPixelMetaChannels(const Image *magick_restrict image)
0397 {
0398   return(image->number_meta_channels);
0399 }
0400 
0401 static inline size_t GetPixelMetacontentExtent(
0402   const Image *magick_restrict image)
0403 {
0404   return(image->metacontent_extent);
0405 }
0406 
0407 static inline Quantum GetPixelOpacity(const Image *magick_restrict image,
0408   const Quantum *magick_restrict pixel)
0409 {
0410   if (image->channel_map[AlphaPixelChannel].traits != BlendPixelTrait)
0411     return(QuantumRange-OpaqueAlpha);
0412   return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
0413 }
0414 
0415 static inline Quantum GetPixelRed(const Image *magick_restrict image,
0416   const Quantum *magick_restrict pixel)
0417 {
0418   return(pixel[image->channel_map[RedPixelChannel].offset]);
0419 }
0420 
0421 static inline PixelTrait GetPixelRedTraits(const Image *magick_restrict image)
0422 {
0423   return(image->channel_map[RedPixelChannel].traits);
0424 }
0425 
0426 static inline void GetPixelInfoPixel(const Image *magick_restrict image,
0427   const Quantum *magick_restrict pixel,PixelInfo *magick_restrict pixel_info)
0428 {
0429   (void) ResetMagickMemory(pixel_info,0,sizeof(*pixel_info));
0430   pixel_info->storage_class=DirectClass;
0431   pixel_info->colorspace=sRGBColorspace;
0432   pixel_info->depth=MAGICKCORE_QUANTUM_DEPTH;
0433   pixel_info->alpha_trait=UndefinedPixelTrait;
0434   pixel_info->alpha=(MagickRealType) OpaqueAlpha;
0435   if (image != (Image *) NULL)
0436     {
0437       pixel_info->storage_class=image->storage_class;
0438       pixel_info->colorspace=image->colorspace;
0439       pixel_info->fuzz=image->fuzz;
0440       pixel_info->depth=image->depth;
0441       pixel_info->alpha_trait=image->alpha_trait;
0442       if (pixel != (Quantum *) NULL)
0443         {
0444           pixel_info->red=(MagickRealType)
0445             pixel[image->channel_map[RedPixelChannel].offset];
0446           pixel_info->green=(MagickRealType)
0447             pixel[image->channel_map[GreenPixelChannel].offset];
0448           pixel_info->blue=(MagickRealType)
0449             pixel[image->channel_map[BluePixelChannel].offset];
0450           if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
0451             pixel_info->black=(MagickRealType)
0452               pixel[image->channel_map[BlackPixelChannel].offset];
0453           if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
0454             pixel_info->alpha=(MagickRealType)
0455               pixel[image->channel_map[AlphaPixelChannel].offset];
0456           if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
0457             pixel_info->index=(MagickRealType)
0458               pixel[image->channel_map[IndexPixelChannel].offset];
0459         }
0460     }
0461 }
0462 
0463 static inline PixelTrait GetPixelTraits(const Image *magick_restrict image,
0464   const PixelChannel channel)
0465 {
0466   if ((size_t) channel >= MaxPixelChannels)
0467     return(UndefinedPixelTrait);
0468   return(image->channel_map[channel].traits);
0469 }
0470 
0471 static inline PixelTrait GetPixelWriteMaskTraits(
0472   const Image *magick_restrict image)
0473 {
0474   return(image->channel_map[WriteMaskPixelChannel].traits);
0475 }
0476 
0477 static inline Quantum GetPixelY(const Image *magick_restrict image,
0478   const Quantum *magick_restrict pixel)
0479 {
0480   return(pixel[image->channel_map[YPixelChannel].offset]);
0481 }
0482 
0483 static inline PixelTrait GetPixelYTraits(const Image *magick_restrict image)
0484 {
0485   return(image->channel_map[YPixelChannel].traits);
0486 }
0487 
0488 static inline Quantum GetPixelYellow(const Image *magick_restrict image,
0489   const Quantum *magick_restrict pixel)
0490 {
0491   return(pixel[image->channel_map[YellowPixelChannel].offset]);
0492 }
0493 
0494 static inline PixelTrait GetPixelYellowTraits(
0495   const Image *magick_restrict image)
0496 {
0497   return(image->channel_map[YellowPixelChannel].traits);
0498 }
0499 
0500 static inline MagickRealType AbsolutePixelValue(const MagickRealType x)
0501 {
0502   return(x < 0.0f ? -x : x);
0503 }
0504 
0505 static inline MagickBooleanType IsPixelAtDepth(const Quantum pixel,
0506   const QuantumAny range)
0507 {
0508   Quantum
0509     quantum;
0510 
0511   if (range == 0)
0512     return(MagickTrue);
0513 #if !defined(MAGICKCORE_HDRI_SUPPORT)
0514   quantum=(Quantum) (((MagickRealType) QuantumRange*((QuantumAny)
0515     (((MagickRealType) range*pixel)/QuantumRange+0.5)))/range+0.5);
0516 #else
0517   quantum=(Quantum) (((MagickRealType) QuantumRange*((QuantumAny)
0518     (((MagickRealType) range*pixel)/QuantumRange+0.5)))/(MagickRealType) range);
0519 #endif
0520   return(pixel == quantum ? MagickTrue : MagickFalse);
0521 }
0522 
0523 static inline MagickBooleanType IsPixelEquivalent(
0524   const Image *magick_restrict image,const Quantum *magick_restrict p,
0525   const PixelInfo *magick_restrict q)
0526 {
0527   MagickRealType
0528     alpha,
0529     beta,
0530     color;
0531 
0532   color=(MagickRealType) p[image->channel_map[AlphaPixelChannel].offset];
0533   alpha=image->alpha_trait == UndefinedPixelTrait ? (MagickRealType)
0534     OpaqueAlpha : color;
0535   beta=q->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
0536     q->alpha;
0537   if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
0538     return(MagickFalse);
0539   if ((AbsolutePixelValue(alpha-TransparentAlpha) < MagickEpsilon) ||
0540       (AbsolutePixelValue(beta-TransparentAlpha) < MagickEpsilon))
0541     return(MagickTrue);  /* no color component if pixel is transparent */
0542   color=(MagickRealType) p[image->channel_map[RedPixelChannel].offset];
0543   if (AbsolutePixelValue(color-q->red) >= MagickEpsilon)
0544     return(MagickFalse);
0545   color=(MagickRealType) p[image->channel_map[GreenPixelChannel].offset];
0546   if (AbsolutePixelValue(color-q->green) >= MagickEpsilon)
0547     return(MagickFalse);
0548   color=(MagickRealType) p[image->channel_map[BluePixelChannel].offset];
0549   if (AbsolutePixelValue(color-q->blue) >= MagickEpsilon)
0550     return(MagickFalse);
0551   if (image->colorspace == CMYKColorspace)
0552     {
0553       color=(MagickRealType) p[image->channel_map[BlackPixelChannel].offset];
0554       if (AbsolutePixelValue(color-q->black) >= MagickEpsilon)
0555         return(MagickFalse);
0556     }
0557   return(MagickTrue);
0558 }
0559 
0560 static inline MagickBooleanType IsPixelGray(const Image *magick_restrict image,
0561   const Quantum *magick_restrict pixel)
0562 {
0563   MagickRealType
0564     green_blue,
0565     red_green;
0566 
0567   red_green=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
0568     pixel[image->channel_map[GreenPixelChannel].offset];
0569   green_blue=(MagickRealType)
0570     pixel[image->channel_map[GreenPixelChannel].offset]-
0571     pixel[image->channel_map[BluePixelChannel].offset];
0572   if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
0573       (AbsolutePixelValue(green_blue) < MagickEpsilon))
0574     return(MagickTrue);
0575   return(MagickFalse);
0576 }
0577 
0578 static inline MagickBooleanType IsPixelInfoEquivalent(
0579   const PixelInfo *magick_restrict p,const PixelInfo *magick_restrict q)
0580 {
0581   MagickRealType
0582     alpha,
0583     beta;
0584 
0585   alpha=p->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
0586     p->alpha;
0587   beta=q->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
0588     q->alpha;
0589   if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
0590     return(MagickFalse);
0591   if ((AbsolutePixelValue(alpha-TransparentAlpha) < MagickEpsilon) ||
0592       (AbsolutePixelValue(beta-TransparentAlpha) < MagickEpsilon))
0593     return(MagickTrue);  /* no color component if pixel is transparent */
0594   if (AbsolutePixelValue(p->red-q->red) >= MagickEpsilon)
0595     return(MagickFalse);
0596   if (AbsolutePixelValue(p->green-q->green) >= MagickEpsilon)
0597     return(MagickFalse);
0598   if (AbsolutePixelValue(p->blue-q->blue) >= MagickEpsilon)
0599     return(MagickFalse);
0600   if (p->colorspace == CMYKColorspace)
0601     {
0602       if (AbsolutePixelValue(p->black-q->black) >= MagickEpsilon)
0603         return(MagickFalse);
0604     }
0605   return(MagickTrue);
0606 }
0607 
0608 static inline MagickBooleanType IsPixelMonochrome(
0609   const Image *magick_restrict image,const Quantum *magick_restrict pixel)
0610 {
0611   MagickRealType
0612     green_blue,
0613     red,
0614     red_green;
0615 
0616   red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
0617   if ((AbsolutePixelValue(red) >= MagickEpsilon) &&
0618       (AbsolutePixelValue(red-QuantumRange) >= MagickEpsilon))
0619     return(MagickFalse);
0620   red_green=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
0621     pixel[image->channel_map[GreenPixelChannel].offset];
0622   green_blue=(MagickRealType)
0623     pixel[image->channel_map[GreenPixelChannel].offset]-
0624     pixel[image->channel_map[BluePixelChannel].offset];
0625   if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
0626       (AbsolutePixelValue(green_blue) < MagickEpsilon))
0627     return(MagickTrue);
0628   return(MagickFalse);
0629 }
0630 
0631 static inline MagickBooleanType IsPixelInfoGray(
0632   const PixelInfo *magick_restrict pixel)
0633 {
0634   if ((AbsolutePixelValue(pixel->red-pixel->green) < MagickEpsilon) &&
0635       (AbsolutePixelValue(pixel->green-pixel->blue) < MagickEpsilon))
0636     return(MagickTrue);
0637   return(MagickFalse);
0638 }
0639 
0640 static inline MagickBooleanType IsPixelInfoMonochrome(
0641   const PixelInfo *magick_restrict pixel_info)
0642 {
0643   MagickRealType
0644     green_blue,
0645     red_green;
0646 
0647   if ((AbsolutePixelValue(pixel_info->red) >= MagickEpsilon) ||
0648       (AbsolutePixelValue(pixel_info->red-QuantumRange) >= MagickEpsilon))
0649     return(MagickFalse);
0650   red_green=pixel_info->red-pixel_info->green;
0651   green_blue=pixel_info->green-pixel_info->blue;
0652   if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
0653       (AbsolutePixelValue(green_blue) < MagickEpsilon))
0654     return(MagickTrue);
0655   return(MagickFalse);
0656 }
0657 
0658 static inline void SetPixela(const Image *magick_restrict image,
0659   const Quantum a,Quantum *magick_restrict pixel)
0660 {
0661   if (image->channel_map[aPixelChannel].traits != UndefinedPixelTrait)
0662     pixel[image->channel_map[aPixelChannel].offset]=a;
0663 }
0664 
0665 static inline void SetPixelAlpha(const Image *magick_restrict image,
0666   const Quantum alpha,Quantum *magick_restrict pixel)
0667 {
0668   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
0669     pixel[image->channel_map[AlphaPixelChannel].offset]=alpha;
0670 }
0671 
0672 static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
0673 {
0674   image->channel_map[AlphaPixelChannel].traits=traits;
0675 }
0676 
0677 static inline void SetPixelb(const Image *magick_restrict image,
0678   const Quantum b,Quantum *magick_restrict pixel)
0679 {
0680   if (image->channel_map[bPixelChannel].traits != UndefinedPixelTrait)
0681     pixel[image->channel_map[bPixelChannel].offset]=b;
0682 }
0683 
0684 static inline void SetPixelBackgroundColor(const Image *magick_restrict image,
0685   Quantum *magick_restrict pixel)
0686 {
0687   ssize_t
0688     i;
0689 
0690   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
0691     pixel[i]=(Quantum) 0;
0692   pixel[image->channel_map[RedPixelChannel].offset]=
0693     ClampToQuantum(image->background_color.red);
0694   pixel[image->channel_map[GreenPixelChannel].offset]=
0695     ClampToQuantum(image->background_color.green);
0696   pixel[image->channel_map[BluePixelChannel].offset]=
0697     ClampToQuantum(image->background_color.blue);
0698   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
0699     pixel[image->channel_map[BlackPixelChannel].offset]=
0700       ClampToQuantum(image->background_color.black);
0701   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
0702     pixel[image->channel_map[AlphaPixelChannel].offset]=
0703       image->background_color.alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
0704       ClampToQuantum(image->background_color.alpha);
0705 }
0706 
0707 static inline void SetPixelBackgoundColor(const Image *magick_restrict image,
0708   Quantum *magick_restrict pixel) magick_attribute((deprecated));
0709 
0710 static inline void SetPixelBackgoundColor(const Image *magick_restrict image,
0711   Quantum *magick_restrict pixel)
0712 {
0713   SetPixelBackgroundColor(image,pixel);
0714 }
0715 
0716 static inline void SetPixelBlack(const Image *magick_restrict image,
0717   const Quantum black,Quantum *magick_restrict pixel)
0718 {
0719   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
0720     pixel[image->channel_map[BlackPixelChannel].offset]=black;
0721 }
0722 
0723 static inline void SetPixelBlackTraits(Image *image,const PixelTrait traits)
0724 {
0725   image->channel_map[BlackPixelChannel].traits=traits;
0726 }
0727 
0728 static inline void SetPixelBlue(const Image *magick_restrict image,
0729   const Quantum blue,Quantum *magick_restrict pixel)
0730 {
0731   pixel[image->channel_map[BluePixelChannel].offset]=blue;
0732 }
0733 
0734 static inline void SetPixelBlueTraits(Image *image,const PixelTrait traits)
0735 {
0736   image->channel_map[BluePixelChannel].traits=traits;
0737 }
0738 
0739 static inline void SetPixelCb(const Image *magick_restrict image,
0740   const Quantum cb,Quantum *magick_restrict pixel)
0741 {
0742   pixel[image->channel_map[CbPixelChannel].offset]=cb;
0743 }
0744 
0745 static inline void SetPixelCbTraits(Image *image,const PixelTrait traits)
0746 {
0747   image->channel_map[CbPixelChannel].traits=traits;
0748 }
0749 
0750 static inline void SetPixelChannel(const Image *magick_restrict image,
0751   const PixelChannel channel,const Quantum quantum,
0752   Quantum *magick_restrict pixel)
0753 {
0754   if ((size_t) channel >= MaxPixelChannels)
0755     return;
0756   if (image->channel_map[channel].traits != UndefinedPixelTrait)
0757     pixel[image->channel_map[channel].offset]=quantum;
0758 }
0759 
0760 static inline void SetPixelChannelAttributes(
0761   const Image *magick_restrict image,const PixelChannel channel,
0762   const PixelTrait traits,const ssize_t offset)
0763 {
0764   if ((offset < 0) || (offset >= MaxPixelChannels))
0765     return;
0766   if ((size_t) channel >= MaxPixelChannels)
0767     return;
0768   image->channel_map[offset].channel=channel;
0769   image->channel_map[channel].offset=offset;
0770   image->channel_map[channel].traits=traits;
0771 }
0772 
0773 static inline void SetPixelChannelChannel(const Image *magick_restrict image,
0774   const PixelChannel channel,const ssize_t offset)
0775 {
0776   if ((offset < 0) || (offset >= MaxPixelChannels))
0777     return;
0778   if ((size_t) channel >= MaxPixelChannels)
0779     return;
0780   image->channel_map[offset].channel=channel;
0781   image->channel_map[channel].offset=offset;
0782 }
0783 
0784 static inline void SetPixelChannels(Image *image,const size_t number_channels)
0785 {
0786   image->number_channels=number_channels;
0787 }
0788 
0789 static inline void SetPixelChannelTraits(Image *image,
0790   const PixelChannel channel,const PixelTrait traits)
0791 {
0792   if ((size_t) channel >= MaxPixelChannels)
0793     return;
0794   image->channel_map[channel].traits=traits;
0795 }
0796 
0797 static inline void SetPixelCompositeMask(const Image *magick_restrict image,
0798   const Quantum mask,Quantum *magick_restrict pixel)
0799 {
0800   if (image->channel_map[CompositeMaskPixelChannel].traits != UndefinedPixelTrait)
0801     pixel[image->channel_map[CompositeMaskPixelChannel].offset]=mask;
0802 }
0803 
0804 static inline void SetPixelCr(const Image *magick_restrict image,
0805   const Quantum cr,Quantum *magick_restrict pixel)
0806 {
0807   pixel[image->channel_map[CrPixelChannel].offset]=cr;
0808 }
0809 
0810 static inline void SetPixelCrTraits(Image *image,const PixelTrait traits)
0811 {
0812   image->channel_map[CrPixelChannel].traits=traits;
0813 }
0814 
0815 static inline void SetPixelCyan(const Image *magick_restrict image,
0816   const Quantum cyan,Quantum *magick_restrict pixel)
0817 {
0818   pixel[image->channel_map[CyanPixelChannel].offset]=cyan;
0819 }
0820 
0821 static inline void SetPixelGray(const Image *magick_restrict image,
0822   const Quantum gray,Quantum *magick_restrict pixel)
0823 {
0824   pixel[image->channel_map[GrayPixelChannel].offset]=gray;
0825 }
0826 
0827 static inline void SetPixelGrayTraits(Image *image,const PixelTrait traits)
0828 {
0829   image->channel_map[GrayPixelChannel].traits=traits;
0830 }
0831 
0832 static inline void SetPixelGreen(const Image *magick_restrict image,
0833   const Quantum green,Quantum *magick_restrict pixel)
0834 {
0835   pixel[image->channel_map[GreenPixelChannel].offset]=green;
0836 }
0837 
0838 static inline void SetPixelGreenTraits(Image *image,const PixelTrait traits)
0839 {
0840   image->channel_map[GreenPixelChannel].traits=traits;
0841 }
0842 
0843 static inline void SetPixelIndex(const Image *magick_restrict image,
0844   const Quantum index,Quantum *magick_restrict pixel)
0845 {
0846   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
0847     pixel[image->channel_map[IndexPixelChannel].offset]=index;
0848 }
0849 
0850 static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
0851 {
0852   image->channel_map[IndexPixelChannel].traits=traits;
0853 }
0854 
0855 static inline void SetPixelViaPixelInfo(const Image *magick_restrict image,
0856   const PixelInfo *magick_restrict pixel_info,Quantum *magick_restrict pixel)
0857 {
0858   pixel[image->channel_map[RedPixelChannel].offset]=
0859     ClampToQuantum(pixel_info->red);
0860   pixel[image->channel_map[GreenPixelChannel].offset]=
0861     ClampToQuantum(pixel_info->green);
0862   pixel[image->channel_map[BluePixelChannel].offset]=
0863     ClampToQuantum(pixel_info->blue);
0864   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
0865     pixel[image->channel_map[BlackPixelChannel].offset]=
0866       ClampToQuantum(pixel_info->black);
0867   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
0868     pixel[image->channel_map[AlphaPixelChannel].offset]=
0869       pixel_info->alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
0870       ClampToQuantum(pixel_info->alpha);
0871 }
0872 
0873 static inline void SetPixelL(const Image *magick_restrict image,const Quantum L,
0874   Quantum *magick_restrict pixel)
0875 {
0876   if (image->channel_map[LPixelChannel].traits != UndefinedPixelTrait)
0877     pixel[image->channel_map[LPixelChannel].offset]=L;
0878 }
0879 
0880 static inline void SetPixelMagenta(const Image *magick_restrict image,
0881   const Quantum magenta,Quantum *magick_restrict pixel)
0882 {
0883   pixel[image->channel_map[MagentaPixelChannel].offset]=magenta;
0884 }
0885 
0886 static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
0887 {
0888   image->channel_map[MagentaPixelChannel].traits=traits;
0889 }
0890 
0891 static inline void SetPixelMeta(const Image *magick_restrict image,
0892   const Quantum red,Quantum *magick_restrict pixel)
0893 {
0894   pixel[image->channel_map[MetaPixelChannels].offset]=red;
0895 }
0896 
0897 static inline void SetPixelMetaTraits(Image *image,const PixelTrait traits)
0898 {
0899   image->channel_map[MetaPixelChannels].traits=traits;
0900 }
0901 
0902 static inline void SetPixelReadMask(const Image *magick_restrict image,
0903   const Quantum mask,Quantum *magick_restrict pixel)
0904 {
0905   if (image->channel_map[ReadMaskPixelChannel].traits != UndefinedPixelTrait)
0906     pixel[image->channel_map[ReadMaskPixelChannel].offset]=mask;
0907 }
0908 
0909 static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
0910 {
0911   image->metacontent_extent=extent;
0912 }
0913 
0914 static inline void SetPixelOpacity(const Image *magick_restrict image,
0915   const Quantum alpha,Quantum *magick_restrict pixel)
0916 {
0917   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
0918     pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
0919 }
0920 
0921 static inline void SetPixelRed(const Image *magick_restrict image,
0922   const Quantum red,Quantum *magick_restrict pixel)
0923 {
0924   pixel[image->channel_map[RedPixelChannel].offset]=red;
0925 }
0926 
0927 static inline void SetPixelRedTraits(Image *image,const PixelTrait traits)
0928 {
0929   image->channel_map[RedPixelChannel].traits=traits;
0930 }
0931 
0932 static inline void SetPixelWriteMask(const Image *magick_restrict image,
0933   const Quantum mask,Quantum *magick_restrict pixel)
0934 {
0935   if (image->channel_map[WriteMaskPixelChannel].traits != UndefinedPixelTrait)
0936     pixel[image->channel_map[WriteMaskPixelChannel].offset]=mask;
0937 }
0938 
0939 static inline void SetPixelYellow(const Image *magick_restrict image,
0940   const Quantum yellow,Quantum *magick_restrict pixel)
0941 {
0942   pixel[image->channel_map[YellowPixelChannel].offset]=yellow;
0943 }
0944 
0945 static inline void SetPixelYellowTraits(Image *image,const PixelTrait traits)
0946 {
0947   image->channel_map[YellowPixelChannel].traits=traits;
0948 }
0949 
0950 static inline void SetPixelY(const Image *magick_restrict image,
0951   const Quantum y,Quantum *magick_restrict pixel)
0952 {
0953   pixel[image->channel_map[YPixelChannel].offset]=y;
0954 }
0955 
0956 static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
0957 {
0958   image->channel_map[YPixelChannel].traits=traits;
0959 }
0960 
0961 #if defined(__cplusplus) || defined(c_plusplus)
0962 }
0963 #endif
0964 
0965 #endif