]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/pixel-accessor.h
(no commit message)
[imagemagick] / MagickCore / pixel-accessor.h
index ff007ba7549c5787187247e3ad851ef17c7a3198..a53128ca23347eef2ae0c5d7ff29a7a047f55fd7 100644 (file)
@@ -31,18 +31,24 @@ extern "C" {
 
 #undef index
 
-static inline double CompandsRGB(const double intensity)
+static inline double InversesRGBCompandor(const double pixel)
 {
-  if (intensity <= 0.0031308)
-    return(intensity*12.92);
-  return(1.055*pow(intensity,1.0/2.4)-0.055);
+  if (pixel <= (0.04045*QuantumRange))
+    return(pixel/12.92);
+  return(QuantumRange*pow((QuantumScale*pixel+0.055)/1.055,2.4));
 }
 
-static inline double DecompandsRGB(const double intensity)
+static inline double sRGBCompandor(const double pixel)
 {
-  if (intensity <= 0.04045)
-    return(intensity/12.92);
-  return(pow((intensity+0.055)/1.055,2.4));
+  if (pixel <= (0.0031308*QuantumRange))
+    return(12.92*pixel);
+  return(QuantumRange*(1.055*pow(QuantumScale*pixel,1.0/2.4)-0.055));
+}
+
+static inline Quantum GetPixela(const Image *restrict image,
+  const Quantum *restrict pixel)
+{
+  return(pixel[image->channel_map[aPixelChannel].offset]);
 }
 
 static inline Quantum GetPixelAlpha(const Image *restrict image,
@@ -58,11 +64,17 @@ static inline PixelTrait GetPixelAlphaTraits(const Image *restrict image)
   return(image->channel_map[AlphaPixelChannel].traits);
 }
 
+static inline Quantum GetPixelb(const Image *restrict image,
+  const Quantum *restrict pixel)
+{
+  return(pixel[image->channel_map[bPixelChannel].offset]);
+}
+
 static inline Quantum GetPixelBlack(const Image *restrict image,
   const Quantum *restrict pixel)
 {
   if (image->channel_map[BlackPixelChannel].traits == UndefinedPixelTrait)
-    return(0);
+    return((Quantum) 0);
   return(pixel[image->channel_map[BlackPixelChannel].offset]);
 }
 
@@ -97,7 +109,7 @@ static inline Quantum GetPixelChannel(const Image *restrict image,
   const PixelChannel channel,const Quantum *restrict pixel)
 {
   if (image->channel_map[channel].traits == UndefinedPixelTrait)
-    return(0);
+    return((Quantum) 0);
   return(pixel[image->channel_map[channel].offset]);
 }
 
@@ -172,7 +184,7 @@ static inline Quantum GetPixelIndex(const Image *restrict image,
   const Quantum *restrict pixel)
 {
   if (image->channel_map[IndexPixelChannel].traits == UndefinedPixelTrait)
-    return(0);
+    return((Quantum) 0);
   return(pixel[image->channel_map[IndexPixelChannel].offset]);
 }
 
@@ -181,8 +193,22 @@ static inline PixelTrait GetPixelIndexTraits(const Image *restrict image)
   return(image->channel_map[IndexPixelChannel].traits);
 }
 
-static inline Quantum GetPixelInfoIntensity(
-  const PixelInfo *restrict pixel_info)
+static inline double GetPixelInfoChannel(const PixelInfo *restrict pixel_info,
+  const PixelChannel channel)
+{
+  switch (channel)
+  {
+    case RedPixelChannel: return(pixel_info->red);
+    case GreenPixelChannel: return(pixel_info->green);
+    case BluePixelChannel: return(pixel_info->blue);
+    case BlackPixelChannel: return(pixel_info->black);
+    case AlphaPixelChannel: return(pixel_info->alpha);
+    case IndexPixelChannel: return(pixel_info->index);
+    default: return(0.0);
+  }
+}
+
+static inline double GetPixelInfoIntensity(const PixelInfo *restrict pixel_info)
 {
   double
     blue,
@@ -190,18 +216,17 @@ static inline Quantum GetPixelInfoIntensity(
     red;
 
   if (pixel_info->colorspace == GRAYColorspace)
-    return(ClampToQuantum(pixel_info->red));
+    return(pixel_info->red);
   if (pixel_info->colorspace != sRGBColorspace)
-    return(ClampToQuantum(0.298839*pixel_info->red+0.586811*pixel_info->green+
-      0.114350*pixel_info->blue));
-  red=QuantumRange*DecompandsRGB(QuantumScale*pixel_info->red);
-  green=QuantumRange*DecompandsRGB(QuantumScale*pixel_info->green);
-  blue=QuantumRange*DecompandsRGB(QuantumScale*pixel_info->blue);
-  return(ClampToQuantum(0.298839*red+0.586811*green+0.114350*blue));
+    return(0.298839*pixel_info->red+0.586811*pixel_info->green+
+      0.114350*pixel_info->blue);
+  red=InversesRGBCompandor(pixel_info->red);
+  green=InversesRGBCompandor(pixel_info->green);
+  blue=InversesRGBCompandor(pixel_info->blue);
+  return(0.298839*red+0.586811*green+0.114350*blue);
 }
 
-static inline Quantum GetPixelInfoLuminance(
-  const PixelInfo *restrict pixel_info)
+static inline double GetPixelInfoLuminance(const PixelInfo *restrict pixel_info)
 {
   double
     blue,
@@ -209,17 +234,17 @@ static inline Quantum GetPixelInfoLuminance(
     red;
 
   if (pixel_info->colorspace == GRAYColorspace)
-    return((Quantum) pixel_info->red);
+    return(pixel_info->red);
   if (pixel_info->colorspace != sRGBColorspace)
-    return(ClampToQuantum(0.21267*pixel_info->red+0.71516*pixel_info->green+
-      0.07217*pixel_info->blue));
-  red=QuantumRange*DecompandsRGB(QuantumScale*pixel_info->red);
-  green=QuantumRange*DecompandsRGB(QuantumScale*pixel_info->green);
-  blue=QuantumRange*DecompandsRGB(QuantumScale*pixel_info->blue);
-  return(ClampToQuantum(0.21267*red+0.71516*green+0.07217*blue));
+    return(0.21267*pixel_info->red+0.71516*pixel_info->green+
+      0.07217*pixel_info->blue);
+  red=InversesRGBCompandor(pixel_info->red);
+  green=InversesRGBCompandor(pixel_info->green);
+  blue=InversesRGBCompandor(pixel_info->blue);
+  return(0.21267*red+0.71516*green+0.07217*blue);
 }
 
-static inline Quantum GetPixelIntensity(const Image *restrict image,
+static inline double GetPixelIntensity(const Image *restrict image,
   const Quantum *restrict pixel)
 {
   double
@@ -228,22 +253,27 @@ static inline Quantum GetPixelIntensity(const Image *restrict image,
     red;
 
   if (image->colorspace == GRAYColorspace)
-    return(pixel[image->channel_map[GrayPixelChannel].offset]);
+    return((double) pixel[image->channel_map[GrayPixelChannel].offset]);
   if (image->colorspace != sRGBColorspace)
-    return(ClampToQuantum(
-      0.298839*pixel[image->channel_map[RedPixelChannel].offset]+
+    return(0.298839*pixel[image->channel_map[RedPixelChannel].offset]+
       0.586811*pixel[image->channel_map[GreenPixelChannel].offset]+
-      0.114350*pixel[image->channel_map[BluePixelChannel].offset]));
-  red=QuantumRange*DecompandsRGB(QuantumScale*
+      0.114350*pixel[image->channel_map[BluePixelChannel].offset]);
+  red=InversesRGBCompandor((double)
     pixel[image->channel_map[RedPixelChannel].offset]);
-  green=QuantumRange*DecompandsRGB(QuantumScale*
+  green=InversesRGBCompandor((double)
     pixel[image->channel_map[GreenPixelChannel].offset]);
-  blue=QuantumRange*DecompandsRGB(QuantumScale*
+  blue=InversesRGBCompandor((double)
     pixel[image->channel_map[BluePixelChannel].offset]);
-  return(ClampToQuantum(0.298839*red+0.586811*green+0.114350*blue));
+  return(0.298839*red+0.586811*green+0.114350*blue);
 }
 
-static inline Quantum GetPixelLuminance(const Image *restrict image,
+static inline Quantum GetPixelL(const Image *restrict image,
+  const Quantum *restrict pixel)
+{
+  return(pixel[image->channel_map[LPixelChannel].offset]);
+}
+
+static inline double GetPixelLuminance(const Image *restrict image,
   const Quantum *restrict pixel)
 {
   double
@@ -252,19 +282,18 @@ static inline Quantum GetPixelLuminance(const Image *restrict image,
     red;
 
   if (image->colorspace == GRAYColorspace)
-    return(pixel[image->channel_map[GrayPixelChannel].offset]);
+    return((double) pixel[image->channel_map[GrayPixelChannel].offset]);
   if (image->colorspace != sRGBColorspace)
-    return(ClampToQuantum(
-      0.298839*pixel[image->channel_map[RedPixelChannel].offset]+
+    return(0.298839*pixel[image->channel_map[RedPixelChannel].offset]+
       0.586811*pixel[image->channel_map[GreenPixelChannel].offset]+
-      0.114350*pixel[image->channel_map[BluePixelChannel].offset]));
-  red=QuantumRange*DecompandsRGB(QuantumScale*
+      0.114350*pixel[image->channel_map[BluePixelChannel].offset]);
+  red=InversesRGBCompandor((double)
     pixel[image->channel_map[RedPixelChannel].offset]);
-  green=QuantumRange*DecompandsRGB(QuantumScale*
+  green=InversesRGBCompandor((double)
     pixel[image->channel_map[GreenPixelChannel].offset]);
-  blue=QuantumRange*DecompandsRGB(QuantumScale*
+  blue=InversesRGBCompandor((double)
     pixel[image->channel_map[BluePixelChannel].offset]);
-  return(ClampToQuantum(0.21267*red+0.71516*green+0.07217*blue));
+  return(0.21267*red+0.71516*green+0.07217*blue);
 }
 
 static inline Quantum GetPixelMagenta(const Image *restrict image,
@@ -282,7 +311,7 @@ static inline Quantum GetPixelMask(const Image *restrict image,
   const Quantum *restrict pixel)
 {
   if (image->channel_map[MaskPixelChannel].traits == UndefinedPixelTrait)
-    return(0);
+    return((Quantum) 0);
   return(pixel[image->channel_map[MaskPixelChannel].offset]);
 }
 
@@ -329,7 +358,7 @@ static inline void GetPixelInfoPixel(const Image *restrict image,
     pixel[image->channel_map[GreenPixelChannel].offset];
   pixel_info->blue=(double)
     pixel[image->channel_map[BluePixelChannel].offset];
-  pixel_info->black=0;
+  pixel_info->black=0.0;
   if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
     pixel_info->black=(double)
       pixel[image->channel_map[BlackPixelChannel].offset];
@@ -337,7 +366,7 @@ static inline void GetPixelInfoPixel(const Image *restrict image,
   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
     pixel_info->alpha=(double)
       pixel[image->channel_map[AlphaPixelChannel].offset];
-  pixel_info->index=0;
+  pixel_info->index=0.0;
   if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
     pixel_info->index=(double)
       pixel[image->channel_map[IndexPixelChannel].offset];
@@ -478,6 +507,13 @@ static inline MagickBooleanType IsPixelInfoMonochrome(
   return(MagickFalse);
 }
 
+static inline void SetPixela(const Image *restrict image,
+  const Quantum a,Quantum *restrict pixel)
+{
+  if (image->channel_map[aPixelChannel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[aPixelChannel].offset]=a;
+}
+
 static inline void SetPixelAlpha(const Image *restrict image,
   const Quantum alpha,Quantum *restrict pixel)
 {
@@ -490,6 +526,13 @@ static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
   image->channel_map[AlphaPixelChannel].traits=traits;
 }
 
+static inline void SetPixelb(const Image *restrict image,
+  const Quantum b,Quantum *restrict pixel)
+{
+  if (image->channel_map[bPixelChannel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[bPixelChannel].offset]=b;
+}
+
 static inline void SetPixelBlack(const Image *restrict image,
   const Quantum black,Quantum *restrict pixel)
 {
@@ -631,6 +674,13 @@ static inline void SetPixelInfoPixel(const Image *restrict image,
       MagickFalse ? OpaqueAlpha : ClampToQuantum(pixel_info->alpha);
 }
 
+static inline void SetPixelL(const Image *restrict image,
+  const Quantum L,Quantum *restrict pixel)
+{
+  if (image->channel_map[LPixelChannel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[LPixelChannel].offset]=L;
+}
+
 static inline void SetPixelMagenta(const Image *restrict image,
   const Quantum magenta,Quantum *restrict pixel)
 {