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