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