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