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