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