Home | History | Annotate | Download | only in MagickCore
      1 /*
      2   Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization
      3   dedicated to making software imaging solutions freely available.
      4 
      5   You may not use this file except in compliance with the License.
      6   obtain a copy of the License at
      7 
      8     http://www.imagemagick.org/script/license.php
      9 
     10   Unless required by applicable law or agreed to in writing, software
     11   distributed under the License is distributed on an "AS IS" BASIS,
     12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13   See the License for the specific language governing permissions and
     14   limitations under the License.
     15 
     16   MagickCore pixel accessor methods.
     17 */
     18 #ifndef MAGICKCORE_PIXEL_ACCESSOR_H
     19 #define MAGICKCORE_PIXEL_ACCESSOR_H
     20 
     21 #include "MagickCore/cache.h"
     22 #include "MagickCore/cache-view.h"
     23 #include "MagickCore/color.h"
     24 #include "MagickCore/colorspace.h"
     25 #include "MagickCore/gem.h"
     26 #include "MagickCore/image.h"
     27 
     28 #if defined(__cplusplus) || defined(c_plusplus)
     29 extern "C" {
     30 #endif
     31 
     32 #undef index
     33 
     34 static inline Quantum ClampPixel(const MagickRealType value)
     35 {
     36   if (value < 0.0f)
     37     return(0);
     38   if (value >= (MagickRealType) QuantumRange)
     39     return((Quantum) QuantumRange);
     40 #if !defined(MAGICKCORE_HDRI_SUPPORT)
     41   return((Quantum) (value+0.5f));
     42 #else
     43   return((Quantum) value);
     44 #endif
     45 }
     46 
     47 static inline Quantum GetPixela(const Image *magick_restrict image,
     48   const Quantum *magick_restrict pixel)
     49 {
     50   return(pixel[image->channel_map[aPixelChannel].offset]);
     51 }
     52 
     53 static inline Quantum GetPixelAlpha(const Image *magick_restrict image,
     54   const Quantum *magick_restrict pixel)
     55 {
     56   if (image->channel_map[AlphaPixelChannel].traits == UndefinedPixelTrait)
     57     return(OpaqueAlpha);
     58   return(pixel[image->channel_map[AlphaPixelChannel].offset]);
     59 }
     60 
     61 static inline PixelTrait GetPixelAlphaTraits(
     62   const Image *magick_restrict image)
     63 {
     64   return(image->channel_map[AlphaPixelChannel].traits);
     65 }
     66 
     67 static inline Quantum GetPixelb(const Image *magick_restrict image,
     68   const Quantum *magick_restrict pixel)
     69 {
     70   return(pixel[image->channel_map[bPixelChannel].offset]);
     71 }
     72 
     73 static inline Quantum GetPixelBlack(const Image *magick_restrict image,
     74   const Quantum *magick_restrict pixel)
     75 {
     76   if (image->channel_map[BlackPixelChannel].traits == UndefinedPixelTrait)
     77     return((Quantum) 0);
     78   return(pixel[image->channel_map[BlackPixelChannel].offset]);
     79 }
     80 
     81 static inline PixelTrait GetPixelBlackTraits(
     82   const Image *magick_restrict image)
     83 {
     84   return(image->channel_map[BlackPixelChannel].traits);
     85 }
     86 
     87 static inline Quantum GetPixelBlue(const Image *magick_restrict image,
     88   const Quantum *magick_restrict pixel)
     89 {
     90   return(pixel[image->channel_map[BluePixelChannel].offset]);
     91 }
     92 
     93 static inline PixelTrait GetPixelBlueTraits(const Image *magick_restrict image)
     94 {
     95   return(image->channel_map[BluePixelChannel].traits);
     96 }
     97 
     98 static inline Quantum GetPixelCb(const Image *magick_restrict image,
     99   const Quantum *magick_restrict pixel)
    100 {
    101   return(pixel[image->channel_map[CbPixelChannel].offset]);
    102 }
    103 
    104 static inline PixelTrait GetPixelCbTraits(const Image *magick_restrict image)
    105 {
    106   return(image->channel_map[CbPixelChannel].traits);
    107 }
    108 
    109 static inline Quantum GetPixelChannel(const Image *magick_restrict image,
    110   const PixelChannel channel,const Quantum *magick_restrict pixel)
    111 {
    112   if (image->channel_map[channel].traits == UndefinedPixelTrait)
    113     return((Quantum) 0);
    114   return(pixel[image->channel_map[channel].offset]);
    115 }
    116 
    117 static inline PixelChannel GetPixelChannelChannel(
    118   const Image *magick_restrict image,const ssize_t offset)
    119 {
    120   return(image->channel_map[offset].channel);
    121 }
    122 
    123 static inline ssize_t GetPixelChannelOffset(const Image *magick_restrict image,
    124   const PixelChannel channel)
    125 {
    126   return(image->channel_map[channel].offset);
    127 }
    128 
    129 static inline PixelTrait GetPixelChannelTraits(
    130   const Image *magick_restrict image,const PixelChannel channel)
    131 {
    132   return(image->channel_map[channel].traits);
    133 }
    134 
    135 static inline size_t GetPixelChannels(const Image *magick_restrict image)
    136 {
    137   return(image->number_channels);
    138 }
    139 
    140 static inline Quantum GetPixelCr(const Image *magick_restrict image,
    141   const Quantum *magick_restrict pixel)
    142 {
    143   return(pixel[image->channel_map[CrPixelChannel].offset]);
    144 }
    145 
    146 static inline PixelTrait GetPixelCrTraits(const Image *magick_restrict image)
    147 {
    148   return(image->channel_map[CrPixelChannel].traits);
    149 }
    150 
    151 static inline Quantum GetPixelCyan(const Image *magick_restrict image,
    152   const Quantum *magick_restrict pixel)
    153 {
    154   return(pixel[image->channel_map[CyanPixelChannel].offset]);
    155 }
    156 
    157 static inline PixelTrait GetPixelCyanTraits(const Image *magick_restrict image)
    158 {
    159   return(image->channel_map[CyanPixelChannel].traits);
    160 }
    161 
    162 static inline Quantum GetPixelGray(const Image *magick_restrict image,
    163   const Quantum *magick_restrict pixel)
    164 {
    165   return(pixel[image->channel_map[GrayPixelChannel].offset]);
    166 }
    167 
    168 static inline PixelTrait GetPixelGrayTraits(const Image *magick_restrict image)
    169 {
    170   return(image->channel_map[GrayPixelChannel].traits);
    171 }
    172 
    173 static inline Quantum GetPixelGreen(const Image *magick_restrict image,
    174   const Quantum *magick_restrict pixel)
    175 {
    176   return(pixel[image->channel_map[GreenPixelChannel].offset]);
    177 }
    178 
    179 static inline PixelTrait GetPixelGreenTraits(
    180   const Image *magick_restrict image)
    181 {
    182   return(image->channel_map[GreenPixelChannel].traits);
    183 }
    184 
    185 static inline Quantum GetPixelIndex(const Image *magick_restrict image,
    186   const Quantum *magick_restrict pixel)
    187 {
    188   if (image->channel_map[IndexPixelChannel].traits == UndefinedPixelTrait)
    189     return((Quantum) 0);
    190   return(pixel[image->channel_map[IndexPixelChannel].offset]);
    191 }
    192 
    193 static inline PixelTrait GetPixelIndexTraits(
    194   const Image *magick_restrict image)
    195 {
    196   return(image->channel_map[IndexPixelChannel].traits);
    197 }
    198 
    199 static inline MagickRealType GetPixelInfoChannel(
    200   const PixelInfo *magick_restrict pixel_info,const PixelChannel channel)
    201 {
    202   switch (channel)
    203   {
    204     case RedPixelChannel: return(pixel_info->red);
    205     case GreenPixelChannel: return(pixel_info->green);
    206     case BluePixelChannel: return(pixel_info->blue);
    207     case BlackPixelChannel: return(pixel_info->black);
    208     case AlphaPixelChannel: return(pixel_info->alpha);
    209     case IndexPixelChannel: return(pixel_info->index);
    210     default: return((MagickRealType) 0.0);
    211   }
    212 }
    213 
    214 static inline double PerceptibleReciprocal(const double x)
    215 {
    216   double
    217     sign;
    218 
    219   /*
    220     Return 1/x where x is perceptible (not unlimited or infinitesimal).
    221   */
    222   sign=x < 0.0 ? -1.0 : 1.0;
    223   if ((sign*x) >= MagickEpsilon)
    224     return(1.0/x);
    225   return(sign/MagickEpsilon);
    226 }
    227 
    228 static inline MagickRealType GetPixelInfoLuma(
    229   const PixelInfo *magick_restrict pixel)
    230 {
    231   MagickRealType
    232     intensity;
    233 
    234   if (pixel->colorspace == sRGBColorspace)
    235     {
    236       intensity=(MagickRealType) (0.212656f*pixel->red+0.715158f*pixel->green+
    237         0.072186f*pixel->blue);
    238       return(intensity);
    239     }
    240   intensity=(MagickRealType) (0.212656f*EncodePixelGamma(pixel->red)+
    241     0.715158f*EncodePixelGamma(pixel->green)+
    242     0.072186f*EncodePixelGamma(pixel->blue));
    243   return(intensity);
    244 }
    245 
    246 static inline MagickRealType GetPixelInfoLuminance(
    247   const PixelInfo *magick_restrict pixel)
    248 {
    249   MagickRealType
    250     intensity;
    251 
    252   if (pixel->colorspace != sRGBColorspace)
    253     {
    254       intensity=(MagickRealType) (0.212656f*pixel->red+0.715158f*pixel->green+
    255         0.072186f*pixel->blue);
    256       return(intensity);
    257     }
    258   intensity=(MagickRealType) (0.212656f*DecodePixelGamma(pixel->red)+
    259     0.715158f*DecodePixelGamma(pixel->green)+
    260     0.072186f*DecodePixelGamma(pixel->blue));
    261   return(intensity);
    262 }
    263 
    264 static inline Quantum GetPixelL(const Image *magick_restrict image,
    265   const Quantum *magick_restrict pixel)
    266 {
    267   return(pixel[image->channel_map[LPixelChannel].offset]);
    268 }
    269 
    270 static inline ssize_t GetPixelLabel(const Image *magick_restrict image,
    271   const Quantum *magick_restrict pixel)
    272 {
    273   return((ssize_t) pixel[image->channel_map[LabelPixelChannel].offset]);
    274 }
    275 
    276 static inline MagickRealType GetPixelLuma(const Image *magick_restrict image,
    277   const Quantum *magick_restrict pixel)
    278 {
    279   MagickRealType
    280     intensity;
    281 
    282   intensity=(MagickRealType) (
    283     0.212656f*pixel[image->channel_map[RedPixelChannel].offset]+
    284     0.715158f*pixel[image->channel_map[GreenPixelChannel].offset]+
    285     0.072186f*pixel[image->channel_map[BluePixelChannel].offset]);
    286   return(intensity);
    287 }
    288 
    289 static inline MagickRealType GetPixelLuminance(
    290   const Image *magick_restrict image,const Quantum *magick_restrict pixel)
    291 {
    292   MagickRealType
    293     intensity;
    294 
    295   if (image->colorspace != sRGBColorspace)
    296     {
    297       intensity=(MagickRealType) (
    298         0.212656f*pixel[image->channel_map[RedPixelChannel].offset]+
    299         0.715158f*pixel[image->channel_map[GreenPixelChannel].offset]+
    300         0.072186f*pixel[image->channel_map[BluePixelChannel].offset]);
    301       return(intensity);
    302     }
    303   intensity=(MagickRealType) (0.212656f*DecodePixelGamma((MagickRealType)
    304     pixel[image->channel_map[RedPixelChannel].offset])+0.715158f*
    305     DecodePixelGamma((MagickRealType)
    306     pixel[image->channel_map[GreenPixelChannel].offset])+0.072186f*
    307     DecodePixelGamma((MagickRealType)
    308     pixel[image->channel_map[BluePixelChannel].offset]));
    309   return(intensity);
    310 }
    311 
    312 static inline Quantum GetPixelMagenta(const Image *magick_restrict image,
    313   const Quantum *magick_restrict pixel)
    314 {
    315   return(pixel[image->channel_map[MagentaPixelChannel].offset]);
    316 }
    317 
    318 static inline PixelTrait GetPixelMagentaTraits(
    319   const Image *magick_restrict image)
    320 {
    321   return(image->channel_map[MagentaPixelChannel].traits);
    322 }
    323 
    324 static inline Quantum GetPixelReadMask(const Image *magick_restrict image,
    325   const Quantum *magick_restrict pixel)
    326 {
    327   if (image->channel_map[ReadMaskPixelChannel].traits == UndefinedPixelTrait)
    328     return((Quantum) QuantumRange);
    329   return(pixel[image->channel_map[ReadMaskPixelChannel].offset]);
    330 }
    331 
    332 static inline Quantum GetPixelWriteMask(const Image *magick_restrict image,
    333   const Quantum *magick_restrict pixel)
    334 {
    335   if (image->channel_map[WriteMaskPixelChannel].traits == UndefinedPixelTrait)
    336     return((Quantum) QuantumRange);
    337   return(pixel[image->channel_map[WriteMaskPixelChannel].offset]);
    338 }
    339 
    340 static inline PixelTrait GetPixelReadMaskTraits(
    341   const Image *magick_restrict image)
    342 {
    343   return(image->channel_map[ReadMaskPixelChannel].traits);
    344 }
    345 
    346 static inline size_t GetPixelMetaChannels(const Image *magick_restrict image)
    347 {
    348   return(image->number_meta_channels);
    349 }
    350 
    351 static inline size_t GetPixelMetacontentExtent(
    352   const Image *magick_restrict image)
    353 {
    354   return(image->metacontent_extent);
    355 }
    356 
    357 static inline Quantum GetPixelOpacity(const Image *magick_restrict image,
    358   const Quantum *magick_restrict pixel)
    359 {
    360   if (image->channel_map[AlphaPixelChannel].traits != BlendPixelTrait)
    361     return(QuantumRange-OpaqueAlpha);
    362   return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
    363 }
    364 
    365 static inline Quantum GetPixelRed(const Image *magick_restrict image,
    366   const Quantum *magick_restrict pixel)
    367 {
    368   return(pixel[image->channel_map[RedPixelChannel].offset]);
    369 }
    370 
    371 static inline PixelTrait GetPixelRedTraits(const Image *magick_restrict image)
    372 {
    373   return(image->channel_map[RedPixelChannel].traits);
    374 }
    375 
    376 static inline void GetPixelInfoPixel(const Image *magick_restrict image,
    377   const Quantum *magick_restrict pixel,PixelInfo *magick_restrict pixel_info)
    378 {
    379   pixel_info->storage_class=image->storage_class;
    380   pixel_info->colorspace=image->colorspace;
    381   pixel_info->fuzz=image->fuzz;
    382   pixel_info->depth=image->depth;
    383   pixel_info->red=(MagickRealType)
    384     pixel[image->channel_map[RedPixelChannel].offset];
    385   pixel_info->green=(MagickRealType)
    386     pixel[image->channel_map[GreenPixelChannel].offset];
    387   pixel_info->blue=(MagickRealType)
    388     pixel[image->channel_map[BluePixelChannel].offset];
    389   pixel_info->black=0.0f;
    390   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
    391     pixel_info->black=(MagickRealType)
    392       pixel[image->channel_map[BlackPixelChannel].offset];
    393   pixel_info->alpha=(MagickRealType) OpaqueAlpha;
    394   pixel_info->alpha_trait=UndefinedPixelTrait;
    395   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
    396     {
    397       pixel_info->alpha=(MagickRealType)
    398         pixel[image->channel_map[AlphaPixelChannel].offset];
    399       pixel_info->alpha_trait=BlendPixelTrait;
    400     }
    401   pixel_info->index=0.0f;
    402   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
    403     pixel_info->index=(MagickRealType)
    404       pixel[image->channel_map[IndexPixelChannel].offset];
    405   pixel_info->count=0;
    406 }
    407 
    408 static inline PixelTrait GetPixelTraits(const Image *magick_restrict image,
    409   const PixelChannel channel)
    410 {
    411   return(image->channel_map[channel].traits);
    412 }
    413 
    414 static inline Quantum GetPixelY(const Image *magick_restrict image,
    415   const Quantum *magick_restrict pixel)
    416 {
    417   return(pixel[image->channel_map[YPixelChannel].offset]);
    418 }
    419 
    420 static inline PixelTrait GetPixelYTraits(const Image *magick_restrict image)
    421 {
    422   return(image->channel_map[YPixelChannel].traits);
    423 }
    424 
    425 static inline Quantum GetPixelYellow(const Image *magick_restrict image,
    426   const Quantum *magick_restrict pixel)
    427 {
    428   return(pixel[image->channel_map[YellowPixelChannel].offset]);
    429 }
    430 
    431 static inline PixelTrait GetPixelYellowTraits(
    432   const Image *magick_restrict image)
    433 {
    434   return(image->channel_map[YellowPixelChannel].traits);
    435 }
    436 
    437 static inline MagickRealType AbsolutePixelValue(const MagickRealType x)
    438 {
    439   return(x < 0.0f ? -x : x);
    440 }
    441 
    442 static inline MagickBooleanType IsPixelAtDepth(const Quantum pixel,
    443   const QuantumAny range)
    444 {
    445   Quantum
    446     quantum;
    447 
    448 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    449   quantum=(Quantum) (((MagickRealType) QuantumRange*((QuantumAny)
    450     (((MagickRealType) range*pixel)/QuantumRange+0.5)))/range+0.5);
    451 #else
    452   quantum=(Quantum) (((MagickRealType) QuantumRange*((QuantumAny)
    453     (((MagickRealType) range*pixel)/QuantumRange+0.5)))/range);
    454 #endif
    455   return(pixel == quantum ? MagickTrue : MagickFalse);
    456 }
    457 
    458 static inline MagickBooleanType IsPixelEquivalent(
    459   const Image *magick_restrict image,const Quantum *magick_restrict p,
    460   const PixelInfo *magick_restrict q)
    461 {
    462   MagickRealType
    463     value;
    464 
    465   value=(MagickRealType) p[image->channel_map[AlphaPixelChannel].offset];
    466   if ((image->alpha_trait != UndefinedPixelTrait) &&
    467       (q->alpha_trait == UndefinedPixelTrait) &&
    468       (AbsolutePixelValue(value-OpaqueAlpha) >= MagickEpsilon))
    469     return(MagickFalse);
    470   if ((q->alpha_trait != UndefinedPixelTrait) &&
    471       (image->alpha_trait == UndefinedPixelTrait) &&
    472       (AbsolutePixelValue(q->alpha-OpaqueAlpha)) >= MagickEpsilon)
    473     return(MagickFalse);
    474   if ((image->alpha_trait != UndefinedPixelTrait) &&
    475       (q->alpha_trait != UndefinedPixelTrait))
    476     {
    477       if (AbsolutePixelValue(value-q->alpha) >= MagickEpsilon)
    478         return(MagickFalse);
    479       if (AbsolutePixelValue(value-TransparentAlpha) < MagickEpsilon)
    480         return(MagickTrue);
    481     }
    482   value=(MagickRealType) p[image->channel_map[RedPixelChannel].offset];
    483   if (AbsolutePixelValue(value-q->red) >= MagickEpsilon)
    484     return(MagickFalse);
    485   value=(MagickRealType) p[image->channel_map[GreenPixelChannel].offset];
    486   if (AbsolutePixelValue(value-q->green) >= MagickEpsilon)
    487     return(MagickFalse);
    488   value=(MagickRealType) p[image->channel_map[BluePixelChannel].offset];
    489   if (AbsolutePixelValue(value-q->blue) >= MagickEpsilon)
    490     return(MagickFalse);
    491   if (image->colorspace == CMYKColorspace)
    492     {
    493       value=(MagickRealType) p[image->channel_map[BlackPixelChannel].offset];
    494       if (AbsolutePixelValue(value-q->black) >= MagickEpsilon)
    495         return(MagickFalse);
    496     }
    497   return(MagickTrue);
    498 }
    499 
    500 static inline MagickBooleanType IsPixelGray(const Image *magick_restrict image,
    501   const Quantum *magick_restrict pixel)
    502 {
    503   MagickRealType
    504     green_blue,
    505     red_green;
    506 
    507   red_green=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
    508     pixel[image->channel_map[GreenPixelChannel].offset];
    509   green_blue=(MagickRealType)
    510     pixel[image->channel_map[GreenPixelChannel].offset]-
    511     pixel[image->channel_map[BluePixelChannel].offset];
    512   if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
    513       (AbsolutePixelValue(green_blue) < MagickEpsilon))
    514     return(MagickTrue);
    515   return(MagickFalse);
    516 }
    517 
    518 static inline MagickBooleanType IsPixelInfoEquivalent(
    519   const PixelInfo *magick_restrict p,const PixelInfo *magick_restrict q)
    520 {
    521   if ((p->alpha_trait != UndefinedPixelTrait) &&
    522       (q->alpha_trait == UndefinedPixelTrait) &&
    523       (AbsolutePixelValue(p->alpha-OpaqueAlpha) >= MagickEpsilon))
    524     return(MagickFalse);
    525   if ((q->alpha_trait != UndefinedPixelTrait) &&
    526       (p->alpha_trait == UndefinedPixelTrait) &&
    527       (AbsolutePixelValue(q->alpha-OpaqueAlpha)) >= MagickEpsilon)
    528     return(MagickFalse);
    529   if ((p->alpha_trait != UndefinedPixelTrait) &&
    530       (q->alpha_trait != UndefinedPixelTrait))
    531     {
    532       if (AbsolutePixelValue(p->alpha-q->alpha) >= MagickEpsilon)
    533         return(MagickFalse);
    534       if (AbsolutePixelValue(p->alpha-TransparentAlpha) < MagickEpsilon)
    535         return(MagickTrue);
    536     }
    537   if (AbsolutePixelValue(p->red-q->red) >= MagickEpsilon)
    538     return(MagickFalse);
    539   if (AbsolutePixelValue(p->green-q->green) >= MagickEpsilon)
    540     return(MagickFalse);
    541   if (AbsolutePixelValue(p->blue-q->blue) >= MagickEpsilon)
    542     return(MagickFalse);
    543   if ((p->colorspace == CMYKColorspace) &&
    544       (AbsolutePixelValue(p->black-q->black) >= MagickEpsilon))
    545     return(MagickFalse);
    546   return(MagickTrue);
    547 }
    548 
    549 static inline MagickBooleanType IsPixelMonochrome(
    550   const Image *magick_restrict image,const Quantum *magick_restrict pixel)
    551 {
    552   MagickRealType
    553     green_blue,
    554     red,
    555     red_green;
    556 
    557   red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
    558   if ((AbsolutePixelValue(red) >= MagickEpsilon) &&
    559       (AbsolutePixelValue(red-QuantumRange) >= MagickEpsilon))
    560     return(MagickFalse);
    561   red_green=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
    562     pixel[image->channel_map[GreenPixelChannel].offset];
    563   green_blue=(MagickRealType)
    564     pixel[image->channel_map[GreenPixelChannel].offset]-
    565     pixel[image->channel_map[BluePixelChannel].offset];
    566   if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
    567       (AbsolutePixelValue(green_blue) < MagickEpsilon))
    568     return(MagickTrue);
    569   return(MagickFalse);
    570 }
    571 
    572 static inline MagickBooleanType IsPixelInfoGray(
    573   const PixelInfo *magick_restrict pixel)
    574 {
    575   if ((AbsolutePixelValue(pixel->red-pixel->green) < MagickEpsilon) &&
    576       (AbsolutePixelValue(pixel->green-pixel->blue) < MagickEpsilon))
    577     return(MagickTrue);
    578   return(MagickFalse);
    579 }
    580 
    581 static inline MagickBooleanType IsPixelInfoMonochrome(
    582   const PixelInfo *magick_restrict pixel_info)
    583 {
    584   MagickRealType
    585     green_blue,
    586     red_green;
    587 
    588   if ((AbsolutePixelValue(pixel_info->red) >= MagickEpsilon) ||
    589       (AbsolutePixelValue(pixel_info->red-QuantumRange) >= MagickEpsilon))
    590     return(MagickFalse);
    591   red_green=pixel_info->red-pixel_info->green;
    592   green_blue=pixel_info->green-pixel_info->blue;
    593   if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
    594       (AbsolutePixelValue(green_blue) < MagickEpsilon))
    595     return(MagickTrue);
    596   return(MagickFalse);
    597 }
    598 
    599 static inline void SetPixela(const Image *magick_restrict image,
    600   const Quantum a,Quantum *magick_restrict pixel)
    601 {
    602   if (image->channel_map[aPixelChannel].traits != UndefinedPixelTrait)
    603     pixel[image->channel_map[aPixelChannel].offset]=a;
    604 }
    605 
    606 static inline void SetPixelAlpha(const Image *magick_restrict image,
    607   const Quantum alpha,Quantum *magick_restrict pixel)
    608 {
    609   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
    610     pixel[image->channel_map[AlphaPixelChannel].offset]=alpha;
    611 }
    612 
    613 static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
    614 {
    615   image->channel_map[AlphaPixelChannel].traits=traits;
    616 }
    617 
    618 static inline void SetPixelb(const Image *magick_restrict image,
    619   const Quantum b,Quantum *magick_restrict pixel)
    620 {
    621   if (image->channel_map[bPixelChannel].traits != UndefinedPixelTrait)
    622     pixel[image->channel_map[bPixelChannel].offset]=b;
    623 }
    624 
    625 static inline void SetPixelBackgoundColor(const Image *magick_restrict image,
    626   Quantum *magick_restrict pixel)
    627 {
    628   register ssize_t
    629     i;
    630 
    631   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
    632     pixel[i]=0;
    633   pixel[image->channel_map[RedPixelChannel].offset]=
    634     ClampToQuantum(image->background_color.red);
    635   pixel[image->channel_map[GreenPixelChannel].offset]=
    636     ClampToQuantum(image->background_color.green);
    637   pixel[image->channel_map[BluePixelChannel].offset]=
    638     ClampToQuantum(image->background_color.blue);
    639   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
    640     pixel[image->channel_map[BlackPixelChannel].offset]=
    641       ClampToQuantum(image->background_color.black);
    642   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
    643     pixel[image->channel_map[AlphaPixelChannel].offset]=
    644       image->background_color.alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
    645       ClampToQuantum(image->background_color.alpha);
    646 }
    647 
    648 static inline void SetPixelBlack(const Image *magick_restrict image,
    649   const Quantum black,Quantum *magick_restrict pixel)
    650 {
    651   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
    652     pixel[image->channel_map[BlackPixelChannel].offset]=black;
    653 }
    654 
    655 static inline void SetPixelBlackTraits(Image *image,const PixelTrait traits)
    656 {
    657   image->channel_map[BlackPixelChannel].traits=traits;
    658 }
    659 
    660 static inline void SetPixelBlue(const Image *magick_restrict image,
    661   const Quantum blue,Quantum *magick_restrict pixel)
    662 {
    663   pixel[image->channel_map[BluePixelChannel].offset]=blue;
    664 }
    665 
    666 static inline void SetPixelBlueTraits(Image *image,const PixelTrait traits)
    667 {
    668   image->channel_map[BluePixelChannel].traits=traits;
    669 }
    670 
    671 static inline void SetPixelCb(const Image *magick_restrict image,
    672   const Quantum cb,Quantum *magick_restrict pixel)
    673 {
    674   pixel[image->channel_map[CbPixelChannel].offset]=cb;
    675 }
    676 
    677 static inline void SetPixelCbTraits(Image *image,const PixelTrait traits)
    678 {
    679   image->channel_map[CbPixelChannel].traits=traits;
    680 }
    681 
    682 static inline void SetPixelChannel(const Image *magick_restrict image,
    683   const PixelChannel channel,const Quantum quantum,
    684   Quantum *magick_restrict pixel)
    685 {
    686   if (image->channel_map[channel].traits != UndefinedPixelTrait)
    687     pixel[image->channel_map[channel].offset]=quantum;
    688 }
    689 
    690 static inline void SetPixelChannelAttributes(
    691   const Image *magick_restrict image,const PixelChannel channel,
    692   const PixelTrait traits,const ssize_t offset)
    693 {
    694   image->channel_map[offset].channel=channel;
    695   image->channel_map[channel].offset=offset;
    696   image->channel_map[channel].traits=traits;
    697 }
    698 
    699 static inline void SetPixelChannelChannel(const Image *magick_restrict image,
    700   const PixelChannel channel,const ssize_t offset)
    701 {
    702   image->channel_map[offset].channel=channel;
    703   image->channel_map[channel].offset=offset;
    704 }
    705 
    706 static inline void SetPixelChannels(Image *image,const size_t number_channels)
    707 {
    708   image->number_channels=number_channels;
    709 }
    710 
    711 static inline void SetPixelChannelTraits(Image *image,
    712   const PixelChannel channel,const PixelTrait traits)
    713 {
    714   image->channel_map[channel].traits=traits;
    715 }
    716 
    717 static inline void SetPixelCr(const Image *magick_restrict image,
    718   const Quantum cr,Quantum *magick_restrict pixel)
    719 {
    720   pixel[image->channel_map[CrPixelChannel].offset]=cr;
    721 }
    722 
    723 static inline void SetPixelCrTraits(Image *image,const PixelTrait traits)
    724 {
    725   image->channel_map[CrPixelChannel].traits=traits;
    726 }
    727 
    728 static inline void SetPixelCyan(const Image *magick_restrict image,
    729   const Quantum cyan,Quantum *magick_restrict pixel)
    730 {
    731   pixel[image->channel_map[CyanPixelChannel].offset]=cyan;
    732 }
    733 
    734 static inline void SetPixelGray(const Image *magick_restrict image,
    735   const Quantum gray,Quantum *magick_restrict pixel)
    736 {
    737   pixel[image->channel_map[GrayPixelChannel].offset]=gray;
    738 }
    739 
    740 static inline void SetPixelGrayTraits(Image *image,const PixelTrait traits)
    741 {
    742   image->channel_map[GrayPixelChannel].traits=traits;
    743 }
    744 
    745 static inline void SetPixelGreen(const Image *magick_restrict image,
    746   const Quantum green,Quantum *magick_restrict pixel)
    747 {
    748   pixel[image->channel_map[GreenPixelChannel].offset]=green;
    749 }
    750 
    751 static inline void SetPixelGreenTraits(Image *image,const PixelTrait traits)
    752 {
    753   image->channel_map[GreenPixelChannel].traits=traits;
    754 }
    755 
    756 static inline void SetPixelIndex(const Image *magick_restrict image,
    757   const Quantum index,Quantum *magick_restrict pixel)
    758 {
    759   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
    760     pixel[image->channel_map[IndexPixelChannel].offset]=index;
    761 }
    762 
    763 static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
    764 {
    765   image->channel_map[IndexPixelChannel].traits=traits;
    766 }
    767 
    768 static inline void SetPixelViaPixelInfo(const Image *magick_restrict image,
    769   const PixelInfo *magick_restrict pixel_info,Quantum *magick_restrict pixel)
    770 {
    771   pixel[image->channel_map[RedPixelChannel].offset]=
    772     ClampToQuantum(pixel_info->red);
    773   pixel[image->channel_map[GreenPixelChannel].offset]=
    774     ClampToQuantum(pixel_info->green);
    775   pixel[image->channel_map[BluePixelChannel].offset]=
    776     ClampToQuantum(pixel_info->blue);
    777   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
    778     pixel[image->channel_map[BlackPixelChannel].offset]=
    779       ClampToQuantum(pixel_info->black);
    780   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
    781     pixel[image->channel_map[AlphaPixelChannel].offset]=
    782       pixel_info->alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
    783       ClampToQuantum(pixel_info->alpha);
    784 }
    785 
    786 static inline void SetPixelL(const Image *magick_restrict image,const Quantum L,
    787   Quantum *magick_restrict pixel)
    788 {
    789   if (image->channel_map[LPixelChannel].traits != UndefinedPixelTrait)
    790     pixel[image->channel_map[LPixelChannel].offset]=L;
    791 }
    792 
    793 static inline void SetPixelMagenta(const Image *magick_restrict image,
    794   const Quantum magenta,Quantum *magick_restrict pixel)
    795 {
    796   pixel[image->channel_map[MagentaPixelChannel].offset]=magenta;
    797 }
    798 
    799 static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
    800 {
    801   image->channel_map[MagentaPixelChannel].traits=traits;
    802 }
    803 
    804 static inline void SetPixelReadMask(const Image *magick_restrict image,
    805   const Quantum mask,Quantum *magick_restrict pixel)
    806 {
    807   if (image->channel_map[ReadMaskPixelChannel].traits != UndefinedPixelTrait)
    808     pixel[image->channel_map[ReadMaskPixelChannel].offset]=mask;
    809 }
    810 
    811 static inline void SetPixelWriteMask(const Image *magick_restrict image,
    812   const Quantum mask,Quantum *magick_restrict pixel)
    813 {
    814   if (image->channel_map[WriteMaskPixelChannel].traits != UndefinedPixelTrait)
    815     pixel[image->channel_map[WriteMaskPixelChannel].offset]=mask;
    816 }
    817 
    818 static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
    819 {
    820   image->metacontent_extent=extent;
    821 }
    822 
    823 static inline void SetPixelOpacity(const Image *magick_restrict image,
    824   const Quantum alpha,Quantum *magick_restrict pixel)
    825 {
    826   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
    827     pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
    828 }
    829 
    830 static inline void SetPixelRed(const Image *magick_restrict image,
    831   const Quantum red,Quantum *magick_restrict pixel)
    832 {
    833   pixel[image->channel_map[RedPixelChannel].offset]=red;
    834 }
    835 
    836 static inline void SetPixelRedTraits(Image *image,const PixelTrait traits)
    837 {
    838   image->channel_map[RedPixelChannel].traits=traits;
    839 }
    840 
    841 static inline void SetPixelYellow(const Image *magick_restrict image,
    842   const Quantum yellow,Quantum *magick_restrict pixel)
    843 {
    844   pixel[image->channel_map[YellowPixelChannel].offset]=yellow;
    845 }
    846 
    847 static inline void SetPixelYellowTraits(Image *image,const PixelTrait traits)
    848 {
    849   image->channel_map[YellowPixelChannel].traits=traits;
    850 }
    851 
    852 static inline void SetPixelY(const Image *magick_restrict image,
    853   const Quantum y,Quantum *magick_restrict pixel)
    854 {
    855   pixel[image->channel_map[YPixelChannel].offset]=y;
    856 }
    857 
    858 static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
    859 {
    860   image->channel_map[YPixelChannel].traits=traits;
    861 }
    862 
    863 #if defined(__cplusplus) || defined(c_plusplus)
    864 }
    865 #endif
    866 
    867 #endif
    868