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 if ((
size_t) channel >= MaxPixelChannels)
131 return(image->channel_map[channel].offset);
134static inline PixelTrait GetPixelChannelTraits(
135 const Image *magick_restrict image,
const PixelChannel channel)
137 if ((
size_t) channel >= MaxPixelChannels)
138 return(UndefinedPixelTrait);
139 return(image->channel_map[channel].traits);
142static inline size_t GetPixelChannels(
const Image *magick_restrict image)
144 return(image->number_channels);
147static inline Quantum GetPixelCompositeMask(
148 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
150 if (image->channel_map[CompositeMaskPixelChannel].traits == UndefinedPixelTrait)
151 return((Quantum) QuantumRange);
152 return(pixel[image->channel_map[CompositeMaskPixelChannel].offset]);
155static inline PixelTrait GetPixelCompositeMaskTraits(
156 const Image *magick_restrict image)
158 return(image->channel_map[CompositeMaskPixelChannel].traits);
161static inline Quantum GetPixelCr(
const Image *magick_restrict image,
162 const Quantum *magick_restrict pixel)
164 return(pixel[image->channel_map[CrPixelChannel].offset]);
167static inline PixelTrait GetPixelCrTraits(
const Image *magick_restrict image)
169 return(image->channel_map[CrPixelChannel].traits);
172static inline Quantum GetPixelCyan(
const Image *magick_restrict image,
173 const Quantum *magick_restrict pixel)
175 return(pixel[image->channel_map[CyanPixelChannel].offset]);
178static inline PixelTrait GetPixelCyanTraits(
const Image *magick_restrict image)
180 return(image->channel_map[CyanPixelChannel].traits);
183static inline Quantum GetPixelGray(
const Image *magick_restrict image,
184 const Quantum *magick_restrict pixel)
186 return(pixel[image->channel_map[GrayPixelChannel].offset]);
189static inline PixelTrait GetPixelGrayTraits(
const Image *magick_restrict image)
191 return(image->channel_map[GrayPixelChannel].traits);
194static inline Quantum GetPixelGreen(
const Image *magick_restrict image,
195 const Quantum *magick_restrict pixel)
197 return(pixel[image->channel_map[GreenPixelChannel].offset]);
200static inline PixelTrait GetPixelGreenTraits(
const Image *magick_restrict image)
202 return(image->channel_map[GreenPixelChannel].traits);
205static inline Quantum GetPixelIndex(
const Image *magick_restrict image,
206 const Quantum *magick_restrict pixel)
208 if (image->channel_map[IndexPixelChannel].traits == UndefinedPixelTrait)
210#if defined(MAGICKCORE_HDRI_SUPPORT)
211 if (pixel[image->channel_map[IndexPixelChannel].offset] < 0)
214 return(pixel[image->channel_map[IndexPixelChannel].offset]);
217static inline PixelTrait GetPixelIndexTraits(
const Image *magick_restrict image)
219 return(image->channel_map[IndexPixelChannel].traits);
222static inline MagickRealType GetPixelInfoChannel(
223 const PixelInfo *magick_restrict pixel_info,
const PixelChannel channel)
227 case RedPixelChannel:
return(pixel_info->red);
228 case GreenPixelChannel:
return(pixel_info->green);
229 case BluePixelChannel:
return(pixel_info->blue);
230 case BlackPixelChannel:
232 if (pixel_info->colorspace != CMYKColorspace)
234 return(pixel_info->black);
236 case AlphaPixelChannel:
238 if (pixel_info->alpha_trait == UndefinedPixelTrait)
239 return((MagickRealType) OpaqueAlpha);
240 return(pixel_info->alpha);
242 case IndexPixelChannel:
return(pixel_info->index);
245 return((MagickRealType) 0.0);
248static inline MagickRealType GetPixelInfoLuma(
249 const PixelInfo *magick_restrict pixel)
254 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
256 if (pixel->colorspace == sRGBColorspace)
258 return(EncodePixelGamma(pixel->red));
260 if (pixel->colorspace == sRGBColorspace)
262 intensity=(MagickRealType) (0.212656*pixel->red+0.715158*pixel->green+
263 0.072186*pixel->blue);
266 intensity=(MagickRealType) (0.212656*EncodePixelGamma(pixel->red)+
267 0.715158*EncodePixelGamma(pixel->green)+
268 0.072186*EncodePixelGamma(pixel->blue));
272static inline MagickRealType GetPixelInfoLuminance(
273 const PixelInfo *magick_restrict pixel)
278 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
280 if (pixel->colorspace != sRGBColorspace)
282 return(DecodePixelGamma(pixel->red));
284 if (pixel->colorspace != sRGBColorspace)
286 intensity=(MagickRealType) (0.212656*pixel->red+0.715158*pixel->green+
287 0.072186*pixel->blue);
290 intensity=(MagickRealType) (0.212656*DecodePixelGamma(pixel->red)+
291 0.715158*DecodePixelGamma(pixel->green)+
292 0.072186*DecodePixelGamma(pixel->blue));
296static inline Quantum GetPixelL(
const Image *magick_restrict image,
297 const Quantum *magick_restrict pixel)
299 return(pixel[image->channel_map[LPixelChannel].offset]);
302static inline ssize_t GetPixelLabel(
const Image *magick_restrict image,
303 const Quantum *magick_restrict pixel)
305 return((ssize_t) pixel[image->channel_map[LabelPixelChannel].offset]);
308static inline MagickRealType GetPixelLuma(
309 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
317 red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
318 green=(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
319 blue=(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
320 if ((red == green) && (green == blue))
323 intensity=0.212656*red+0.715158*green+0.072186*blue;
327static inline MagickRealType GetPixelLuminance(
328 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
336 if (image->colorspace != sRGBColorspace)
338 red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
339 green=(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
340 blue=(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
344 red=DecodePixelGamma((MagickRealType)
345 pixel[image->channel_map[RedPixelChannel].offset]);
346 green=DecodePixelGamma((MagickRealType)
347 pixel[image->channel_map[GreenPixelChannel].offset]);
348 blue=DecodePixelGamma((MagickRealType)
349 pixel[image->channel_map[BluePixelChannel].offset]);
351 if ((red == green) && (green == blue))
354 intensity=0.212656*red+0.715158*green+0.072186*blue;
358static inline Quantum GetPixelMagenta(
const Image *magick_restrict image,
359 const Quantum *magick_restrict pixel)
361 return(pixel[image->channel_map[MagentaPixelChannel].offset]);
364static inline PixelTrait GetPixelMagentaTraits(
365 const Image *magick_restrict image)
367 return(image->channel_map[MagentaPixelChannel].traits);
370static inline Quantum GetPixelMeta(
const Image *magick_restrict image,
371 const Quantum *magick_restrict pixel)
373 if (image->channel_map[MetaPixelChannels].traits == UndefinedPixelTrait)
375 return(pixel[image->channel_map[MetaPixelChannels].offset]);
378static inline PixelTrait GetPixelMetaTraits(
const Image *magick_restrict image)
380 return(image->channel_map[MetaPixelChannels].traits);
383static inline Quantum GetPixelReadMask(
const Image *magick_restrict image,
384 const Quantum *magick_restrict pixel)
386 if (image->channel_map[ReadMaskPixelChannel].traits == UndefinedPixelTrait)
387 return((Quantum) QuantumRange);
388 return(pixel[image->channel_map[ReadMaskPixelChannel].offset]);
391static inline void GetPixelInfoRGBA(
const Quantum red,
const Quantum green,
392 const Quantum blue,
const Quantum alpha,PixelInfo *magick_restrict pixel)
394 GetPixelInfo((Image *) NULL,pixel);
395 pixel->red=(MagickRealType) red;
396 pixel->green=(MagickRealType) green;
397 pixel->blue=(MagickRealType) blue;
398 pixel->alpha=(MagickRealType) alpha;
401static inline Quantum GetPixelWriteMask(
402 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
404 if (image->channel_map[WriteMaskPixelChannel].traits == UndefinedPixelTrait)
405 return((Quantum) QuantumRange);
406 return(pixel[image->channel_map[WriteMaskPixelChannel].offset]);
409static inline PixelTrait GetPixelReadMaskTraits(
410 const Image *magick_restrict image)
412 return(image->channel_map[ReadMaskPixelChannel].traits);
415static inline size_t GetPixelMetaChannels(
const Image *magick_restrict image)
417 return(image->number_meta_channels);
420static inline size_t GetPixelMetacontentExtent(
421 const Image *magick_restrict image)
423 return(image->metacontent_extent);
426static inline Quantum GetPixelOpacity(
const Image *magick_restrict image,
427 const Quantum *magick_restrict pixel)
429 if (image->channel_map[AlphaPixelChannel].traits != BlendPixelTrait)
430 return(QuantumRange-OpaqueAlpha);
431 return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
434static inline Quantum GetPixelRed(
const Image *magick_restrict image,
435 const Quantum *magick_restrict pixel)
437 return(pixel[image->channel_map[RedPixelChannel].offset]);
440static inline PixelTrait GetPixelRedTraits(
const Image *magick_restrict image)
442 return(image->channel_map[RedPixelChannel].traits);
445static inline void GetPixelInfoPixel(
const Image *magick_restrict image,
446 const Quantum *magick_restrict pixel,PixelInfo *magick_restrict pixel_info)
448 (void) ResetMagickMemory(pixel_info,0,
sizeof(*pixel_info));
449 pixel_info->storage_class=DirectClass;
450 pixel_info->colorspace=sRGBColorspace;
451 pixel_info->depth=MAGICKCORE_QUANTUM_DEPTH;
452 pixel_info->alpha_trait=UndefinedPixelTrait;
453 pixel_info->alpha=(MagickRealType) OpaqueAlpha;
454 if (image != (Image *) NULL)
456 pixel_info->storage_class=image->storage_class;
457 pixel_info->colorspace=image->colorspace;
458 pixel_info->fuzz=image->fuzz;
459 pixel_info->depth=image->depth;
460 pixel_info->alpha_trait=image->alpha_trait;
461 if (pixel != (Quantum *) NULL)
463 pixel_info->red=(MagickRealType)
464 pixel[image->channel_map[RedPixelChannel].offset];
465 pixel_info->green=(MagickRealType)
466 pixel[image->channel_map[GreenPixelChannel].offset];
467 pixel_info->blue=(MagickRealType)
468 pixel[image->channel_map[BluePixelChannel].offset];
469 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
470 pixel_info->black=(MagickRealType)
471 pixel[image->channel_map[BlackPixelChannel].offset];
472 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
473 pixel_info->alpha=(MagickRealType)
474 pixel[image->channel_map[AlphaPixelChannel].offset];
475 if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
476 pixel_info->index=(MagickRealType)
477 pixel[image->channel_map[IndexPixelChannel].offset];
482static inline PixelTrait GetPixelTraits(
const Image *magick_restrict image,
483 const PixelChannel channel)
485 if ((
size_t) channel >= MaxPixelChannels)
486 return(UndefinedPixelTrait);
487 return(image->channel_map[channel].traits);
490static inline PixelTrait GetPixelWriteMaskTraits(
491 const Image *magick_restrict image)
493 return(image->channel_map[WriteMaskPixelChannel].traits);
496static inline Quantum GetPixelY(
const Image *magick_restrict image,
497 const Quantum *magick_restrict pixel)
499 return(pixel[image->channel_map[YPixelChannel].offset]);
502static inline PixelTrait GetPixelYTraits(
const Image *magick_restrict image)
504 return(image->channel_map[YPixelChannel].traits);
507static inline Quantum GetPixelYellow(
const Image *magick_restrict image,
508 const Quantum *magick_restrict pixel)
510 return(pixel[image->channel_map[YellowPixelChannel].offset]);
513static inline PixelTrait GetPixelYellowTraits(
514 const Image *magick_restrict image)
516 return(image->channel_map[YellowPixelChannel].traits);
519static inline MagickRealType AbsolutePixelValue(
const MagickRealType x)
521 return(x < 0.0 ? -x : x);
524static inline QuantumAny CastDoubleToQuantumAny(
const double x)
534 value=(x < 0.0) ? ceil(x) : floor(x);
540 if (value >= ((
double) ((QuantumAny) ~0)))
543 return((QuantumAny) ~0);
545 return((QuantumAny) value);
548static inline MagickBooleanType IsPixelAtDepth(
const Quantum pixel,
549 const QuantumAny range)
556#if !defined(MAGICKCORE_HDRI_SUPPORT)
557 quantum=(Quantum) (((
double) QuantumRange*((QuantumAny) (((
double) range*
558 pixel)/(
double) QuantumRange+0.5)))/(
double) range+0.5);
560 quantum=(Quantum) (((
double) QuantumRange*((
double) CastDoubleToQuantumAny(
561 ((
double) range*(
double) pixel)/(
double) QuantumRange+0.5)))/
564 return(pixel == quantum ? MagickTrue : MagickFalse);
567static inline MagickBooleanType IsPixelEquivalent(
568 const Image *magick_restrict image,
const Quantum *magick_restrict p,
569 const PixelInfo *magick_restrict q)
576 if ((image->alpha_trait == UndefinedPixelTrait) ||
577 (image->channel_map[AlphaPixelChannel].traits == UndefinedPixelTrait))
578 alpha=(MagickRealType) OpaqueAlpha;
580 alpha=(MagickRealType) p[image->channel_map[AlphaPixelChannel].offset];
581 beta=q->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
583 if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
585 if ((AbsolutePixelValue(alpha-(MagickRealType) TransparentAlpha) < MagickEpsilon) ||
586 (AbsolutePixelValue(beta-(MagickRealType) TransparentAlpha) < MagickEpsilon))
588 color=(MagickRealType) p[image->channel_map[RedPixelChannel].offset];
589 if (AbsolutePixelValue(color-q->red) >= MagickEpsilon)
591 color=(MagickRealType) p[image->channel_map[GreenPixelChannel].offset];
592 if (AbsolutePixelValue(color-q->green) >= MagickEpsilon)
594 color=(MagickRealType) p[image->channel_map[BluePixelChannel].offset];
595 if (AbsolutePixelValue(color-q->blue) >= MagickEpsilon)
597 if (image->colorspace == CMYKColorspace)
599 color=(MagickRealType) p[image->channel_map[BlackPixelChannel].offset];
600 if (AbsolutePixelValue(color-q->black) >= MagickEpsilon)
606static inline MagickBooleanType IsPixelGray(
const Image *magick_restrict image,
607 const Quantum *magick_restrict pixel)
614 (MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
615 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
617 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]-
618 (MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
619 if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
620 (AbsolutePixelValue(green_blue) < MagickEpsilon))
625static inline MagickBooleanType IsPixelInfoEquivalent(
626 const PixelInfo *magick_restrict p,
const PixelInfo *magick_restrict q)
632 alpha=p->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
634 beta=q->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
636 if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
638 if ((AbsolutePixelValue(alpha-(MagickRealType) TransparentAlpha) < MagickEpsilon) ||
639 (AbsolutePixelValue(beta-(MagickRealType) TransparentAlpha) < MagickEpsilon))
641 if (AbsolutePixelValue(p->red-q->red) >= MagickEpsilon)
643 if (AbsolutePixelValue(p->green-q->green) >= MagickEpsilon)
645 if (AbsolutePixelValue(p->blue-q->blue) >= MagickEpsilon)
647 if (p->colorspace == CMYKColorspace)
649 if (AbsolutePixelValue(p->black-q->black) >= MagickEpsilon)
655static inline MagickBooleanType IsPixelMonochrome(
656 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
663 red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
664 if ((AbsolutePixelValue(red) >= MagickEpsilon) &&
665 (AbsolutePixelValue(red-(MagickRealType) QuantumRange) >= MagickEpsilon))
668 (MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
669 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
671 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]-
672 (MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
673 if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
674 (AbsolutePixelValue(green_blue) < MagickEpsilon))
679static inline MagickBooleanType IsPixelInfoGray(
680 const PixelInfo *magick_restrict pixel)
682 if ((AbsolutePixelValue(pixel->red-pixel->green) < MagickEpsilon) &&
683 (AbsolutePixelValue(pixel->green-pixel->blue) < MagickEpsilon))
688static inline MagickBooleanType IsPixelInfoMonochrome(
689 const PixelInfo *magick_restrict pixel_info)
695 if ((AbsolutePixelValue(pixel_info->red) >= MagickEpsilon) &&
696 (AbsolutePixelValue(pixel_info->red-(MagickRealType) QuantumRange) >= MagickEpsilon))
698 red_green=pixel_info->red-pixel_info->green;
699 green_blue=pixel_info->green-pixel_info->blue;
700 if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
701 (AbsolutePixelValue(green_blue) < MagickEpsilon))
706static inline void SetPixela(
const Image *magick_restrict image,
707 const Quantum a,Quantum *magick_restrict pixel)
709 if (image->channel_map[aPixelChannel].traits != UndefinedPixelTrait)
710 pixel[image->channel_map[aPixelChannel].offset]=a;
713static inline void SetPixelAlpha(
const Image *magick_restrict image,
714 const Quantum alpha,Quantum *magick_restrict pixel)
716 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
717 pixel[image->channel_map[AlphaPixelChannel].offset]=alpha;
720static inline void SetPixelAlphaTraits(Image *image,
const PixelTrait traits)
722 image->channel_map[AlphaPixelChannel].traits=traits;
725static inline void SetPixelb(
const Image *magick_restrict image,
726 const Quantum b,Quantum *magick_restrict pixel)
728 if (image->channel_map[bPixelChannel].traits != UndefinedPixelTrait)
729 pixel[image->channel_map[bPixelChannel].offset]=b;
732static inline void SetPixelBackgroundColor(
const Image *magick_restrict image,
733 Quantum *magick_restrict pixel)
738 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
739 pixel[i]=(Quantum) 0;
740 pixel[image->channel_map[RedPixelChannel].offset]=
741 ClampToQuantum(image->background_color.red);
742 pixel[image->channel_map[GreenPixelChannel].offset]=
743 ClampToQuantum(image->background_color.green);
744 pixel[image->channel_map[BluePixelChannel].offset]=
745 ClampToQuantum(image->background_color.blue);
746 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
747 pixel[image->channel_map[BlackPixelChannel].offset]=
748 ClampToQuantum(image->background_color.black);
749 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
750 pixel[image->channel_map[AlphaPixelChannel].offset]=
751 image->background_color.alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
752 ClampToQuantum(image->background_color.alpha);
755static inline void SetPixelBackgoundColor(
const Image *magick_restrict image,
756 Quantum *magick_restrict pixel) magick_attribute((deprecated));
758static inline void SetPixelBackgoundColor(
const Image *magick_restrict image,
759 Quantum *magick_restrict pixel)
761 SetPixelBackgroundColor(image,pixel);
764static inline void SetPixelBlack(
const Image *magick_restrict image,
765 const Quantum black,Quantum *magick_restrict pixel)
767 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
768 pixel[image->channel_map[BlackPixelChannel].offset]=black;
771static inline void SetPixelBlackTraits(Image *image,
const PixelTrait traits)
773 image->channel_map[BlackPixelChannel].traits=traits;
776static inline void SetPixelBlue(
const Image *magick_restrict image,
777 const Quantum blue,Quantum *magick_restrict pixel)
779 pixel[image->channel_map[BluePixelChannel].offset]=blue;
782static inline void SetPixelBlueTraits(Image *image,
const PixelTrait traits)
784 image->channel_map[BluePixelChannel].traits=traits;
787static inline void SetPixelCb(
const Image *magick_restrict image,
788 const Quantum cb,Quantum *magick_restrict pixel)
790 pixel[image->channel_map[CbPixelChannel].offset]=cb;
793static inline void SetPixelCbTraits(Image *image,
const PixelTrait traits)
795 image->channel_map[CbPixelChannel].traits=traits;
798static inline void SetPixelChannel(
const Image *magick_restrict image,
799 const PixelChannel channel,
const Quantum quantum,
800 Quantum *magick_restrict pixel)
802 if ((
size_t) channel >= MaxPixelChannels)
804 if (image->channel_map[channel].traits != UndefinedPixelTrait)
805 pixel[image->channel_map[channel].offset]=quantum;
808static inline void SetPixelChannelAttributes(
809 const Image *magick_restrict image,
const PixelChannel channel,
810 const PixelTrait traits,
const ssize_t offset)
812 if ((offset < 0) || (offset >= MaxPixelChannels))
814 if ((
size_t) channel >= MaxPixelChannels)
816 image->channel_map[offset].channel=channel;
817 image->channel_map[channel].offset=offset;
818 image->channel_map[channel].traits=traits;
821static inline void SetPixelChannelChannel(
const Image *magick_restrict image,
822 const PixelChannel channel,
const ssize_t offset)
824 if ((offset < 0) || (offset >= MaxPixelChannels))
826 if ((
size_t) channel >= MaxPixelChannels)
828 image->channel_map[offset].channel=channel;
829 image->channel_map[channel].offset=offset;
832static inline void SetPixelChannels(Image *image,
const size_t number_channels)
834 image->number_channels=number_channels;
837static inline void SetPixelChannelTraits(Image *image,
838 const PixelChannel channel,
const PixelTrait traits)
840 if ((
size_t) channel >= MaxPixelChannels)
842 image->channel_map[channel].traits=traits;
845static inline void SetPixelCompositeMask(
const Image *magick_restrict image,
846 const Quantum mask,Quantum *magick_restrict pixel)
848 if (image->channel_map[CompositeMaskPixelChannel].traits != UndefinedPixelTrait)
849 pixel[image->channel_map[CompositeMaskPixelChannel].offset]=mask;
852static inline void SetPixelCr(
const Image *magick_restrict image,
853 const Quantum cr,Quantum *magick_restrict pixel)
855 pixel[image->channel_map[CrPixelChannel].offset]=cr;
858static inline void SetPixelCrTraits(Image *image,
const PixelTrait traits)
860 image->channel_map[CrPixelChannel].traits=traits;
863static inline void SetPixelCyan(
const Image *magick_restrict image,
864 const Quantum cyan,Quantum *magick_restrict pixel)
866 pixel[image->channel_map[CyanPixelChannel].offset]=cyan;
869static inline void SetPixelGray(
const Image *magick_restrict image,
870 const Quantum gray,Quantum *magick_restrict pixel)
872 pixel[image->channel_map[GrayPixelChannel].offset]=gray;
875static inline void SetPixelGrayTraits(Image *image,
const PixelTrait traits)
877 image->channel_map[GrayPixelChannel].traits=traits;
880static inline void SetPixelGreen(
const Image *magick_restrict image,
881 const Quantum green,Quantum *magick_restrict pixel)
883 pixel[image->channel_map[GreenPixelChannel].offset]=green;
886static inline void SetPixelGreenTraits(Image *image,
const PixelTrait traits)
888 image->channel_map[GreenPixelChannel].traits=traits;
891static inline void SetPixelIndex(
const Image *magick_restrict image,
892 const Quantum index,Quantum *magick_restrict pixel)
894 if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
895 pixel[image->channel_map[IndexPixelChannel].offset]=index;
898static inline void SetPixelIndexTraits(Image *image,
const PixelTrait traits)
900 image->channel_map[IndexPixelChannel].traits=traits;
903static inline void SetPixelViaPixelInfo(
const Image *magick_restrict image,
904 const PixelInfo *magick_restrict pixel_info,Quantum *magick_restrict pixel)
906 pixel[image->channel_map[RedPixelChannel].offset]=
907 ClampToQuantum(pixel_info->red);
908 pixel[image->channel_map[GreenPixelChannel].offset]=
909 ClampToQuantum(pixel_info->green);
910 pixel[image->channel_map[BluePixelChannel].offset]=
911 ClampToQuantum(pixel_info->blue);
912 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
913 pixel[image->channel_map[BlackPixelChannel].offset]=
914 ClampToQuantum(pixel_info->black);
915 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
916 pixel[image->channel_map[AlphaPixelChannel].offset]=
917 pixel_info->alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
918 ClampToQuantum(pixel_info->alpha);
921static inline void SetPixelL(
const Image *magick_restrict image,
const Quantum L,
922 Quantum *magick_restrict pixel)
924 if (image->channel_map[LPixelChannel].traits != UndefinedPixelTrait)
925 pixel[image->channel_map[LPixelChannel].offset]=L;
928static inline void SetPixelMagenta(
const Image *magick_restrict image,
929 const Quantum magenta,Quantum *magick_restrict pixel)
931 pixel[image->channel_map[MagentaPixelChannel].offset]=magenta;
934static inline void SetPixelMagentaTraits(Image *image,
const PixelTrait traits)
936 image->channel_map[MagentaPixelChannel].traits=traits;
939static inline void SetPixelMeta(
const Image *magick_restrict image,
940 const Quantum red,Quantum *magick_restrict pixel)
942 pixel[image->channel_map[MetaPixelChannels].offset]=red;
945static inline void SetPixelMetaTraits(Image *image,
const PixelTrait traits)
947 image->channel_map[MetaPixelChannels].traits=traits;
950static inline void SetPixelReadMask(
const Image *magick_restrict image,
951 const Quantum mask,Quantum *magick_restrict pixel)
953 if (image->channel_map[ReadMaskPixelChannel].traits != UndefinedPixelTrait)
954 pixel[image->channel_map[ReadMaskPixelChannel].offset]=mask;
957static inline void SetPixelMetacontentExtent(Image *image,
const size_t extent)
959 image->metacontent_extent=extent;
962static inline void SetPixelOpacity(
const Image *magick_restrict image,
963 const Quantum alpha,Quantum *magick_restrict pixel)
965 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
966 pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
969static inline void SetPixelRed(
const Image *magick_restrict image,
970 const Quantum red,Quantum *magick_restrict pixel)
972 pixel[image->channel_map[RedPixelChannel].offset]=red;
975static inline void SetPixelRedTraits(Image *image,
const PixelTrait traits)
977 image->channel_map[RedPixelChannel].traits=traits;
980static inline void SetPixelWriteMask(
const Image *magick_restrict image,
981 const Quantum mask,Quantum *magick_restrict pixel)
983 if (image->channel_map[WriteMaskPixelChannel].traits != UndefinedPixelTrait)
984 pixel[image->channel_map[WriteMaskPixelChannel].offset]=mask;
987static inline void SetPixelYellow(
const Image *magick_restrict image,
988 const Quantum yellow,Quantum *magick_restrict pixel)
990 pixel[image->channel_map[YellowPixelChannel].offset]=yellow;
993static inline void SetPixelYellowTraits(Image *image,
const PixelTrait traits)
995 image->channel_map[YellowPixelChannel].traits=traits;
998static inline void SetPixelY(
const Image *magick_restrict image,
999 const Quantum y,Quantum *magick_restrict pixel)
1001 pixel[image->channel_map[YPixelChannel].offset]=y;
1004static inline void SetPixelYTraits(Image *image,
const PixelTrait traits)
1006 image->channel_map[YPixelChannel].traits=traits;
1009static inline size_t GetImageChannels(
const Image *image)
1018 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1020 PixelChannel channel = GetPixelChannelChannel(image,i);
1021 PixelTrait traits = GetPixelChannelTraits(image,channel);
1022 if ((traits & UpdatePixelTrait) != 0)
1025 return(channels == 0 ? (
size_t) 1 : channels);
1028#if defined(__cplusplus) || defined(c_plusplus)