]> granicus.if.org Git - imagemagick/blob - MagickCore/pixel-accessor.h
(no commit message)
[imagemagick] / MagickCore / pixel-accessor.h
1 /*
2   Copyright 1999-2014 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 GetPixela(const Image *restrict image,
35   const Quantum *restrict pixel)
36 {
37   return(pixel[image->channel_map[aPixelChannel].offset]);
38 }
39
40 static inline Quantum GetPixelAlpha(const Image *restrict image,
41   const Quantum *restrict pixel)
42 {
43   if (image->channel_map[AlphaPixelChannel].traits == UndefinedPixelTrait)
44     return(OpaqueAlpha);
45   return(pixel[image->channel_map[AlphaPixelChannel].offset]);
46 }
47
48 static inline PixelTrait GetPixelAlphaTraits(const Image *restrict image)
49 {
50   return(image->channel_map[AlphaPixelChannel].traits);
51 }
52
53 static inline Quantum GetPixelb(const Image *restrict image,
54   const Quantum *restrict pixel)
55 {
56   return(pixel[image->channel_map[bPixelChannel].offset]);
57 }
58
59 static inline Quantum GetPixelBlack(const Image *restrict image,
60   const Quantum *restrict pixel)
61 {
62   if (image->channel_map[BlackPixelChannel].traits == UndefinedPixelTrait)
63     return((Quantum) 0);
64   return(pixel[image->channel_map[BlackPixelChannel].offset]);
65 }
66
67 static inline PixelTrait GetPixelBlackTraits(const Image *restrict image)
68 {
69   return(image->channel_map[BlackPixelChannel].traits);
70 }
71
72 static inline Quantum GetPixelBlue(const Image *restrict image,
73   const Quantum *restrict pixel)
74 {
75   return(pixel[image->channel_map[BluePixelChannel].offset]);
76 }
77
78 static inline PixelTrait GetPixelBlueTraits(const Image *restrict image)
79 {
80   return(image->channel_map[BluePixelChannel].traits);
81 }
82
83 static inline Quantum GetPixelCb(const Image *restrict image,
84   const Quantum *restrict pixel)
85 {
86   return(pixel[image->channel_map[CbPixelChannel].offset]);
87 }
88
89 static inline PixelTrait GetPixelCbTraits(const Image *restrict image)
90 {
91   return(image->channel_map[CbPixelChannel].traits);
92 }
93
94 static inline Quantum GetPixelChannel(const Image *restrict image,
95   const PixelChannel channel,const Quantum *restrict pixel)
96 {
97   if (image->channel_map[channel].traits == UndefinedPixelTrait)
98     return((Quantum) 0);
99   return(pixel[image->channel_map[channel].offset]);
100 }
101
102 static inline PixelChannel GetPixelChannelChannel(const Image *restrict image,
103   const ssize_t offset)
104 {
105   return(image->channel_map[offset].channel);
106 }
107
108 static inline ssize_t GetPixelChannelOffset(const Image *restrict image,
109   const PixelChannel channel)
110 {
111   return(image->channel_map[channel].offset);
112 }
113
114 static inline PixelTrait GetPixelChannelTraits(const Image *restrict image,
115   const PixelChannel channel)
116 {
117   return(image->channel_map[channel].traits);
118 }
119
120 static inline size_t GetPixelChannels(const Image *restrict image)
121 {
122   return(image->number_channels);
123 }
124
125 static inline Quantum GetPixelCr(const Image *restrict image,
126   const Quantum *restrict pixel)
127 {
128   return(pixel[image->channel_map[CrPixelChannel].offset]);
129 }
130
131 static inline PixelTrait GetPixelCrTraits(const Image *restrict image)
132 {
133   return(image->channel_map[CrPixelChannel].traits);
134 }
135
136 static inline Quantum GetPixelCyan(const Image *restrict image,
137   const Quantum *restrict pixel)
138 {
139   return(pixel[image->channel_map[CyanPixelChannel].offset]);
140 }
141
142 static inline PixelTrait GetPixelCyanTraits(const Image *restrict image)
143 {
144   return(image->channel_map[CyanPixelChannel].traits);
145 }
146
147 static inline Quantum GetPixelGray(const Image *restrict image,
148   const Quantum *restrict pixel)
149 {
150   return(pixel[image->channel_map[GrayPixelChannel].offset]);
151 }
152
153 static inline PixelTrait GetPixelGrayTraits(const Image *restrict image)
154 {
155   return(image->channel_map[GrayPixelChannel].traits);
156 }
157
158 static inline Quantum GetPixelGreen(const Image *restrict image,
159   const Quantum *restrict pixel)
160 {
161   return(pixel[image->channel_map[GreenPixelChannel].offset]);
162 }
163
164 static inline PixelTrait GetPixelGreenTraits(const Image *restrict image)
165 {
166   return(image->channel_map[GreenPixelChannel].traits);
167 }
168
169 static inline Quantum GetPixelIndex(const Image *restrict image,
170   const Quantum *restrict pixel)
171 {
172   if (image->channel_map[IndexPixelChannel].traits == UndefinedPixelTrait)
173     return((Quantum) 0);
174   return(pixel[image->channel_map[IndexPixelChannel].offset]);
175 }
176
177 static inline PixelTrait GetPixelIndexTraits(const Image *restrict image)
178 {
179   return(image->channel_map[IndexPixelChannel].traits);
180 }
181
182 static inline MagickRealType GetPixelInfoChannel(
183   const PixelInfo *restrict pixel_info,const PixelChannel channel)
184 {
185   switch (channel)
186   {
187     case RedPixelChannel: return(pixel_info->red);
188     case GreenPixelChannel: return(pixel_info->green);
189     case BluePixelChannel: return(pixel_info->blue);
190     case BlackPixelChannel: return(pixel_info->black);
191     case AlphaPixelChannel: return(pixel_info->alpha);
192     case IndexPixelChannel: return(pixel_info->index);
193     default: return((MagickRealType) 0.0);
194   }
195 }
196
197 static inline MagickRealType GetPixelInfoIntensity(
198   const PixelInfo *restrict pixel_info)
199 {
200   if (pixel_info->colorspace == GRAYColorspace)
201     return(pixel_info->red);
202   return(0.212656*pixel_info->red+0.715158*pixel_info->green+0.072186*
203     pixel_info->blue);
204 }
205
206 static inline MagickRealType GetPixelInfoLuma(const PixelInfo *restrict pixel)
207 {
208   MagickRealType
209     blue,
210     green,
211     red;
212
213   if (pixel->colorspace == GRAYColorspace)
214     return(pixel->red);
215   if (pixel->colorspace == sRGBColorspace)
216     return(0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue);
217   red=EncodePixelGamma(pixel->red);
218   green=EncodePixelGamma(pixel->green);
219   blue=EncodePixelGamma(pixel->blue);
220   return(0.212656*red+0.715158*green+0.072186*blue);
221 }
222
223 static inline MagickRealType GetPixelInfoLuminance(
224   const PixelInfo *restrict pixel)
225 {
226   MagickRealType
227     blue,
228     green,
229     red;
230
231   if (pixel->colorspace == GRAYColorspace)
232     return(pixel->red);
233   if (pixel->colorspace != sRGBColorspace)
234     return(0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue);
235   red=DecodePixelGamma(pixel->red);
236   green=DecodePixelGamma(pixel->green);
237   blue=DecodePixelGamma(pixel->blue);
238   return(0.212656*red+0.715158*green+0.072186*blue);
239 }
240
241 static inline Quantum GetPixelL(const Image *restrict image,
242   const Quantum *restrict pixel)
243 {
244   return(pixel[image->channel_map[LPixelChannel].offset]);
245 }
246
247 static inline MagickRealType GetPixelLuma(const Image *restrict image,
248   const Quantum *restrict pixel)
249 {
250   if (image->colorspace == GRAYColorspace)
251     return((MagickRealType) pixel[image->channel_map[GrayPixelChannel].offset]);
252   return(0.212656f*pixel[image->channel_map[RedPixelChannel].offset]+
253     0.715158f*pixel[image->channel_map[GreenPixelChannel].offset]+
254     0.072186f*pixel[image->channel_map[BluePixelChannel].offset]);  /* Rec709 */
255 }
256
257 static inline MagickRealType GetPixelLuminance(const Image *restrict image,
258   const Quantum *restrict pixel)
259 {
260   MagickRealType
261     blue,
262     green,
263     red;
264
265   if (image->colorspace == GRAYColorspace)
266     return((MagickRealType) pixel[image->channel_map[GrayPixelChannel].offset]);
267   if (image->colorspace != sRGBColorspace)
268     return(0.212656*pixel[image->channel_map[RedPixelChannel].offset]+
269       0.715158*pixel[image->channel_map[GreenPixelChannel].offset]+
270       0.072186*pixel[image->channel_map[BluePixelChannel].offset]);
271   red=DecodePixelGamma((MagickRealType)
272     pixel[image->channel_map[RedPixelChannel].offset]);
273   green=DecodePixelGamma((MagickRealType)
274     pixel[image->channel_map[GreenPixelChannel].offset]);
275   blue=DecodePixelGamma((MagickRealType)
276     pixel[image->channel_map[BluePixelChannel].offset]);
277   return(0.212656*red+0.715158*green+0.072186*blue);  /* Rec709 */
278 }
279
280 static inline Quantum GetPixelMagenta(const Image *restrict image,
281   const Quantum *restrict pixel)
282 {
283   return(pixel[image->channel_map[MagentaPixelChannel].offset]);
284 }
285
286 static inline PixelTrait GetPixelMagentaTraits(const Image *restrict image)
287 {
288   return(image->channel_map[MagentaPixelChannel].traits);
289 }
290
291 static inline Quantum GetPixelReadMask(const Image *restrict image,
292   const Quantum *restrict pixel)
293 {
294   if (image->channel_map[ReadMaskPixelChannel].traits == UndefinedPixelTrait)
295     return((Quantum) QuantumRange);
296   return(pixel[image->channel_map[ReadMaskPixelChannel].offset]);
297 }
298
299 static inline Quantum GetPixelWriteMask(const Image *restrict image,
300   const Quantum *restrict pixel)
301 {
302   if (image->channel_map[WriteMaskPixelChannel].traits == UndefinedPixelTrait)
303     return((Quantum) QuantumRange);
304   return(pixel[image->channel_map[WriteMaskPixelChannel].offset]);
305 }
306
307 static inline PixelTrait GetPixelReadMaskTraits(const Image *restrict image)
308 {
309   return(image->channel_map[ReadMaskPixelChannel].traits);
310 }
311
312 static inline size_t GetPixelMetaChannels(const Image *restrict image)
313 {
314   return(image->number_meta_channels);
315 }
316
317 static inline size_t GetPixelMetacontentExtent(const Image *restrict image)
318 {
319   return(image->metacontent_extent);
320 }
321
322 static inline Quantum GetPixelOpacity(const Image *restrict image,
323   const Quantum *restrict pixel)
324 {
325   if (image->channel_map[AlphaPixelChannel].traits == UndefinedPixelTrait)
326     return(QuantumRange-OpaqueAlpha);
327   return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
328 }
329
330 static inline Quantum GetPixelRed(const Image *restrict image,
331   const Quantum *restrict pixel)
332 {
333   return(pixel[image->channel_map[RedPixelChannel].offset]);
334 }
335
336 static inline PixelTrait GetPixelRedTraits(const Image *restrict image)
337 {
338   return(image->channel_map[RedPixelChannel].traits);
339 }
340
341 static inline void GetPixelInfoPixel(const Image *restrict image,
342   const Quantum *restrict pixel,PixelInfo *restrict pixel_info)
343 {
344   pixel_info->red=(MagickRealType)
345     pixel[image->channel_map[RedPixelChannel].offset];
346   pixel_info->green=(MagickRealType)
347     pixel[image->channel_map[GreenPixelChannel].offset];
348   pixel_info->blue=(MagickRealType)
349     pixel[image->channel_map[BluePixelChannel].offset];
350   pixel_info->black=0.0f;
351   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
352     pixel_info->black=(MagickRealType)
353       pixel[image->channel_map[BlackPixelChannel].offset];
354   pixel_info->alpha=(MagickRealType) OpaqueAlpha;
355   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
356     pixel_info->alpha=(MagickRealType)
357       pixel[image->channel_map[AlphaPixelChannel].offset];
358   pixel_info->index=0.0f;
359   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
360     pixel_info->index=(MagickRealType)
361       pixel[image->channel_map[IndexPixelChannel].offset];
362 }
363
364 static inline PixelTrait GetPixelTraits(const Image *restrict image,
365   const PixelChannel channel)
366 {
367   return(image->channel_map[channel].traits);
368 }
369
370 static inline Quantum GetPixelY(const Image *restrict image,
371   const Quantum *restrict pixel)
372 {
373   return(pixel[image->channel_map[YPixelChannel].offset]);
374 }
375
376 static inline PixelTrait GetPixelYTraits(const Image *restrict image)
377 {
378   return(image->channel_map[YPixelChannel].traits);
379 }
380
381 static inline Quantum GetPixelYellow(const Image *restrict image,
382   const Quantum *restrict pixel)
383 {
384   return(pixel[image->channel_map[YellowPixelChannel].offset]);
385 }
386
387 static inline PixelTrait GetPixelYellowTraits(const Image *restrict image)
388 {
389   return(image->channel_map[YellowPixelChannel].traits);
390 }
391
392 static inline MagickRealType AbsolutePixelValue(const MagickRealType x)
393 {
394   return(x < 0.0f ? -x : x);
395 }
396
397 static inline MagickBooleanType IsPixelAtDepth(const Quantum pixel,
398   const QuantumAny range)
399 {
400   Quantum
401     quantum;
402
403 #if !defined(MAGICKCORE_HDRI_SUPPORT)
404   quantum=(Quantum) (((MagickRealType) QuantumRange*((QuantumAny) 
405     (((MagickRealType) range*pixel)/QuantumRange+0.5)))/range+0.5);
406 #else
407   quantum=(Quantum) (((MagickRealType) QuantumRange*((QuantumAny) 
408     (((MagickRealType) range*pixel)/QuantumRange+0.5)))/range);
409 #endif
410   return(pixel == quantum ? MagickTrue : MagickFalse);
411 }
412
413 static inline MagickBooleanType IsPixelEquivalent(const Image *restrict image,
414   const Quantum *restrict p,const PixelInfo *restrict q)
415 {
416   MagickRealType
417     blue,
418     green,
419     red;
420
421   red=(MagickRealType) p[image->channel_map[RedPixelChannel].offset];
422   green=(MagickRealType) p[image->channel_map[GreenPixelChannel].offset];
423   blue=(MagickRealType) p[image->channel_map[BluePixelChannel].offset];
424   if ((AbsolutePixelValue(red-q->red) < MagickEpsilon) &&
425       (AbsolutePixelValue(green-q->green) < MagickEpsilon) &&
426       (AbsolutePixelValue(blue-q->blue) < MagickEpsilon))
427     return(MagickTrue);
428   return(MagickFalse);
429 }
430
431 static inline MagickBooleanType IsPixelGray(const Image *restrict image,
432   const Quantum *restrict pixel)
433 {
434   MagickRealType
435     blue,
436     green,
437     red;
438
439   red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
440   green=(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
441   blue=(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
442   if ((AbsolutePixelValue(red-green) < MagickEpsilon) &&
443       (AbsolutePixelValue(green-blue) < MagickEpsilon))
444     return(MagickTrue);
445   return(MagickFalse);
446 }
447
448 static inline MagickBooleanType IsPixelInfoEquivalent(
449   const PixelInfo *restrict p,const PixelInfo *restrict q)
450 {
451   if ((p->alpha_trait == BlendPixelTrait) &&
452       (q->alpha_trait != BlendPixelTrait) &&
453       (AbsolutePixelValue(p->alpha-OpaqueAlpha) >= MagickEpsilon))
454     return(MagickFalse);
455   if ((q->alpha_trait == BlendPixelTrait) &&
456       (p->alpha_trait != BlendPixelTrait) &&
457       (AbsolutePixelValue(q->alpha-OpaqueAlpha)) >= MagickEpsilon)
458     return(MagickFalse);
459   if ((p->alpha_trait == BlendPixelTrait) &&
460       (q->alpha_trait == BlendPixelTrait))
461     {
462       if (AbsolutePixelValue(p->alpha-q->alpha) >= MagickEpsilon)
463         return(MagickFalse);
464       if (AbsolutePixelValue(p->alpha-TransparentAlpha) < MagickEpsilon)
465         return(MagickTrue);
466     }
467   if (AbsolutePixelValue(p->red-q->red) >= MagickEpsilon)
468     return(MagickFalse);
469   if (AbsolutePixelValue(p->green-q->green) >= MagickEpsilon)
470     return(MagickFalse);
471   if (AbsolutePixelValue(p->blue-q->blue) >= MagickEpsilon)
472     return(MagickFalse);
473   if ((p->colorspace == CMYKColorspace) &&
474       (AbsolutePixelValue(p->black-q->black) >= MagickEpsilon))
475     return(MagickFalse);
476   return(MagickTrue);
477 }
478
479 static inline MagickBooleanType IsPixelMonochrome(const Image *restrict image,
480   const Quantum *restrict pixel)
481 {
482   MagickRealType
483     blue,
484     green,
485     red;
486
487   red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
488   if ((AbsolutePixelValue(red) >= MagickEpsilon) ||
489       (AbsolutePixelValue(red-QuantumRange) >= MagickEpsilon))
490     return(MagickFalse);
491   green=(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
492   blue=(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
493   if ((AbsolutePixelValue(red-green) < MagickEpsilon) &&
494       (AbsolutePixelValue(green-blue) < MagickEpsilon))
495     return(MagickTrue);
496   return(MagickFalse);
497 }
498
499 static inline MagickBooleanType IsPixelInfoGray(
500   const PixelInfo *restrict pixel_info)
501 {
502   if ((pixel_info->colorspace != GRAYColorspace) &&
503       (pixel_info->colorspace != RGBColorspace))
504     return(MagickFalse);
505   if ((AbsolutePixelValue(pixel_info->red-pixel_info->green) < MagickEpsilon) &&
506       (AbsolutePixelValue(pixel_info->green-pixel_info->blue) < MagickEpsilon))
507     return(MagickTrue);
508   return(MagickFalse);
509 }
510
511 static inline MagickBooleanType IsPixelInfoMonochrome(
512   const PixelInfo *restrict pixel_info)
513 {
514   if ((pixel_info->colorspace != GRAYColorspace) &&
515       (pixel_info->colorspace != RGBColorspace))
516     return(MagickFalse);
517   if ((AbsolutePixelValue(pixel_info->red) >= MagickEpsilon) ||
518       (AbsolutePixelValue(pixel_info->red-QuantumRange) >= MagickEpsilon))
519     return(MagickFalse);
520   if ((AbsolutePixelValue(pixel_info->red-pixel_info->green) < MagickEpsilon) &&
521       (AbsolutePixelValue(pixel_info->green-pixel_info->blue) < MagickEpsilon))
522     return(MagickTrue);
523   return(MagickFalse);
524 }
525
526 static inline void SetPixela(const Image *restrict image,
527   const Quantum a,Quantum *restrict pixel)
528 {
529   if (image->channel_map[aPixelChannel].traits != UndefinedPixelTrait)
530     pixel[image->channel_map[aPixelChannel].offset]=a;
531 }
532
533 static inline void SetPixelAlpha(const Image *restrict image,
534   const Quantum alpha,Quantum *restrict pixel)
535 {
536   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
537     pixel[image->channel_map[AlphaPixelChannel].offset]=alpha;
538 }
539
540 static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
541 {
542   image->channel_map[AlphaPixelChannel].traits=traits;
543 }
544
545 static inline void SetPixelb(const Image *restrict image,
546   const Quantum b,Quantum *restrict pixel)
547 {
548   if (image->channel_map[bPixelChannel].traits != UndefinedPixelTrait)
549     pixel[image->channel_map[bPixelChannel].offset]=b;
550 }
551
552 static inline void SetPixelBackgoundColor(const Image *restrict image,
553   Quantum *restrict pixel)
554 {
555   register ssize_t
556     i;
557
558   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
559     pixel[i]=0;
560   pixel[image->channel_map[RedPixelChannel].offset]=
561     ClampToQuantum(image->background_color.red);
562   pixel[image->channel_map[GreenPixelChannel].offset]=
563     ClampToQuantum(image->background_color.green);
564   pixel[image->channel_map[BluePixelChannel].offset]=
565     ClampToQuantum(image->background_color.blue);
566   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
567     pixel[image->channel_map[BlackPixelChannel].offset]=
568       ClampToQuantum(image->background_color.black);
569   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
570     pixel[image->channel_map[AlphaPixelChannel].offset]=
571       image->background_color.alpha_trait != BlendPixelTrait ? OpaqueAlpha :
572       ClampToQuantum(image->background_color.alpha);
573 }
574
575 static inline void SetPixelBlack(const Image *restrict image,
576   const Quantum black,Quantum *restrict pixel)
577 {
578   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
579     pixel[image->channel_map[BlackPixelChannel].offset]=black;
580 }
581
582 static inline void SetPixelBlackTraits(Image *image,const PixelTrait traits)
583 {
584   image->channel_map[BlackPixelChannel].traits=traits;
585 }
586
587 static inline void SetPixelBlue(const Image *restrict image,const Quantum blue,
588   Quantum *restrict pixel)
589 {
590   pixel[image->channel_map[BluePixelChannel].offset]=blue;
591 }
592
593 static inline void SetPixelBlueTraits(Image *image,const PixelTrait traits)
594 {
595   image->channel_map[BluePixelChannel].traits=traits;
596 }
597
598 static inline void SetPixelCb(const Image *restrict image,const Quantum cb,
599   Quantum *restrict pixel)
600 {
601   pixel[image->channel_map[CbPixelChannel].offset]=cb;
602 }
603
604 static inline void SetPixelCbTraits(Image *image,const PixelTrait traits)
605 {
606   image->channel_map[CbPixelChannel].traits=traits;
607 }
608
609 static inline void SetPixelChannel(const Image *restrict image,
610   const PixelChannel channel,const Quantum quantum,Quantum *restrict pixel)
611 {
612   if (image->channel_map[channel].traits != UndefinedPixelTrait)
613     pixel[image->channel_map[channel].offset]=quantum;
614 }
615
616 static inline void SetPixelChannelAttributes(const Image *restrict image,
617   const PixelChannel channel,const PixelTrait traits,const ssize_t offset)
618 {
619   image->channel_map[offset].channel=channel;
620   image->channel_map[channel].offset=offset;
621   image->channel_map[channel].traits=traits;
622 }
623
624 static inline void SetPixelChannelChannel(const Image *restrict image,
625   const PixelChannel channel,const ssize_t offset)
626 {
627   image->channel_map[offset].channel=channel;
628   image->channel_map[channel].offset=offset;
629 }
630
631 static inline void SetPixelChannels(Image *image,const size_t number_channels)
632 {
633   image->number_channels=number_channels;
634 }
635
636 static inline void SetPixelChannelTraits(Image *image,
637   const PixelChannel channel,const PixelTrait traits)
638 {
639   image->channel_map[channel].traits=traits;
640 }
641
642 static inline void SetPixelCr(const Image *restrict image,const Quantum cr,
643   Quantum *restrict pixel)
644 {
645   pixel[image->channel_map[CrPixelChannel].offset]=cr;
646 }
647
648 static inline void SetPixelCrTraits(Image *image,const PixelTrait traits)
649 {
650   image->channel_map[CrPixelChannel].traits=traits;
651 }
652
653 static inline void SetPixelCyan(const Image *restrict image,const Quantum cyan,
654   Quantum *restrict pixel)
655 {
656   pixel[image->channel_map[CyanPixelChannel].offset]=cyan;
657 }
658
659 static inline void SetPixelGray(const Image *restrict image,const Quantum gray,
660   Quantum *restrict pixel)
661 {
662   pixel[image->channel_map[GrayPixelChannel].offset]=gray;
663 }
664
665 static inline void SetPixelGrayTraits(Image *image,const PixelTrait traits)
666 {
667   image->channel_map[GrayPixelChannel].traits=traits;
668 }
669
670 static inline void SetPixelGreen(const Image *restrict image,
671   const Quantum green,Quantum *restrict pixel)
672 {
673   pixel[image->channel_map[GreenPixelChannel].offset]=green;
674 }
675
676 static inline void SetPixelGreenTraits(Image *image,const PixelTrait traits)
677 {
678   image->channel_map[GreenPixelChannel].traits=traits;
679 }
680
681 static inline void SetPixelIndex(const Image *restrict image,
682   const Quantum index,Quantum *restrict pixel)
683 {
684   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
685     pixel[image->channel_map[IndexPixelChannel].offset]=index;
686 }
687
688 static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
689 {
690   image->channel_map[IndexPixelChannel].traits=traits;
691 }
692
693 static inline void SetPixelInfoPixel(const Image *restrict image,
694   const PixelInfo *restrict pixel_info,Quantum *restrict pixel)
695 {
696   pixel[image->channel_map[RedPixelChannel].offset]=
697     ClampToQuantum(pixel_info->red);
698   pixel[image->channel_map[GreenPixelChannel].offset]=
699     ClampToQuantum(pixel_info->green);
700   pixel[image->channel_map[BluePixelChannel].offset]=
701     ClampToQuantum(pixel_info->blue);
702   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
703     pixel[image->channel_map[BlackPixelChannel].offset]=
704       ClampToQuantum(pixel_info->black);
705   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
706     pixel[image->channel_map[AlphaPixelChannel].offset]=
707       pixel_info->alpha_trait != BlendPixelTrait ? OpaqueAlpha :
708       ClampToQuantum(pixel_info->alpha);
709 }
710
711 static inline void SetPixelL(const Image *restrict image,const Quantum L,
712   Quantum *restrict pixel)
713 {
714   if (image->channel_map[LPixelChannel].traits != UndefinedPixelTrait)
715     pixel[image->channel_map[LPixelChannel].offset]=L;
716 }
717
718 static inline void SetPixelMagenta(const Image *restrict image,
719   const Quantum magenta,Quantum *restrict pixel)
720 {
721   pixel[image->channel_map[MagentaPixelChannel].offset]=magenta;
722 }
723
724 static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
725 {
726   image->channel_map[MagentaPixelChannel].traits=traits;
727 }
728
729 static inline void SetPixelReadMask(const Image *restrict image,
730   const Quantum mask,Quantum *restrict pixel)
731 {
732   if (image->channel_map[ReadMaskPixelChannel].traits != UndefinedPixelTrait)
733     pixel[image->channel_map[ReadMaskPixelChannel].offset]=mask;
734 }
735
736 static inline void SetPixelWriteMask(const Image *restrict image,
737   const Quantum mask,Quantum *restrict pixel)
738 {
739   if (image->channel_map[WriteMaskPixelChannel].traits != UndefinedPixelTrait)
740     pixel[image->channel_map[WriteMaskPixelChannel].offset]=mask;
741 }
742
743 static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
744 {
745   image->metacontent_extent=extent;
746 }
747
748 static inline void SetPixelOpacity(const Image *restrict image,
749   const Quantum alpha,Quantum *restrict pixel)
750 {
751   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
752     pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
753 }
754
755 static inline void SetPixelRed(const Image *restrict image,const Quantum red,
756   Quantum *restrict pixel)
757 {
758   pixel[image->channel_map[RedPixelChannel].offset]=red;
759 }
760
761 static inline void SetPixelRedTraits(Image *image,const PixelTrait traits)
762 {
763   image->channel_map[RedPixelChannel].traits=traits;
764 }
765
766 static inline void SetPixelYellow(const Image *restrict image,
767   const Quantum yellow,Quantum *restrict pixel)
768 {
769   pixel[image->channel_map[YellowPixelChannel].offset]=yellow;
770 }
771
772 static inline void SetPixelYellowTraits(Image *image,const PixelTrait traits)
773 {
774   image->channel_map[YellowPixelChannel].traits=traits;
775 }
776
777 static inline void SetPixelY(const Image *restrict image,const Quantum y,
778   Quantum *restrict pixel)
779 {
780   pixel[image->channel_map[YPixelChannel].offset]=y;
781 }
782
783 static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
784 {
785   image->channel_map[YPixelChannel].traits=traits;
786 }
787
788 #if defined(__cplusplus) || defined(c_plusplus)
789 }
790 #endif
791
792 #endif