]> granicus.if.org Git - imagemagick/blob - MagickCore/pixel-accessor.h
(no commit message)
[imagemagick] / MagickCore / pixel-accessor.h
1 /*
2   Copyright 1999-2012 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 #if defined(__cplusplus) || defined(c_plusplus)
22 extern "C" {
23 #endif
24
25 #include <MagickCore/cache.h>
26 #include <MagickCore/cache-view.h>
27 #include <MagickCore/color.h>
28 #include <MagickCore/colorspace.h>
29 #include <MagickCore/gem.h>
30 #include <MagickCore/image.h>
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(
103   const Image *restrict image,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 double GetPixelInfoChannel(const PixelInfo *restrict pixel_info,
183   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(0.0);
194   }
195 }
196
197 static inline double GetPixelInfoIntensity(const PixelInfo *restrict pixel_info)
198 {
199   double
200     blue,
201     green,
202     red;
203
204   if (pixel_info->colorspace == GRAYColorspace)
205     return(pixel_info->red);
206   if (pixel_info->colorspace != sRGBColorspace)
207     return(0.298839*pixel_info->red+0.586811*pixel_info->green+
208       0.114350*pixel_info->blue);
209   red=InversesRGBCompandor(pixel_info->red);
210   green=InversesRGBCompandor(pixel_info->green);
211   blue=InversesRGBCompandor(pixel_info->blue);
212   return(0.298839*red+0.586811*green+0.114350*blue);
213 }
214
215 static inline double GetPixelInfoLuminance(const PixelInfo *restrict pixel_info)
216 {
217   double
218     blue,
219     green,
220     red;
221
222   if (pixel_info->colorspace == GRAYColorspace)
223     return(pixel_info->red);
224   if (pixel_info->colorspace != sRGBColorspace)
225     return(0.21267*pixel_info->red+0.71516*pixel_info->green+
226       0.07217*pixel_info->blue);
227   red=InversesRGBCompandor(pixel_info->red);
228   green=InversesRGBCompandor(pixel_info->green);
229   blue=InversesRGBCompandor(pixel_info->blue);
230   return(0.21267*red+0.71516*green+0.07217*blue);
231 }
232
233 static inline double GetPixelIntensity(const Image *restrict image,
234   const Quantum *restrict pixel)
235 {
236   double
237     blue,
238     green,
239     red;
240
241   if (image->colorspace == GRAYColorspace)
242     return((double) pixel[image->channel_map[GrayPixelChannel].offset]);
243   if (image->colorspace != sRGBColorspace)
244     return(0.298839*pixel[image->channel_map[RedPixelChannel].offset]+
245       0.586811*pixel[image->channel_map[GreenPixelChannel].offset]+
246       0.114350*pixel[image->channel_map[BluePixelChannel].offset]);
247   red=InversesRGBCompandor((double)
248     pixel[image->channel_map[RedPixelChannel].offset]);
249   green=InversesRGBCompandor((double)
250     pixel[image->channel_map[GreenPixelChannel].offset]);
251   blue=InversesRGBCompandor((double)
252     pixel[image->channel_map[BluePixelChannel].offset]);
253   return(0.298839*red+0.586811*green+0.114350*blue);
254 }
255
256 static inline Quantum GetPixelL(const Image *restrict image,
257   const Quantum *restrict pixel)
258 {
259   return(pixel[image->channel_map[LPixelChannel].offset]);
260 }
261
262 static inline double GetPixelLuminance(const Image *restrict image,
263   const Quantum *restrict pixel)
264 {
265   double
266     blue,
267     green,
268     red;
269
270   if (image->colorspace == GRAYColorspace)
271     return((double) pixel[image->channel_map[GrayPixelChannel].offset]);
272   if (image->colorspace != sRGBColorspace)
273     return(0.298839*pixel[image->channel_map[RedPixelChannel].offset]+
274       0.586811*pixel[image->channel_map[GreenPixelChannel].offset]+
275       0.114350*pixel[image->channel_map[BluePixelChannel].offset]);
276   red=InversesRGBCompandor((double)
277     pixel[image->channel_map[RedPixelChannel].offset]);
278   green=InversesRGBCompandor((double)
279     pixel[image->channel_map[GreenPixelChannel].offset]);
280   blue=InversesRGBCompandor((double)
281     pixel[image->channel_map[BluePixelChannel].offset]);
282   return(0.21267*red+0.71516*green+0.07217*blue);
283 }
284
285 static inline Quantum GetPixelMagenta(const Image *restrict image,
286   const Quantum *restrict pixel)
287 {
288   return(pixel[image->channel_map[MagentaPixelChannel].offset]);
289 }
290
291 static inline PixelTrait GetPixelMagentaTraits(const Image *restrict image)
292 {
293   return(image->channel_map[MagentaPixelChannel].traits);
294 }
295
296 static inline Quantum GetPixelMask(const Image *restrict image,
297   const Quantum *restrict pixel)
298 {
299   if (image->channel_map[MaskPixelChannel].traits == UndefinedPixelTrait)
300     return((Quantum) 0);
301   return(pixel[image->channel_map[MaskPixelChannel].offset]);
302 }
303
304 static inline PixelTrait GetPixelMaskTraits(const Image *restrict image)
305 {
306   return(image->channel_map[MaskPixelChannel].traits);
307 }
308
309 static inline size_t GetPixelMetaChannels(const Image *restrict image)
310 {
311   return(image->number_meta_channels);
312 }
313
314 static inline size_t GetPixelMetacontentExtent(const Image *restrict image)
315 {
316   return(image->metacontent_extent);
317 }
318
319 static inline Quantum GetPixelOpacity(const Image *restrict image,
320   const Quantum *restrict pixel)
321 {
322   if (image->channel_map[AlphaPixelChannel].traits == UndefinedPixelTrait)
323     return(QuantumRange-OpaqueAlpha);
324   return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
325 }
326
327 static inline Quantum GetPixelRed(const Image *restrict image,
328   const Quantum *restrict pixel)
329 {
330   return(pixel[image->channel_map[RedPixelChannel].offset]);
331 }
332
333 static inline PixelTrait GetPixelRedTraits(const Image *restrict image)
334 {
335   return(image->channel_map[RedPixelChannel].traits);
336 }
337
338 static inline void GetPixelInfoPixel(const Image *restrict image,
339   const Quantum *restrict pixel,PixelInfo *restrict pixel_info)
340 {
341   pixel_info->red=(double)
342     pixel[image->channel_map[RedPixelChannel].offset];
343   pixel_info->green=(double)
344     pixel[image->channel_map[GreenPixelChannel].offset];
345   pixel_info->blue=(double)
346     pixel[image->channel_map[BluePixelChannel].offset];
347   pixel_info->black=0.0;
348   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
349     pixel_info->black=(double)
350       pixel[image->channel_map[BlackPixelChannel].offset];
351   pixel_info->alpha=OpaqueAlpha;
352   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
353     pixel_info->alpha=(double)
354       pixel[image->channel_map[AlphaPixelChannel].offset];
355   pixel_info->index=0.0;
356   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
357     pixel_info->index=(double)
358       pixel[image->channel_map[IndexPixelChannel].offset];
359 }
360
361 static inline PixelTrait GetPixelTraits(const Image *restrict image,
362   const PixelChannel channel)
363 {
364   return(image->channel_map[channel].traits);
365 }
366
367 static inline Quantum GetPixelY(const Image *restrict image,
368   const Quantum *restrict pixel)
369 {
370   return(pixel[image->channel_map[YPixelChannel].offset]);
371 }
372
373 static inline PixelTrait GetPixelYTraits(const Image *restrict image)
374 {
375   return(image->channel_map[YPixelChannel].traits);
376 }
377
378 static inline Quantum GetPixelYellow(const Image *restrict image,
379   const Quantum *restrict pixel)
380 {
381   return(pixel[image->channel_map[YellowPixelChannel].offset]);
382 }
383
384 static inline PixelTrait GetPixelYellowTraits(const Image *restrict image)
385 {
386   return(image->channel_map[YellowPixelChannel].traits);
387 }
388
389 static inline double AbsolutePixelValue(const double x)
390 {
391   return(x < 0.0 ? -x : x);
392 }
393
394 static inline MagickBooleanType IsPixelEquivalent(const Image *restrict image,
395   const Quantum *restrict p,const PixelInfo *restrict q)
396 {
397   double
398     blue,
399     green,
400     red;
401
402   red=(double) p[image->channel_map[RedPixelChannel].offset];
403   green=(double) p[image->channel_map[GreenPixelChannel].offset];
404   blue=(double) p[image->channel_map[BluePixelChannel].offset];
405   if ((AbsolutePixelValue(red-q->red) < MagickEpsilon) &&
406       (AbsolutePixelValue(green-q->green) < MagickEpsilon) &&
407       (AbsolutePixelValue(blue-q->blue) < MagickEpsilon))
408     return(MagickTrue);
409   return(MagickFalse);
410 }
411
412 static inline MagickBooleanType IsPixelGray(const Image *restrict image,
413   const Quantum *restrict pixel)
414 {
415   double
416     blue,
417     green,
418     red;
419
420   red=(double) pixel[image->channel_map[RedPixelChannel].offset];
421   green=(double) pixel[image->channel_map[GreenPixelChannel].offset];
422   blue=(double) pixel[image->channel_map[BluePixelChannel].offset];
423   if ((AbsolutePixelValue(red-green) < MagickEpsilon) &&
424       (AbsolutePixelValue(green-blue) < MagickEpsilon))
425     return(MagickTrue);
426   return(MagickFalse);
427 }
428
429 static inline MagickBooleanType IsPixelInfoEquivalent(
430   const PixelInfo *restrict p,const PixelInfo *restrict q)
431 {
432   if ((p->alpha_trait == BlendPixelTrait) &&
433       (q->alpha_trait != BlendPixelTrait) &&
434       (AbsolutePixelValue(p->alpha-OpaqueAlpha) >= MagickEpsilon))
435     return(MagickFalse);
436   if ((q->alpha_trait == BlendPixelTrait) &&
437       (p->alpha_trait != BlendPixelTrait) &&
438       (AbsolutePixelValue(q->alpha-OpaqueAlpha)) >= MagickEpsilon)
439     return(MagickFalse);
440   if ((p->alpha_trait == BlendPixelTrait) &&
441       (q->alpha_trait == BlendPixelTrait))
442     {
443       if (AbsolutePixelValue(p->alpha-q->alpha) >= MagickEpsilon)
444         return(MagickFalse);
445       if (AbsolutePixelValue(p->alpha-TransparentAlpha) < MagickEpsilon)
446         return(MagickTrue);
447     }
448   if (AbsolutePixelValue(p->red-q->red) >= MagickEpsilon)
449     return(MagickFalse);
450   if (AbsolutePixelValue(p->green-q->green) >= MagickEpsilon)
451     return(MagickFalse);
452   if (AbsolutePixelValue(p->blue-q->blue) >= MagickEpsilon)
453     return(MagickFalse);
454   if ((p->colorspace == CMYKColorspace) &&
455       (AbsolutePixelValue(p->black-q->black) >= MagickEpsilon))
456     return(MagickFalse);
457   return(MagickTrue);
458 }
459
460 static inline MagickBooleanType IsPixelMonochrome(const Image *restrict image,
461   const Quantum *restrict pixel)
462 {
463   double
464     blue,
465     green,
466     red;
467
468   red=(double) pixel[image->channel_map[RedPixelChannel].offset];
469   if ((AbsolutePixelValue(red) >= MagickEpsilon) ||
470       (AbsolutePixelValue(red-QuantumRange) >= MagickEpsilon))
471     return(MagickFalse);
472   green=(double) pixel[image->channel_map[GreenPixelChannel].offset];
473   blue=(double) pixel[image->channel_map[BluePixelChannel].offset];
474   if ((AbsolutePixelValue(red-green) < MagickEpsilon) &&
475       (AbsolutePixelValue(green-blue) < MagickEpsilon))
476     return(MagickTrue);
477   return(MagickFalse);
478 }
479
480 static inline MagickBooleanType IsPixelInfoGray(
481   const PixelInfo *restrict pixel_info)
482 {
483   if ((pixel_info->colorspace != GRAYColorspace) &&
484       (pixel_info->colorspace != RGBColorspace))
485     return(MagickFalse);
486   if ((AbsolutePixelValue(pixel_info->red-pixel_info->green) < MagickEpsilon) &&
487       (AbsolutePixelValue(pixel_info->green-pixel_info->blue) < MagickEpsilon))
488     return(MagickTrue);
489   return(MagickFalse);
490 }
491
492 static inline MagickBooleanType IsPixelInfoMonochrome(
493   const PixelInfo *restrict pixel_info)
494 {
495   if ((pixel_info->colorspace != GRAYColorspace) &&
496       (pixel_info->colorspace != RGBColorspace))
497     return(MagickFalse);
498   if ((AbsolutePixelValue(pixel_info->red) >= MagickEpsilon) ||
499       (AbsolutePixelValue(pixel_info->red-QuantumRange) >= MagickEpsilon))
500     return(MagickFalse);
501   if ((AbsolutePixelValue(pixel_info->red-pixel_info->green) < MagickEpsilon) &&
502       (AbsolutePixelValue(pixel_info->green-pixel_info->blue) < MagickEpsilon))
503     return(MagickTrue);
504   return(MagickFalse);
505 }
506
507 static inline void SetPixela(const Image *restrict image,
508   const Quantum a,Quantum *restrict pixel)
509 {
510   if (image->channel_map[aPixelChannel].traits != UndefinedPixelTrait)
511     pixel[image->channel_map[aPixelChannel].offset]=a;
512 }
513
514 static inline void SetPixelAlpha(const Image *restrict image,
515   const Quantum alpha,Quantum *restrict pixel)
516 {
517   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
518     pixel[image->channel_map[AlphaPixelChannel].offset]=alpha;
519 }
520
521 static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
522 {
523   image->channel_map[AlphaPixelChannel].traits=traits;
524 }
525
526 static inline void SetPixelb(const Image *restrict image,
527   const Quantum b,Quantum *restrict pixel)
528 {
529   if (image->channel_map[bPixelChannel].traits != UndefinedPixelTrait)
530     pixel[image->channel_map[bPixelChannel].offset]=b;
531 }
532
533 static inline void SetPixelBlack(const Image *restrict image,
534   const Quantum black,Quantum *restrict pixel)
535 {
536   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
537     pixel[image->channel_map[BlackPixelChannel].offset]=black;
538 }
539
540 static inline void SetPixelBlackTraits(Image *image,const PixelTrait traits)
541 {
542   image->channel_map[BlackPixelChannel].traits=traits;
543 }
544
545 static inline void SetPixelBlue(const Image *restrict image,const Quantum blue,
546   Quantum *restrict pixel)
547 {
548   pixel[image->channel_map[BluePixelChannel].offset]=blue;
549 }
550
551 static inline void SetPixelBlueTraits(Image *image,const PixelTrait traits)
552 {
553   image->channel_map[BluePixelChannel].traits=traits;
554 }
555
556 static inline void SetPixelCb(const Image *restrict image,const Quantum cb,
557   Quantum *restrict pixel)
558 {
559   pixel[image->channel_map[CbPixelChannel].offset]=cb;
560 }
561
562 static inline void SetPixelCbTraits(Image *image,const PixelTrait traits)
563 {
564   image->channel_map[CbPixelChannel].traits=traits;
565 }
566
567 static inline void SetPixelChannel(const Image *restrict image,
568   const PixelChannel channel,const Quantum quantum,Quantum *restrict pixel)
569 {
570   if (image->channel_map[channel].traits != UndefinedPixelTrait)
571     pixel[image->channel_map[channel].offset]=quantum;
572 }
573
574 static inline void SetPixelChannelAttributes(const Image *restrict image,
575   const PixelChannel channel,const PixelTrait traits,const ssize_t offset)
576 {
577   image->channel_map[offset].channel=channel;
578   image->channel_map[channel].offset=offset;
579   image->channel_map[channel].traits=traits;
580 }
581
582 static inline void SetPixelChannelChannel(const Image *restrict image,
583   const PixelChannel channel,const ssize_t offset)
584 {
585   image->channel_map[offset].channel=channel;
586   image->channel_map[channel].offset=offset;
587 }
588
589 static inline void SetPixelChannels(Image *image,const size_t number_channels)
590 {
591   image->number_channels=number_channels;
592 }
593
594 static inline void SetPixelChannelTraits(Image *image,
595   const PixelChannel channel,const PixelTrait traits)
596 {
597   image->channel_map[channel].traits=traits;
598 }
599
600 static inline void SetPixelCr(const Image *restrict image,const Quantum cr,
601   Quantum *restrict pixel)
602 {
603   pixel[image->channel_map[CrPixelChannel].offset]=cr;
604 }
605
606 static inline void SetPixelCrTraits(Image *image,const PixelTrait traits)
607 {
608   image->channel_map[CrPixelChannel].traits=traits;
609 }
610
611 static inline void SetPixelCyan(const Image *restrict image,const Quantum cyan,
612   Quantum *restrict pixel)
613 {
614   pixel[image->channel_map[CyanPixelChannel].offset]=cyan;
615 }
616
617 static inline void SetPixelGray(const Image *restrict image,const Quantum gray,
618   Quantum *restrict pixel)
619 {
620   pixel[image->channel_map[GrayPixelChannel].offset]=gray;
621 }
622
623 static inline void SetPixelGrayTraits(Image *image,const PixelTrait traits)
624 {
625   image->channel_map[GrayPixelChannel].traits=traits;
626 }
627
628 static inline void SetPixelGreen(const Image *restrict image,
629   const Quantum green,Quantum *restrict pixel)
630 {
631   pixel[image->channel_map[GreenPixelChannel].offset]=green;
632 }
633
634 static inline void SetPixelGreenTraits(Image *image,const PixelTrait traits)
635 {
636   image->channel_map[GreenPixelChannel].traits=traits;
637 }
638
639 static inline void SetPixelIndex(const Image *restrict image,
640   const Quantum index,Quantum *restrict pixel)
641 {
642   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
643     pixel[image->channel_map[IndexPixelChannel].offset]=index;
644 }
645
646 static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
647 {
648   image->channel_map[IndexPixelChannel].traits=traits;
649 }
650
651 static inline void SetPixelInfoPixel(const Image *restrict image,
652   const PixelInfo *restrict pixel_info,Quantum *restrict pixel)
653 {
654   pixel[image->channel_map[RedPixelChannel].offset]=
655     ClampToQuantum(pixel_info->red);
656   pixel[image->channel_map[GreenPixelChannel].offset]=
657     ClampToQuantum(pixel_info->green);
658   pixel[image->channel_map[BluePixelChannel].offset]=
659     ClampToQuantum(pixel_info->blue);
660   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
661     pixel[image->channel_map[BlackPixelChannel].offset]=
662       ClampToQuantum(pixel_info->black);
663   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
664     pixel[image->channel_map[AlphaPixelChannel].offset]=
665       pixel_info->alpha_trait != BlendPixelTrait ? OpaqueAlpha :
666       ClampToQuantum(pixel_info->alpha);
667 }
668
669 static inline void SetPixelL(const Image *restrict image,const Quantum L,
670   Quantum *restrict pixel)
671 {
672   if (image->channel_map[LPixelChannel].traits != UndefinedPixelTrait)
673     pixel[image->channel_map[LPixelChannel].offset]=L;
674 }
675
676 static inline void SetPixelMagenta(const Image *restrict image,
677   const Quantum magenta,Quantum *restrict pixel)
678 {
679   pixel[image->channel_map[MagentaPixelChannel].offset]=magenta;
680 }
681
682 static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
683 {
684   image->channel_map[MagentaPixelChannel].traits=traits;
685 }
686
687 static inline void SetPixelMask(const Image *restrict image,
688   const Quantum mask,Quantum *restrict pixel)
689 {
690   if (image->channel_map[MaskPixelChannel].traits != UndefinedPixelTrait)
691     pixel[image->channel_map[MaskPixelChannel].offset]=mask;
692 }
693
694 static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
695 {
696   image->metacontent_extent=extent;
697 }
698
699 static inline void SetPixelOpacity(const Image *restrict image,
700   const Quantum alpha,Quantum *restrict pixel)
701 {
702   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
703     pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
704 }
705
706 static inline void SetPixelRed(const Image *restrict image,const Quantum red,
707   Quantum *restrict pixel)
708 {
709   pixel[image->channel_map[RedPixelChannel].offset]=red;
710 }
711
712 static inline void SetPixelRedTraits(Image *image,const PixelTrait traits)
713 {
714   image->channel_map[RedPixelChannel].traits=traits;
715 }
716
717 static inline void SetPixelYellow(const Image *restrict image,
718   const Quantum yellow,Quantum *restrict pixel)
719 {
720   pixel[image->channel_map[YellowPixelChannel].offset]=yellow;
721 }
722
723 static inline void SetPixelYellowTraits(Image *image,const PixelTrait traits)
724 {
725   image->channel_map[YellowPixelChannel].traits=traits;
726 }
727
728 static inline void SetPixelY(const Image *restrict image,const Quantum y,
729   Quantum *restrict pixel)
730 {
731   pixel[image->channel_map[YPixelChannel].offset]=y;
732 }
733
734 static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
735 {
736   image->channel_map[YPixelChannel].traits=traits;
737 }
738
739 #if defined(__cplusplus) || defined(c_plusplus)
740 }
741 #endif
742
743 #endif