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