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