18#ifndef MAGICKCORE_PIXEL_ACCESSOR_H
19#define MAGICKCORE_PIXEL_ACCESSOR_H
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#include "MagickCore/memory_.h"
29#if defined(__cplusplus) || defined(c_plusplus)
35static inline Quantum ClampPixel(
const MagickRealType pixel)
39 if (pixel >= (MagickRealType) QuantumRange)
40 return((Quantum) QuantumRange);
41#if !defined(MAGICKCORE_HDRI_SUPPORT)
42 return((Quantum) (pixel+0.5f));
44 return((Quantum) pixel);
48static inline Quantum GetPixela(
const Image *magick_restrict image,
49 const Quantum *magick_restrict pixel)
51 return(pixel[image->channel_map[aPixelChannel].offset]);
54static inline Quantum GetPixelAlpha(
const Image *magick_restrict image,
55 const Quantum *magick_restrict pixel)
57 if (image->channel_map[AlphaPixelChannel].traits == UndefinedPixelTrait)
59 return(pixel[image->channel_map[AlphaPixelChannel].offset]);
62static inline PixelTrait GetPixelAlphaTraits(
const Image *magick_restrict image)
64 return(image->channel_map[AlphaPixelChannel].traits);
67static inline Quantum GetPixelb(
const Image *magick_restrict image,
68 const Quantum *magick_restrict pixel)
70 return(pixel[image->channel_map[bPixelChannel].offset]);
73static inline Quantum GetPixelBlack(
const Image *magick_restrict image,
74 const Quantum *magick_restrict pixel)
76 if (image->channel_map[BlackPixelChannel].traits == UndefinedPixelTrait)
78 return(pixel[image->channel_map[BlackPixelChannel].offset]);
81static inline PixelTrait GetPixelBlackTraits(
const Image *magick_restrict image)
83 return(image->channel_map[BlackPixelChannel].traits);
86static inline Quantum GetPixelBlue(
const Image *magick_restrict image,
87 const Quantum *magick_restrict pixel)
89 return(pixel[image->channel_map[BluePixelChannel].offset]);
92static inline PixelTrait GetPixelBlueTraits(
const Image *magick_restrict image)
94 return(image->channel_map[BluePixelChannel].traits);
97static inline Quantum GetPixelCb(
const Image *magick_restrict image,
98 const Quantum *magick_restrict pixel)
100 return(pixel[image->channel_map[CbPixelChannel].offset]);
103static inline PixelTrait GetPixelCbTraits(
const Image *magick_restrict image)
105 return(image->channel_map[CbPixelChannel].traits);
108static inline Quantum GetPixelChannel(
const Image *magick_restrict image,
109 const PixelChannel channel,
const Quantum *magick_restrict pixel)
111 if ((
size_t) channel >= MaxPixelChannels)
113 if (image->channel_map[channel].traits == UndefinedPixelTrait)
115 return(pixel[image->channel_map[channel].offset]);
118static inline PixelChannel GetPixelChannelChannel(
119 const Image *magick_restrict image,
const ssize_t offset)
121 if ((offset < 0) || (offset >= MaxPixelChannels))
122 return(UndefinedPixelChannel);
123 return(image->channel_map[offset].channel);
126static inline ssize_t GetPixelChannelOffset(
const Image *magick_restrict image,
127 const PixelChannel channel)
129 return(image->channel_map[channel].offset);
132static inline PixelTrait GetPixelChannelTraits(
133 const Image *magick_restrict image,
const PixelChannel channel)
135 if ((
size_t) channel >= MaxPixelChannels)
136 return(UndefinedPixelTrait);
137 return(image->channel_map[channel].traits);
140static inline size_t GetPixelChannels(
const Image *magick_restrict image)
142 return(image->number_channels);
145static inline Quantum GetPixelCompositeMask(
146 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
148 if (image->channel_map[CompositeMaskPixelChannel].traits == UndefinedPixelTrait)
149 return((Quantum) QuantumRange);
150 return(pixel[image->channel_map[CompositeMaskPixelChannel].offset]);
153static inline PixelTrait GetPixelCompositeMaskTraits(
154 const Image *magick_restrict image)
156 return(image->channel_map[CompositeMaskPixelChannel].traits);
159static inline Quantum GetPixelCr(
const Image *magick_restrict image,
160 const Quantum *magick_restrict pixel)
162 return(pixel[image->channel_map[CrPixelChannel].offset]);
165static inline PixelTrait GetPixelCrTraits(
const Image *magick_restrict image)
167 return(image->channel_map[CrPixelChannel].traits);
170static inline Quantum GetPixelCyan(
const Image *magick_restrict image,
171 const Quantum *magick_restrict pixel)
173 return(pixel[image->channel_map[CyanPixelChannel].offset]);
176static inline PixelTrait GetPixelCyanTraits(
const Image *magick_restrict image)
178 return(image->channel_map[CyanPixelChannel].traits);
181static inline Quantum GetPixelGray(
const Image *magick_restrict image,
182 const Quantum *magick_restrict pixel)
184 return(pixel[image->channel_map[GrayPixelChannel].offset]);
187static inline PixelTrait GetPixelGrayTraits(
const Image *magick_restrict image)
189 return(image->channel_map[GrayPixelChannel].traits);
192static inline Quantum GetPixelGreen(
const Image *magick_restrict image,
193 const Quantum *magick_restrict pixel)
195 return(pixel[image->channel_map[GreenPixelChannel].offset]);
198static inline PixelTrait GetPixelGreenTraits(
const Image *magick_restrict image)
200 return(image->channel_map[GreenPixelChannel].traits);
203static inline Quantum GetPixelIndex(
const Image *magick_restrict image,
204 const Quantum *magick_restrict pixel)
206 if (image->channel_map[IndexPixelChannel].traits == UndefinedPixelTrait)
208#if defined(MAGICKCORE_HDRI_SUPPORT)
209 if (pixel[image->channel_map[IndexPixelChannel].offset] < 0)
212 return(pixel[image->channel_map[IndexPixelChannel].offset]);
215static inline PixelTrait GetPixelIndexTraits(
const Image *magick_restrict image)
217 return(image->channel_map[IndexPixelChannel].traits);
220static inline MagickRealType GetPixelInfoChannel(
221 const PixelInfo *magick_restrict pixel_info,
const PixelChannel channel)
225 case RedPixelChannel:
return(pixel_info->red);
226 case GreenPixelChannel:
return(pixel_info->green);
227 case BluePixelChannel:
return(pixel_info->blue);
228 case BlackPixelChannel:
230 if (pixel_info->colorspace != CMYKColorspace)
232 return(pixel_info->black);
234 case AlphaPixelChannel:
236 if (pixel_info->alpha_trait == UndefinedPixelTrait)
237 return((MagickRealType) OpaqueAlpha);
238 return(pixel_info->alpha);
240 case IndexPixelChannel:
return(pixel_info->index);
243 return((MagickRealType) 0.0);
246static inline MagickRealType GetPixelInfoLuma(
247 const PixelInfo *magick_restrict pixel)
252 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
254 if (pixel->colorspace == sRGBColorspace)
256 return(EncodePixelGamma(pixel->red));
258 if (pixel->colorspace == sRGBColorspace)
260 intensity=(MagickRealType) (0.212656*pixel->red+0.715158*pixel->green+
261 0.072186*pixel->blue);
264 intensity=(MagickRealType) (0.212656*EncodePixelGamma(pixel->red)+
265 0.715158*EncodePixelGamma(pixel->green)+
266 0.072186*EncodePixelGamma(pixel->blue));
270static inline MagickRealType GetPixelInfoLuminance(
271 const PixelInfo *magick_restrict pixel)
276 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
278 if (pixel->colorspace != sRGBColorspace)
280 return(DecodePixelGamma(pixel->red));
282 if (pixel->colorspace != sRGBColorspace)
284 intensity=(MagickRealType) (0.212656*pixel->red+0.715158*pixel->green+
285 0.072186*pixel->blue);
288 intensity=(MagickRealType) (0.212656*DecodePixelGamma(pixel->red)+
289 0.715158*DecodePixelGamma(pixel->green)+
290 0.072186*DecodePixelGamma(pixel->blue));
294static inline Quantum GetPixelL(
const Image *magick_restrict image,
295 const Quantum *magick_restrict pixel)
297 return(pixel[image->channel_map[LPixelChannel].offset]);
300static inline ssize_t GetPixelLabel(
const Image *magick_restrict image,
301 const Quantum *magick_restrict pixel)
303 return((ssize_t) pixel[image->channel_map[LabelPixelChannel].offset]);
306static inline MagickRealType GetPixelLuma(
307 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
315 red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
316 green=(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
317 blue=(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
318 if ((red == green) && (green == blue))
321 intensity=0.212656*red+0.715158*green+0.072186*blue;
325static inline MagickRealType GetPixelLuminance(
326 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
334 if (image->colorspace != sRGBColorspace)
336 red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
337 green=(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
338 blue=(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
342 red=DecodePixelGamma((MagickRealType)
343 pixel[image->channel_map[RedPixelChannel].offset]);
344 green=DecodePixelGamma((MagickRealType)
345 pixel[image->channel_map[GreenPixelChannel].offset]);
346 blue=DecodePixelGamma((MagickRealType)
347 pixel[image->channel_map[BluePixelChannel].offset]);
349 if ((red == green) && (green == blue))
352 intensity=0.212656*red+0.715158*green+0.072186*blue;
356static inline Quantum GetPixelMagenta(
const Image *magick_restrict image,
357 const Quantum *magick_restrict pixel)
359 return(pixel[image->channel_map[MagentaPixelChannel].offset]);
362static inline PixelTrait GetPixelMagentaTraits(
363 const Image *magick_restrict image)
365 return(image->channel_map[MagentaPixelChannel].traits);
368static inline Quantum GetPixelMeta(
const Image *magick_restrict image,
369 const Quantum *magick_restrict pixel)
371 if (image->channel_map[MetaPixelChannels].traits == UndefinedPixelTrait)
373 return(pixel[image->channel_map[MetaPixelChannels].offset]);
376static inline PixelTrait GetPixelMetaTraits(
const Image *magick_restrict image)
378 return(image->channel_map[MetaPixelChannels].traits);
381static inline Quantum GetPixelReadMask(
const Image *magick_restrict image,
382 const Quantum *magick_restrict pixel)
384 if (image->channel_map[ReadMaskPixelChannel].traits == UndefinedPixelTrait)
385 return((Quantum) QuantumRange);
386 return(pixel[image->channel_map[ReadMaskPixelChannel].offset]);
389static inline void GetPixelInfoRGBA(
const Quantum red,
const Quantum green,
390 const Quantum blue,
const Quantum alpha,PixelInfo *magick_restrict pixel)
392 GetPixelInfo((Image *) NULL,pixel);
393 pixel->red=(MagickRealType) red;
394 pixel->green=(MagickRealType) green;
395 pixel->blue=(MagickRealType) blue;
396 pixel->alpha=(MagickRealType) alpha;
399static inline Quantum GetPixelWriteMask(
400 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
402 if (image->channel_map[WriteMaskPixelChannel].traits == UndefinedPixelTrait)
403 return((Quantum) QuantumRange);
404 return(pixel[image->channel_map[WriteMaskPixelChannel].offset]);
407static inline PixelTrait GetPixelReadMaskTraits(
408 const Image *magick_restrict image)
410 return(image->channel_map[ReadMaskPixelChannel].traits);
413static inline size_t GetPixelMetaChannels(
const Image *magick_restrict image)
415 return(image->number_meta_channels);
418static inline size_t GetPixelMetacontentExtent(
419 const Image *magick_restrict image)
421 return(image->metacontent_extent);
424static inline Quantum GetPixelOpacity(
const Image *magick_restrict image,
425 const Quantum *magick_restrict pixel)
427 if (image->channel_map[AlphaPixelChannel].traits != BlendPixelTrait)
428 return(QuantumRange-OpaqueAlpha);
429 return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
432static inline Quantum GetPixelRed(
const Image *magick_restrict image,
433 const Quantum *magick_restrict pixel)
435 return(pixel[image->channel_map[RedPixelChannel].offset]);
438static inline PixelTrait GetPixelRedTraits(
const Image *magick_restrict image)
440 return(image->channel_map[RedPixelChannel].traits);
443static inline void GetPixelInfoPixel(
const Image *magick_restrict image,
444 const Quantum *magick_restrict pixel,PixelInfo *magick_restrict pixel_info)
446 (void) ResetMagickMemory(pixel_info,0,
sizeof(*pixel_info));
447 pixel_info->storage_class=DirectClass;
448 pixel_info->colorspace=sRGBColorspace;
449 pixel_info->depth=MAGICKCORE_QUANTUM_DEPTH;
450 pixel_info->alpha_trait=UndefinedPixelTrait;
451 pixel_info->alpha=(MagickRealType) OpaqueAlpha;
452 if (image != (Image *) NULL)
454 pixel_info->storage_class=image->storage_class;
455 pixel_info->colorspace=image->colorspace;
456 pixel_info->fuzz=image->fuzz;
457 pixel_info->depth=image->depth;
458 pixel_info->alpha_trait=image->alpha_trait;
459 if (pixel != (Quantum *) NULL)
461 pixel_info->red=(MagickRealType)
462 pixel[image->channel_map[RedPixelChannel].offset];
463 pixel_info->green=(MagickRealType)
464 pixel[image->channel_map[GreenPixelChannel].offset];
465 pixel_info->blue=(MagickRealType)
466 pixel[image->channel_map[BluePixelChannel].offset];
467 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
468 pixel_info->black=(MagickRealType)
469 pixel[image->channel_map[BlackPixelChannel].offset];
470 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
471 pixel_info->alpha=(MagickRealType)
472 pixel[image->channel_map[AlphaPixelChannel].offset];
473 if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
474 pixel_info->index=(MagickRealType)
475 pixel[image->channel_map[IndexPixelChannel].offset];
480static inline PixelTrait GetPixelTraits(
const Image *magick_restrict image,
481 const PixelChannel channel)
483 if ((
size_t) channel >= MaxPixelChannels)
484 return(UndefinedPixelTrait);
485 return(image->channel_map[channel].traits);
488static inline PixelTrait GetPixelWriteMaskTraits(
489 const Image *magick_restrict image)
491 return(image->channel_map[WriteMaskPixelChannel].traits);
494static inline Quantum GetPixelY(
const Image *magick_restrict image,
495 const Quantum *magick_restrict pixel)
497 return(pixel[image->channel_map[YPixelChannel].offset]);
500static inline PixelTrait GetPixelYTraits(
const Image *magick_restrict image)
502 return(image->channel_map[YPixelChannel].traits);
505static inline Quantum GetPixelYellow(
const Image *magick_restrict image,
506 const Quantum *magick_restrict pixel)
508 return(pixel[image->channel_map[YellowPixelChannel].offset]);
511static inline PixelTrait GetPixelYellowTraits(
512 const Image *magick_restrict image)
514 return(image->channel_map[YellowPixelChannel].traits);
517static inline MagickRealType AbsolutePixelValue(
const MagickRealType x)
519 return(x < 0.0 ? -x : x);
522static inline QuantumAny CastDoubleToQuantumAny(
const double x)
532 value=(x < 0.0) ? ceil(x) : floor(x);
538 if (value >= ((
double) ((QuantumAny) ~0)))
541 return((QuantumAny) ~0);
543 return((QuantumAny) value);
546static inline MagickBooleanType IsPixelAtDepth(
const Quantum pixel,
547 const QuantumAny range)
554#if !defined(MAGICKCORE_HDRI_SUPPORT)
555 quantum=(Quantum) (((
double) QuantumRange*((QuantumAny) (((
double) range*
556 pixel)/(
double) QuantumRange+0.5)))/(
double) range+0.5);
558 quantum=(Quantum) (((
double) QuantumRange*((
double) CastDoubleToQuantumAny(
559 ((
double) range*(
double) pixel)/(
double) QuantumRange+0.5)))/
562 return(pixel == quantum ? MagickTrue : MagickFalse);
565static inline MagickBooleanType IsPixelEquivalent(
566 const Image *magick_restrict image,
const Quantum *magick_restrict p,
567 const PixelInfo *magick_restrict q)
574 color=(MagickRealType) p[image->channel_map[AlphaPixelChannel].offset];
575 alpha=image->alpha_trait == UndefinedPixelTrait ? (MagickRealType)
577 beta=q->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
579 if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
581 if ((AbsolutePixelValue(alpha-(MagickRealType) TransparentAlpha) < MagickEpsilon) ||
582 (AbsolutePixelValue(beta-(MagickRealType) TransparentAlpha) < MagickEpsilon))
584 color=(MagickRealType) p[image->channel_map[RedPixelChannel].offset];
585 if (AbsolutePixelValue(color-q->red) >= MagickEpsilon)
587 color=(MagickRealType) p[image->channel_map[GreenPixelChannel].offset];
588 if (AbsolutePixelValue(color-q->green) >= MagickEpsilon)
590 color=(MagickRealType) p[image->channel_map[BluePixelChannel].offset];
591 if (AbsolutePixelValue(color-q->blue) >= MagickEpsilon)
593 if (image->colorspace == CMYKColorspace)
595 color=(MagickRealType) p[image->channel_map[BlackPixelChannel].offset];
596 if (AbsolutePixelValue(color-q->black) >= MagickEpsilon)
602static inline MagickBooleanType IsPixelGray(
const Image *magick_restrict image,
603 const Quantum *magick_restrict pixel)
610 (MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
611 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
613 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]-
614 (MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
615 if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
616 (AbsolutePixelValue(green_blue) < MagickEpsilon))
621static inline MagickBooleanType IsPixelInfoEquivalent(
622 const PixelInfo *magick_restrict p,
const PixelInfo *magick_restrict q)
628 alpha=p->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
630 beta=q->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
632 if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
634 if ((AbsolutePixelValue(alpha-(MagickRealType) TransparentAlpha) < MagickEpsilon) ||
635 (AbsolutePixelValue(beta-(MagickRealType) TransparentAlpha) < MagickEpsilon))
637 if (AbsolutePixelValue(p->red-q->red) >= MagickEpsilon)
639 if (AbsolutePixelValue(p->green-q->green) >= MagickEpsilon)
641 if (AbsolutePixelValue(p->blue-q->blue) >= MagickEpsilon)
643 if (p->colorspace == CMYKColorspace)
645 if (AbsolutePixelValue(p->black-q->black) >= MagickEpsilon)
651static inline MagickBooleanType IsPixelMonochrome(
652 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
659 red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
660 if ((AbsolutePixelValue(red) >= MagickEpsilon) &&
661 (AbsolutePixelValue(red-(MagickRealType) QuantumRange) >= MagickEpsilon))
664 (MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
665 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
667 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]-
668 (MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
669 if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
670 (AbsolutePixelValue(green_blue) < MagickEpsilon))
675static inline MagickBooleanType IsPixelInfoGray(
676 const PixelInfo *magick_restrict pixel)
678 if ((AbsolutePixelValue(pixel->red-pixel->green) < MagickEpsilon) &&
679 (AbsolutePixelValue(pixel->green-pixel->blue) < MagickEpsilon))
684static inline MagickBooleanType IsPixelInfoMonochrome(
685 const PixelInfo *magick_restrict pixel_info)
691 if ((AbsolutePixelValue(pixel_info->red) >= MagickEpsilon) ||
692 (AbsolutePixelValue(pixel_info->red-(MagickRealType) QuantumRange) >= MagickEpsilon))
694 red_green=pixel_info->red-pixel_info->green;
695 green_blue=pixel_info->green-pixel_info->blue;
696 if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
697 (AbsolutePixelValue(green_blue) < MagickEpsilon))
702static inline void SetPixela(
const Image *magick_restrict image,
703 const Quantum a,Quantum *magick_restrict pixel)
705 if (image->channel_map[aPixelChannel].traits != UndefinedPixelTrait)
706 pixel[image->channel_map[aPixelChannel].offset]=a;
709static inline void SetPixelAlpha(
const Image *magick_restrict image,
710 const Quantum alpha,Quantum *magick_restrict pixel)
712 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
713 pixel[image->channel_map[AlphaPixelChannel].offset]=alpha;
716static inline void SetPixelAlphaTraits(Image *image,
const PixelTrait traits)
718 image->channel_map[AlphaPixelChannel].traits=traits;
721static inline void SetPixelb(
const Image *magick_restrict image,
722 const Quantum b,Quantum *magick_restrict pixel)
724 if (image->channel_map[bPixelChannel].traits != UndefinedPixelTrait)
725 pixel[image->channel_map[bPixelChannel].offset]=b;
728static inline void SetPixelBackgroundColor(
const Image *magick_restrict image,
729 Quantum *magick_restrict pixel)
734 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
735 pixel[i]=(Quantum) 0;
736 pixel[image->channel_map[RedPixelChannel].offset]=
737 ClampToQuantum(image->background_color.red);
738 pixel[image->channel_map[GreenPixelChannel].offset]=
739 ClampToQuantum(image->background_color.green);
740 pixel[image->channel_map[BluePixelChannel].offset]=
741 ClampToQuantum(image->background_color.blue);
742 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
743 pixel[image->channel_map[BlackPixelChannel].offset]=
744 ClampToQuantum(image->background_color.black);
745 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
746 pixel[image->channel_map[AlphaPixelChannel].offset]=
747 image->background_color.alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
748 ClampToQuantum(image->background_color.alpha);
751static inline void SetPixelBackgoundColor(
const Image *magick_restrict image,
752 Quantum *magick_restrict pixel) magick_attribute((deprecated));
754static inline void SetPixelBackgoundColor(
const Image *magick_restrict image,
755 Quantum *magick_restrict pixel)
757 SetPixelBackgroundColor(image,pixel);
760static inline void SetPixelBlack(
const Image *magick_restrict image,
761 const Quantum black,Quantum *magick_restrict pixel)
763 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
764 pixel[image->channel_map[BlackPixelChannel].offset]=black;
767static inline void SetPixelBlackTraits(Image *image,
const PixelTrait traits)
769 image->channel_map[BlackPixelChannel].traits=traits;
772static inline void SetPixelBlue(
const Image *magick_restrict image,
773 const Quantum blue,Quantum *magick_restrict pixel)
775 pixel[image->channel_map[BluePixelChannel].offset]=blue;
778static inline void SetPixelBlueTraits(Image *image,
const PixelTrait traits)
780 image->channel_map[BluePixelChannel].traits=traits;
783static inline void SetPixelCb(
const Image *magick_restrict image,
784 const Quantum cb,Quantum *magick_restrict pixel)
786 pixel[image->channel_map[CbPixelChannel].offset]=cb;
789static inline void SetPixelCbTraits(Image *image,
const PixelTrait traits)
791 image->channel_map[CbPixelChannel].traits=traits;
794static inline void SetPixelChannel(
const Image *magick_restrict image,
795 const PixelChannel channel,
const Quantum quantum,
796 Quantum *magick_restrict pixel)
798 if ((
size_t) channel >= MaxPixelChannels)
800 if (image->channel_map[channel].traits != UndefinedPixelTrait)
801 pixel[image->channel_map[channel].offset]=quantum;
804static inline void SetPixelChannelAttributes(
805 const Image *magick_restrict image,
const PixelChannel channel,
806 const PixelTrait traits,
const ssize_t offset)
808 if ((offset < 0) || (offset >= MaxPixelChannels))
810 if ((
size_t) channel >= MaxPixelChannels)
812 image->channel_map[offset].channel=channel;
813 image->channel_map[channel].offset=offset;
814 image->channel_map[channel].traits=traits;
817static inline void SetPixelChannelChannel(
const Image *magick_restrict image,
818 const PixelChannel channel,
const ssize_t offset)
820 if ((offset < 0) || (offset >= MaxPixelChannels))
822 if ((
size_t) channel >= MaxPixelChannels)
824 image->channel_map[offset].channel=channel;
825 image->channel_map[channel].offset=offset;
828static inline void SetPixelChannels(Image *image,
const size_t number_channels)
830 image->number_channels=number_channels;
833static inline void SetPixelChannelTraits(Image *image,
834 const PixelChannel channel,
const PixelTrait traits)
836 if ((
size_t) channel >= MaxPixelChannels)
838 image->channel_map[channel].traits=traits;
841static inline void SetPixelCompositeMask(
const Image *magick_restrict image,
842 const Quantum mask,Quantum *magick_restrict pixel)
844 if (image->channel_map[CompositeMaskPixelChannel].traits != UndefinedPixelTrait)
845 pixel[image->channel_map[CompositeMaskPixelChannel].offset]=mask;
848static inline void SetPixelCr(
const Image *magick_restrict image,
849 const Quantum cr,Quantum *magick_restrict pixel)
851 pixel[image->channel_map[CrPixelChannel].offset]=cr;
854static inline void SetPixelCrTraits(Image *image,
const PixelTrait traits)
856 image->channel_map[CrPixelChannel].traits=traits;
859static inline void SetPixelCyan(
const Image *magick_restrict image,
860 const Quantum cyan,Quantum *magick_restrict pixel)
862 pixel[image->channel_map[CyanPixelChannel].offset]=cyan;
865static inline void SetPixelGray(
const Image *magick_restrict image,
866 const Quantum gray,Quantum *magick_restrict pixel)
868 pixel[image->channel_map[GrayPixelChannel].offset]=gray;
871static inline void SetPixelGrayTraits(Image *image,
const PixelTrait traits)
873 image->channel_map[GrayPixelChannel].traits=traits;
876static inline void SetPixelGreen(
const Image *magick_restrict image,
877 const Quantum green,Quantum *magick_restrict pixel)
879 pixel[image->channel_map[GreenPixelChannel].offset]=green;
882static inline void SetPixelGreenTraits(Image *image,
const PixelTrait traits)
884 image->channel_map[GreenPixelChannel].traits=traits;
887static inline void SetPixelIndex(
const Image *magick_restrict image,
888 const Quantum index,Quantum *magick_restrict pixel)
890 if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
891 pixel[image->channel_map[IndexPixelChannel].offset]=index;
894static inline void SetPixelIndexTraits(Image *image,
const PixelTrait traits)
896 image->channel_map[IndexPixelChannel].traits=traits;
899static inline void SetPixelViaPixelInfo(
const Image *magick_restrict image,
900 const PixelInfo *magick_restrict pixel_info,Quantum *magick_restrict pixel)
902 pixel[image->channel_map[RedPixelChannel].offset]=
903 ClampToQuantum(pixel_info->red);
904 pixel[image->channel_map[GreenPixelChannel].offset]=
905 ClampToQuantum(pixel_info->green);
906 pixel[image->channel_map[BluePixelChannel].offset]=
907 ClampToQuantum(pixel_info->blue);
908 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
909 pixel[image->channel_map[BlackPixelChannel].offset]=
910 ClampToQuantum(pixel_info->black);
911 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
912 pixel[image->channel_map[AlphaPixelChannel].offset]=
913 pixel_info->alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
914 ClampToQuantum(pixel_info->alpha);
917static inline void SetPixelL(
const Image *magick_restrict image,
const Quantum L,
918 Quantum *magick_restrict pixel)
920 if (image->channel_map[LPixelChannel].traits != UndefinedPixelTrait)
921 pixel[image->channel_map[LPixelChannel].offset]=L;
924static inline void SetPixelMagenta(
const Image *magick_restrict image,
925 const Quantum magenta,Quantum *magick_restrict pixel)
927 pixel[image->channel_map[MagentaPixelChannel].offset]=magenta;
930static inline void SetPixelMagentaTraits(Image *image,
const PixelTrait traits)
932 image->channel_map[MagentaPixelChannel].traits=traits;
935static inline void SetPixelMeta(
const Image *magick_restrict image,
936 const Quantum red,Quantum *magick_restrict pixel)
938 pixel[image->channel_map[MetaPixelChannels].offset]=red;
941static inline void SetPixelMetaTraits(Image *image,
const PixelTrait traits)
943 image->channel_map[MetaPixelChannels].traits=traits;
946static inline void SetPixelReadMask(
const Image *magick_restrict image,
947 const Quantum mask,Quantum *magick_restrict pixel)
949 if (image->channel_map[ReadMaskPixelChannel].traits != UndefinedPixelTrait)
950 pixel[image->channel_map[ReadMaskPixelChannel].offset]=mask;
953static inline void SetPixelMetacontentExtent(Image *image,
const size_t extent)
955 image->metacontent_extent=extent;
958static inline void SetPixelOpacity(
const Image *magick_restrict image,
959 const Quantum alpha,Quantum *magick_restrict pixel)
961 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
962 pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
965static inline void SetPixelRed(
const Image *magick_restrict image,
966 const Quantum red,Quantum *magick_restrict pixel)
968 pixel[image->channel_map[RedPixelChannel].offset]=red;
971static inline void SetPixelRedTraits(Image *image,
const PixelTrait traits)
973 image->channel_map[RedPixelChannel].traits=traits;
976static inline void SetPixelWriteMask(
const Image *magick_restrict image,
977 const Quantum mask,Quantum *magick_restrict pixel)
979 if (image->channel_map[WriteMaskPixelChannel].traits != UndefinedPixelTrait)
980 pixel[image->channel_map[WriteMaskPixelChannel].offset]=mask;
983static inline void SetPixelYellow(
const Image *magick_restrict image,
984 const Quantum yellow,Quantum *magick_restrict pixel)
986 pixel[image->channel_map[YellowPixelChannel].offset]=yellow;
989static inline void SetPixelYellowTraits(Image *image,
const PixelTrait traits)
991 image->channel_map[YellowPixelChannel].traits=traits;
994static inline void SetPixelY(
const Image *magick_restrict image,
995 const Quantum y,Quantum *magick_restrict pixel)
997 pixel[image->channel_map[YPixelChannel].offset]=y;
1000static inline void SetPixelYTraits(Image *image,
const PixelTrait traits)
1002 image->channel_map[YPixelChannel].traits=traits;
1005static inline size_t GetImageChannels(
const Image *image)
1014 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1016 PixelChannel channel = GetPixelChannelChannel(image,i);
1017 PixelTrait traits = GetPixelChannelTraits(image,channel);
1018 if ((traits & UpdatePixelTrait) != 0)
1021 return(channels == 0 ? (
size_t) 1 : channels);
1024#if defined(__cplusplus) || defined(c_plusplus)