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->colorspace == sRGBColorspace)
254 intensity=(MagickRealType) (0.212656*pixel->red+0.715158*pixel->green+
255 0.072186*pixel->blue);
258 intensity=(MagickRealType) (0.212656*EncodePixelGamma(pixel->red)+
259 0.715158*EncodePixelGamma(pixel->green)+
260 0.072186*EncodePixelGamma(pixel->blue));
264static inline MagickRealType GetPixelInfoLuminance(
265 const PixelInfo *magick_restrict pixel)
270 if (pixel->colorspace != sRGBColorspace)
272 intensity=(MagickRealType) (0.212656*pixel->red+0.715158*pixel->green+
273 0.072186*pixel->blue);
276 intensity=(MagickRealType) (0.212656*DecodePixelGamma(pixel->red)+
277 0.715158*DecodePixelGamma(pixel->green)+
278 0.072186*DecodePixelGamma(pixel->blue));
282static inline Quantum GetPixelL(
const Image *magick_restrict image,
283 const Quantum *magick_restrict pixel)
285 return(pixel[image->channel_map[LPixelChannel].offset]);
288static inline ssize_t GetPixelLabel(
const Image *magick_restrict image,
289 const Quantum *magick_restrict pixel)
291 return((ssize_t) pixel[image->channel_map[LabelPixelChannel].offset]);
294static inline MagickRealType GetPixelLuma(
295 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
301 0.212656*(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]+
302 0.715158*(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]+
303 0.072186*(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
307static inline MagickRealType GetPixelLuminance(
308 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
313 if (image->colorspace != sRGBColorspace)
316 0.212656*(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]+
317 0.715158*(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]+
318 0.072186*(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
321 intensity=(MagickRealType) (0.212656*DecodePixelGamma((MagickRealType)
322 pixel[image->channel_map[RedPixelChannel].offset])+0.715158*
323 DecodePixelGamma((MagickRealType)
324 pixel[image->channel_map[GreenPixelChannel].offset])+0.072186*
325 DecodePixelGamma((MagickRealType)
326 pixel[image->channel_map[BluePixelChannel].offset]));
330static inline Quantum GetPixelMagenta(
const Image *magick_restrict image,
331 const Quantum *magick_restrict pixel)
333 return(pixel[image->channel_map[MagentaPixelChannel].offset]);
336static inline PixelTrait GetPixelMagentaTraits(
337 const Image *magick_restrict image)
339 return(image->channel_map[MagentaPixelChannel].traits);
342static inline Quantum GetPixelMeta(
const Image *magick_restrict image,
343 const Quantum *magick_restrict pixel)
345 if (image->channel_map[MetaPixelChannels].traits == UndefinedPixelTrait)
347 return(pixel[image->channel_map[MetaPixelChannels].offset]);
350static inline PixelTrait GetPixelMetaTraits(
const Image *magick_restrict image)
352 return(image->channel_map[MetaPixelChannels].traits);
355static inline Quantum GetPixelReadMask(
const Image *magick_restrict image,
356 const Quantum *magick_restrict pixel)
358 if (image->channel_map[ReadMaskPixelChannel].traits == UndefinedPixelTrait)
359 return((Quantum) QuantumRange);
360 return(pixel[image->channel_map[ReadMaskPixelChannel].offset]);
363static inline void GetPixelInfoRGBA(
const Quantum red,
const Quantum green,
364 const Quantum blue,
const Quantum alpha,PixelInfo *magick_restrict pixel)
366 GetPixelInfo((Image *) NULL,pixel);
367 pixel->red=(MagickRealType) red;
368 pixel->green=(MagickRealType) green;
369 pixel->blue=(MagickRealType) blue;
370 pixel->alpha=(MagickRealType) alpha;
373static inline Quantum GetPixelWriteMask(
374 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
376 if (image->channel_map[WriteMaskPixelChannel].traits == UndefinedPixelTrait)
377 return((Quantum) QuantumRange);
378 return(pixel[image->channel_map[WriteMaskPixelChannel].offset]);
381static inline PixelTrait GetPixelReadMaskTraits(
382 const Image *magick_restrict image)
384 return(image->channel_map[ReadMaskPixelChannel].traits);
387static inline size_t GetPixelMetaChannels(
const Image *magick_restrict image)
389 return(image->number_meta_channels);
392static inline size_t GetPixelMetacontentExtent(
393 const Image *magick_restrict image)
395 return(image->metacontent_extent);
398static inline Quantum GetPixelOpacity(
const Image *magick_restrict image,
399 const Quantum *magick_restrict pixel)
401 if (image->channel_map[AlphaPixelChannel].traits != BlendPixelTrait)
402 return(QuantumRange-OpaqueAlpha);
403 return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
406static inline Quantum GetPixelRed(
const Image *magick_restrict image,
407 const Quantum *magick_restrict pixel)
409 return(pixel[image->channel_map[RedPixelChannel].offset]);
412static inline PixelTrait GetPixelRedTraits(
const Image *magick_restrict image)
414 return(image->channel_map[RedPixelChannel].traits);
417static inline void GetPixelInfoPixel(
const Image *magick_restrict image,
418 const Quantum *magick_restrict pixel,PixelInfo *magick_restrict pixel_info)
420 (void) ResetMagickMemory(pixel_info,0,
sizeof(*pixel_info));
421 pixel_info->storage_class=DirectClass;
422 pixel_info->colorspace=sRGBColorspace;
423 pixel_info->depth=MAGICKCORE_QUANTUM_DEPTH;
424 pixel_info->alpha_trait=UndefinedPixelTrait;
425 pixel_info->alpha=(MagickRealType) OpaqueAlpha;
426 if (image != (Image *) NULL)
428 pixel_info->storage_class=image->storage_class;
429 pixel_info->colorspace=image->colorspace;
430 pixel_info->fuzz=image->fuzz;
431 pixel_info->depth=image->depth;
432 pixel_info->alpha_trait=image->alpha_trait;
433 if (pixel != (Quantum *) NULL)
435 pixel_info->red=(MagickRealType)
436 pixel[image->channel_map[RedPixelChannel].offset];
437 pixel_info->green=(MagickRealType)
438 pixel[image->channel_map[GreenPixelChannel].offset];
439 pixel_info->blue=(MagickRealType)
440 pixel[image->channel_map[BluePixelChannel].offset];
441 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
442 pixel_info->black=(MagickRealType)
443 pixel[image->channel_map[BlackPixelChannel].offset];
444 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
445 pixel_info->alpha=(MagickRealType)
446 pixel[image->channel_map[AlphaPixelChannel].offset];
447 if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
448 pixel_info->index=(MagickRealType)
449 pixel[image->channel_map[IndexPixelChannel].offset];
454static inline PixelTrait GetPixelTraits(
const Image *magick_restrict image,
455 const PixelChannel channel)
457 if ((
size_t) channel >= MaxPixelChannels)
458 return(UndefinedPixelTrait);
459 return(image->channel_map[channel].traits);
462static inline PixelTrait GetPixelWriteMaskTraits(
463 const Image *magick_restrict image)
465 return(image->channel_map[WriteMaskPixelChannel].traits);
468static inline Quantum GetPixelY(
const Image *magick_restrict image,
469 const Quantum *magick_restrict pixel)
471 return(pixel[image->channel_map[YPixelChannel].offset]);
474static inline PixelTrait GetPixelYTraits(
const Image *magick_restrict image)
476 return(image->channel_map[YPixelChannel].traits);
479static inline Quantum GetPixelYellow(
const Image *magick_restrict image,
480 const Quantum *magick_restrict pixel)
482 return(pixel[image->channel_map[YellowPixelChannel].offset]);
485static inline PixelTrait GetPixelYellowTraits(
486 const Image *magick_restrict image)
488 return(image->channel_map[YellowPixelChannel].traits);
491static inline MagickRealType AbsolutePixelValue(
const MagickRealType x)
493 return(x < 0.0 ? -x : x);
496static inline QuantumAny CastDoubleToQuantumAny(
const double x)
506 value=(x < 0.0) ? ceil(x) : floor(x);
512 if (value >= ((
double) ((QuantumAny) ~0)))
515 return((QuantumAny) ~0);
517 return((QuantumAny) value);
520static inline MagickBooleanType IsPixelAtDepth(
const Quantum pixel,
521 const QuantumAny range)
528#if !defined(MAGICKCORE_HDRI_SUPPORT)
529 quantum=(Quantum) (((
double) QuantumRange*((QuantumAny) (((
double) range*
530 pixel)/(
double) QuantumRange+0.5)))/(
double) range+0.5);
532 quantum=(Quantum) (((
double) QuantumRange*((
double) CastDoubleToQuantumAny(
533 ((
double) range*(
double) pixel)/(
double) QuantumRange+0.5)))/
536 return(pixel == quantum ? MagickTrue : MagickFalse);
539static inline MagickBooleanType IsPixelEquivalent(
540 const Image *magick_restrict image,
const Quantum *magick_restrict p,
541 const PixelInfo *magick_restrict q)
548 color=(MagickRealType) p[image->channel_map[AlphaPixelChannel].offset];
549 alpha=image->alpha_trait == UndefinedPixelTrait ? (MagickRealType)
551 beta=q->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
553 if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
555 if ((AbsolutePixelValue(alpha-(MagickRealType) TransparentAlpha) < MagickEpsilon) ||
556 (AbsolutePixelValue(beta-(MagickRealType) TransparentAlpha) < MagickEpsilon))
558 color=(MagickRealType) p[image->channel_map[RedPixelChannel].offset];
559 if (AbsolutePixelValue(color-q->red) >= MagickEpsilon)
561 color=(MagickRealType) p[image->channel_map[GreenPixelChannel].offset];
562 if (AbsolutePixelValue(color-q->green) >= MagickEpsilon)
564 color=(MagickRealType) p[image->channel_map[BluePixelChannel].offset];
565 if (AbsolutePixelValue(color-q->blue) >= MagickEpsilon)
567 if (image->colorspace == CMYKColorspace)
569 color=(MagickRealType) p[image->channel_map[BlackPixelChannel].offset];
570 if (AbsolutePixelValue(color-q->black) >= MagickEpsilon)
576static inline MagickBooleanType IsPixelGray(
const Image *magick_restrict image,
577 const Quantum *magick_restrict pixel)
584 (MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
585 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
587 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]-
588 (MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
589 if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
590 (AbsolutePixelValue(green_blue) < MagickEpsilon))
595static inline MagickBooleanType IsPixelInfoEquivalent(
596 const PixelInfo *magick_restrict p,
const PixelInfo *magick_restrict q)
602 alpha=p->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
604 beta=q->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
606 if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
608 if ((AbsolutePixelValue(alpha-(MagickRealType) TransparentAlpha) < MagickEpsilon) ||
609 (AbsolutePixelValue(beta-(MagickRealType) TransparentAlpha) < MagickEpsilon))
611 if (AbsolutePixelValue(p->red-q->red) >= MagickEpsilon)
613 if (AbsolutePixelValue(p->green-q->green) >= MagickEpsilon)
615 if (AbsolutePixelValue(p->blue-q->blue) >= MagickEpsilon)
617 if (p->colorspace == CMYKColorspace)
619 if (AbsolutePixelValue(p->black-q->black) >= MagickEpsilon)
625static inline MagickBooleanType IsPixelMonochrome(
626 const Image *magick_restrict image,
const Quantum *magick_restrict pixel)
633 red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
634 if ((AbsolutePixelValue(red) >= MagickEpsilon) &&
635 (AbsolutePixelValue(red-(MagickRealType) QuantumRange) >= MagickEpsilon))
638 (MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
639 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
641 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]-
642 (MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
643 if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
644 (AbsolutePixelValue(green_blue) < MagickEpsilon))
649static inline MagickBooleanType IsPixelInfoGray(
650 const PixelInfo *magick_restrict pixel)
652 if ((AbsolutePixelValue(pixel->red-pixel->green) < MagickEpsilon) &&
653 (AbsolutePixelValue(pixel->green-pixel->blue) < MagickEpsilon))
658static inline MagickBooleanType IsPixelInfoMonochrome(
659 const PixelInfo *magick_restrict pixel_info)
665 if ((AbsolutePixelValue(pixel_info->red) >= MagickEpsilon) ||
666 (AbsolutePixelValue(pixel_info->red-(MagickRealType) QuantumRange) >= MagickEpsilon))
668 red_green=pixel_info->red-pixel_info->green;
669 green_blue=pixel_info->green-pixel_info->blue;
670 if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
671 (AbsolutePixelValue(green_blue) < MagickEpsilon))
676static inline void SetPixela(
const Image *magick_restrict image,
677 const Quantum a,Quantum *magick_restrict pixel)
679 if (image->channel_map[aPixelChannel].traits != UndefinedPixelTrait)
680 pixel[image->channel_map[aPixelChannel].offset]=a;
683static inline void SetPixelAlpha(
const Image *magick_restrict image,
684 const Quantum alpha,Quantum *magick_restrict pixel)
686 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
687 pixel[image->channel_map[AlphaPixelChannel].offset]=alpha;
690static inline void SetPixelAlphaTraits(Image *image,
const PixelTrait traits)
692 image->channel_map[AlphaPixelChannel].traits=traits;
695static inline void SetPixelb(
const Image *magick_restrict image,
696 const Quantum b,Quantum *magick_restrict pixel)
698 if (image->channel_map[bPixelChannel].traits != UndefinedPixelTrait)
699 pixel[image->channel_map[bPixelChannel].offset]=b;
702static inline void SetPixelBackgroundColor(
const Image *magick_restrict image,
703 Quantum *magick_restrict pixel)
708 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
709 pixel[i]=(Quantum) 0;
710 pixel[image->channel_map[RedPixelChannel].offset]=
711 ClampToQuantum(image->background_color.red);
712 pixel[image->channel_map[GreenPixelChannel].offset]=
713 ClampToQuantum(image->background_color.green);
714 pixel[image->channel_map[BluePixelChannel].offset]=
715 ClampToQuantum(image->background_color.blue);
716 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
717 pixel[image->channel_map[BlackPixelChannel].offset]=
718 ClampToQuantum(image->background_color.black);
719 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
720 pixel[image->channel_map[AlphaPixelChannel].offset]=
721 image->background_color.alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
722 ClampToQuantum(image->background_color.alpha);
725static inline void SetPixelBackgoundColor(
const Image *magick_restrict image,
726 Quantum *magick_restrict pixel) magick_attribute((deprecated));
728static inline void SetPixelBackgoundColor(
const Image *magick_restrict image,
729 Quantum *magick_restrict pixel)
731 SetPixelBackgroundColor(image,pixel);
734static inline void SetPixelBlack(
const Image *magick_restrict image,
735 const Quantum black,Quantum *magick_restrict pixel)
737 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
738 pixel[image->channel_map[BlackPixelChannel].offset]=black;
741static inline void SetPixelBlackTraits(Image *image,
const PixelTrait traits)
743 image->channel_map[BlackPixelChannel].traits=traits;
746static inline void SetPixelBlue(
const Image *magick_restrict image,
747 const Quantum blue,Quantum *magick_restrict pixel)
749 pixel[image->channel_map[BluePixelChannel].offset]=blue;
752static inline void SetPixelBlueTraits(Image *image,
const PixelTrait traits)
754 image->channel_map[BluePixelChannel].traits=traits;
757static inline void SetPixelCb(
const Image *magick_restrict image,
758 const Quantum cb,Quantum *magick_restrict pixel)
760 pixel[image->channel_map[CbPixelChannel].offset]=cb;
763static inline void SetPixelCbTraits(Image *image,
const PixelTrait traits)
765 image->channel_map[CbPixelChannel].traits=traits;
768static inline void SetPixelChannel(
const Image *magick_restrict image,
769 const PixelChannel channel,
const Quantum quantum,
770 Quantum *magick_restrict pixel)
772 if ((
size_t) channel >= MaxPixelChannels)
774 if (image->channel_map[channel].traits != UndefinedPixelTrait)
775 pixel[image->channel_map[channel].offset]=quantum;
778static inline void SetPixelChannelAttributes(
779 const Image *magick_restrict image,
const PixelChannel channel,
780 const PixelTrait traits,
const ssize_t offset)
782 if ((offset < 0) || (offset >= MaxPixelChannels))
784 if ((
size_t) channel >= MaxPixelChannels)
786 image->channel_map[offset].channel=channel;
787 image->channel_map[channel].offset=offset;
788 image->channel_map[channel].traits=traits;
791static inline void SetPixelChannelChannel(
const Image *magick_restrict image,
792 const PixelChannel channel,
const ssize_t offset)
794 if ((offset < 0) || (offset >= MaxPixelChannels))
796 if ((
size_t) channel >= MaxPixelChannels)
798 image->channel_map[offset].channel=channel;
799 image->channel_map[channel].offset=offset;
802static inline void SetPixelChannels(Image *image,
const size_t number_channels)
804 image->number_channels=number_channels;
807static inline void SetPixelChannelTraits(Image *image,
808 const PixelChannel channel,
const PixelTrait traits)
810 if ((
size_t) channel >= MaxPixelChannels)
812 image->channel_map[channel].traits=traits;
815static inline void SetPixelCompositeMask(
const Image *magick_restrict image,
816 const Quantum mask,Quantum *magick_restrict pixel)
818 if (image->channel_map[CompositeMaskPixelChannel].traits != UndefinedPixelTrait)
819 pixel[image->channel_map[CompositeMaskPixelChannel].offset]=mask;
822static inline void SetPixelCr(
const Image *magick_restrict image,
823 const Quantum cr,Quantum *magick_restrict pixel)
825 pixel[image->channel_map[CrPixelChannel].offset]=cr;
828static inline void SetPixelCrTraits(Image *image,
const PixelTrait traits)
830 image->channel_map[CrPixelChannel].traits=traits;
833static inline void SetPixelCyan(
const Image *magick_restrict image,
834 const Quantum cyan,Quantum *magick_restrict pixel)
836 pixel[image->channel_map[CyanPixelChannel].offset]=cyan;
839static inline void SetPixelGray(
const Image *magick_restrict image,
840 const Quantum gray,Quantum *magick_restrict pixel)
842 pixel[image->channel_map[GrayPixelChannel].offset]=gray;
845static inline void SetPixelGrayTraits(Image *image,
const PixelTrait traits)
847 image->channel_map[GrayPixelChannel].traits=traits;
850static inline void SetPixelGreen(
const Image *magick_restrict image,
851 const Quantum green,Quantum *magick_restrict pixel)
853 pixel[image->channel_map[GreenPixelChannel].offset]=green;
856static inline void SetPixelGreenTraits(Image *image,
const PixelTrait traits)
858 image->channel_map[GreenPixelChannel].traits=traits;
861static inline void SetPixelIndex(
const Image *magick_restrict image,
862 const Quantum index,Quantum *magick_restrict pixel)
864 if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
865 pixel[image->channel_map[IndexPixelChannel].offset]=index;
868static inline void SetPixelIndexTraits(Image *image,
const PixelTrait traits)
870 image->channel_map[IndexPixelChannel].traits=traits;
873static inline void SetPixelViaPixelInfo(
const Image *magick_restrict image,
874 const PixelInfo *magick_restrict pixel_info,Quantum *magick_restrict pixel)
876 pixel[image->channel_map[RedPixelChannel].offset]=
877 ClampToQuantum(pixel_info->red);
878 pixel[image->channel_map[GreenPixelChannel].offset]=
879 ClampToQuantum(pixel_info->green);
880 pixel[image->channel_map[BluePixelChannel].offset]=
881 ClampToQuantum(pixel_info->blue);
882 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
883 pixel[image->channel_map[BlackPixelChannel].offset]=
884 ClampToQuantum(pixel_info->black);
885 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
886 pixel[image->channel_map[AlphaPixelChannel].offset]=
887 pixel_info->alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
888 ClampToQuantum(pixel_info->alpha);
891static inline void SetPixelL(
const Image *magick_restrict image,
const Quantum L,
892 Quantum *magick_restrict pixel)
894 if (image->channel_map[LPixelChannel].traits != UndefinedPixelTrait)
895 pixel[image->channel_map[LPixelChannel].offset]=L;
898static inline void SetPixelMagenta(
const Image *magick_restrict image,
899 const Quantum magenta,Quantum *magick_restrict pixel)
901 pixel[image->channel_map[MagentaPixelChannel].offset]=magenta;
904static inline void SetPixelMagentaTraits(Image *image,
const PixelTrait traits)
906 image->channel_map[MagentaPixelChannel].traits=traits;
909static inline void SetPixelMeta(
const Image *magick_restrict image,
910 const Quantum red,Quantum *magick_restrict pixel)
912 pixel[image->channel_map[MetaPixelChannels].offset]=red;
915static inline void SetPixelMetaTraits(Image *image,
const PixelTrait traits)
917 image->channel_map[MetaPixelChannels].traits=traits;
920static inline void SetPixelReadMask(
const Image *magick_restrict image,
921 const Quantum mask,Quantum *magick_restrict pixel)
923 if (image->channel_map[ReadMaskPixelChannel].traits != UndefinedPixelTrait)
924 pixel[image->channel_map[ReadMaskPixelChannel].offset]=mask;
927static inline void SetPixelMetacontentExtent(Image *image,
const size_t extent)
929 image->metacontent_extent=extent;
932static inline void SetPixelOpacity(
const Image *magick_restrict image,
933 const Quantum alpha,Quantum *magick_restrict pixel)
935 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
936 pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
939static inline void SetPixelRed(
const Image *magick_restrict image,
940 const Quantum red,Quantum *magick_restrict pixel)
942 pixel[image->channel_map[RedPixelChannel].offset]=red;
945static inline void SetPixelRedTraits(Image *image,
const PixelTrait traits)
947 image->channel_map[RedPixelChannel].traits=traits;
950static inline void SetPixelWriteMask(
const Image *magick_restrict image,
951 const Quantum mask,Quantum *magick_restrict pixel)
953 if (image->channel_map[WriteMaskPixelChannel].traits != UndefinedPixelTrait)
954 pixel[image->channel_map[WriteMaskPixelChannel].offset]=mask;
957static inline void SetPixelYellow(
const Image *magick_restrict image,
958 const Quantum yellow,Quantum *magick_restrict pixel)
960 pixel[image->channel_map[YellowPixelChannel].offset]=yellow;
963static inline void SetPixelYellowTraits(Image *image,
const PixelTrait traits)
965 image->channel_map[YellowPixelChannel].traits=traits;
968static inline void SetPixelY(
const Image *magick_restrict image,
969 const Quantum y,Quantum *magick_restrict pixel)
971 pixel[image->channel_map[YPixelChannel].offset]=y;
974static inline void SetPixelYTraits(Image *image,
const PixelTrait traits)
976 image->channel_map[YPixelChannel].traits=traits;
979static inline size_t GetImageChannels(
const Image *image)
988 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
990 PixelChannel channel = GetPixelChannelChannel(image,i);
991 PixelTrait traits = GetPixelChannelTraits(image,channel);
992 if ((traits & UpdatePixelTrait) != 0)
995 return(channels == 0 ? (
size_t) 1 : channels);
998#if defined(__cplusplus) || defined(c_plusplus)