2 Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
5 You may not use this file except in compliance with the License.
6 obtain a copy of the License at
8 http://www.imagemagick.org/script/license.php
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.
16 MagickCore pixel accessor methods.
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"
28 #if defined(__cplusplus) || defined(c_plusplus)
34 static inline Quantum ClampPixel(const MagickRealType value)
38 if (value >= (MagickRealType) QuantumRange)
39 return((Quantum) QuantumRange);
40 #if !defined(MAGICKCORE_HDRI_SUPPORT)
41 return((Quantum) (value+0.5f));
43 return((Quantum) value);
47 static inline Quantum GetPixela(const Image *restrict image,
48 const Quantum *restrict pixel)
50 return(pixel[image->channel_map[aPixelChannel].offset]);
53 static inline Quantum GetPixelAlpha(const Image *restrict image,
54 const Quantum *restrict pixel)
56 if (image->channel_map[AlphaPixelChannel].traits == UndefinedPixelTrait)
58 return(pixel[image->channel_map[AlphaPixelChannel].offset]);
61 static inline PixelTrait GetPixelAlphaTraits(const Image *restrict image)
63 return(image->channel_map[AlphaPixelChannel].traits);
66 static inline Quantum GetPixelb(const Image *restrict image,
67 const Quantum *restrict pixel)
69 return(pixel[image->channel_map[bPixelChannel].offset]);
72 static inline Quantum GetPixelBlack(const Image *restrict image,
73 const Quantum *restrict pixel)
75 if (image->channel_map[BlackPixelChannel].traits == UndefinedPixelTrait)
77 return(pixel[image->channel_map[BlackPixelChannel].offset]);
80 static inline PixelTrait GetPixelBlackTraits(const Image *restrict image)
82 return(image->channel_map[BlackPixelChannel].traits);
85 static inline Quantum GetPixelBlue(const Image *restrict image,
86 const Quantum *restrict pixel)
88 return(pixel[image->channel_map[BluePixelChannel].offset]);
91 static inline PixelTrait GetPixelBlueTraits(const Image *restrict image)
93 return(image->channel_map[BluePixelChannel].traits);
96 static inline Quantum GetPixelCb(const Image *restrict image,
97 const Quantum *restrict pixel)
99 return(pixel[image->channel_map[CbPixelChannel].offset]);
102 static inline PixelTrait GetPixelCbTraits(const Image *restrict image)
104 return(image->channel_map[CbPixelChannel].traits);
107 static inline Quantum GetPixelChannel(const Image *restrict image,
108 const PixelChannel channel,const Quantum *restrict pixel)
110 if (image->channel_map[channel].traits == UndefinedPixelTrait)
112 return(pixel[image->channel_map[channel].offset]);
115 static inline PixelChannel GetPixelChannelChannel(const Image *restrict image,
116 const ssize_t offset)
118 return(image->channel_map[offset].channel);
121 static inline ssize_t GetPixelChannelOffset(const Image *restrict image,
122 const PixelChannel channel)
124 return(image->channel_map[channel].offset);
127 static inline PixelTrait GetPixelChannelTraits(const Image *restrict image,
128 const PixelChannel channel)
130 return(image->channel_map[channel].traits);
133 static inline size_t GetPixelChannels(const Image *restrict image)
135 return(image->number_channels);
138 static inline Quantum GetPixelCr(const Image *restrict image,
139 const Quantum *restrict pixel)
141 return(pixel[image->channel_map[CrPixelChannel].offset]);
144 static inline PixelTrait GetPixelCrTraits(const Image *restrict image)
146 return(image->channel_map[CrPixelChannel].traits);
149 static inline Quantum GetPixelCyan(const Image *restrict image,
150 const Quantum *restrict pixel)
152 return(pixel[image->channel_map[CyanPixelChannel].offset]);
155 static inline PixelTrait GetPixelCyanTraits(const Image *restrict image)
157 return(image->channel_map[CyanPixelChannel].traits);
160 static inline Quantum GetPixelGray(const Image *restrict image,
161 const Quantum *restrict pixel)
163 return(pixel[image->channel_map[GrayPixelChannel].offset]);
166 static inline PixelTrait GetPixelGrayTraits(const Image *restrict image)
168 return(image->channel_map[GrayPixelChannel].traits);
171 static inline Quantum GetPixelGreen(const Image *restrict image,
172 const Quantum *restrict pixel)
174 return(pixel[image->channel_map[GreenPixelChannel].offset]);
177 static inline PixelTrait GetPixelGreenTraits(const Image *restrict image)
179 return(image->channel_map[GreenPixelChannel].traits);
182 static inline Quantum GetPixelIndex(const Image *restrict image,
183 const Quantum *restrict pixel)
185 if (image->channel_map[IndexPixelChannel].traits == UndefinedPixelTrait)
187 return(pixel[image->channel_map[IndexPixelChannel].offset]);
190 static inline PixelTrait GetPixelIndexTraits(const Image *restrict image)
192 return(image->channel_map[IndexPixelChannel].traits);
195 static inline MagickRealType GetPixelInfoChannel(
196 const PixelInfo *restrict pixel_info,const PixelChannel channel)
200 case RedPixelChannel: return(pixel_info->red);
201 case GreenPixelChannel: return(pixel_info->green);
202 case BluePixelChannel: return(pixel_info->blue);
203 case BlackPixelChannel: return(pixel_info->black);
204 case AlphaPixelChannel: return(pixel_info->alpha);
205 case IndexPixelChannel: return(pixel_info->index);
206 default: return((MagickRealType) 0.0);
210 static inline double PerceptibleReciprocal(const double x)
216 Return 1/x where x is perceptible (not unlimited or infinitesimal).
218 sign=x < 0.0 ? -1.0 : 1.0;
219 if ((sign*x) >= MagickEpsilon)
221 return(sign/MagickEpsilon);
224 static inline MagickRealType GetPixelInfoLuma(const PixelInfo *restrict pixel)
231 if (pixel->alpha_trait != UndefinedPixelTrait)
232 gamma=(MagickRealType) PerceptibleReciprocal(QuantumScale*pixel->alpha);
233 if (pixel->colorspace == sRGBColorspace)
235 intensity=0.212656f*gamma*pixel->red+0.715158f*gamma*pixel->green+
236 0.072186f*gamma*pixel->blue;
239 intensity=0.212656f*EncodePixelGamma(gamma*pixel->red)+
240 0.715158f*EncodePixelGamma(gamma*pixel->green)+
241 0.072186f*EncodePixelGamma(gamma*pixel->blue);
245 static inline MagickRealType GetPixelInfoLuminance(
246 const PixelInfo *restrict pixel)
253 if (pixel->alpha_trait != UndefinedPixelTrait)
254 gamma=(MagickRealType) PerceptibleReciprocal(QuantumScale*pixel->alpha);
255 if (pixel->colorspace != sRGBColorspace)
257 intensity=0.212656f*gamma*pixel->red+0.715158f*gamma*pixel->green+
258 0.072186f*gamma*pixel->blue;
261 intensity=0.212656f*DecodePixelGamma(gamma*pixel->red)+
262 0.715158f*DecodePixelGamma(gamma*pixel->green)+
263 0.072186f*DecodePixelGamma(gamma*pixel->blue);
267 static inline Quantum GetPixelL(const Image *restrict image,
268 const Quantum *restrict pixel)
270 return(pixel[image->channel_map[LPixelChannel].offset]);
273 static inline MagickRealType GetPixelLuma(const Image *restrict image,
274 const Quantum *restrict pixel)
281 if (image->alpha_trait != UndefinedPixelTrait)
282 gamma=(MagickRealType) PerceptibleReciprocal(QuantumScale*
283 pixel[image->channel_map[AlphaPixelChannel].offset]);
284 intensity=0.212656f*gamma*pixel[image->channel_map[RedPixelChannel].offset]+
285 0.715158f*gamma*pixel[image->channel_map[GreenPixelChannel].offset]+
286 0.072186f*gamma*pixel[image->channel_map[BluePixelChannel].offset];
290 static inline MagickRealType GetPixelLuminance(const Image *restrict image,
291 const Quantum *restrict pixel)
298 if (image->alpha_trait != UndefinedPixelTrait)
299 gamma=(MagickRealType) PerceptibleReciprocal(QuantumScale*
300 pixel[image->channel_map[AlphaPixelChannel].offset]);
301 if (image->colorspace != sRGBColorspace)
304 0.212656f*gamma*pixel[image->channel_map[RedPixelChannel].offset]+
305 0.715158f*gamma*pixel[image->channel_map[GreenPixelChannel].offset]+
306 0.072186f*gamma*pixel[image->channel_map[BluePixelChannel].offset];
309 intensity=0.212656f*DecodePixelGamma(gamma*
310 pixel[image->channel_map[RedPixelChannel].offset])+0.715158f*
311 DecodePixelGamma(gamma*pixel[image->channel_map[GreenPixelChannel].offset])+
312 0.072186f*DecodePixelGamma(gamma*
313 pixel[image->channel_map[BluePixelChannel].offset]);
317 static inline Quantum GetPixelMagenta(const Image *restrict image,
318 const Quantum *restrict pixel)
320 return(pixel[image->channel_map[MagentaPixelChannel].offset]);
323 static inline PixelTrait GetPixelMagentaTraits(const Image *restrict image)
325 return(image->channel_map[MagentaPixelChannel].traits);
328 static inline Quantum GetPixelReadMask(const Image *restrict image,
329 const Quantum *restrict pixel)
331 if (image->channel_map[ReadMaskPixelChannel].traits == UndefinedPixelTrait)
332 return((Quantum) QuantumRange);
333 return(pixel[image->channel_map[ReadMaskPixelChannel].offset]);
336 static inline Quantum GetPixelWriteMask(const Image *restrict image,
337 const Quantum *restrict pixel)
339 if (image->channel_map[WriteMaskPixelChannel].traits == UndefinedPixelTrait)
340 return((Quantum) QuantumRange);
341 return(pixel[image->channel_map[WriteMaskPixelChannel].offset]);
344 static inline PixelTrait GetPixelReadMaskTraits(const Image *restrict image)
346 return(image->channel_map[ReadMaskPixelChannel].traits);
349 static inline size_t GetPixelMetaChannels(const Image *restrict image)
351 return(image->number_meta_channels);
354 static inline size_t GetPixelMetacontentExtent(const Image *restrict image)
356 return(image->metacontent_extent);
359 static inline Quantum GetPixelOpacity(const Image *restrict image,
360 const Quantum *restrict pixel)
362 if (image->channel_map[AlphaPixelChannel].traits != BlendPixelTrait)
363 return(QuantumRange-OpaqueAlpha);
364 return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
367 static inline Quantum GetPixelRed(const Image *restrict image,
368 const Quantum *restrict pixel)
370 return(pixel[image->channel_map[RedPixelChannel].offset]);
373 static inline PixelTrait GetPixelRedTraits(const Image *restrict image)
375 return(image->channel_map[RedPixelChannel].traits);
378 static inline void GetPixelInfoPixel(const Image *restrict image,
379 const Quantum *restrict pixel,PixelInfo *restrict pixel_info)
381 pixel_info->storage_class=image->storage_class;
382 pixel_info->colorspace=image->colorspace;
383 pixel_info->fuzz=image->fuzz;
384 pixel_info->depth=image->depth;
385 pixel_info->red=(MagickRealType)
386 pixel[image->channel_map[RedPixelChannel].offset];
387 pixel_info->green=(MagickRealType)
388 pixel[image->channel_map[GreenPixelChannel].offset];
389 pixel_info->blue=(MagickRealType)
390 pixel[image->channel_map[BluePixelChannel].offset];
391 pixel_info->black=0.0f;
392 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
393 pixel_info->black=(MagickRealType)
394 pixel[image->channel_map[BlackPixelChannel].offset];
395 pixel_info->alpha=(MagickRealType) OpaqueAlpha;
396 pixel_info->alpha_trait=UndefinedPixelTrait;
397 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
399 pixel_info->alpha=(MagickRealType)
400 pixel[image->channel_map[AlphaPixelChannel].offset];
401 pixel_info->alpha_trait=BlendPixelTrait;
403 pixel_info->index=0.0f;
404 if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
405 pixel_info->index=(MagickRealType)
406 pixel[image->channel_map[IndexPixelChannel].offset];
410 static inline PixelTrait GetPixelTraits(const Image *restrict image,
411 const PixelChannel channel)
413 return(image->channel_map[channel].traits);
416 static inline Quantum GetPixelY(const Image *restrict image,
417 const Quantum *restrict pixel)
419 return(pixel[image->channel_map[YPixelChannel].offset]);
422 static inline PixelTrait GetPixelYTraits(const Image *restrict image)
424 return(image->channel_map[YPixelChannel].traits);
427 static inline Quantum GetPixelYellow(const Image *restrict image,
428 const Quantum *restrict pixel)
430 return(pixel[image->channel_map[YellowPixelChannel].offset]);
433 static inline PixelTrait GetPixelYellowTraits(const Image *restrict image)
435 return(image->channel_map[YellowPixelChannel].traits);
438 static inline MagickRealType AbsolutePixelValue(const MagickRealType x)
440 return(x < 0.0f ? -x : x);
443 static inline MagickBooleanType IsPixelAtDepth(const Quantum pixel,
444 const QuantumAny range)
449 #if !defined(MAGICKCORE_HDRI_SUPPORT)
450 quantum=(Quantum) (((MagickRealType) QuantumRange*((QuantumAny)
451 (((MagickRealType) range*pixel)/QuantumRange+0.5)))/range+0.5);
453 quantum=(Quantum) (((MagickRealType) QuantumRange*((QuantumAny)
454 (((MagickRealType) range*pixel)/QuantumRange+0.5)))/range);
456 return(pixel == quantum ? MagickTrue : MagickFalse);
459 static inline MagickBooleanType IsPixelEquivalent(const Image *restrict image,
460 const Quantum *restrict p,const PixelInfo *restrict q)
467 red=(MagickRealType) p[image->channel_map[RedPixelChannel].offset];
468 green=(MagickRealType) p[image->channel_map[GreenPixelChannel].offset];
469 blue=(MagickRealType) p[image->channel_map[BluePixelChannel].offset];
470 if ((AbsolutePixelValue(red-q->red) < MagickEpsilon) &&
471 (AbsolutePixelValue(green-q->green) < MagickEpsilon) &&
472 (AbsolutePixelValue(blue-q->blue) < MagickEpsilon))
477 static inline MagickBooleanType IsPixelGray(const Image *restrict image,
478 const Quantum *restrict pixel)
484 red_green=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
485 pixel[image->channel_map[GreenPixelChannel].offset];
486 green_blue=(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]-
487 pixel[image->channel_map[BluePixelChannel].offset];
488 if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
489 (AbsolutePixelValue(green_blue) < MagickEpsilon))
494 static inline MagickBooleanType IsPixelInfoEquivalent(
495 const PixelInfo *restrict p,const PixelInfo *restrict q)
497 if ((p->alpha_trait != UndefinedPixelTrait) &&
498 (q->alpha_trait == UndefinedPixelTrait) &&
499 (AbsolutePixelValue(p->alpha-OpaqueAlpha) >= MagickEpsilon))
501 if ((q->alpha_trait != UndefinedPixelTrait) &&
502 (p->alpha_trait == UndefinedPixelTrait) &&
503 (AbsolutePixelValue(q->alpha-OpaqueAlpha)) >= MagickEpsilon)
505 if ((p->alpha_trait != UndefinedPixelTrait) &&
506 (q->alpha_trait != UndefinedPixelTrait))
508 if (AbsolutePixelValue(p->alpha-q->alpha) >= MagickEpsilon)
510 if (AbsolutePixelValue(p->alpha-TransparentAlpha) < MagickEpsilon)
513 if (AbsolutePixelValue(p->red-q->red) >= MagickEpsilon)
515 if (AbsolutePixelValue(p->green-q->green) >= MagickEpsilon)
517 if (AbsolutePixelValue(p->blue-q->blue) >= MagickEpsilon)
519 if ((p->colorspace == CMYKColorspace) &&
520 (AbsolutePixelValue(p->black-q->black) >= MagickEpsilon))
525 static inline MagickBooleanType IsPixelMonochrome(const Image *restrict image,
526 const Quantum *restrict pixel)
533 red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
534 if ((AbsolutePixelValue(red) >= MagickEpsilon) &&
535 (AbsolutePixelValue(red-QuantumRange) >= MagickEpsilon))
537 red_green=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
538 pixel[image->channel_map[GreenPixelChannel].offset];
539 green_blue=(MagickRealType)
540 pixel[image->channel_map[GreenPixelChannel].offset]-
541 pixel[image->channel_map[BluePixelChannel].offset];
542 if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
543 (AbsolutePixelValue(green_blue) < MagickEpsilon))
548 static inline MagickBooleanType IsPixelInfoGray(
549 const PixelInfo *restrict pixel_info)
551 if ((pixel_info->colorspace != GRAYColorspace) &&
552 (pixel_info->colorspace != RGBColorspace))
554 if ((AbsolutePixelValue(pixel_info->red-pixel_info->green) < MagickEpsilon) &&
555 (AbsolutePixelValue(pixel_info->green-pixel_info->blue) < MagickEpsilon))
560 static inline MagickBooleanType IsPixelInfoMonochrome(
561 const PixelInfo *restrict pixel_info)
567 if ((pixel_info->colorspace != GRAYColorspace) &&
568 (pixel_info->colorspace != RGBColorspace))
570 if ((AbsolutePixelValue(pixel_info->red) >= MagickEpsilon) ||
571 (AbsolutePixelValue(pixel_info->red-QuantumRange) >= MagickEpsilon))
573 red_green=pixel_info->red-pixel_info->green;
574 green_blue=pixel_info->green-pixel_info->blue;
575 if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
576 (AbsolutePixelValue(green_blue) < MagickEpsilon))
581 static inline void SetPixela(const Image *restrict image,
582 const Quantum a,Quantum *restrict pixel)
584 if (image->channel_map[aPixelChannel].traits != UndefinedPixelTrait)
585 pixel[image->channel_map[aPixelChannel].offset]=a;
588 static inline void SetPixelAlpha(const Image *restrict image,
589 const Quantum alpha,Quantum *restrict pixel)
591 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
592 pixel[image->channel_map[AlphaPixelChannel].offset]=alpha;
595 static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
597 image->channel_map[AlphaPixelChannel].traits=traits;
600 static inline void SetPixelb(const Image *restrict image,const Quantum b,
601 Quantum *restrict pixel)
603 if (image->channel_map[bPixelChannel].traits != UndefinedPixelTrait)
604 pixel[image->channel_map[bPixelChannel].offset]=b;
607 static inline void SetPixelBackgoundColor(const Image *restrict image,
608 Quantum *restrict pixel)
613 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
615 pixel[image->channel_map[RedPixelChannel].offset]=
616 ClampToQuantum(image->background_color.red);
617 pixel[image->channel_map[GreenPixelChannel].offset]=
618 ClampToQuantum(image->background_color.green);
619 pixel[image->channel_map[BluePixelChannel].offset]=
620 ClampToQuantum(image->background_color.blue);
621 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
622 pixel[image->channel_map[BlackPixelChannel].offset]=
623 ClampToQuantum(image->background_color.black);
624 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
625 pixel[image->channel_map[AlphaPixelChannel].offset]=
626 image->background_color.alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
627 ClampToQuantum(image->background_color.alpha);
630 static inline void SetPixelBlack(const Image *restrict image,
631 const Quantum black,Quantum *restrict pixel)
633 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
634 pixel[image->channel_map[BlackPixelChannel].offset]=black;
637 static inline void SetPixelBlackTraits(Image *image,const PixelTrait traits)
639 image->channel_map[BlackPixelChannel].traits=traits;
642 static inline void SetPixelBlue(const Image *restrict image,const Quantum blue,
643 Quantum *restrict pixel)
645 pixel[image->channel_map[BluePixelChannel].offset]=blue;
648 static inline void SetPixelBlueTraits(Image *image,const PixelTrait traits)
650 image->channel_map[BluePixelChannel].traits=traits;
653 static inline void SetPixelCb(const Image *restrict image,const Quantum cb,
654 Quantum *restrict pixel)
656 pixel[image->channel_map[CbPixelChannel].offset]=cb;
659 static inline void SetPixelCbTraits(Image *image,const PixelTrait traits)
661 image->channel_map[CbPixelChannel].traits=traits;
664 static inline void SetPixelChannel(const Image *restrict image,
665 const PixelChannel channel,const Quantum quantum,Quantum *restrict pixel)
667 if (image->channel_map[channel].traits != UndefinedPixelTrait)
668 pixel[image->channel_map[channel].offset]=quantum;
671 static inline void SetPixelChannelAttributes(const Image *restrict image,
672 const PixelChannel channel,const PixelTrait traits,const ssize_t offset)
674 image->channel_map[offset].channel=channel;
675 image->channel_map[channel].offset=offset;
676 image->channel_map[channel].traits=traits;
679 static inline void SetPixelChannelChannel(const Image *restrict image,
680 const PixelChannel channel,const ssize_t offset)
682 image->channel_map[offset].channel=channel;
683 image->channel_map[channel].offset=offset;
686 static inline void SetPixelChannels(Image *image,const size_t number_channels)
688 image->number_channels=number_channels;
691 static inline void SetPixelChannelTraits(Image *image,
692 const PixelChannel channel,const PixelTrait traits)
694 image->channel_map[channel].traits=traits;
697 static inline void SetPixelCr(const Image *restrict image,const Quantum cr,
698 Quantum *restrict pixel)
700 pixel[image->channel_map[CrPixelChannel].offset]=cr;
703 static inline void SetPixelCrTraits(Image *image,const PixelTrait traits)
705 image->channel_map[CrPixelChannel].traits=traits;
708 static inline void SetPixelCyan(const Image *restrict image,const Quantum cyan,
709 Quantum *restrict pixel)
711 pixel[image->channel_map[CyanPixelChannel].offset]=cyan;
714 static inline void SetPixelGray(const Image *restrict image,const Quantum gray,
715 Quantum *restrict pixel)
717 pixel[image->channel_map[GrayPixelChannel].offset]=gray;
720 static inline void SetPixelGrayTraits(Image *image,const PixelTrait traits)
722 image->channel_map[GrayPixelChannel].traits=traits;
725 static inline void SetPixelGreen(const Image *restrict image,
726 const Quantum green,Quantum *restrict pixel)
728 pixel[image->channel_map[GreenPixelChannel].offset]=green;
731 static inline void SetPixelGreenTraits(Image *image,const PixelTrait traits)
733 image->channel_map[GreenPixelChannel].traits=traits;
736 static inline void SetPixelIndex(const Image *restrict image,
737 const Quantum index,Quantum *restrict pixel)
739 if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
740 pixel[image->channel_map[IndexPixelChannel].offset]=index;
743 static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
745 image->channel_map[IndexPixelChannel].traits=traits;
748 static inline void SetPixelViaPixelInfo(const Image *restrict image,
749 const PixelInfo *restrict pixel_info,Quantum *restrict pixel)
751 pixel[image->channel_map[RedPixelChannel].offset]=
752 ClampToQuantum(pixel_info->red);
753 pixel[image->channel_map[GreenPixelChannel].offset]=
754 ClampToQuantum(pixel_info->green);
755 pixel[image->channel_map[BluePixelChannel].offset]=
756 ClampToQuantum(pixel_info->blue);
757 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
758 pixel[image->channel_map[BlackPixelChannel].offset]=
759 ClampToQuantum(pixel_info->black);
760 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
761 pixel[image->channel_map[AlphaPixelChannel].offset]=
762 pixel_info->alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
763 ClampToQuantum(pixel_info->alpha);
766 static inline void SetPixelL(const Image *restrict image,const Quantum L,
767 Quantum *restrict pixel)
769 if (image->channel_map[LPixelChannel].traits != UndefinedPixelTrait)
770 pixel[image->channel_map[LPixelChannel].offset]=L;
773 static inline void SetPixelMagenta(const Image *restrict image,
774 const Quantum magenta,Quantum *restrict pixel)
776 pixel[image->channel_map[MagentaPixelChannel].offset]=magenta;
779 static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
781 image->channel_map[MagentaPixelChannel].traits=traits;
784 static inline void SetPixelReadMask(const Image *restrict image,
785 const Quantum mask,Quantum *restrict pixel)
787 if (image->channel_map[ReadMaskPixelChannel].traits != UndefinedPixelTrait)
788 pixel[image->channel_map[ReadMaskPixelChannel].offset]=mask;
791 static inline void SetPixelWriteMask(const Image *restrict image,
792 const Quantum mask,Quantum *restrict pixel)
794 if (image->channel_map[WriteMaskPixelChannel].traits != UndefinedPixelTrait)
795 pixel[image->channel_map[WriteMaskPixelChannel].offset]=mask;
798 static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
800 image->metacontent_extent=extent;
803 static inline void SetPixelOpacity(const Image *restrict image,
804 const Quantum alpha,Quantum *restrict pixel)
806 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
807 pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
810 static inline void SetPixelRed(const Image *restrict image,const Quantum red,
811 Quantum *restrict pixel)
813 pixel[image->channel_map[RedPixelChannel].offset]=red;
816 static inline void SetPixelRedTraits(Image *image,const PixelTrait traits)
818 image->channel_map[RedPixelChannel].traits=traits;
821 static inline void SetPixelYellow(const Image *restrict image,
822 const Quantum yellow,Quantum *restrict pixel)
824 pixel[image->channel_map[YellowPixelChannel].offset]=yellow;
827 static inline void SetPixelYellowTraits(Image *image,const PixelTrait traits)
829 image->channel_map[YellowPixelChannel].traits=traits;
832 static inline void SetPixelY(const Image *restrict image,const Quantum y,
833 Quantum *restrict pixel)
835 pixel[image->channel_map[YPixelChannel].offset]=y;
838 static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
840 image->channel_map[YPixelChannel].traits=traits;
843 #if defined(__cplusplus) || defined(c_plusplus)