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