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