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