]> granicus.if.org Git - imagemagick/blob - MagickCore/pixel-accessor.h
(no commit message)
[imagemagick] / MagickCore / pixel-accessor.h
1 /*
2   Copyright 1999-2011 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.
6   obtain a copy of the License at
7
8     http://www.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 #if defined(__cplusplus) || defined(c_plusplus)
22 extern "C" {
23 #endif
24
25 #include <math.h>
26 #include <MagickCore/cache-view.h>
27 #include <MagickCore/color.h>
28 #include <MagickCore/image.h>
29
30 #undef index
31
32 static inline Quantum GetPixelAlpha(const Image *image,const Quantum *pixel)
33 {
34   return(pixel[image->channel_map[AlphaPixelChannel].channel]);
35 }
36
37 static inline PixelTrait GetPixelAlphaTraits(const Image *image)
38 {
39   return(image->channel_map[AlphaPixelChannel].traits);
40 }
41
42 static inline Quantum GetPixelBlack(const Image *image,const Quantum *pixel)
43 {
44   return(pixel[image->channel_map[BlackPixelChannel].channel]);
45 }
46
47 static inline PixelTrait GetPixelBlackTraits(const Image *image)
48 {
49   return(image->channel_map[BlackPixelChannel].traits);
50 }
51
52 static inline Quantum GetPixelBlue(const Image *image,const Quantum *pixel)
53 {
54   return(pixel[image->channel_map[BluePixelChannel].channel]);
55 }
56
57 static inline PixelTrait GetPixelBlueTraits(const Image *image)
58 {
59   return(image->channel_map[BluePixelChannel].traits);
60 }
61
62 static inline Quantum GetPixelCb(const Image *image,const Quantum *pixel)
63 {
64   return(pixel[image->channel_map[CbPixelChannel].channel]);
65 }
66
67 static inline PixelTrait GetPixelCbTraits(const Image *image)
68 {
69   return(image->channel_map[CbPixelChannel].traits);
70 }
71
72 static inline Quantum GetPixelChannel(const Image *image,
73   const PixelChannel channel,const Quantum *pixel)
74 {
75   return(pixel[image->channel_map[channel].channel]);
76 }
77
78 static inline PixelChannel GetPixelChannelMapChannel(const Image *image,
79   const PixelChannel channel)
80 {
81   return(image->channel_map[channel].channel);
82 }
83
84 static inline PixelTrait GetPixelChannelMapTraits(const Image *image,
85   const PixelChannel channel)
86 {
87   return(image->channel_map[channel].traits);
88 }
89
90 static inline size_t GetPixelChannels(const Image *image)
91 {
92   return(image->number_channels);
93 }
94
95 static inline Quantum GetPixelCr(const Image *image,const Quantum *pixel)
96 {
97   return(pixel[image->channel_map[CrPixelChannel].channel]);
98 }
99
100 static inline PixelTrait GetPixelCrTraits(const Image *image)
101 {
102   return(image->channel_map[CrPixelChannel].traits);
103 }
104
105 static inline Quantum GetPixelCyan(const Image *image,const Quantum *pixel)
106 {
107   return(pixel[image->channel_map[CyanPixelChannel].channel]);
108 }
109
110 static inline PixelTrait GetPixelCyanTraits(const Image *image)
111 {
112   return(image->channel_map[CyanPixelChannel].traits);
113 }
114
115 static inline Quantum GetPixelGray(const Image *image,const Quantum *pixel)
116 {
117   return(pixel[image->channel_map[GrayPixelChannel].channel]);
118 }
119
120 static inline PixelTrait GetPixelGrayTraits(const Image *image)
121 {
122   return(image->channel_map[GrayPixelChannel].traits);
123 }
124
125 static inline Quantum GetPixelGreen(const Image *image,const Quantum *pixel)
126 {
127   return(pixel[image->channel_map[GreenPixelChannel].channel]);
128 }
129
130 static inline PixelTrait GetPixelGreenTraits(const Image *image)
131 {
132   return(image->channel_map[GreenPixelChannel].traits);
133 }
134
135 static inline Quantum GetPixelIndex(const Image *image,const Quantum *pixel)
136 {
137   return(pixel[image->channel_map[IndexPixelChannel].channel]);
138 }
139
140 static inline PixelTrait GetPixelIndexTraits(const Image *image)
141 {
142   return(image->channel_map[IndexPixelChannel].traits);
143 }
144
145 static inline Quantum GetPixelInfoIntensity(const PixelInfo *pixel_info)
146 {
147 #if !defined(MAGICKCORE_HDRI_SUPPORT)
148   return((Quantum) (0.299*pixel_info->red+0.587*pixel_info->green+0.114*
149     pixel_info->blue+0.5));
150 #else
151   return((Quantum) (0.299*pixel_info->red+0.587*pixel_info->green+0.114*
152     pixel_info->blue));
153 #endif
154 }
155
156 static inline Quantum GetPixelInfoLuminance(const PixelInfo *pixel_info)
157 {
158   Quantum
159     luminance;
160
161 #if !defined(MAGICKCORE_HDRI_SUPPORT)
162   luminance=(Quantum) (0.21267*pixel_info->red+0.71516*pixel_info->green+
163     0.07217*pixel_info->blue+0.5);
164 #else
165   luminance=(Quantum) (0.21267*pixel_info->red+0.71516*pixel_info->green+
166     0.07217*pixel_info->blue);
167 #endif
168   return((Quantum) luminance);
169 }
170
171 static inline Quantum GetPixelMagenta(const Image *image,const Quantum *pixel)
172 {
173   return(pixel[image->channel_map[MagentaPixelChannel].channel]);
174 }
175
176 static inline PixelTrait GetPixelMagentaTraits(const Image *image)
177 {
178   return(image->channel_map[MagentaPixelChannel].traits);
179 }
180
181 static inline size_t GetPixelMetaChannels(const Image *image)
182 {
183   return(image->number_meta_channels);
184 }
185
186 static inline size_t GetPixelMetacontentExtent(const Image *image)
187 {
188   return(image->metacontent_extent);
189 }
190
191 static inline Quantum GetPixelRed(const Image *image,const Quantum *pixel)
192 {
193   return(pixel[image->channel_map[RedPixelChannel].channel]);
194 }
195
196 static inline PixelTrait GetPixelRedTraits(const Image *image)
197 {
198   return(image->channel_map[RedPixelChannel].traits);
199 }
200
201 static inline void GetPixelPacket(const Image *image,const Quantum *pixel,
202   PixelPacket *packet)
203 {
204   packet->red=GetPixelRed(image,pixel);
205   packet->green=GetPixelGreen(image,pixel);
206   packet->blue=GetPixelBlue(image,pixel);
207   packet->alpha=GetPixelAlpha(image,pixel);
208 }
209
210 static inline Quantum GetPixelPacketIntensity(const PixelPacket *pixel)
211 {
212 #if !defined(MAGICKCORE_HDRI_SUPPORT)
213   if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
214     return(pixel->red);
215   return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue+0.5));
216 #else
217   {
218     double
219       alpha,
220       beta;
221
222     alpha=pixel->red-pixel->green;
223     beta=pixel->green-pixel->blue;
224     if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
225       return(pixel->red);
226     return((Quantum) (0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue));
227   }
228 #endif
229 }
230
231 static inline PixelTrait GetPixelTraits(const Image *image,
232   const PixelChannel channel)
233 {
234   return(image->channel_map[channel].traits);
235 }
236
237 static inline Quantum GetPixelY(const Image *image,const Quantum *pixel)
238 {
239   return(pixel[image->channel_map[YPixelChannel].channel]);
240 }
241
242 static inline PixelTrait GetPixelYTraits(const Image *image)
243 {
244   return(image->channel_map[YPixelChannel].traits);
245 }
246
247 static inline Quantum GetPixelYellow(const Image *image,const Quantum *pixel)
248 {
249   return(pixel[image->channel_map[YellowPixelChannel].channel]);
250 }
251
252 static inline PixelTrait GetPixelYellowTraits(const Image *image)
253 {
254   return(image->channel_map[YellowPixelChannel].traits);
255 }
256
257 static inline MagickBooleanType IsPixelEquivalent(const Image *image,
258   const Quantum *p,const PixelPacket *q)
259 {
260   if ((GetPixelRed(image,p) == q->red) &&
261       (GetPixelGreen(image,p) == q->green) &&
262       (GetPixelBlue(image,p) == q->blue))
263     return(MagickTrue);
264   return(MagickFalse);
265 }
266
267 static inline MagickBooleanType IsPixelGray(const Image *image,
268   const Quantum *pixel)
269 {
270 #if !defined(MAGICKCORE_HDRI_SUPPORT)
271   if ((GetPixelRed(image,pixel) == GetPixelGreen(image,pixel)) &&
272       (GetPixelGreen(image,pixel) == GetPixelBlue(image,pixel)))
273     return(MagickTrue);
274 #else
275   {
276     double
277       alpha,
278       beta;
279
280     alpha=GetPixelRed(image,pixel)-(double) GetPixelGreen(image,pixel);
281     beta=GetPixelGreen(image,pixel)-(double) GetPixelBlue(image,pixel);
282     if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
283       return(MagickTrue);
284   }
285 #endif
286   return(MagickFalse);
287 }
288
289 static inline MagickBooleanType IsPixelInfoEquivalent(const PixelInfo *p,
290   const PixelInfo *q)
291 {
292 #if !defined(MAGICKCORE_HDRI_SUPPORT)
293   if ((p->matte != MagickFalse) && (q->matte == MagickFalse) &&
294       (p->alpha != OpaqueAlpha))
295     return(MagickFalse);
296   if ((q->matte != MagickFalse) && (p->matte == MagickFalse) &&
297       (q->alpha != OpaqueAlpha))
298     return(MagickFalse);
299   if ((p->matte != MagickFalse) && (q->matte != MagickFalse))
300     {
301       if (p->alpha != q->alpha)
302         return(MagickFalse);
303       if (p->alpha == TransparentAlpha)
304         return(MagickTrue);
305     }
306   if (p->red != q->red)
307     return(MagickFalse);
308   if (p->green != q->green)
309     return(MagickFalse);
310   if (p->blue != q->blue)
311     return(MagickFalse);
312   if ((p->colorspace == CMYKColorspace) && (p->black != q->black))
313     return(MagickFalse);
314 #else
315   if ((p->matte != MagickFalse) && (q->matte == MagickFalse) &&
316       (fabs(p->alpha-OpaqueAlpha) > 0.5))
317     return(MagickFalse);
318   if ((q->matte != MagickFalse) && (p->matte == MagickFalse) &&
319       (fabs(q->alpha-OpaqueAlpha)) > 0.5)
320     return(MagickFalse);
321   if ((p->matte != MagickFalse) && (q->matte != MagickFalse))
322     {
323       if (fabs(p->alpha-q->alpha) > 0.5)
324         return(MagickFalse);
325       if (fabs(p->alpha-TransparentAlpha) <= 0.5)
326         return(MagickTrue);
327     }
328   if (fabs(p->red-q->red) > 0.5)
329     return(MagickFalse);
330   if (fabs(p->green-q->green) > 0.5)
331     return(MagickFalse);
332   if (fabs(p->blue-q->blue) > 0.5)
333     return(MagickFalse);
334   if ((p->colorspace == CMYKColorspace) && (fabs(p->black-q->black) > 0.5))
335     return(MagickFalse);
336 #endif
337   return(MagickTrue);
338 }
339
340 static inline MagickBooleanType IsPixelMonochrome(const Image *image,
341   const Quantum *pixel)
342 {
343 #if !defined(MAGICKCORE_HDRI_SUPPORT)
344   if (((GetPixelRed(image,pixel) == 0) ||
345       (GetPixelRed(image,pixel) == (Quantum) QuantumRange)) &&
346       (GetPixelRed(image,pixel) == GetPixelGreen(image,pixel)) &&
347       (GetPixelGreen(image,pixel) == GetPixelBlue(image,pixel)))
348     return(MagickTrue);
349 #else
350   {
351     double
352       alpha,
353       beta;
354
355     alpha=GetPixelRed(image,pixel)-(double) GetPixelGreen(image,pixel);
356     beta=GetPixelGreen(image,pixel)-(double) GetPixelBlue(image,pixel);
357     if (((fabs(GetPixelRed(image,pixel)) <= MagickEpsilon) ||
358          (fabs(GetPixelRed(image,pixel)-QuantumRange) <= MagickEpsilon)) &&
359         (fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
360       return(MagickTrue);
361     }
362 #endif
363   return(MagickFalse);
364 }
365
366 static inline MagickBooleanType IsPixelPacketEquivalent(const PixelPacket *p,
367   const PixelPacket *q)
368 {
369   if ((p->red == q->red) && (p->green == q->green) && (p->blue == q->blue))
370     return(MagickTrue);
371   return(MagickFalse);
372 }
373
374 static inline MagickBooleanType IsPixelPacketGray(const PixelPacket *pixel)
375 {
376 #if !defined(MAGICKCORE_HDRI_SUPPORT)
377   if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
378     return(MagickTrue);
379 #else
380   {
381     double
382       alpha,
383       beta;
384
385     alpha=pixel->red-(double) pixel->green;
386     beta=pixel->green-(double) pixel->blue;
387     if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
388       return(MagickTrue);
389   }
390 #endif
391   return(MagickFalse);
392 }
393
394 static inline MagickBooleanType IsPixelPacketMonochrome(
395   const PixelPacket *pixel)
396 {
397 #if !defined(MAGICKCORE_HDRI_SUPPORT)
398   if (((pixel->red == 0) || (pixel->red == (Quantum) QuantumRange)) &&
399       (pixel->red == pixel->green) && (pixel->green == pixel->blue))
400     return(MagickTrue);
401 #else
402   {
403     double
404       alpha,
405       beta;
406
407     alpha=pixel->red-(double) pixel->green;
408     beta=pixel->green-(double) pixel->blue;
409     if (((fabs(pixel->red) <= MagickEpsilon) ||
410          (fabs(pixel->red-QuantumRange) <= MagickEpsilon)) &&
411         (fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
412       return(MagickTrue);
413     }
414 #endif
415   return(MagickFalse);
416 }
417
418 static inline void SetPacketPixelInfo(const Image *image,
419   const PixelInfo *pixel_info,PixelPacket *packet)
420 {
421   packet->red=ClampToQuantum(pixel_info->red);
422   packet->green=ClampToQuantum(pixel_info->green);
423   packet->blue=ClampToQuantum(pixel_info->blue);
424   packet->alpha=ClampToQuantum(pixel_info->alpha);
425   if (image->colorspace == CMYKColorspace)
426     packet->black=ClampToQuantum(pixel_info->black);
427   if (image->storage_class == PseudoClass)
428     packet->index=ClampToQuantum(pixel_info->index);
429 }
430
431 static inline void SetPixelAlpha(const Image *image,const Quantum alpha,
432   Quantum *pixel)
433 {
434   pixel[image->channel_map[AlphaPixelChannel].channel]=alpha;
435 }
436
437 static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
438 {
439   image->channel_map[AlphaPixelChannel].traits=traits;
440 }
441
442 static inline void SetPixelBlack(const Image *image,const Quantum black,
443   Quantum *pixel)
444 {
445   pixel[image->channel_map[BlackPixelChannel].channel]=black;
446 }
447
448 static inline void SetPixelBlackTraits(Image *image,const PixelTrait traits)
449 {
450   image->channel_map[BlackPixelChannel].traits=traits;
451 }
452
453 static inline void SetPixelBlue(const Image *image,const Quantum blue,
454   Quantum *pixel)
455 {
456   pixel[image->channel_map[BluePixelChannel].channel]=blue;
457 }
458
459 static inline void SetPixelBlueTraits(Image *image,const PixelTrait traits)
460 {
461   image->channel_map[BluePixelChannel].traits=traits;
462 }
463
464 static inline void SetPixelCb(const Image *image,const Quantum cb,
465   Quantum *pixel)
466 {
467   pixel[image->channel_map[CbPixelChannel].channel]=cb;
468 }
469
470 static inline void SetPixelCbTraits(Image *image,const PixelTrait traits)
471 {
472   image->channel_map[CbPixelChannel].traits=traits;
473 }
474
475 static inline void SetPixelChannel(const Image *image,
476   const PixelChannel channel,const Quantum quantum,Quantum *pixel)
477 {
478   pixel[image->channel_map[channel].channel]=quantum;
479 }
480
481 static inline void SetPixelChannelMapChannel(const Image *image,
482   const PixelChannel channel,const PixelChannel channels)
483 {
484   image->channel_map[channel].channel=channels;
485 }
486
487 static inline void SetPixelChannels(Image *image,const size_t number_channels)
488 {
489   image->number_channels=number_channels;
490 }
491
492 static inline void SetPixelChannelTraits(Image *image,
493   const PixelChannel channel,const PixelTrait traits)
494 {
495   image->channel_map[channel].traits=traits;
496 }
497
498 static inline void SetPixelChannelMapTraits(Image *image,
499   const PixelChannel channel,const PixelTrait traits)
500 {
501   image->channel_map[channel].traits=traits;
502 }
503
504 static inline void SetPixelCr(const Image *image,const Quantum cr,
505   Quantum *pixel)
506 {
507   pixel[image->channel_map[CrPixelChannel].channel]=cr;
508 }
509
510 static inline void SetPixelCrTraits(Image *image,const PixelTrait traits)
511 {
512   image->channel_map[CrPixelChannel].traits=traits;
513 }
514
515 static inline void SetPixelCyan(const Image *image,const Quantum cyan,
516   Quantum *pixel)
517 {
518   pixel[image->channel_map[CyanPixelChannel].channel]=cyan;
519 }
520
521 static inline void SetPixelGray(const Image *image,const Quantum gray,
522   Quantum *pixel)
523 {
524   pixel[image->channel_map[GrayPixelChannel].channel]=gray;
525 }
526
527 static inline void SetPixelGrayTraits(Image *image,const PixelTrait traits)
528 {
529   image->channel_map[GrayPixelChannel].traits=traits;
530 }
531
532 static inline void SetPixelGreen(const Image *image,const Quantum green,
533   Quantum *pixel)
534 {
535   pixel[image->channel_map[GreenPixelChannel].channel]=green;
536 }
537
538 static inline void SetPixelGreenTraits(Image *image,const PixelTrait traits)
539 {
540   image->channel_map[GreenPixelChannel].traits=traits;
541 }
542
543 static inline void SetPixelIndex(const Image *image,const Quantum index,
544   Quantum *pixel)
545 {
546   pixel[image->channel_map[IndexPixelChannel].channel]=index;
547 }
548
549 static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
550 {
551   image->channel_map[IndexPixelChannel].traits=traits;
552 }
553
554 static inline void SetPixelInfo(const Image *image,const Quantum *pixel,
555   PixelInfo *pixel_info)
556 {
557   pixel_info->red=(MagickRealType) GetPixelRed(image,pixel);
558   pixel_info->green=(MagickRealType) GetPixelGreen(image,pixel);
559   pixel_info->blue=(MagickRealType) GetPixelBlue(image,pixel);
560   pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel);
561   if (image->colorspace == CMYKColorspace)
562     pixel_info->black=(MagickRealType) GetPixelBlack(image,pixel);
563   if (image->storage_class == PseudoClass)
564     pixel_info->index=(MagickRealType) GetPixelIndex(image,pixel);
565 }
566
567 static inline void SetPixelInfoBias(const Image *image,PixelInfo *pixel_info)
568 {
569   /*
570     Obsoleted by MorphologyApply().
571   */
572   pixel_info->red=image->bias;
573   pixel_info->green=image->bias;
574   pixel_info->blue=image->bias;
575   pixel_info->alpha=image->bias;
576   pixel_info->black=image->bias;
577 }
578
579 static inline void SetPixelInfoPacket(const Image *image,
580   const PixelPacket *pixel,PixelInfo *pixel_info)
581 {
582   pixel_info->red=(MagickRealType) pixel->red;
583   pixel_info->green=(MagickRealType) pixel->green;
584   pixel_info->blue=(MagickRealType) pixel->blue;
585   pixel_info->alpha=(MagickRealType) pixel->alpha;
586   if (image->colorspace == CMYKColorspace)
587     pixel_info->black=(MagickRealType) pixel->black;
588   if (image->storage_class == PseudoClass)
589     pixel_info->index=(MagickRealType) pixel->index;
590 }
591
592 static inline void SetPixelMagenta(const Image *image,const Quantum magenta,
593   Quantum *pixel)
594 {
595   pixel[image->channel_map[MagentaPixelChannel].channel]=magenta;
596 }
597
598 static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
599 {
600   image->channel_map[MagentaPixelChannel].traits=traits;
601 }
602
603 static inline void SetPixelMetaChannels(Image *image,
604   const size_t number_meta_channels)
605 {
606   image->number_meta_channels=number_meta_channels;
607 }
608
609 static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
610 {
611   image->metacontent_extent=extent;
612 }
613
614 static inline void SetPixelRed(const Image *image,const Quantum red,
615   Quantum *pixel)
616 {
617   pixel[image->channel_map[RedPixelChannel].channel]=red;
618 }
619
620 static inline void SetPixelRedTraits(Image *image,const PixelTrait traits)
621 {
622   image->channel_map[RedPixelChannel].traits=traits;
623 }
624
625 static inline void SetPixelPacket(const Image *image,const PixelPacket *packet,
626   Quantum *pixel)
627 {
628   SetPixelRed(image,packet->red,pixel);
629   SetPixelGreen(image,packet->green,pixel);
630   SetPixelBlue(image,packet->blue,pixel);
631   SetPixelAlpha(image,packet->alpha,pixel);
632 }
633
634 static inline void SetPixelPixelInfo(const Image *image,
635   const PixelInfo *pixel_info,Quantum *packet)
636 {
637   SetPixelRed(image,ClampToQuantum(pixel_info->red),packet);
638   SetPixelGreen(image,ClampToQuantum(pixel_info->green),packet);
639   SetPixelBlue(image,ClampToQuantum(pixel_info->blue),packet);
640   SetPixelAlpha(image,ClampToQuantum(pixel_info->alpha),packet);
641   if (image->colorspace == CMYKColorspace)
642     SetPixelBlack(image,ClampToQuantum(pixel_info->black),packet);
643 }
644
645 static inline void SetPixelYellow(const Image *image,const Quantum yellow,
646   Quantum *pixel)
647 {
648   pixel[image->channel_map[YellowPixelChannel].channel]=yellow;
649 }
650
651 static inline void SetPixelYellowTraits(Image *image,const PixelTrait traits)
652 {
653   image->channel_map[YellowPixelChannel].traits=traits;
654 }
655
656 static inline void SetPixelY(const Image *image,const Quantum y,Quantum *pixel)
657 {
658   pixel[image->channel_map[YPixelChannel].channel]=y;
659 }
660
661 static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
662 {
663   image->channel_map[YPixelChannel].traits=traits;
664 }
665
666 static inline Quantum GetPixelIntensity(const Image *image,const Quantum *pixel)
667 {
668 #if !defined(MAGICKCORE_HDRI_SUPPORT)
669   if ((GetPixelRed(image,pixel) == GetPixelGreen(image,pixel)) &&
670       (GetPixelGreen(image,pixel) == GetPixelBlue(image,pixel)))
671     return(GetPixelRed(image,pixel));
672   return((Quantum) (0.299*GetPixelRed(image,pixel)+0.587*
673     GetPixelGreen(image,pixel)+0.114*GetPixelBlue(image,pixel)+0.5));
674 #else
675   {
676     double
677       alpha,
678       beta;
679
680     alpha=GetPixelRed(image,pixel)-(double) GetPixelGreen(image,pixel);
681     beta=GetPixelGreen(image,pixel)-(double) GetPixelBlue(image,pixel);
682     if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
683       return(GetPixelRed(image,pixel));
684     return((Quantum) (0.299*GetPixelRed(image,pixel)+0.587*
685       GetPixelGreen(image,pixel)+0.114*GetPixelBlue(image,pixel)));
686   }
687 #endif
688 }
689
690 static inline Quantum GetPixelLuminance(const Image *image,const Quantum *pixel)
691 {
692 #if !defined(MAGICKCORE_HDRI_SUPPORT)
693   return((Quantum) (0.21267*GetPixelRed(image,pixel)+0.71516*
694     GetPixelGreen(image,pixel)+0.07217*GetPixelBlue(image,pixel)+0.5));
695 #else
696   return((Quantum) (0.21267*GetPixelRed(image,pixel)+0.71516*
697     GetPixelGreen(image,pixel)+0.07217*GetPixelBlue(image,pixel)));
698 #endif
699 }
700
701 #if defined(__cplusplus) || defined(c_plusplus)
702 }
703 #endif
704
705 #endif