]> 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=pixel[image->channel_map[RedPixelChannel].channel];
205   packet->green=pixel[image->channel_map[GreenPixelChannel].channel];
206   packet->blue=pixel[image->channel_map[BluePixelChannel].channel];
207   packet->alpha=pixel[image->channel_map[AlphaPixelChannel].channel];
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 ((p[image->channel_map[RedPixelChannel].channel] == q->red) &&
261       (p[image->channel_map[GreenPixelChannel].channel] == q->green) &&
262       (p[image->channel_map[BluePixelChannel].channel] == 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 ((pixel[image->channel_map[RedPixelChannel].channel] ==
272        pixel[image->channel_map[GreenPixelChannel].channel]) &&
273       (pixel[image->channel_map[GreenPixelChannel].channel] ==
274        pixel[image->channel_map[BluePixelChannel].channel]))
275     return(MagickTrue);
276 #else
277   {
278     double
279       alpha,
280       beta;
281
282     alpha=pixel[image->channel_map[RedPixelChannel].channel]-(double)
283       pixel[image->channel_map[GreenPixelChannel].channel];
284     beta=pixel[image->channel_map[GreenPixelChannel].channel]-(double)
285       pixel[image->channel_map[BluePixelChannel].channel];
286     if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
287       return(MagickTrue);
288   }
289 #endif
290   return(MagickFalse);
291 }
292
293 static inline MagickBooleanType IsPixelInfoEquivalent(const PixelInfo *p,
294   const PixelInfo *q)
295 {
296   if ((p->matte != MagickFalse) && (q->matte == MagickFalse) &&
297       (fabs(p->alpha-OpaqueAlpha) > 0.5))
298     return(MagickFalse);
299   if ((q->matte != MagickFalse) && (p->matte == MagickFalse) &&
300       (fabs(q->alpha-OpaqueAlpha)) > 0.5)
301     return(MagickFalse);
302   if ((p->matte != MagickFalse) && (q->matte != MagickFalse))
303     {
304       if (fabs(p->alpha-q->alpha) > 0.5)
305         return(MagickFalse);
306       if (fabs(p->alpha-TransparentAlpha) <= 0.5)
307         return(MagickTrue);
308     }
309   if (fabs(p->red-q->red) > 0.5)
310     return(MagickFalse);
311   if (fabs(p->green-q->green) > 0.5)
312     return(MagickFalse);
313   if (fabs(p->blue-q->blue) > 0.5)
314     return(MagickFalse);
315   if ((p->colorspace == CMYKColorspace) && (fabs(p->black-q->black) > 0.5))
316     return(MagickFalse);
317   return(MagickTrue);
318 }
319
320 static inline MagickBooleanType IsPixelMonochrome(const Image *image,
321   const Quantum *pixel)
322 {
323 #if !defined(MAGICKCORE_HDRI_SUPPORT)
324   if (((pixel[image->channel_map[RedPixelChannel].channel] == 0) ||
325       (pixel[image->channel_map[RedPixelChannel].channel] == (Quantum) QuantumRange)) &&
326       (pixel[image->channel_map[RedPixelChannel].channel] ==
327        pixel[image->channel_map[GreenPixelChannel].channel]) &&
328       (pixel[image->channel_map[GreenPixelChannel].channel] ==
329        pixel[image->channel_map[BluePixelChannel].channel]))
330     return(MagickTrue);
331 #else
332   {
333     double
334       alpha,
335       beta;
336
337     alpha=pixel[image->channel_map[RedPixelChannel].channel]-(double)
338       pixel[image->channel_map[GreenPixelChannel].channel];
339     beta=pixel[image->channel_map[GreenPixelChannel].channel]-(double)
340       pixel[image->channel_map[BluePixelChannel].channel];
341     if (((fabs(pixel[image->channel_map[RedPixelChannel].channel]) <= MagickEpsilon) ||
342          (fabs(pixel[image->channel_map[RedPixelChannel].channel]-QuantumRange) <= MagickEpsilon)) &&
343         (fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
344       return(MagickTrue);
345     }
346 #endif
347   return(MagickFalse);
348 }
349
350 static inline MagickBooleanType IsPixelPacketEquivalent(const PixelPacket *p,
351   const PixelPacket *q)
352 {
353   if ((p->red == q->red) && (p->green == q->green) && (p->blue == q->blue))
354     return(MagickTrue);
355   return(MagickFalse);
356 }
357
358 static inline MagickBooleanType IsPixelPacketGray(const PixelPacket *pixel)
359 {
360 #if !defined(MAGICKCORE_HDRI_SUPPORT)
361   if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
362     return(MagickTrue);
363 #else
364   {
365     double
366       alpha,
367       beta;
368
369     alpha=pixel->red-(double) pixel->green;
370     beta=pixel->green-(double) pixel->blue;
371     if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
372       return(MagickTrue);
373   }
374 #endif
375   return(MagickFalse);
376 }
377
378 static inline MagickBooleanType IsPixelPacketMonochrome(
379   const PixelPacket *pixel)
380 {
381 #if !defined(MAGICKCORE_HDRI_SUPPORT)
382   if (((pixel->red == 0) || (pixel->red == (Quantum) QuantumRange)) &&
383       (pixel->red == pixel->green) && (pixel->green == pixel->blue))
384     return(MagickTrue);
385 #else
386   {
387     double
388       alpha,
389       beta;
390
391     alpha=pixel->red-(double) pixel->green;
392     beta=pixel->green-(double) pixel->blue;
393     if (((fabs(pixel->red) <= MagickEpsilon) ||
394          (fabs(pixel->red-QuantumRange) <= MagickEpsilon)) &&
395         (fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
396       return(MagickTrue);
397     }
398 #endif
399   return(MagickFalse);
400 }
401
402 static inline void SetPacketPixelInfo(const Image *image,
403   const PixelInfo *pixel_info,PixelPacket *packet)
404 {
405   packet->red=ClampToQuantum(pixel_info->red);
406   packet->green=ClampToQuantum(pixel_info->green);
407   packet->blue=ClampToQuantum(pixel_info->blue);
408   packet->alpha=ClampToQuantum(pixel_info->alpha);
409   if (image->colorspace == CMYKColorspace)
410     packet->black=ClampToQuantum(pixel_info->black);
411   if (image->storage_class == PseudoClass)
412     packet->index=ClampToQuantum(pixel_info->index);
413 }
414
415 static inline void SetPixelAlpha(const Image *image,const Quantum alpha,
416   Quantum *pixel)
417 {
418   pixel[image->channel_map[AlphaPixelChannel].channel]=alpha;
419 }
420
421 static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
422 {
423   image->channel_map[AlphaPixelChannel].traits=traits;
424 }
425
426 static inline void SetPixelBlack(const Image *image,const Quantum black,
427   Quantum *pixel)
428 {
429   pixel[image->channel_map[BlackPixelChannel].channel]=black;
430 }
431
432 static inline void SetPixelBlackTraits(Image *image,const PixelTrait traits)
433 {
434   image->channel_map[BlackPixelChannel].traits=traits;
435 }
436
437 static inline void SetPixelBlue(const Image *image,const Quantum blue,
438   Quantum *pixel)
439 {
440   pixel[image->channel_map[BluePixelChannel].channel]=blue;
441 }
442
443 static inline void SetPixelBlueTraits(Image *image,const PixelTrait traits)
444 {
445   image->channel_map[BluePixelChannel].traits=traits;
446 }
447
448 static inline void SetPixelCb(const Image *image,const Quantum cb,
449   Quantum *pixel)
450 {
451   pixel[image->channel_map[CbPixelChannel].channel]=cb;
452 }
453
454 static inline void SetPixelCbTraits(Image *image,const PixelTrait traits)
455 {
456   image->channel_map[CbPixelChannel].traits=traits;
457 }
458
459 static inline void SetPixelChannel(const Image *image,
460   const PixelChannel channel,const Quantum quantum,Quantum *pixel)
461 {
462   pixel[image->channel_map[channel].channel]=quantum;
463 }
464
465 static inline void SetPixelChannelMapChannel(const Image *image,
466   const PixelChannel channel,const PixelChannel channels)
467 {
468   image->channel_map[channel].channel=channels;
469 }
470
471 static inline void SetPixelChannels(Image *image,const size_t number_channels)
472 {
473   image->number_channels=number_channels;
474 }
475
476 static inline void SetPixelChannelTraits(Image *image,
477   const PixelChannel channel,const PixelTrait traits)
478 {
479   image->channel_map[channel].traits=traits;
480 }
481
482 static inline void SetPixelChannelMapTraits(Image *image,
483   const PixelChannel channel,const PixelTrait traits)
484 {
485   image->channel_map[channel].traits=traits;
486 }
487
488 static inline void SetPixelCr(const Image *image,const Quantum cr,
489   Quantum *pixel)
490 {
491   pixel[image->channel_map[CrPixelChannel].channel]=cr;
492 }
493
494 static inline void SetPixelCrTraits(Image *image,const PixelTrait traits)
495 {
496   image->channel_map[CrPixelChannel].traits=traits;
497 }
498
499 static inline void SetPixelCyan(const Image *image,const Quantum cyan,
500   Quantum *pixel)
501 {
502   pixel[image->channel_map[CyanPixelChannel].channel]=cyan;
503 }
504
505 static inline void SetPixelGray(const Image *image,const Quantum gray,
506   Quantum *pixel)
507 {
508   pixel[image->channel_map[GrayPixelChannel].channel]=gray;
509 }
510
511 static inline void SetPixelGrayTraits(Image *image,const PixelTrait traits)
512 {
513   image->channel_map[GrayPixelChannel].traits=traits;
514 }
515
516 static inline void SetPixelGreen(const Image *image,const Quantum green,
517   Quantum *pixel)
518 {
519   pixel[image->channel_map[GreenPixelChannel].channel]=green;
520 }
521
522 static inline void SetPixelGreenTraits(Image *image,const PixelTrait traits)
523 {
524   image->channel_map[GreenPixelChannel].traits=traits;
525 }
526
527 static inline void SetPixelIndex(const Image *image,const Quantum index,
528   Quantum *pixel)
529 {
530   pixel[image->channel_map[IndexPixelChannel].channel]=index;
531 }
532
533 static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
534 {
535   image->channel_map[IndexPixelChannel].traits=traits;
536 }
537
538 static inline void SetPixelInfo(const Image *image,const Quantum *pixel,
539   PixelInfo *pixel_info)
540 {
541   pixel_info->red=(MagickRealType)
542     pixel[image->channel_map[RedPixelChannel].channel];
543   pixel_info->green=(MagickRealType)
544     pixel[image->channel_map[GreenPixelChannel].channel];
545   pixel_info->blue=(MagickRealType)
546     pixel[image->channel_map[BluePixelChannel].channel];
547   if (image->colorspace == CMYKColorspace)
548     pixel_info->black=(MagickRealType)
549       pixel[image->channel_map[BlackPixelChannel].channel];
550   pixel_info->alpha=(MagickRealType)
551     pixel[image->channel_map[AlphaPixelChannel].channel];
552   if (image->storage_class == PseudoClass)
553     pixel_info->index=(MagickRealType)
554       pixel[image->channel_map[IndexPixelChannel].channel];
555 }
556
557 static inline void SetPixelInfoBias(const Image *image,PixelInfo *pixel_info)
558 {
559   /*
560     Obsoleted by MorphologyApply().
561   */
562   pixel_info->red=image->bias;
563   pixel_info->green=image->bias;
564   pixel_info->blue=image->bias;
565   pixel_info->alpha=image->bias;
566   pixel_info->black=image->bias;
567 }
568
569 static inline void SetPixelInfoPacket(const Image *image,
570   const PixelPacket *pixel,PixelInfo *pixel_info)
571 {
572   pixel_info->red=(MagickRealType) pixel->red;
573   pixel_info->green=(MagickRealType) pixel->green;
574   pixel_info->blue=(MagickRealType) pixel->blue;
575   pixel_info->alpha=(MagickRealType) pixel->alpha;
576   if (image->colorspace == CMYKColorspace)
577     pixel_info->black=(MagickRealType) pixel->black;
578   if (image->storage_class == PseudoClass)
579     pixel_info->index=(MagickRealType) pixel->index;
580 }
581
582 static inline void SetPixelMagenta(const Image *image,const Quantum magenta,
583   Quantum *pixel)
584 {
585   pixel[image->channel_map[MagentaPixelChannel].channel]=magenta;
586 }
587
588 static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
589 {
590   image->channel_map[MagentaPixelChannel].traits=traits;
591 }
592
593 static inline void SetPixelMetaChannels(Image *image,
594   const size_t number_meta_channels)
595 {
596   image->number_meta_channels=number_meta_channels;
597 }
598
599 static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
600 {
601   image->metacontent_extent=extent;
602 }
603
604 static inline void SetPixelRed(const Image *image,const Quantum red,
605   Quantum *pixel)
606 {
607   pixel[image->channel_map[RedPixelChannel].channel]=red;
608 }
609
610 static inline void SetPixelRedTraits(Image *image,const PixelTrait traits)
611 {
612   image->channel_map[RedPixelChannel].traits=traits;
613 }
614
615 static inline void SetPixelPacket(const Image *image,const PixelPacket *packet,
616   Quantum *pixel)
617 {
618   pixel[image->channel_map[RedPixelChannel].channel]=packet->red;
619   pixel[image->channel_map[GreenPixelChannel].channel]=packet->green;
620   pixel[image->channel_map[BluePixelChannel].channel]=packet->blue;
621   pixel[image->channel_map[AlphaPixelChannel].channel]=packet->alpha;
622 }
623
624 static inline void SetPixelPixelInfo(const Image *image,
625   const PixelInfo *pixel_info,Quantum *pixel)
626 {
627   pixel[image->channel_map[RedPixelChannel].channel]=
628     ClampToQuantum(pixel_info->red);
629   pixel[image->channel_map[GreenPixelChannel].channel]=
630     ClampToQuantum(pixel_info->green);
631   pixel[image->channel_map[BluePixelChannel].channel]=
632     ClampToQuantum(pixel_info->blue);
633   pixel[image->channel_map[AlphaPixelChannel].channel]=
634     ClampToQuantum(pixel_info->alpha);
635   if (image->colorspace == CMYKColorspace)
636     pixel[image->channel_map[BlackPixelChannel].channel]=
637       ClampToQuantum(pixel_info->black);
638 }
639
640 static inline void SetPixelYellow(const Image *image,const Quantum yellow,
641   Quantum *pixel)
642 {
643   pixel[image->channel_map[YellowPixelChannel].channel]=yellow;
644 }
645
646 static inline void SetPixelYellowTraits(Image *image,const PixelTrait traits)
647 {
648   image->channel_map[YellowPixelChannel].traits=traits;
649 }
650
651 static inline void SetPixelY(const Image *image,const Quantum y,Quantum *pixel)
652 {
653   pixel[image->channel_map[YPixelChannel].channel]=y;
654 }
655
656 static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
657 {
658   image->channel_map[YPixelChannel].traits=traits;
659 }
660
661 static inline Quantum GetPixelIntensity(const Image *image,const Quantum *pixel)
662 {
663 #if !defined(MAGICKCORE_HDRI_SUPPORT)
664   if ((pixel[image->channel_map[RedPixelChannel].channel] ==
665        pixel[image->channel_map[GreenPixelChannel].channel]) &&
666       (pixel[image->channel_map[GreenPixelChannel].channel] ==
667        pixel[image->channel_map[BluePixelChannel].channel]))
668     return(pixel[image->channel_map[RedPixelChannel].channel]);
669   return((Quantum) (0.299*pixel[image->channel_map[RedPixelChannel].channel]+
670     0.587*pixel[image->channel_map[GreenPixelChannel].channel]+0.114*
671     pixel[image->channel_map[BluePixelChannel].channel]+0.5));
672 #else
673   {
674     double
675       alpha,
676       beta;
677
678     alpha=pixel[image->channel_map[RedPixelChannel].channel]-(double)
679       pixel[image->channel_map[GreenPixelChannel].channel];
680     beta=pixel[image->channel_map[GreenPixelChannel].channel]-(double)
681       pixel[image->channel_map[BluePixelChannel].channel];
682     if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
683       return(pixel[image->channel_map[RedPixelChannel].channel]);
684     return((Quantum) (0.299*pixel[image->channel_map[RedPixelChannel].channel]+
685       0.587*pixel[image->channel_map[GreenPixelChannel].channel]+0.114*
686       pixel[image->channel_map[BluePixelChannel].channel]));
687   }
688 #endif
689 }
690
691 static inline Quantum GetPixelLuminance(const Image *image,const Quantum *pixel)
692 {
693 #if !defined(MAGICKCORE_HDRI_SUPPORT)
694   return((Quantum) (0.21267*pixel[image->channel_map[RedPixelChannel].channel]+
695     0.71516*pixel[image->channel_map[GreenPixelChannel].channel]+0.07217*
696     pixel[image->channel_map[BluePixelChannel].channel]+0.5));
697 #else
698   return((Quantum) (0.21267*pixel[image->channel_map[RedPixelChannel].channel]+
699     0.71516*pixel[image->channel_map[GreenPixelChannel].channel]+0.07217*
700     pixel[image->channel_map[BluePixelChannel].channel]));
701 #endif
702 }
703
704 #if defined(__cplusplus) || defined(c_plusplus)
705 }
706 #endif
707
708 #endif