MagickCore 7.1.2-32
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
pixel-accessor.h
1/*
2 Copyright @ 1999 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. You may
6 obtain a copy of the License at
7
8 https://imagemagick.org/license/
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#include "MagickCore/memory_.h"
28
29#if defined(__cplusplus) || defined(c_plusplus)
30extern "C" {
31#endif
32
33#undef index
34
35static inline Quantum ClampPixel(const MagickRealType pixel)
36{
37 if (pixel < 0.0)
38 return((Quantum) 0);
39 if (pixel >= (MagickRealType) QuantumRange)
40 return((Quantum) QuantumRange);
41#if !defined(MAGICKCORE_HDRI_SUPPORT)
42 return((Quantum) (pixel+0.5f));
43#else
44 return((Quantum) pixel);
45#endif
46}
47
48static inline Quantum GetPixela(const Image *magick_restrict image,
49 const Quantum *magick_restrict pixel)
50{
51 return(pixel[image->channel_map[aPixelChannel].offset]);
52}
53
54static inline Quantum GetPixelAlpha(const Image *magick_restrict image,
55 const Quantum *magick_restrict pixel)
56{
57 if (image->channel_map[AlphaPixelChannel].traits == UndefinedPixelTrait)
58 return(OpaqueAlpha);
59 return(pixel[image->channel_map[AlphaPixelChannel].offset]);
60}
61
62static inline PixelTrait GetPixelAlphaTraits(const Image *magick_restrict image)
63{
64 return(image->channel_map[AlphaPixelChannel].traits);
65}
66
67static 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
73static 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
81static inline PixelTrait GetPixelBlackTraits(const Image *magick_restrict image)
82{
83 return(image->channel_map[BlackPixelChannel].traits);
84}
85
86static inline Quantum GetPixelBlue(const Image *magick_restrict image,
87 const Quantum *magick_restrict pixel)
88{
89 return(pixel[image->channel_map[BluePixelChannel].offset]);
90}
91
92static inline PixelTrait GetPixelBlueTraits(const Image *magick_restrict image)
93{
94 return(image->channel_map[BluePixelChannel].traits);
95}
96
97static inline Quantum GetPixelCb(const Image *magick_restrict image,
98 const Quantum *magick_restrict pixel)
99{
100 return(pixel[image->channel_map[CbPixelChannel].offset]);
101}
102
103static inline PixelTrait GetPixelCbTraits(const Image *magick_restrict image)
104{
105 return(image->channel_map[CbPixelChannel].traits);
106}
107
108static inline Quantum GetPixelChannel(const Image *magick_restrict image,
109 const PixelChannel channel,const Quantum *magick_restrict pixel)
110{
111 if ((size_t) channel >= MaxPixelChannels)
112 return((Quantum) 0);
113 if (image->channel_map[channel].traits == UndefinedPixelTrait)
114 return((Quantum) 0);
115 return(pixel[image->channel_map[channel].offset]);
116}
117
118static inline PixelChannel GetPixelChannelChannel(
119 const Image *magick_restrict image,const ssize_t offset)
120{
121 if ((offset < 0) || (offset >= MaxPixelChannels))
122 return(UndefinedPixelChannel);
123 return(image->channel_map[offset].channel);
124}
125
126static inline ssize_t GetPixelChannelOffset(const Image *magick_restrict image,
127 const PixelChannel channel)
128{
129 return(image->channel_map[channel].offset);
130}
131
132static inline PixelTrait GetPixelChannelTraits(
133 const Image *magick_restrict image,const PixelChannel channel)
134{
135 if ((size_t) channel >= MaxPixelChannels)
136 return(UndefinedPixelTrait);
137 return(image->channel_map[channel].traits);
138}
139
140static inline size_t GetPixelChannels(const Image *magick_restrict image)
141{
142 return(image->number_channels);
143}
144
145static inline Quantum GetPixelCompositeMask(
146 const Image *magick_restrict image,const Quantum *magick_restrict pixel)
147{
148 if (image->channel_map[CompositeMaskPixelChannel].traits == UndefinedPixelTrait)
149 return((Quantum) QuantumRange);
150 return(pixel[image->channel_map[CompositeMaskPixelChannel].offset]);
151}
152
153static inline PixelTrait GetPixelCompositeMaskTraits(
154 const Image *magick_restrict image)
155{
156 return(image->channel_map[CompositeMaskPixelChannel].traits);
157}
158
159static inline Quantum GetPixelCr(const Image *magick_restrict image,
160 const Quantum *magick_restrict pixel)
161{
162 return(pixel[image->channel_map[CrPixelChannel].offset]);
163}
164
165static inline PixelTrait GetPixelCrTraits(const Image *magick_restrict image)
166{
167 return(image->channel_map[CrPixelChannel].traits);
168}
169
170static inline Quantum GetPixelCyan(const Image *magick_restrict image,
171 const Quantum *magick_restrict pixel)
172{
173 return(pixel[image->channel_map[CyanPixelChannel].offset]);
174}
175
176static inline PixelTrait GetPixelCyanTraits(const Image *magick_restrict image)
177{
178 return(image->channel_map[CyanPixelChannel].traits);
179}
180
181static inline Quantum GetPixelGray(const Image *magick_restrict image,
182 const Quantum *magick_restrict pixel)
183{
184 return(pixel[image->channel_map[GrayPixelChannel].offset]);
185}
186
187static inline PixelTrait GetPixelGrayTraits(const Image *magick_restrict image)
188{
189 return(image->channel_map[GrayPixelChannel].traits);
190}
191
192static inline Quantum GetPixelGreen(const Image *magick_restrict image,
193 const Quantum *magick_restrict pixel)
194{
195 return(pixel[image->channel_map[GreenPixelChannel].offset]);
196}
197
198static inline PixelTrait GetPixelGreenTraits(const Image *magick_restrict image)
199{
200 return(image->channel_map[GreenPixelChannel].traits);
201}
202
203static inline Quantum GetPixelIndex(const Image *magick_restrict image,
204 const Quantum *magick_restrict pixel)
205{
206 if (image->channel_map[IndexPixelChannel].traits == UndefinedPixelTrait)
207 return((Quantum) 0);
208#if defined(MAGICKCORE_HDRI_SUPPORT)
209 if (pixel[image->channel_map[IndexPixelChannel].offset] < 0)
210 return((Quantum) 0);
211#endif
212 return(pixel[image->channel_map[IndexPixelChannel].offset]);
213}
214
215static inline PixelTrait GetPixelIndexTraits(const Image *magick_restrict image)
216{
217 return(image->channel_map[IndexPixelChannel].traits);
218}
219
220static inline MagickRealType GetPixelInfoChannel(
221 const PixelInfo *magick_restrict pixel_info,const PixelChannel channel)
222{
223 switch (channel)
224 {
225 case RedPixelChannel: return(pixel_info->red);
226 case GreenPixelChannel: return(pixel_info->green);
227 case BluePixelChannel: return(pixel_info->blue);
228 case BlackPixelChannel:
229 {
230 if (pixel_info->colorspace != CMYKColorspace)
231 return(0.0);
232 return(pixel_info->black);
233 }
234 case AlphaPixelChannel:
235 {
236 if (pixel_info->alpha_trait == UndefinedPixelTrait)
237 return((MagickRealType) OpaqueAlpha);
238 return(pixel_info->alpha);
239 }
240 case IndexPixelChannel: return(pixel_info->index);
241 default: break;
242 }
243 return((MagickRealType) 0.0);
244}
245
246static inline MagickRealType GetPixelInfoLuma(
247 const PixelInfo *magick_restrict pixel)
248{
249 MagickRealType
250 intensity;
251
252 if (pixel->colorspace == sRGBColorspace)
253 {
254 intensity=(MagickRealType) (0.212656*pixel->red+0.715158*pixel->green+
255 0.072186*pixel->blue);
256 return(intensity);
257 }
258 intensity=(MagickRealType) (0.212656*EncodePixelGamma(pixel->red)+
259 0.715158*EncodePixelGamma(pixel->green)+
260 0.072186*EncodePixelGamma(pixel->blue));
261 return(intensity);
262}
263
264static inline MagickRealType GetPixelInfoLuminance(
265 const PixelInfo *magick_restrict pixel)
266{
267 MagickRealType
268 intensity;
269
270 if (pixel->colorspace != sRGBColorspace)
271 {
272 intensity=(MagickRealType) (0.212656*pixel->red+0.715158*pixel->green+
273 0.072186*pixel->blue);
274 return(intensity);
275 }
276 intensity=(MagickRealType) (0.212656*DecodePixelGamma(pixel->red)+
277 0.715158*DecodePixelGamma(pixel->green)+
278 0.072186*DecodePixelGamma(pixel->blue));
279 return(intensity);
280}
281
282static inline Quantum GetPixelL(const Image *magick_restrict image,
283 const Quantum *magick_restrict pixel)
284{
285 return(pixel[image->channel_map[LPixelChannel].offset]);
286}
287
288static inline ssize_t GetPixelLabel(const Image *magick_restrict image,
289 const Quantum *magick_restrict pixel)
290{
291 return((ssize_t) pixel[image->channel_map[LabelPixelChannel].offset]);
292}
293
294static inline MagickRealType GetPixelLuma(
295 const Image *magick_restrict image,const Quantum *magick_restrict pixel)
296{
297 MagickRealType
298 intensity;
299
300 intensity=
301 0.212656*(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]+
302 0.715158*(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]+
303 0.072186*(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
304 return(intensity);
305}
306
307static inline MagickRealType GetPixelLuminance(
308 const Image *magick_restrict image,const Quantum *magick_restrict pixel)
309{
310 MagickRealType
311 intensity;
312
313 if (image->colorspace != sRGBColorspace)
314 {
315 intensity=
316 0.212656*(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]+
317 0.715158*(MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]+
318 0.072186*(MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
319 return(intensity);
320 }
321 intensity=(MagickRealType) (0.212656*DecodePixelGamma((MagickRealType)
322 pixel[image->channel_map[RedPixelChannel].offset])+0.715158*
323 DecodePixelGamma((MagickRealType)
324 pixel[image->channel_map[GreenPixelChannel].offset])+0.072186*
325 DecodePixelGamma((MagickRealType)
326 pixel[image->channel_map[BluePixelChannel].offset]));
327 return(intensity);
328}
329
330static inline Quantum GetPixelMagenta(const Image *magick_restrict image,
331 const Quantum *magick_restrict pixel)
332{
333 return(pixel[image->channel_map[MagentaPixelChannel].offset]);
334}
335
336static inline PixelTrait GetPixelMagentaTraits(
337 const Image *magick_restrict image)
338{
339 return(image->channel_map[MagentaPixelChannel].traits);
340}
341
342static inline Quantum GetPixelMeta(const Image *magick_restrict image,
343 const Quantum *magick_restrict pixel)
344{
345 if (image->channel_map[MetaPixelChannels].traits == UndefinedPixelTrait)
346 return(OpaqueAlpha);
347 return(pixel[image->channel_map[MetaPixelChannels].offset]);
348}
349
350static inline PixelTrait GetPixelMetaTraits(const Image *magick_restrict image)
351{
352 return(image->channel_map[MetaPixelChannels].traits);
353}
354
355static inline Quantum GetPixelReadMask(const Image *magick_restrict image,
356 const Quantum *magick_restrict pixel)
357{
358 if (image->channel_map[ReadMaskPixelChannel].traits == UndefinedPixelTrait)
359 return((Quantum) QuantumRange);
360 return(pixel[image->channel_map[ReadMaskPixelChannel].offset]);
361}
362
363static inline void GetPixelInfoRGBA(const Quantum red,const Quantum green,
364 const Quantum blue,const Quantum alpha,PixelInfo *magick_restrict pixel)
365{
366 GetPixelInfo((Image *) NULL,pixel);
367 pixel->red=(MagickRealType) red;
368 pixel->green=(MagickRealType) green;
369 pixel->blue=(MagickRealType) blue;
370 pixel->alpha=(MagickRealType) alpha;
371}
372
373static inline Quantum GetPixelWriteMask(
374 const Image *magick_restrict image,const Quantum *magick_restrict pixel)
375{
376 if (image->channel_map[WriteMaskPixelChannel].traits == UndefinedPixelTrait)
377 return((Quantum) QuantumRange);
378 return(pixel[image->channel_map[WriteMaskPixelChannel].offset]);
379}
380
381static inline PixelTrait GetPixelReadMaskTraits(
382 const Image *magick_restrict image)
383{
384 return(image->channel_map[ReadMaskPixelChannel].traits);
385}
386
387static inline size_t GetPixelMetaChannels(const Image *magick_restrict image)
388{
389 return(image->number_meta_channels);
390}
391
392static inline size_t GetPixelMetacontentExtent(
393 const Image *magick_restrict image)
394{
395 return(image->metacontent_extent);
396}
397
398static inline Quantum GetPixelOpacity(const Image *magick_restrict image,
399 const Quantum *magick_restrict pixel)
400{
401 if (image->channel_map[AlphaPixelChannel].traits != BlendPixelTrait)
402 return(QuantumRange-OpaqueAlpha);
403 return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
404}
405
406static inline Quantum GetPixelRed(const Image *magick_restrict image,
407 const Quantum *magick_restrict pixel)
408{
409 return(pixel[image->channel_map[RedPixelChannel].offset]);
410}
411
412static inline PixelTrait GetPixelRedTraits(const Image *magick_restrict image)
413{
414 return(image->channel_map[RedPixelChannel].traits);
415}
416
417static inline void GetPixelInfoPixel(const Image *magick_restrict image,
418 const Quantum *magick_restrict pixel,PixelInfo *magick_restrict pixel_info)
419{
420 (void) ResetMagickMemory(pixel_info,0,sizeof(*pixel_info));
421 pixel_info->storage_class=DirectClass;
422 pixel_info->colorspace=sRGBColorspace;
423 pixel_info->depth=MAGICKCORE_QUANTUM_DEPTH;
424 pixel_info->alpha_trait=UndefinedPixelTrait;
425 pixel_info->alpha=(MagickRealType) OpaqueAlpha;
426 if (image != (Image *) NULL)
427 {
428 pixel_info->storage_class=image->storage_class;
429 pixel_info->colorspace=image->colorspace;
430 pixel_info->fuzz=image->fuzz;
431 pixel_info->depth=image->depth;
432 pixel_info->alpha_trait=image->alpha_trait;
433 if (pixel != (Quantum *) NULL)
434 {
435 pixel_info->red=(MagickRealType)
436 pixel[image->channel_map[RedPixelChannel].offset];
437 pixel_info->green=(MagickRealType)
438 pixel[image->channel_map[GreenPixelChannel].offset];
439 pixel_info->blue=(MagickRealType)
440 pixel[image->channel_map[BluePixelChannel].offset];
441 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
442 pixel_info->black=(MagickRealType)
443 pixel[image->channel_map[BlackPixelChannel].offset];
444 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
445 pixel_info->alpha=(MagickRealType)
446 pixel[image->channel_map[AlphaPixelChannel].offset];
447 if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
448 pixel_info->index=(MagickRealType)
449 pixel[image->channel_map[IndexPixelChannel].offset];
450 }
451 }
452}
453
454static inline PixelTrait GetPixelTraits(const Image *magick_restrict image,
455 const PixelChannel channel)
456{
457 if ((size_t) channel >= MaxPixelChannels)
458 return(UndefinedPixelTrait);
459 return(image->channel_map[channel].traits);
460}
461
462static inline PixelTrait GetPixelWriteMaskTraits(
463 const Image *magick_restrict image)
464{
465 return(image->channel_map[WriteMaskPixelChannel].traits);
466}
467
468static inline Quantum GetPixelY(const Image *magick_restrict image,
469 const Quantum *magick_restrict pixel)
470{
471 return(pixel[image->channel_map[YPixelChannel].offset]);
472}
473
474static inline PixelTrait GetPixelYTraits(const Image *magick_restrict image)
475{
476 return(image->channel_map[YPixelChannel].traits);
477}
478
479static inline Quantum GetPixelYellow(const Image *magick_restrict image,
480 const Quantum *magick_restrict pixel)
481{
482 return(pixel[image->channel_map[YellowPixelChannel].offset]);
483}
484
485static inline PixelTrait GetPixelYellowTraits(
486 const Image *magick_restrict image)
487{
488 return(image->channel_map[YellowPixelChannel].traits);
489}
490
491static inline MagickRealType AbsolutePixelValue(const MagickRealType x)
492{
493 return(x < 0.0 ? -x : x);
494}
495
496static inline QuantumAny CastDoubleToQuantumAny(const double x)
497{
498 double
499 value;
500
501 if (IsNaN(x) != 0)
502 {
503 errno=ERANGE;
504 return(0);
505 }
506 value=(x < 0.0) ? ceil(x) : floor(x);
507 if (value < 0.0)
508 {
509 errno=ERANGE;
510 return(0);
511 }
512 if (value >= ((double) ((QuantumAny) ~0)))
513 {
514 errno=ERANGE;
515 return((QuantumAny) ~0);
516 }
517 return((QuantumAny) value);
518}
519
520static inline MagickBooleanType IsPixelAtDepth(const Quantum pixel,
521 const QuantumAny range)
522{
523 Quantum
524 quantum;
525
526 if (range == 0)
527 return(MagickTrue);
528#if !defined(MAGICKCORE_HDRI_SUPPORT)
529 quantum=(Quantum) (((double) QuantumRange*((QuantumAny) (((double) range*
530 pixel)/(double) QuantumRange+0.5)))/(double) range+0.5);
531#else
532 quantum=(Quantum) (((double) QuantumRange*((double) CastDoubleToQuantumAny(
533 ((double) range*(double) pixel)/(double) QuantumRange+0.5)))/
534 (double) range);
535#endif
536 return(pixel == quantum ? MagickTrue : MagickFalse);
537}
538
539static inline MagickBooleanType IsPixelEquivalent(
540 const Image *magick_restrict image,const Quantum *magick_restrict p,
541 const PixelInfo *magick_restrict q)
542{
543 MagickRealType
544 alpha,
545 beta,
546 color;
547
548 color=(MagickRealType) p[image->channel_map[AlphaPixelChannel].offset];
549 alpha=image->alpha_trait == UndefinedPixelTrait ? (MagickRealType)
550 OpaqueAlpha : color;
551 beta=q->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
552 q->alpha;
553 if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
554 return(MagickFalse);
555 if ((AbsolutePixelValue(alpha-(MagickRealType) TransparentAlpha) < MagickEpsilon) ||
556 (AbsolutePixelValue(beta-(MagickRealType) TransparentAlpha) < MagickEpsilon))
557 return(MagickTrue); /* no color component if pixel is transparent */
558 color=(MagickRealType) p[image->channel_map[RedPixelChannel].offset];
559 if (AbsolutePixelValue(color-q->red) >= MagickEpsilon)
560 return(MagickFalse);
561 color=(MagickRealType) p[image->channel_map[GreenPixelChannel].offset];
562 if (AbsolutePixelValue(color-q->green) >= MagickEpsilon)
563 return(MagickFalse);
564 color=(MagickRealType) p[image->channel_map[BluePixelChannel].offset];
565 if (AbsolutePixelValue(color-q->blue) >= MagickEpsilon)
566 return(MagickFalse);
567 if (image->colorspace == CMYKColorspace)
568 {
569 color=(MagickRealType) p[image->channel_map[BlackPixelChannel].offset];
570 if (AbsolutePixelValue(color-q->black) >= MagickEpsilon)
571 return(MagickFalse);
572 }
573 return(MagickTrue);
574}
575
576static inline MagickBooleanType IsPixelGray(const Image *magick_restrict image,
577 const Quantum *magick_restrict pixel)
578{
579 MagickRealType
580 green_blue,
581 red_green;
582
583 red_green=
584 (MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
585 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
586 green_blue=
587 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]-
588 (MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
589 if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
590 (AbsolutePixelValue(green_blue) < MagickEpsilon))
591 return(MagickTrue);
592 return(MagickFalse);
593}
594
595static inline MagickBooleanType IsPixelInfoEquivalent(
596 const PixelInfo *magick_restrict p,const PixelInfo *magick_restrict q)
597{
598 MagickRealType
599 alpha,
600 beta;
601
602 alpha=p->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
603 p->alpha;
604 beta=q->alpha_trait == UndefinedPixelTrait ? (MagickRealType) OpaqueAlpha :
605 q->alpha;
606 if (AbsolutePixelValue(alpha-beta) >= MagickEpsilon)
607 return(MagickFalse);
608 if ((AbsolutePixelValue(alpha-(MagickRealType) TransparentAlpha) < MagickEpsilon) ||
609 (AbsolutePixelValue(beta-(MagickRealType) TransparentAlpha) < MagickEpsilon))
610 return(MagickTrue); /* no color component if pixel is transparent */
611 if (AbsolutePixelValue(p->red-q->red) >= MagickEpsilon)
612 return(MagickFalse);
613 if (AbsolutePixelValue(p->green-q->green) >= MagickEpsilon)
614 return(MagickFalse);
615 if (AbsolutePixelValue(p->blue-q->blue) >= MagickEpsilon)
616 return(MagickFalse);
617 if (p->colorspace == CMYKColorspace)
618 {
619 if (AbsolutePixelValue(p->black-q->black) >= MagickEpsilon)
620 return(MagickFalse);
621 }
622 return(MagickTrue);
623}
624
625static inline MagickBooleanType IsPixelMonochrome(
626 const Image *magick_restrict image,const Quantum *magick_restrict pixel)
627{
628 MagickRealType
629 green_blue,
630 red,
631 red_green;
632
633 red=(MagickRealType) pixel[image->channel_map[RedPixelChannel].offset];
634 if ((AbsolutePixelValue(red) >= MagickEpsilon) &&
635 (AbsolutePixelValue(red-(MagickRealType) QuantumRange) >= MagickEpsilon))
636 return(MagickFalse);
637 red_green=
638 (MagickRealType) pixel[image->channel_map[RedPixelChannel].offset]-
639 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset];
640 green_blue=
641 (MagickRealType) pixel[image->channel_map[GreenPixelChannel].offset]-
642 (MagickRealType) pixel[image->channel_map[BluePixelChannel].offset];
643 if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
644 (AbsolutePixelValue(green_blue) < MagickEpsilon))
645 return(MagickTrue);
646 return(MagickFalse);
647}
648
649static inline MagickBooleanType IsPixelInfoGray(
650 const PixelInfo *magick_restrict pixel)
651{
652 if ((AbsolutePixelValue(pixel->red-pixel->green) < MagickEpsilon) &&
653 (AbsolutePixelValue(pixel->green-pixel->blue) < MagickEpsilon))
654 return(MagickTrue);
655 return(MagickFalse);
656}
657
658static inline MagickBooleanType IsPixelInfoMonochrome(
659 const PixelInfo *magick_restrict pixel_info)
660{
661 MagickRealType
662 green_blue,
663 red_green;
664
665 if ((AbsolutePixelValue(pixel_info->red) >= MagickEpsilon) ||
666 (AbsolutePixelValue(pixel_info->red-(MagickRealType) QuantumRange) >= MagickEpsilon))
667 return(MagickFalse);
668 red_green=pixel_info->red-pixel_info->green;
669 green_blue=pixel_info->green-pixel_info->blue;
670 if ((AbsolutePixelValue(red_green) < MagickEpsilon) &&
671 (AbsolutePixelValue(green_blue) < MagickEpsilon))
672 return(MagickTrue);
673 return(MagickFalse);
674}
675
676static inline void SetPixela(const Image *magick_restrict image,
677 const Quantum a,Quantum *magick_restrict pixel)
678{
679 if (image->channel_map[aPixelChannel].traits != UndefinedPixelTrait)
680 pixel[image->channel_map[aPixelChannel].offset]=a;
681}
682
683static inline void SetPixelAlpha(const Image *magick_restrict image,
684 const Quantum alpha,Quantum *magick_restrict pixel)
685{
686 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
687 pixel[image->channel_map[AlphaPixelChannel].offset]=alpha;
688}
689
690static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
691{
692 image->channel_map[AlphaPixelChannel].traits=traits;
693}
694
695static inline void SetPixelb(const Image *magick_restrict image,
696 const Quantum b,Quantum *magick_restrict pixel)
697{
698 if (image->channel_map[bPixelChannel].traits != UndefinedPixelTrait)
699 pixel[image->channel_map[bPixelChannel].offset]=b;
700}
701
702static inline void SetPixelBackgroundColor(const Image *magick_restrict image,
703 Quantum *magick_restrict pixel)
704{
705 ssize_t
706 i;
707
708 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
709 pixel[i]=(Quantum) 0;
710 pixel[image->channel_map[RedPixelChannel].offset]=
711 ClampToQuantum(image->background_color.red);
712 pixel[image->channel_map[GreenPixelChannel].offset]=
713 ClampToQuantum(image->background_color.green);
714 pixel[image->channel_map[BluePixelChannel].offset]=
715 ClampToQuantum(image->background_color.blue);
716 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
717 pixel[image->channel_map[BlackPixelChannel].offset]=
718 ClampToQuantum(image->background_color.black);
719 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
720 pixel[image->channel_map[AlphaPixelChannel].offset]=
721 image->background_color.alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
722 ClampToQuantum(image->background_color.alpha);
723}
724
725static inline void SetPixelBackgoundColor(const Image *magick_restrict image,
726 Quantum *magick_restrict pixel) magick_attribute((deprecated));
727
728static inline void SetPixelBackgoundColor(const Image *magick_restrict image,
729 Quantum *magick_restrict pixel)
730{
731 SetPixelBackgroundColor(image,pixel);
732}
733
734static inline void SetPixelBlack(const Image *magick_restrict image,
735 const Quantum black,Quantum *magick_restrict pixel)
736{
737 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
738 pixel[image->channel_map[BlackPixelChannel].offset]=black;
739}
740
741static inline void SetPixelBlackTraits(Image *image,const PixelTrait traits)
742{
743 image->channel_map[BlackPixelChannel].traits=traits;
744}
745
746static inline void SetPixelBlue(const Image *magick_restrict image,
747 const Quantum blue,Quantum *magick_restrict pixel)
748{
749 pixel[image->channel_map[BluePixelChannel].offset]=blue;
750}
751
752static inline void SetPixelBlueTraits(Image *image,const PixelTrait traits)
753{
754 image->channel_map[BluePixelChannel].traits=traits;
755}
756
757static inline void SetPixelCb(const Image *magick_restrict image,
758 const Quantum cb,Quantum *magick_restrict pixel)
759{
760 pixel[image->channel_map[CbPixelChannel].offset]=cb;
761}
762
763static inline void SetPixelCbTraits(Image *image,const PixelTrait traits)
764{
765 image->channel_map[CbPixelChannel].traits=traits;
766}
767
768static inline void SetPixelChannel(const Image *magick_restrict image,
769 const PixelChannel channel,const Quantum quantum,
770 Quantum *magick_restrict pixel)
771{
772 if ((size_t) channel >= MaxPixelChannels)
773 return;
774 if (image->channel_map[channel].traits != UndefinedPixelTrait)
775 pixel[image->channel_map[channel].offset]=quantum;
776}
777
778static inline void SetPixelChannelAttributes(
779 const Image *magick_restrict image,const PixelChannel channel,
780 const PixelTrait traits,const ssize_t offset)
781{
782 if ((offset < 0) || (offset >= MaxPixelChannels))
783 return;
784 if ((size_t) channel >= MaxPixelChannels)
785 return;
786 image->channel_map[offset].channel=channel;
787 image->channel_map[channel].offset=offset;
788 image->channel_map[channel].traits=traits;
789}
790
791static inline void SetPixelChannelChannel(const Image *magick_restrict image,
792 const PixelChannel channel,const ssize_t offset)
793{
794 if ((offset < 0) || (offset >= MaxPixelChannels))
795 return;
796 if ((size_t) channel >= MaxPixelChannels)
797 return;
798 image->channel_map[offset].channel=channel;
799 image->channel_map[channel].offset=offset;
800}
801
802static inline void SetPixelChannels(Image *image,const size_t number_channels)
803{
804 image->number_channels=number_channels;
805}
806
807static inline void SetPixelChannelTraits(Image *image,
808 const PixelChannel channel,const PixelTrait traits)
809{
810 if ((size_t) channel >= MaxPixelChannels)
811 return;
812 image->channel_map[channel].traits=traits;
813}
814
815static inline void SetPixelCompositeMask(const Image *magick_restrict image,
816 const Quantum mask,Quantum *magick_restrict pixel)
817{
818 if (image->channel_map[CompositeMaskPixelChannel].traits != UndefinedPixelTrait)
819 pixel[image->channel_map[CompositeMaskPixelChannel].offset]=mask;
820}
821
822static inline void SetPixelCr(const Image *magick_restrict image,
823 const Quantum cr,Quantum *magick_restrict pixel)
824{
825 pixel[image->channel_map[CrPixelChannel].offset]=cr;
826}
827
828static inline void SetPixelCrTraits(Image *image,const PixelTrait traits)
829{
830 image->channel_map[CrPixelChannel].traits=traits;
831}
832
833static inline void SetPixelCyan(const Image *magick_restrict image,
834 const Quantum cyan,Quantum *magick_restrict pixel)
835{
836 pixel[image->channel_map[CyanPixelChannel].offset]=cyan;
837}
838
839static inline void SetPixelGray(const Image *magick_restrict image,
840 const Quantum gray,Quantum *magick_restrict pixel)
841{
842 pixel[image->channel_map[GrayPixelChannel].offset]=gray;
843}
844
845static inline void SetPixelGrayTraits(Image *image,const PixelTrait traits)
846{
847 image->channel_map[GrayPixelChannel].traits=traits;
848}
849
850static inline void SetPixelGreen(const Image *magick_restrict image,
851 const Quantum green,Quantum *magick_restrict pixel)
852{
853 pixel[image->channel_map[GreenPixelChannel].offset]=green;
854}
855
856static inline void SetPixelGreenTraits(Image *image,const PixelTrait traits)
857{
858 image->channel_map[GreenPixelChannel].traits=traits;
859}
860
861static inline void SetPixelIndex(const Image *magick_restrict image,
862 const Quantum index,Quantum *magick_restrict pixel)
863{
864 if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
865 pixel[image->channel_map[IndexPixelChannel].offset]=index;
866}
867
868static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
869{
870 image->channel_map[IndexPixelChannel].traits=traits;
871}
872
873static inline void SetPixelViaPixelInfo(const Image *magick_restrict image,
874 const PixelInfo *magick_restrict pixel_info,Quantum *magick_restrict pixel)
875{
876 pixel[image->channel_map[RedPixelChannel].offset]=
877 ClampToQuantum(pixel_info->red);
878 pixel[image->channel_map[GreenPixelChannel].offset]=
879 ClampToQuantum(pixel_info->green);
880 pixel[image->channel_map[BluePixelChannel].offset]=
881 ClampToQuantum(pixel_info->blue);
882 if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
883 pixel[image->channel_map[BlackPixelChannel].offset]=
884 ClampToQuantum(pixel_info->black);
885 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
886 pixel[image->channel_map[AlphaPixelChannel].offset]=
887 pixel_info->alpha_trait == UndefinedPixelTrait ? OpaqueAlpha :
888 ClampToQuantum(pixel_info->alpha);
889}
890
891static inline void SetPixelL(const Image *magick_restrict image,const Quantum L,
892 Quantum *magick_restrict pixel)
893{
894 if (image->channel_map[LPixelChannel].traits != UndefinedPixelTrait)
895 pixel[image->channel_map[LPixelChannel].offset]=L;
896}
897
898static inline void SetPixelMagenta(const Image *magick_restrict image,
899 const Quantum magenta,Quantum *magick_restrict pixel)
900{
901 pixel[image->channel_map[MagentaPixelChannel].offset]=magenta;
902}
903
904static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
905{
906 image->channel_map[MagentaPixelChannel].traits=traits;
907}
908
909static inline void SetPixelMeta(const Image *magick_restrict image,
910 const Quantum red,Quantum *magick_restrict pixel)
911{
912 pixel[image->channel_map[MetaPixelChannels].offset]=red;
913}
914
915static inline void SetPixelMetaTraits(Image *image,const PixelTrait traits)
916{
917 image->channel_map[MetaPixelChannels].traits=traits;
918}
919
920static inline void SetPixelReadMask(const Image *magick_restrict image,
921 const Quantum mask,Quantum *magick_restrict pixel)
922{
923 if (image->channel_map[ReadMaskPixelChannel].traits != UndefinedPixelTrait)
924 pixel[image->channel_map[ReadMaskPixelChannel].offset]=mask;
925}
926
927static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
928{
929 image->metacontent_extent=extent;
930}
931
932static inline void SetPixelOpacity(const Image *magick_restrict image,
933 const Quantum alpha,Quantum *magick_restrict pixel)
934{
935 if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
936 pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
937}
938
939static inline void SetPixelRed(const Image *magick_restrict image,
940 const Quantum red,Quantum *magick_restrict pixel)
941{
942 pixel[image->channel_map[RedPixelChannel].offset]=red;
943}
944
945static inline void SetPixelRedTraits(Image *image,const PixelTrait traits)
946{
947 image->channel_map[RedPixelChannel].traits=traits;
948}
949
950static inline void SetPixelWriteMask(const Image *magick_restrict image,
951 const Quantum mask,Quantum *magick_restrict pixel)
952{
953 if (image->channel_map[WriteMaskPixelChannel].traits != UndefinedPixelTrait)
954 pixel[image->channel_map[WriteMaskPixelChannel].offset]=mask;
955}
956
957static inline void SetPixelYellow(const Image *magick_restrict image,
958 const Quantum yellow,Quantum *magick_restrict pixel)
959{
960 pixel[image->channel_map[YellowPixelChannel].offset]=yellow;
961}
962
963static inline void SetPixelYellowTraits(Image *image,const PixelTrait traits)
964{
965 image->channel_map[YellowPixelChannel].traits=traits;
966}
967
968static inline void SetPixelY(const Image *magick_restrict image,
969 const Quantum y,Quantum *magick_restrict pixel)
970{
971 pixel[image->channel_map[YPixelChannel].offset]=y;
972}
973
974static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
975{
976 image->channel_map[YPixelChannel].traits=traits;
977}
978
979static inline size_t GetImageChannels(const Image *image)
980{
981 ssize_t
982 i;
983
984 size_t
985 channels;
986
987 channels=0;
988 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
989 {
990 PixelChannel channel = GetPixelChannelChannel(image,i);
991 PixelTrait traits = GetPixelChannelTraits(image,channel);
992 if ((traits & UpdatePixelTrait) != 0)
993 channels++;
994 }
995 return(channels == 0 ? (size_t) 1 : channels);
996}
997
998#if defined(__cplusplus) || defined(c_plusplus)
999}
1000#endif
1001
1002#endif