]> 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 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 != BlendPixelTrait)
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.212656f*pixel_info->red+0.715158f*pixel_info->green+0.072186f*
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.212656f*pixel->red+0.715158f*pixel->green+0.072186f*pixel->blue);
217   red=EncodePixelGamma(pixel->red);
218   green=EncodePixelGamma(pixel->green);
219   blue=EncodePixelGamma(pixel->blue);
220   return(0.212656f*red+0.715158f*green+0.072186f*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.212656f*pixel->red+0.715158f*pixel->green+0.072186f*pixel->blue);
235   red=DecodePixelGamma(pixel->red);
236   green=DecodePixelGamma(pixel->green);
237   blue=DecodePixelGamma(pixel->blue);
238   return(0.212656f*red+0.715158f*green+0.072186f*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.212656f*pixel[image->channel_map[RedPixelChannel].offset]+
269       0.715158f*pixel[image->channel_map[GreenPixelChannel].offset]+
270       0.072186f*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.212656f*red+0.715158f*green+0.072186f*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 != BlendPixelTrait)
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->colorspace=image->colorspace;
345   pixel_info->fuzz=image->fuzz;
346   pixel_info->red=(MagickRealType)
347     pixel[image->channel_map[RedPixelChannel].offset];
348   pixel_info->green=(MagickRealType)
349     pixel[image->channel_map[GreenPixelChannel].offset];
350   pixel_info->blue=(MagickRealType)
351     pixel[image->channel_map[BluePixelChannel].offset];
352   pixel_info->black=0.0f;
353   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
354     pixel_info->black=(MagickRealType)
355       pixel[image->channel_map[BlackPixelChannel].offset];
356   pixel_info->alpha=(MagickRealType) OpaqueAlpha;
357   pixel_info->alpha_trait=UndefinedPixelTrait;
358   if (image->channel_map[AlphaPixelChannel].traits == BlendPixelTrait)
359     {
360       pixel_info->alpha=(MagickRealType)
361         pixel[image->channel_map[AlphaPixelChannel].offset];
362       pixel_info->alpha_trait=BlendPixelTrait;
363     }
364   pixel_info->index=0.0f;
365   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
366     pixel_info->index=(MagickRealType)
367       pixel[image->channel_map[IndexPixelChannel].offset];
368 }
369
370 static inline PixelTrait GetPixelTraits(const Image *restrict image,
371   const PixelChannel channel)
372 {
373   return(image->channel_map[channel].traits);
374 }
375
376 static inline Quantum GetPixelY(const Image *restrict image,
377   const Quantum *restrict pixel)
378 {
379   return(pixel[image->channel_map[YPixelChannel].offset]);
380 }
381
382 static inline PixelTrait GetPixelYTraits(const Image *restrict image)
383 {
384   return(image->channel_map[YPixelChannel].traits);
385 }
386
387 static inline Quantum GetPixelYellow(const Image *restrict image,
388   const Quantum *restrict pixel)
389 {
390   return(pixel[image->channel_map[YellowPixelChannel].offset]);
391 }
392
393 static inline PixelTrait GetPixelYellowTraits(const Image *restrict image)
394 {
395   return(image->channel_map[YellowPixelChannel].traits);
396 }
397
398 static inline MagickRealType AbsolutePixelValue(const MagickRealType x)
399 {
400   return(x < 0.0f ? -x : x);
401 }
402
403 static inline MagickBooleanType IsPixelAtDepth(const Quantum pixel,
404   const QuantumAny range)
405 {
406   Quantum
407     quantum;
408
409 #if !defined(MAGICKCORE_HDRI_SUPPORT)
410   quantum=(Quantum) (((MagickRealType) QuantumRange*((QuantumAny) 
411     (((MagickRealType) range*pixel)/QuantumRange+0.5)))/range+0.5);
412 #else
413   quantum=(Quantum) (((MagickRealType) QuantumRange*((QuantumAny) 
414     (((MagickRealType) range*pixel)/QuantumRange+0.5)))/range);
415 #endif
416   return(pixel == quantum ? MagickTrue : MagickFalse);
417 }
418
419 static inline MagickBooleanType IsPixelEquivalent(const Image *restrict image,
420   const Quantum *restrict p,const PixelInfo *restrict q)
421 {
422   MagickRealType
423     blue,
424     green,
425     red;
426
427   red=(MagickRealType) p[image->channel_map[RedPixelChannel].offset];
428   green=(MagickRealType) p[image->channel_map[GreenPixelChannel].offset];
429   blue=(MagickRealType) p[image->channel_map[BluePixelChannel].offset];
430   if ((AbsolutePixelValue(red-q->red) < MagickEpsilon) &&
431       (AbsolutePixelValue(green-q->green) < MagickEpsilon) &&
432       (AbsolutePixelValue(blue-q->blue) < MagickEpsilon))
433     return(MagickTrue);
434   return(MagickFalse);
435 }
436
437 static inline MagickBooleanType IsPixelGray(const Image *restrict image,
438   const Quantum *restrict pixel)
439 {
440   MagickRealType
441     blue,
442     green,
443     red;
444
445   red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
446   green=(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
447   blue=(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
448   if ((AbsolutePixelValue(red-green) < MagickEpsilon) &&
449       (AbsolutePixelValue(green-blue) < MagickEpsilon))
450     return(MagickTrue);
451   return(MagickFalse);
452 }
453
454 static inline MagickBooleanType IsPixelInfoEquivalent(
455   const PixelInfo *restrict p,const PixelInfo *restrict q)
456 {
457   if ((p->alpha_trait != UndefinedPixelTrait) &&
458       (q->alpha_trait == UndefinedPixelTrait) &&
459       (AbsolutePixelValue(p->alpha-OpaqueAlpha) >= MagickEpsilon))
460     return(MagickFalse);
461   if ((q->alpha_trait != UndefinedPixelTrait) &&
462       (p->alpha_trait == UndefinedPixelTrait) &&
463       (AbsolutePixelValue(q->alpha-OpaqueAlpha)) >= MagickEpsilon)
464     return(MagickFalse);
465   if ((p->alpha_trait != UndefinedPixelTrait) &&
466       (q->alpha_trait != UndefinedPixelTrait))
467     {
468       if (AbsolutePixelValue(p->alpha-q->alpha) >= MagickEpsilon)
469         return(MagickFalse);
470       if (AbsolutePixelValue(p->alpha-TransparentAlpha) < MagickEpsilon)
471         return(MagickTrue);
472     }
473   if (AbsolutePixelValue(p->red-q->red) >= MagickEpsilon)
474     return(MagickFalse);
475   if (AbsolutePixelValue(p->green-q->green) >= MagickEpsilon)
476     return(MagickFalse);
477   if (AbsolutePixelValue(p->blue-q->blue) >= MagickEpsilon)
478     return(MagickFalse);
479   if ((p->colorspace == CMYKColorspace) &&
480       (AbsolutePixelValue(p->black-q->black) >= MagickEpsilon))
481     return(MagickFalse);
482   return(MagickTrue);
483 }
484
485 static inline MagickBooleanType IsPixelMonochrome(const Image *restrict image,
486   const Quantum *restrict pixel)
487 {
488   MagickRealType
489     blue,
490     green,
491     red;
492
493   red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
494   if ((AbsolutePixelValue(red) >= MagickEpsilon) ||
495       (AbsolutePixelValue(red-QuantumRange) >= MagickEpsilon))
496     return(MagickFalse);
497   green=(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
498   blue=(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
499   if ((AbsolutePixelValue(red-green) < MagickEpsilon) &&
500       (AbsolutePixelValue(green-blue) < MagickEpsilon))
501     return(MagickTrue);
502   return(MagickFalse);
503 }
504
505 static inline MagickBooleanType IsPixelInfoGray(
506   const PixelInfo *restrict pixel_info)
507 {
508   if ((pixel_info->colorspace != GRAYColorspace) &&
509       (pixel_info->colorspace != RGBColorspace))
510     return(MagickFalse);
511   if ((AbsolutePixelValue(pixel_info->red-pixel_info->green) < MagickEpsilon) &&
512       (AbsolutePixelValue(pixel_info->green-pixel_info->blue) < MagickEpsilon))
513     return(MagickTrue);
514   return(MagickFalse);
515 }
516
517 static inline MagickBooleanType IsPixelInfoMonochrome(
518   const PixelInfo *restrict pixel_info)
519 {
520   if ((pixel_info->colorspace != GRAYColorspace) &&
521       (pixel_info->colorspace != RGBColorspace))
522     return(MagickFalse);
523   if ((AbsolutePixelValue(pixel_info->red) >= MagickEpsilon) ||
524       (AbsolutePixelValue(pixel_info->red-QuantumRange) >= MagickEpsilon))
525     return(MagickFalse);
526   if ((AbsolutePixelValue(pixel_info->red-pixel_info->green) < MagickEpsilon) &&
527       (AbsolutePixelValue(pixel_info->green-pixel_info->blue) < MagickEpsilon))
528     return(MagickTrue);
529   return(MagickFalse);
530 }
531
532 static inline void SetPixela(const Image *restrict image,
533   const Quantum a,Quantum *restrict pixel)
534 {
535   if (image->channel_map[aPixelChannel].traits != UndefinedPixelTrait)
536     pixel[image->channel_map[aPixelChannel].offset]=a;
537 }
538
539 static inline void SetPixelAlpha(const Image *restrict image,
540   const Quantum alpha,Quantum *restrict pixel)
541 {
542   if (image->channel_map[AlphaPixelChannel].traits == BlendPixelTrait)
543     pixel[image->channel_map[AlphaPixelChannel].offset]=alpha;
544 }
545
546 static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
547 {
548   image->channel_map[AlphaPixelChannel].traits=traits;
549 }
550
551 static inline void SetPixelb(const Image *restrict image,
552   const Quantum b,Quantum *restrict pixel)
553 {
554   if (image->channel_map[bPixelChannel].traits != UndefinedPixelTrait)
555     pixel[image->channel_map[bPixelChannel].offset]=b;
556 }
557
558 static inline void SetPixelBackgoundColor(const Image *restrict image,
559   Quantum *restrict pixel)
560 {
561   register ssize_t
562     i;
563
564   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
565     pixel[i]=0;
566   pixel[image->channel_map[RedPixelChannel].offset]=
567     ClampToQuantum(image->background_color.red);
568   pixel[image->channel_map[GreenPixelChannel].offset]=
569     ClampToQuantum(image->background_color.green);
570   pixel[image->channel_map[BluePixelChannel].offset]=
571     ClampToQuantum(image->background_color.blue);
572   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
573     pixel[image->channel_map[BlackPixelChannel].offset]=
574       ClampToQuantum(image->background_color.black);
575   if (image->channel_map[AlphaPixelChannel].traits == BlendPixelTrait)
576     pixel[image->channel_map[AlphaPixelChannel].offset]=
577       image->background_color.alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
578       ClampToQuantum(image->background_color.alpha);
579 }
580
581 static inline void SetPixelBlack(const Image *restrict image,
582   const Quantum black,Quantum *restrict pixel)
583 {
584   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
585     pixel[image->channel_map[BlackPixelChannel].offset]=black;
586 }
587
588 static inline void SetPixelBlackTraits(Image *image,const PixelTrait traits)
589 {
590   image->channel_map[BlackPixelChannel].traits=traits;
591 }
592
593 static inline void SetPixelBlue(const Image *restrict image,const Quantum blue,
594   Quantum *restrict pixel)
595 {
596   pixel[image->channel_map[BluePixelChannel].offset]=blue;
597 }
598
599 static inline void SetPixelBlueTraits(Image *image,const PixelTrait traits)
600 {
601   image->channel_map[BluePixelChannel].traits=traits;
602 }
603
604 static inline void SetPixelCb(const Image *restrict image,const Quantum cb,
605   Quantum *restrict pixel)
606 {
607   pixel[image->channel_map[CbPixelChannel].offset]=cb;
608 }
609
610 static inline void SetPixelCbTraits(Image *image,const PixelTrait traits)
611 {
612   image->channel_map[CbPixelChannel].traits=traits;
613 }
614
615 static inline void SetPixelChannel(const Image *restrict image,
616   const PixelChannel channel,const Quantum quantum,Quantum *restrict pixel)
617 {
618   if (image->channel_map[channel].traits != UndefinedPixelTrait)
619     pixel[image->channel_map[channel].offset]=quantum;
620 }
621
622 static inline void SetPixelChannelAttributes(const Image *restrict image,
623   const PixelChannel channel,const PixelTrait traits,const ssize_t offset)
624 {
625   image->channel_map[offset].channel=channel;
626   image->channel_map[channel].offset=offset;
627   image->channel_map[channel].traits=traits;
628 }
629
630 static inline void SetPixelChannelChannel(const Image *restrict image,
631   const PixelChannel channel,const ssize_t offset)
632 {
633   image->channel_map[offset].channel=channel;
634   image->channel_map[channel].offset=offset;
635 }
636
637 static inline void SetPixelChannels(Image *image,const size_t number_channels)
638 {
639   image->number_channels=number_channels;
640 }
641
642 static inline void SetPixelChannelTraits(Image *image,
643   const PixelChannel channel,const PixelTrait traits)
644 {
645   image->channel_map[channel].traits=traits;
646 }
647
648 static inline void SetPixelCr(const Image *restrict image,const Quantum cr,
649   Quantum *restrict pixel)
650 {
651   pixel[image->channel_map[CrPixelChannel].offset]=cr;
652 }
653
654 static inline void SetPixelCrTraits(Image *image,const PixelTrait traits)
655 {
656   image->channel_map[CrPixelChannel].traits=traits;
657 }
658
659 static inline void SetPixelCyan(const Image *restrict image,const Quantum cyan,
660   Quantum *restrict pixel)
661 {
662   pixel[image->channel_map[CyanPixelChannel].offset]=cyan;
663 }
664
665 static inline void SetPixelGray(const Image *restrict image,const Quantum gray,
666   Quantum *restrict pixel)
667 {
668   pixel[image->channel_map[GrayPixelChannel].offset]=gray;
669 }
670
671 static inline void SetPixelGrayTraits(Image *image,const PixelTrait traits)
672 {
673   image->channel_map[GrayPixelChannel].traits=traits;
674 }
675
676 static inline void SetPixelGreen(const Image *restrict image,
677   const Quantum green,Quantum *restrict pixel)
678 {
679   pixel[image->channel_map[GreenPixelChannel].offset]=green;
680 }
681
682 static inline void SetPixelGreenTraits(Image *image,const PixelTrait traits)
683 {
684   image->channel_map[GreenPixelChannel].traits=traits;
685 }
686
687 static inline void SetPixelIndex(const Image *restrict image,
688   const Quantum index,Quantum *restrict pixel)
689 {
690   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
691     pixel[image->channel_map[IndexPixelChannel].offset]=index;
692 }
693
694 static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
695 {
696   image->channel_map[IndexPixelChannel].traits=traits;
697 }
698
699 static inline void SetPixelInfoPixel(const Image *restrict image,
700   const PixelInfo *restrict pixel_info,Quantum *restrict pixel)
701 {
702   pixel[image->channel_map[RedPixelChannel].offset]=
703     ClampToQuantum(pixel_info->red);
704   pixel[image->channel_map[GreenPixelChannel].offset]=
705     ClampToQuantum(pixel_info->green);
706   pixel[image->channel_map[BluePixelChannel].offset]=
707     ClampToQuantum(pixel_info->blue);
708   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
709     pixel[image->channel_map[BlackPixelChannel].offset]=
710       ClampToQuantum(pixel_info->black);
711   if (image->channel_map[AlphaPixelChannel].traits == BlendPixelTrait)
712     pixel[image->channel_map[AlphaPixelChannel].offset]=
713       pixel_info->alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
714       ClampToQuantum(pixel_info->alpha);
715 }
716
717 static inline void SetPixelL(const Image *restrict image,const Quantum L,
718   Quantum *restrict pixel)
719 {
720   if (image->channel_map[LPixelChannel].traits != UndefinedPixelTrait)
721     pixel[image->channel_map[LPixelChannel].offset]=L;
722 }
723
724 static inline void SetPixelMagenta(const Image *restrict image,
725   const Quantum magenta,Quantum *restrict pixel)
726 {
727   pixel[image->channel_map[MagentaPixelChannel].offset]=magenta;
728 }
729
730 static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
731 {
732   image->channel_map[MagentaPixelChannel].traits=traits;
733 }
734
735 static inline void SetPixelReadMask(const Image *restrict image,
736   const Quantum mask,Quantum *restrict pixel)
737 {
738   if (image->channel_map[ReadMaskPixelChannel].traits != UndefinedPixelTrait)
739     pixel[image->channel_map[ReadMaskPixelChannel].offset]=mask;
740 }
741
742 static inline void SetPixelWriteMask(const Image *restrict image,
743   const Quantum mask,Quantum *restrict pixel)
744 {
745   if (image->channel_map[WriteMaskPixelChannel].traits != UndefinedPixelTrait)
746     pixel[image->channel_map[WriteMaskPixelChannel].offset]=mask;
747 }
748
749 static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
750 {
751   image->metacontent_extent=extent;
752 }
753
754 static inline void SetPixelOpacity(const Image *restrict image,
755   const Quantum alpha,Quantum *restrict pixel)
756 {
757   if (image->channel_map[AlphaPixelChannel].traits == BlendPixelTrait)
758     pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
759 }
760
761 static inline void SetPixelRed(const Image *restrict image,const Quantum red,
762   Quantum *restrict pixel)
763 {
764   pixel[image->channel_map[RedPixelChannel].offset]=red;
765 }
766
767 static inline void SetPixelRedTraits(Image *image,const PixelTrait traits)
768 {
769   image->channel_map[RedPixelChannel].traits=traits;
770 }
771
772 static inline void SetPixelYellow(const Image *restrict image,
773   const Quantum yellow,Quantum *restrict pixel)
774 {
775   pixel[image->channel_map[YellowPixelChannel].offset]=yellow;
776 }
777
778 static inline void SetPixelYellowTraits(Image *image,const PixelTrait traits)
779 {
780   image->channel_map[YellowPixelChannel].traits=traits;
781 }
782
783 static inline void SetPixelY(const Image *restrict image,const Quantum y,
784   Quantum *restrict pixel)
785 {
786   pixel[image->channel_map[YPixelChannel].offset]=y;
787 }
788
789 static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
790 {
791   image->channel_map[YPixelChannel].traits=traits;
792 }
793
794 #if defined(__cplusplus) || defined(c_plusplus)
795 }
796 #endif
797
798 #endif