]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Sun, 24 May 2015 22:27:57 +0000 (22:27 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Sun, 24 May 2015 22:27:57 +0000 (22:27 +0000)
MagickCore/gem-private.h
MagickCore/pixel-accessor.h
MagickCore/pixel-private.h

index c258760e4a6f7f7de7467823157ade98eee94b81..0296add2e3bb5ad4456b17bc0f12d7e05cc3dd8a 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef _MAGICKCORE_GEM_PRIVATE_H
 #define _MAGICKCORE_GEM_PRIVATE_H
 
-#include "MagickCore/pixel-private.h"
+#include "MagickCore/pixel-accessor.h"
 
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {
index 83716f0bbe55fe5ddbc68ede34de4b06ba6f4133..89195209617ed59e97ffe7e722377f24cf743581 100644 (file)
@@ -31,6 +31,20 @@ extern "C" {
 
 #undef index
 
+static inline double PerceptibleReciprocal(const double x)
+{
+  double
+    sign;
+
+  /*
+    Return 1/x where x is perceptible (not unlimited or infinitesimal).
+  */
+  sign=x < 0.0 ? -1.0 : 1.0;
+  if ((sign*x) >= MagickEpsilon)
+    return(1.0/x);
+  return(sign/MagickEpsilon);
+}
+
 static inline Quantum ClampPixel(const MagickRealType value)
 { 
   if (value < 0.0f)
@@ -211,16 +225,23 @@ static inline MagickRealType GetPixelInfoLuma(const PixelInfo *restrict pixel)
 {
   MagickRealType
     blue,
+    gamma,
     green,
     red;
 
+  gamma=1.0;
+  if (pixel->alpha_trait != UndefinedPixelTrait)
+    gamma=PerceptibleReciprocal(QuantumScale*pixel->alpha);
+  red=gamma*pixel->red;
+  green=gamma*pixel->green;
+  blue=gamma*pixel->blue;
   if (pixel->colorspace == GRAYColorspace)
-    return(pixel->red);
+    return(red);
   if (pixel->colorspace == sRGBColorspace)
-    return(0.212656f*pixel->red+0.715158f*pixel->green+0.072186f*pixel->blue);
-  red=EncodePixelGamma(pixel->red);
-  green=EncodePixelGamma(pixel->green);
-  blue=EncodePixelGamma(pixel->blue);
+    return(0.212656f*red+0.715158f*green+0.072186f*blue);
+  red=EncodePixelGamma(red);
+  green=EncodePixelGamma(green);
+  blue=EncodePixelGamma(blue);
   return(0.212656f*red+0.715158f*green+0.072186f*blue);
 }
 
@@ -229,16 +250,23 @@ static inline MagickRealType GetPixelInfoLuminance(
 {
   MagickRealType
     blue,
+    gamma,
     green,
     red;
 
+  gamma=1.0;
+  if (pixel->alpha_trait != UndefinedPixelTrait)
+    gamma=PerceptibleReciprocal(QuantumScale*pixel->alpha);
+  red=gamma*pixel->red;
+  green=gamma*pixel->green;
+  blue=gamma*pixel->blue;
   if (pixel->colorspace == GRAYColorspace)
-    return(pixel->red);
+    return(red);
   if (pixel->colorspace != sRGBColorspace)
-    return(0.212656f*pixel->red+0.715158f*pixel->green+0.072186f*pixel->blue);
-  red=DecodePixelGamma(pixel->red);
-  green=DecodePixelGamma(pixel->green);
-  blue=DecodePixelGamma(pixel->blue);
+    return(0.212656f*red+0.715158f*green+0.072186f*blue);
+  red=DecodePixelGamma(red);
+  green=DecodePixelGamma(green);
+  blue=DecodePixelGamma(blue);
   return(0.212656f*red+0.715158f*green+0.072186f*blue);
 }
 
@@ -251,11 +279,22 @@ static inline Quantum GetPixelL(const Image *restrict image,
 static inline MagickRealType GetPixelLuma(const Image *restrict image,
   const Quantum *restrict pixel)
 {
+  MagickRealType
+    blue,
+    gamma,
+    green,
+    red;
+
+  gamma=1.0;
+  if (image->alpha_trait != UndefinedPixelTrait)
+    gamma=PerceptibleReciprocal(QuantumScale*
+      pixel[image->channel_map[AlphaPixelChannel].offset]);
+  red=gamma*pixel[image->channel_map[RedPixelChannel].offset];
+  green=gamma*pixel[image->channel_map[GreenPixelChannel].offset];
+  blue=gamma*pixel[image->channel_map[BluePixelChannel].offset];
   if (image->colorspace == GRAYColorspace)
-    return((MagickRealType) pixel[image->channel_map[GrayPixelChannel].offset]);
-  return(0.212656f*pixel[image->channel_map[RedPixelChannel].offset]+
-    0.715158f*pixel[image->channel_map[GreenPixelChannel].offset]+
-    0.072186f*pixel[image->channel_map[BluePixelChannel].offset]);  /* Rec709 */
+    return(red);
+  return(0.212656f*red+0.715158f*green+0.072186f*blue);
 }
 
 static inline MagickRealType GetPixelLuminance(const Image *restrict image,
@@ -263,22 +302,25 @@ static inline MagickRealType GetPixelLuminance(const Image *restrict image,
 {
   MagickRealType
     blue,
+    gamma,
     green,
     red;
 
+  gamma=1.0;
+  if (image->alpha_trait != UndefinedPixelTrait)
+    gamma=PerceptibleReciprocal(QuantumScale*
+      pixel[image->channel_map[AlphaPixelChannel].offset]);
+  red=gamma*pixel[image->channel_map[RedPixelChannel].offset];
+  green=gamma*pixel[image->channel_map[GreenPixelChannel].offset];
+  blue=gamma*pixel[image->channel_map[BluePixelChannel].offset];
   if (image->colorspace == GRAYColorspace)
-    return((MagickRealType) pixel[image->channel_map[GrayPixelChannel].offset]);
+    return(red);
   if (image->colorspace != sRGBColorspace)
-    return(0.212656f*pixel[image->channel_map[RedPixelChannel].offset]+
-      0.715158f*pixel[image->channel_map[GreenPixelChannel].offset]+
-      0.072186f*pixel[image->channel_map[BluePixelChannel].offset]);
-  red=DecodePixelGamma((MagickRealType)
-    pixel[image->channel_map[RedPixelChannel].offset]);
-  green=DecodePixelGamma((MagickRealType)
-    pixel[image->channel_map[GreenPixelChannel].offset]);
-  blue=DecodePixelGamma((MagickRealType)
-    pixel[image->channel_map[BluePixelChannel].offset]);
-  return(0.212656f*red+0.715158f*green+0.072186f*blue);  /* Rec709 */
+    return(0.212656f*red+0.715158f*green+0.072186f*blue);
+  red=DecodePixelGamma(red);
+  green=DecodePixelGamma(green);
+  blue=DecodePixelGamma(blue);
+  return(0.212656f*red+0.715158f*green+0.072186f*blue);
 }
 
 static inline Quantum GetPixelMagenta(const Image *restrict image,
index 763e4be7e8bbf758a5cd186a6635f36fc87fde38..964bfea9ef62c37c80ac77687e41e7fdde0c34ff 100644 (file)
 extern "C" {
 #endif
 
-static inline double PerceptibleReciprocal(const double x)
-{
-  double
-    sign;
-
-  /*
-    Return 1/x where x is perceptible (not unlimited or infinitesimal).
-  */
-  sign=x < 0.0 ? -1.0 : 1.0;
-  if ((sign*x) >= MagickEpsilon)
-    return(1.0/x);
-  return(sign/MagickEpsilon);
-}
-
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif