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