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