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