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