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