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