]> granicus.if.org Git - imagemagick/blob - MagickCore/pixel-accessor.h
(no commit message)
[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 MagickRealType GetPixelInfoLuma(const PixelInfo *restrict pixel)
211 {
212   MagickRealType
213     blue,
214     green,
215     red;
216
217   if (pixel->colorspace == GRAYColorspace)
218     return(pixel->red);
219   if (pixel->colorspace == sRGBColorspace)
220     return(0.212656f*pixel->red+0.715158f*pixel->green+0.072186f*pixel->blue);
221   red=EncodePixelGamma(pixel->red);
222   green=EncodePixelGamma(pixel->green);
223   blue=EncodePixelGamma(pixel->blue);
224   return(0.212656f*red+0.715158f*green+0.072186f*blue);
225 }
226
227 static inline MagickRealType GetPixelInfoLuminance(
228   const PixelInfo *restrict pixel)
229 {
230   MagickRealType
231     blue,
232     green,
233     red;
234
235   if (pixel->colorspace == GRAYColorspace)
236     return(pixel->red);
237   if (pixel->colorspace != sRGBColorspace)
238     return(0.212656f*pixel->red+0.715158f*pixel->green+0.072186f*pixel->blue);
239   red=DecodePixelGamma(pixel->red);
240   green=DecodePixelGamma(pixel->green);
241   blue=DecodePixelGamma(pixel->blue);
242   return(0.212656f*red+0.715158f*green+0.072186f*blue);
243 }
244
245 static inline Quantum GetPixelL(const Image *restrict image,
246   const Quantum *restrict pixel)
247 {
248   return(pixel[image->channel_map[LPixelChannel].offset]);
249 }
250
251 static inline MagickRealType GetPixelLuma(const Image *restrict image,
252   const Quantum *restrict pixel)
253 {
254   if (image->colorspace == GRAYColorspace)
255     return((MagickRealType) pixel[image->channel_map[GrayPixelChannel].offset]);
256   return(0.212656f*pixel[image->channel_map[RedPixelChannel].offset]+
257     0.715158f*pixel[image->channel_map[GreenPixelChannel].offset]+
258     0.072186f*pixel[image->channel_map[BluePixelChannel].offset]);  /* Rec709 */
259 }
260
261 static inline MagickRealType GetPixelLuminance(const Image *restrict image,
262   const Quantum *restrict pixel)
263 {
264   MagickRealType
265     blue,
266     green,
267     red;
268
269   if (image->colorspace == GRAYColorspace)
270     return((MagickRealType) pixel[image->channel_map[GrayPixelChannel].offset]);
271   if (image->colorspace != sRGBColorspace)
272     return(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   red=DecodePixelGamma((MagickRealType)
276     pixel[image->channel_map[RedPixelChannel].offset]);
277   green=DecodePixelGamma((MagickRealType)
278     pixel[image->channel_map[GreenPixelChannel].offset]);
279   blue=DecodePixelGamma((MagickRealType)
280     pixel[image->channel_map[BluePixelChannel].offset]);
281   return(0.212656f*red+0.715158f*green+0.072186f*blue);  /* Rec709 */
282 }
283
284 static inline Quantum GetPixelMagenta(const Image *restrict image,
285   const Quantum *restrict pixel)
286 {
287   return(pixel[image->channel_map[MagentaPixelChannel].offset]);
288 }
289
290 static inline PixelTrait GetPixelMagentaTraits(const Image *restrict image)
291 {
292   return(image->channel_map[MagentaPixelChannel].traits);
293 }
294
295 static inline Quantum GetPixelReadMask(const Image *restrict image,
296   const Quantum *restrict pixel)
297 {
298   if (image->channel_map[ReadMaskPixelChannel].traits == UndefinedPixelTrait)
299     return((Quantum) QuantumRange);
300   return(pixel[image->channel_map[ReadMaskPixelChannel].offset]);
301 }
302
303 static inline Quantum GetPixelWriteMask(const Image *restrict image,
304   const Quantum *restrict pixel)
305 {
306   if (image->channel_map[WriteMaskPixelChannel].traits == UndefinedPixelTrait)
307     return((Quantum) QuantumRange);
308   return(pixel[image->channel_map[WriteMaskPixelChannel].offset]);
309 }
310
311 static inline PixelTrait GetPixelReadMaskTraits(const Image *restrict image)
312 {
313   return(image->channel_map[ReadMaskPixelChannel].traits);
314 }
315
316 static inline size_t GetPixelMetaChannels(const Image *restrict image)
317 {
318   return(image->number_meta_channels);
319 }
320
321 static inline size_t GetPixelMetacontentExtent(const Image *restrict image)
322 {
323   return(image->metacontent_extent);
324 }
325
326 static inline Quantum GetPixelOpacity(const Image *restrict image,
327   const Quantum *restrict pixel)
328 {
329   if (image->channel_map[AlphaPixelChannel].traits != BlendPixelTrait)
330     return(QuantumRange-OpaqueAlpha);
331   return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
332 }
333
334 static inline Quantum GetPixelRed(const Image *restrict image,
335   const Quantum *restrict pixel)
336 {
337   return(pixel[image->channel_map[RedPixelChannel].offset]);
338 }
339
340 static inline PixelTrait GetPixelRedTraits(const Image *restrict image)
341 {
342   return(image->channel_map[RedPixelChannel].traits);
343 }
344
345 static inline void GetPixelInfoPixel(const Image *restrict image,
346   const Quantum *restrict pixel,PixelInfo *restrict pixel_info)
347 {
348   pixel_info->colorspace=image->colorspace;
349   pixel_info->fuzz=image->fuzz;
350   pixel_info->red=(MagickRealType)
351     pixel[image->channel_map[RedPixelChannel].offset];
352   pixel_info->green=(MagickRealType)
353     pixel[image->channel_map[GreenPixelChannel].offset];
354   pixel_info->blue=(MagickRealType)
355     pixel[image->channel_map[BluePixelChannel].offset];
356   pixel_info->black=0.0f;
357   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
358     pixel_info->black=(MagickRealType)
359       pixel[image->channel_map[BlackPixelChannel].offset];
360   pixel_info->alpha=(MagickRealType) OpaqueAlpha;
361   pixel_info->alpha_trait=UndefinedPixelTrait;
362   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
363     {
364       pixel_info->alpha=(MagickRealType)
365         pixel[image->channel_map[AlphaPixelChannel].offset];
366       pixel_info->alpha_trait=BlendPixelTrait;
367     }
368   pixel_info->index=0.0f;
369   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
370     pixel_info->index=(MagickRealType)
371       pixel[image->channel_map[IndexPixelChannel].offset];
372 }
373
374 static inline PixelTrait GetPixelTraits(const Image *restrict image,
375   const PixelChannel channel)
376 {
377   return(image->channel_map[channel].traits);
378 }
379
380 static inline Quantum GetPixelY(const Image *restrict image,
381   const Quantum *restrict pixel)
382 {
383   return(pixel[image->channel_map[YPixelChannel].offset]);
384 }
385
386 static inline PixelTrait GetPixelYTraits(const Image *restrict image)
387 {
388   return(image->channel_map[YPixelChannel].traits);
389 }
390
391 static inline Quantum GetPixelYellow(const Image *restrict image,
392   const Quantum *restrict pixel)
393 {
394   return(pixel[image->channel_map[YellowPixelChannel].offset]);
395 }
396
397 static inline PixelTrait GetPixelYellowTraits(const Image *restrict image)
398 {
399   return(image->channel_map[YellowPixelChannel].traits);
400 }
401
402 static inline MagickRealType AbsolutePixelValue(const MagickRealType x)
403 {
404   return(x < 0.0f ? -x : x);
405 }
406
407 static inline MagickBooleanType IsPixelAtDepth(const Quantum pixel,
408   const QuantumAny range)
409 {
410   Quantum
411     quantum;
412
413 #if !defined(MAGICKCORE_HDRI_SUPPORT)
414   quantum=(Quantum) (((MagickRealType) QuantumRange*((QuantumAny) 
415     (((MagickRealType) range*pixel)/QuantumRange+0.5)))/range+0.5);
416 #else
417   quantum=(Quantum) (((MagickRealType) QuantumRange*((QuantumAny) 
418     (((MagickRealType) range*pixel)/QuantumRange+0.5)))/range);
419 #endif
420   return(pixel == quantum ? MagickTrue : MagickFalse);
421 }
422
423 static inline MagickBooleanType IsPixelEquivalent(const Image *restrict image,
424   const Quantum *restrict p,const PixelInfo *restrict q)
425 {
426   MagickRealType
427     blue,
428     green,
429     red;
430
431   red=(MagickRealType) p[image->channel_map[RedPixelChannel].offset];
432   green=(MagickRealType) p[image->channel_map[GreenPixelChannel].offset];
433   blue=(MagickRealType) p[image->channel_map[BluePixelChannel].offset];
434   if ((AbsolutePixelValue(red-q->red) < MagickEpsilon) &&
435       (AbsolutePixelValue(green-q->green) < MagickEpsilon) &&
436       (AbsolutePixelValue(blue-q->blue) < MagickEpsilon))
437     return(MagickTrue);
438   return(MagickFalse);
439 }
440
441 static inline MagickBooleanType IsPixelGray(const Image *restrict image,
442   const Quantum *restrict pixel)
443 {
444   MagickRealType
445     blue,
446     green,
447     red;
448
449   red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
450   green=(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
451   blue=(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
452   if ((AbsolutePixelValue(red-green) < MagickEpsilon) &&
453       (AbsolutePixelValue(green-blue) < MagickEpsilon))
454     return(MagickTrue);
455   return(MagickFalse);
456 }
457
458 static inline MagickBooleanType IsPixelInfoEquivalent(
459   const PixelInfo *restrict p,const PixelInfo *restrict q)
460 {
461   if ((p->alpha_trait != UndefinedPixelTrait) &&
462       (q->alpha_trait == UndefinedPixelTrait) &&
463       (AbsolutePixelValue(p->alpha-OpaqueAlpha) >= MagickEpsilon))
464     return(MagickFalse);
465   if ((q->alpha_trait != UndefinedPixelTrait) &&
466       (p->alpha_trait == UndefinedPixelTrait) &&
467       (AbsolutePixelValue(q->alpha-OpaqueAlpha)) >= MagickEpsilon)
468     return(MagickFalse);
469   if ((p->alpha_trait != UndefinedPixelTrait) &&
470       (q->alpha_trait != UndefinedPixelTrait))
471     {
472       if (AbsolutePixelValue(p->alpha-q->alpha) >= MagickEpsilon)
473         return(MagickFalse);
474       if (AbsolutePixelValue(p->alpha-TransparentAlpha) < MagickEpsilon)
475         return(MagickTrue);
476     }
477   if (AbsolutePixelValue(p->red-q->red) >= MagickEpsilon)
478     return(MagickFalse);
479   if (AbsolutePixelValue(p->green-q->green) >= MagickEpsilon)
480     return(MagickFalse);
481   if (AbsolutePixelValue(p->blue-q->blue) >= MagickEpsilon)
482     return(MagickFalse);
483   if ((p->colorspace == CMYKColorspace) &&
484       (AbsolutePixelValue(p->black-q->black) >= MagickEpsilon))
485     return(MagickFalse);
486   return(MagickTrue);
487 }
488
489 static inline MagickBooleanType IsPixelMonochrome(const Image *restrict image,
490   const Quantum *restrict pixel)
491 {
492   MagickRealType
493     blue,
494     green,
495     red;
496
497   red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
498   if ((AbsolutePixelValue(red) >= MagickEpsilon) ||
499       (AbsolutePixelValue(red-QuantumRange) >= MagickEpsilon))
500     return(MagickFalse);
501   green=(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
502   blue=(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
503   if ((AbsolutePixelValue(red-green) < MagickEpsilon) &&
504       (AbsolutePixelValue(green-blue) < MagickEpsilon))
505     return(MagickTrue);
506   return(MagickFalse);
507 }
508
509 static inline MagickBooleanType IsPixelInfoGray(
510   const PixelInfo *restrict pixel_info)
511 {
512   if ((pixel_info->colorspace != GRAYColorspace) &&
513       (pixel_info->colorspace != RGBColorspace))
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 MagickBooleanType IsPixelInfoMonochrome(
522   const PixelInfo *restrict pixel_info)
523 {
524   if ((pixel_info->colorspace != GRAYColorspace) &&
525       (pixel_info->colorspace != RGBColorspace))
526     return(MagickFalse);
527   if ((AbsolutePixelValue(pixel_info->red) >= MagickEpsilon) ||
528       (AbsolutePixelValue(pixel_info->red-QuantumRange) >= MagickEpsilon))
529     return(MagickFalse);
530   if ((AbsolutePixelValue(pixel_info->red-pixel_info->green) < MagickEpsilon) &&
531       (AbsolutePixelValue(pixel_info->green-pixel_info->blue) < MagickEpsilon))
532     return(MagickTrue);
533   return(MagickFalse);
534 }
535
536 static inline void SetPixela(const Image *restrict image,
537   const Quantum a,Quantum *restrict pixel)
538 {
539   if (image->channel_map[aPixelChannel].traits != UndefinedPixelTrait)
540     pixel[image->channel_map[aPixelChannel].offset]=a;
541 }
542
543 static inline void SetPixelAlpha(const Image *restrict image,
544   const Quantum alpha,Quantum *restrict pixel)
545 {
546   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
547     pixel[image->channel_map[AlphaPixelChannel].offset]=alpha;
548 }
549
550 static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
551 {
552   image->channel_map[AlphaPixelChannel].traits=traits;
553 }
554
555 static inline void SetPixelb(const Image *restrict image,
556   const Quantum b,Quantum *restrict pixel)
557 {
558   if (image->channel_map[bPixelChannel].traits != UndefinedPixelTrait)
559     pixel[image->channel_map[bPixelChannel].offset]=b;
560 }
561
562 static inline void SetPixelBackgoundColor(const Image *restrict image,
563   Quantum *restrict pixel)
564 {
565   register ssize_t
566     i;
567
568   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
569     pixel[i]=0;
570   pixel[image->channel_map[RedPixelChannel].offset]=
571     ClampToQuantum(image->background_color.red);
572   pixel[image->channel_map[GreenPixelChannel].offset]=
573     ClampToQuantum(image->background_color.green);
574   pixel[image->channel_map[BluePixelChannel].offset]=
575     ClampToQuantum(image->background_color.blue);
576   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
577     pixel[image->channel_map[BlackPixelChannel].offset]=
578       ClampToQuantum(image->background_color.black);
579   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
580     pixel[image->channel_map[AlphaPixelChannel].offset]=
581       image->background_color.alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
582       ClampToQuantum(image->background_color.alpha);
583 }
584
585 static inline void SetPixelBlack(const Image *restrict image,
586   const Quantum black,Quantum *restrict pixel)
587 {
588   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
589     pixel[image->channel_map[BlackPixelChannel].offset]=black;
590 }
591
592 static inline void SetPixelBlackTraits(Image *image,const PixelTrait traits)
593 {
594   image->channel_map[BlackPixelChannel].traits=traits;
595 }
596
597 static inline void SetPixelBlue(const Image *restrict image,const Quantum blue,
598   Quantum *restrict pixel)
599 {
600   pixel[image->channel_map[BluePixelChannel].offset]=blue;
601 }
602
603 static inline void SetPixelBlueTraits(Image *image,const PixelTrait traits)
604 {
605   image->channel_map[BluePixelChannel].traits=traits;
606 }
607
608 static inline void SetPixelCb(const Image *restrict image,const Quantum cb,
609   Quantum *restrict pixel)
610 {
611   pixel[image->channel_map[CbPixelChannel].offset]=cb;
612 }
613
614 static inline void SetPixelCbTraits(Image *image,const PixelTrait traits)
615 {
616   image->channel_map[CbPixelChannel].traits=traits;
617 }
618
619 static inline void SetPixelChannel(const Image *restrict image,
620   const PixelChannel channel,const Quantum quantum,Quantum *restrict pixel)
621 {
622   if (image->channel_map[channel].traits != UndefinedPixelTrait)
623     pixel[image->channel_map[channel].offset]=quantum;
624 }
625
626 static inline void SetPixelChannelAttributes(const Image *restrict image,
627   const PixelChannel channel,const PixelTrait traits,const ssize_t offset)
628 {
629   image->channel_map[offset].channel=channel;
630   image->channel_map[channel].offset=offset;
631   image->channel_map[channel].traits=traits;
632 }
633
634 static inline void SetPixelChannelChannel(const Image *restrict image,
635   const PixelChannel channel,const ssize_t offset)
636 {
637   image->channel_map[offset].channel=channel;
638   image->channel_map[channel].offset=offset;
639 }
640
641 static inline void SetPixelChannels(Image *image,const size_t number_channels)
642 {
643   image->number_channels=number_channels;
644 }
645
646 static inline void SetPixelChannelTraits(Image *image,
647   const PixelChannel channel,const PixelTrait traits)
648 {
649   image->channel_map[channel].traits=traits;
650 }
651
652 static inline void SetPixelCr(const Image *restrict image,const Quantum cr,
653   Quantum *restrict pixel)
654 {
655   pixel[image->channel_map[CrPixelChannel].offset]=cr;
656 }
657
658 static inline void SetPixelCrTraits(Image *image,const PixelTrait traits)
659 {
660   image->channel_map[CrPixelChannel].traits=traits;
661 }
662
663 static inline void SetPixelCyan(const Image *restrict image,const Quantum cyan,
664   Quantum *restrict pixel)
665 {
666   pixel[image->channel_map[CyanPixelChannel].offset]=cyan;
667 }
668
669 static inline void SetPixelGray(const Image *restrict image,const Quantum gray,
670   Quantum *restrict pixel)
671 {
672   pixel[image->channel_map[GrayPixelChannel].offset]=gray;
673 }
674
675 static inline void SetPixelGrayTraits(Image *image,const PixelTrait traits)
676 {
677   image->channel_map[GrayPixelChannel].traits=traits;
678 }
679
680 static inline void SetPixelGreen(const Image *restrict image,
681   const Quantum green,Quantum *restrict pixel)
682 {
683   pixel[image->channel_map[GreenPixelChannel].offset]=green;
684 }
685
686 static inline void SetPixelGreenTraits(Image *image,const PixelTrait traits)
687 {
688   image->channel_map[GreenPixelChannel].traits=traits;
689 }
690
691 static inline void SetPixelIndex(const Image *restrict image,
692   const Quantum index,Quantum *restrict pixel)
693 {
694   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
695     pixel[image->channel_map[IndexPixelChannel].offset]=index;
696 }
697
698 static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
699 {
700   image->channel_map[IndexPixelChannel].traits=traits;
701 }
702
703 static inline void SetPixelViaPixelInfo(const Image *restrict image,
704   const PixelInfo *restrict pixel_info,Quantum *restrict pixel)
705 {
706   pixel[image->channel_map[RedPixelChannel].offset]=
707     ClampToQuantum(pixel_info->red);
708   pixel[image->channel_map[GreenPixelChannel].offset]=
709     ClampToQuantum(pixel_info->green);
710   pixel[image->channel_map[BluePixelChannel].offset]=
711     ClampToQuantum(pixel_info->blue);
712   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
713     pixel[image->channel_map[BlackPixelChannel].offset]=
714       ClampToQuantum(pixel_info->black);
715   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
716     pixel[image->channel_map[AlphaPixelChannel].offset]=
717       pixel_info->alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
718       ClampToQuantum(pixel_info->alpha);
719 }
720
721 static inline void SetPixelL(const Image *restrict image,const Quantum L,
722   Quantum *restrict pixel)
723 {
724   if (image->channel_map[LPixelChannel].traits != UndefinedPixelTrait)
725     pixel[image->channel_map[LPixelChannel].offset]=L;
726 }
727
728 static inline void SetPixelMagenta(const Image *restrict image,
729   const Quantum magenta,Quantum *restrict pixel)
730 {
731   pixel[image->channel_map[MagentaPixelChannel].offset]=magenta;
732 }
733
734 static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
735 {
736   image->channel_map[MagentaPixelChannel].traits=traits;
737 }
738
739 static inline void SetPixelReadMask(const Image *restrict image,
740   const Quantum mask,Quantum *restrict pixel)
741 {
742   if (image->channel_map[ReadMaskPixelChannel].traits != UndefinedPixelTrait)
743     pixel[image->channel_map[ReadMaskPixelChannel].offset]=mask;
744 }
745
746 static inline void SetPixelWriteMask(const Image *restrict image,
747   const Quantum mask,Quantum *restrict pixel)
748 {
749   if (image->channel_map[WriteMaskPixelChannel].traits != UndefinedPixelTrait)
750     pixel[image->channel_map[WriteMaskPixelChannel].offset]=mask;
751 }
752
753 static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
754 {
755   image->metacontent_extent=extent;
756 }
757
758 static inline void SetPixelOpacity(const Image *restrict image,
759   const Quantum alpha,Quantum *restrict pixel)
760 {
761   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
762     pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
763 }
764
765 static inline void SetPixelRed(const Image *restrict image,const Quantum red,
766   Quantum *restrict pixel)
767 {
768   pixel[image->channel_map[RedPixelChannel].offset]=red;
769 }
770
771 static inline void SetPixelRedTraits(Image *image,const PixelTrait traits)
772 {
773   image->channel_map[RedPixelChannel].traits=traits;
774 }
775
776 static inline void SetPixelYellow(const Image *restrict image,
777   const Quantum yellow,Quantum *restrict pixel)
778 {
779   pixel[image->channel_map[YellowPixelChannel].offset]=yellow;
780 }
781
782 static inline void SetPixelYellowTraits(Image *image,const PixelTrait traits)
783 {
784   image->channel_map[YellowPixelChannel].traits=traits;
785 }
786
787 static inline void SetPixelY(const Image *restrict image,const Quantum y,
788   Quantum *restrict pixel)
789 {
790   pixel[image->channel_map[YPixelChannel].offset]=y;
791 }
792
793 static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
794 {
795   image->channel_map[YPixelChannel].traits=traits;
796 }
797
798 #if defined(__cplusplus) || defined(c_plusplus)
799 }
800 #endif
801
802 #endif