]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/pixel-accessor.h
(no commit message)
[imagemagick] / MagickCore / pixel-accessor.h
index 6040c13b21db1eb55a494d19c55479afe77bdb97..a53128ca23347eef2ae0c5d7ff29a7a047f55fd7 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization
+  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization
   dedicated to making software imaging solutions freely available.
 
   You may not use this file except in compliance with the License.
@@ -23,12 +23,34 @@ extern "C" {
 #endif
 
 #include <math.h>
+#include <MagickCore/cache.h>
 #include <MagickCore/cache-view.h>
 #include <MagickCore/color.h>
+#include <MagickCore/colorspace.h>
 #include <MagickCore/image.h>
 
 #undef index
 
+static inline double InversesRGBCompandor(const double pixel)
+{
+  if (pixel <= (0.04045*QuantumRange))
+    return(pixel/12.92);
+  return(QuantumRange*pow((QuantumScale*pixel+0.055)/1.055,2.4));
+}
+
+static inline double sRGBCompandor(const double pixel)
+{
+  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,
   const Quantum *restrict pixel)
 {
@@ -42,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]);
 }
 
@@ -81,17 +109,17 @@ 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]);
 }
 
 static inline PixelChannel GetPixelChannelMapChannel(
-  const Image *restrict image,const int offset)
+  const Image *restrict image,const ssize_t offset)
 {
   return(image->channel_map[offset].channel);
 }
 
-static inline int GetPixelChannelMapOffset(const Image *restrict image,
+static inline ssize_t GetPixelChannelMapOffset(const Image *restrict image,
   const PixelChannel channel)
 {
   return(image->channel_map[channel].offset);
@@ -156,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]);
 }
 
@@ -165,32 +193,107 @@ 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)
 {
-#if !defined(MAGICKCORE_HDRI_SUPPORT)
-  return((Quantum) (0.299*pixel_info->red+0.587*pixel_info->green+0.114*
-    pixel_info->blue+0.5));
-#else
-  return((Quantum) (0.299*pixel_info->red+0.587*pixel_info->green+0.114*
-    pixel_info->blue));
-#endif
+  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 Quantum GetPixelInfoLuminance(
-  const PixelInfo *restrict pixel_info)
+static inline double GetPixelInfoIntensity(const PixelInfo *restrict pixel_info)
 {
-  Quantum
-    luminance;
+  double
+    blue,
+    green,
+    red;
 
-#if !defined(MAGICKCORE_HDRI_SUPPORT)
-  luminance=(Quantum) (0.21267*pixel_info->red+0.71516*pixel_info->green+
-    0.07217*pixel_info->blue+0.5);
-#else
-  luminance=(Quantum) (0.21267*pixel_info->red+0.71516*pixel_info->green+
-    0.07217*pixel_info->blue);
-#endif
-  return((Quantum) luminance);
+  if (pixel_info->colorspace == GRAYColorspace)
+    return(pixel_info->red);
+  if (pixel_info->colorspace != sRGBColorspace)
+    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 double GetPixelInfoLuminance(const PixelInfo *restrict pixel_info)
+{
+  double
+    blue,
+    green,
+    red;
+
+  if (pixel_info->colorspace == GRAYColorspace)
+    return(pixel_info->red);
+  if (pixel_info->colorspace != sRGBColorspace)
+    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 double GetPixelIntensity(const Image *restrict image,
+  const Quantum *restrict pixel)
+{
+  double
+    blue,
+    green,
+    red;
+
+  if (image->colorspace == GRAYColorspace)
+    return((double) pixel[image->channel_map[GrayPixelChannel].offset]);
+  if (image->colorspace != sRGBColorspace)
+    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=InversesRGBCompandor((double)
+    pixel[image->channel_map[RedPixelChannel].offset]);
+  green=InversesRGBCompandor((double)
+    pixel[image->channel_map[GreenPixelChannel].offset]);
+  blue=InversesRGBCompandor((double)
+    pixel[image->channel_map[BluePixelChannel].offset]);
+  return(0.298839*red+0.586811*green+0.114350*blue);
+}
+
+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
+    blue,
+    green,
+    red;
+
+  if (image->colorspace == GRAYColorspace)
+    return((double) pixel[image->channel_map[GrayPixelChannel].offset]);
+  if (image->colorspace != sRGBColorspace)
+    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=InversesRGBCompandor((double)
+    pixel[image->channel_map[RedPixelChannel].offset]);
+  green=InversesRGBCompandor((double)
+    pixel[image->channel_map[GreenPixelChannel].offset]);
+  blue=InversesRGBCompandor((double)
+    pixel[image->channel_map[BluePixelChannel].offset]);
+  return(0.21267*red+0.71516*green+0.07217*blue);
 }
 
 static inline Quantum GetPixelMagenta(const Image *restrict image,
@@ -204,6 +307,19 @@ static inline PixelTrait GetPixelMagentaTraits(const Image *restrict image)
   return(image->channel_map[MagentaPixelChannel].traits);
 }
 
+static inline Quantum GetPixelMask(const Image *restrict image,
+  const Quantum *restrict pixel)
+{
+  if (image->channel_map[MaskPixelChannel].traits == UndefinedPixelTrait)
+    return((Quantum) 0);
+  return(pixel[image->channel_map[MaskPixelChannel].offset]);
+}
+
+static inline PixelTrait GetPixelMaskTraits(const Image *restrict image)
+{
+  return(image->channel_map[MaskPixelChannel].traits);
+}
+
 static inline size_t GetPixelMetaChannels(const Image *restrict image)
 {
   return(image->number_meta_channels);
@@ -214,6 +330,14 @@ static inline size_t GetPixelMetacontentExtent(const Image *restrict image)
   return(image->metacontent_extent);
 }
 
+static inline Quantum GetPixelOpacity(const Image *restrict image,
+  const Quantum *restrict pixel)
+{
+  if (image->channel_map[AlphaPixelChannel].traits == UndefinedPixelTrait)
+    return(QuantumRange-OpaqueAlpha);
+  return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
+}
+
 static inline Quantum GetPixelRed(const Image *restrict image,
   const Quantum *restrict pixel)
 {
@@ -228,23 +352,23 @@ static inline PixelTrait GetPixelRedTraits(const Image *restrict image)
 static inline void GetPixelInfoPixel(const Image *restrict image,
   const Quantum *restrict pixel,PixelInfo *restrict pixel_info)
 {
-  pixel_info->red=(MagickRealType)
+  pixel_info->red=(double)
     pixel[image->channel_map[RedPixelChannel].offset];
-  pixel_info->green=(MagickRealType)
+  pixel_info->green=(double)
     pixel[image->channel_map[GreenPixelChannel].offset];
-  pixel_info->blue=(MagickRealType)
+  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=(MagickRealType)
+    pixel_info->black=(double)
       pixel[image->channel_map[BlackPixelChannel].offset];
   pixel_info->alpha=OpaqueAlpha;
   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
-    pixel_info->alpha=(MagickRealType)
+    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=(MagickRealType)
+    pixel_info->index=(double)
       pixel[image->channel_map[IndexPixelChannel].offset];
 }
 
@@ -279,9 +403,17 @@ static inline PixelTrait GetPixelYellowTraits(const Image *restrict image)
 static inline MagickBooleanType IsPixelEquivalent(const Image *restrict image,
   const Quantum *restrict p,const PixelInfo *restrict q)
 {
-  if (((double) p[image->channel_map[RedPixelChannel].offset] == q->red) &&
-      ((double) p[image->channel_map[GreenPixelChannel].offset] == q->green) &&
-      ((double) p[image->channel_map[BluePixelChannel].offset] == q->blue))
+  double
+    blue,
+    green,
+    red;
+
+  red=(double) p[image->channel_map[RedPixelChannel].offset];
+  green=(double) p[image->channel_map[GreenPixelChannel].offset];
+  blue=(double) p[image->channel_map[BluePixelChannel].offset];
+  if ((fabs(red-q->red) < MagickEpsilon) &&
+      (fabs(green-q->green) < MagickEpsilon) &&
+      (fabs(blue-q->blue) < MagickEpsilon))
     return(MagickTrue);
   return(MagickFalse);
 }
@@ -289,26 +421,16 @@ static inline MagickBooleanType IsPixelEquivalent(const Image *restrict image,
 static inline MagickBooleanType IsPixelGray(const Image *restrict image,
   const Quantum *restrict pixel)
 {
-#if !defined(MAGICKCORE_HDRI_SUPPORT)
-  if ((pixel[image->channel_map[RedPixelChannel].offset] ==
-       pixel[image->channel_map[GreenPixelChannel].offset]) &&
-      (pixel[image->channel_map[GreenPixelChannel].offset] ==
-       pixel[image->channel_map[BluePixelChannel].offset]))
+  double
+    blue,
+    green,
+    red;
+
+  red=(double) pixel[image->channel_map[RedPixelChannel].offset];
+  green=(double) pixel[image->channel_map[GreenPixelChannel].offset];
+  blue=(double) pixel[image->channel_map[BluePixelChannel].offset];
+  if ((fabs(red-green) < MagickEpsilon) && (fabs(green-blue) < MagickEpsilon))
     return(MagickTrue);
-#else
-  {
-    double
-      alpha,
-      beta;
-
-    alpha=pixel[image->channel_map[RedPixelChannel].offset]-(double)
-      pixel[image->channel_map[GreenPixelChannel].offset];
-    beta=pixel[image->channel_map[GreenPixelChannel].offset]-(double)
-      pixel[image->channel_map[BluePixelChannel].offset];
-    if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
-      return(MagickTrue);
-  }
-#endif
   return(MagickFalse);
 }
 
@@ -316,25 +438,26 @@ static inline MagickBooleanType IsPixelInfoEquivalent(
   const PixelInfo *restrict p,const PixelInfo *restrict q)
 {
   if ((p->matte != MagickFalse) && (q->matte == MagickFalse) &&
-      (fabs(p->alpha-OpaqueAlpha) > 0.5))
+      (fabs(p->alpha-OpaqueAlpha) >= MagickEpsilon))
     return(MagickFalse);
   if ((q->matte != MagickFalse) && (p->matte == MagickFalse) &&
-      (fabs(q->alpha-OpaqueAlpha)) > 0.5)
+      (fabs(q->alpha-OpaqueAlpha)) >= MagickEpsilon)
     return(MagickFalse);
   if ((p->matte != MagickFalse) && (q->matte != MagickFalse))
     {
-      if (fabs(p->alpha-q->alpha) > 0.5)
+      if (fabs(p->alpha-q->alpha) >= MagickEpsilon)
         return(MagickFalse);
-      if (fabs(p->alpha-TransparentAlpha) <= 0.5)
+      if (fabs(p->alpha-TransparentAlpha) < MagickEpsilon)
         return(MagickTrue);
     }
-  if (fabs(p->red-q->red) > 0.5)
+  if (fabs(p->red-q->red) >= MagickEpsilon)
     return(MagickFalse);
-  if (fabs(p->green-q->green) > 0.5)
+  if (fabs(p->green-q->green) >= MagickEpsilon)
     return(MagickFalse);
-  if (fabs(p->blue-q->blue) > 0.5)
+  if (fabs(p->blue-q->blue) >= MagickEpsilon)
     return(MagickFalse);
-  if ((p->colorspace == CMYKColorspace) && (fabs(p->black-q->black) > 0.5))
+  if ((p->colorspace == CMYKColorspace) &&
+      (fabs(p->black-q->black) >= MagickEpsilon))
     return(MagickFalse);
   return(MagickTrue);
 }
@@ -342,80 +465,55 @@ static inline MagickBooleanType IsPixelInfoEquivalent(
 static inline MagickBooleanType IsPixelMonochrome(const Image *restrict image,
   const Quantum *restrict pixel)
 {
-#if !defined(MAGICKCORE_HDRI_SUPPORT)
-  if (((pixel[image->channel_map[RedPixelChannel].offset] == 0) ||
-      (pixel[image->channel_map[RedPixelChannel].offset] == (Quantum) QuantumRange)) &&
-      (pixel[image->channel_map[RedPixelChannel].offset] ==
-       pixel[image->channel_map[GreenPixelChannel].offset]) &&
-      (pixel[image->channel_map[GreenPixelChannel].offset] ==
-       pixel[image->channel_map[BluePixelChannel].offset]))
+  double
+    blue,
+    green,
+    red;
+
+  red=(double) pixel[image->channel_map[RedPixelChannel].offset];
+  if ((fabs(red) >= MagickEpsilon) || (fabs(red-QuantumRange) >= MagickEpsilon))
+    return(MagickFalse);
+  green=(double) pixel[image->channel_map[GreenPixelChannel].offset];
+  blue=(double) pixel[image->channel_map[BluePixelChannel].offset];
+  if ((fabs(red-green) < MagickEpsilon) && (fabs(green-blue) < MagickEpsilon))
     return(MagickTrue);
-#else
-  {
-    double
-      alpha,
-      beta;
-
-    alpha=pixel[image->channel_map[RedPixelChannel].offset]-(double)
-      pixel[image->channel_map[GreenPixelChannel].offset];
-    beta=pixel[image->channel_map[GreenPixelChannel].offset]-(double)
-      pixel[image->channel_map[BluePixelChannel].offset];
-    if (((fabs(pixel[image->channel_map[RedPixelChannel].offset]) <= MagickEpsilon) ||
-         (fabs(pixel[image->channel_map[RedPixelChannel].offset]-QuantumRange) <= MagickEpsilon)) &&
-        (fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
-      return(MagickTrue);
-    }
-#endif
   return(MagickFalse);
 }
 
 static inline MagickBooleanType IsPixelInfoGray(
   const PixelInfo *restrict pixel_info)
 {
-#if !defined(MAGICKCORE_HDRI_SUPPORT)
-  if ((pixel_info->red == pixel_info->green) &&
-      (pixel_info->green == pixel_info->blue))
+  if ((pixel_info->colorspace != GRAYColorspace) &&
+      (pixel_info->colorspace != RGBColorspace))
+    return(MagickFalse);
+  if ((fabs(pixel_info->red-pixel_info->green) < MagickEpsilon) &&
+      (fabs(pixel_info->green-pixel_info->blue) < MagickEpsilon))
     return(MagickTrue);
-#else
-  {
-    double
-      alpha,
-      beta;
-
-    alpha=pixel_info->red-(double) pixel_info->green;
-    beta=pixel_info->green-(double) pixel_info->blue;
-    if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
-      return(MagickTrue);
-  }
-#endif
   return(MagickFalse);
 }
 
 static inline MagickBooleanType IsPixelInfoMonochrome(
   const PixelInfo *restrict pixel_info)
 {
-#if !defined(MAGICKCORE_HDRI_SUPPORT)
-  if (((pixel_info->red == 0) || (pixel_info->red == (Quantum) QuantumRange)) &&
-      (pixel_info->red == pixel_info->green) &&
-      (pixel_info->green == pixel_info->blue))
+  if ((pixel_info->colorspace != GRAYColorspace) &&
+      (pixel_info->colorspace != RGBColorspace))
+    return(MagickFalse);
+  if ((fabs(pixel_info->red) >= MagickEpsilon) ||
+      (fabs(pixel_info->red-QuantumRange) >= MagickEpsilon))
+    return(MagickFalse);
+  if ((fabs(pixel_info->red-pixel_info->green) < MagickEpsilon) &&
+      (fabs(pixel_info->green-pixel_info->blue) < MagickEpsilon))
     return(MagickTrue);
-#else
-  {
-    double
-      alpha,
-      beta;
-
-    alpha=pixel_info->red-(double) pixel_info->green;
-    beta=pixel_info->green-(double) pixel_info->blue;
-    if (((fabs(pixel_info->red) <= MagickEpsilon) ||
-         (fabs(pixel_info->red-QuantumRange) <= MagickEpsilon)) &&
-        (fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
-      return(MagickTrue);
-    }
-#endif
   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)
 {
@@ -428,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)
 {
@@ -470,14 +575,14 @@ static inline void SetPixelChannel(const Image *restrict image,
 }
 
 static inline void SetPixelChannelMapChannel(const Image *restrict image,
-  const PixelChannel channel,const int offset)
+  const PixelChannel channel,const ssize_t offset)
 {
   image->channel_map[offset].channel=channel;
   image->channel_map[channel].offset=offset;
 }
 
 static inline void SetPixelChannelMap(const Image *restrict image,
-  const PixelChannel channel,const PixelTrait traits,const int offset)
+  const PixelChannel channel,const PixelTrait traits,const ssize_t offset)
 {
   image->channel_map[offset].channel=channel;
   image->channel_map[channel].offset=offset;
@@ -552,23 +657,6 @@ static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
   image->channel_map[IndexPixelChannel].traits=traits;
 }
 
-static inline void SetPixelInfo(const Image *restrict image,
-  const PixelInfo *restrict p,PixelInfo *restrict q)
-{
-  q->red=p->red;
-  q->green=p->green;
-  q->blue=p->blue;
-  q->black=0;
-  if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
-    q->black=p->black;
-  q->alpha=OpaqueAlpha;
-  if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
-    q->alpha=p->alpha;
-  q->index=0;
-  if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
-    q->index=p->index;
-}
-
 static inline void SetPixelInfoPixel(const Image *restrict image,
   const PixelInfo *restrict pixel_info,Quantum *restrict pixel)
 {
@@ -578,15 +666,19 @@ static inline void SetPixelInfoPixel(const Image *restrict image,
     ClampToQuantum(pixel_info->green);
   pixel[image->channel_map[BluePixelChannel].offset]=
     ClampToQuantum(pixel_info->blue);
-  if ((image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait) &&
-      (image->colorspace == CMYKColorspace) &&
-      (pixel_info->colorspace == CMYKColorspace))
+  if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
     pixel[image->channel_map[BlackPixelChannel].offset]=
       ClampToQuantum(pixel_info->black);
   if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
-    pixel[image->channel_map[AlphaPixelChannel].offset]=
-      pixel_info->matte == MagickFalse ? OpaqueAlpha :
-      ClampToQuantum(pixel_info->alpha);
+    pixel[image->channel_map[AlphaPixelChannel].offset]=pixel_info->matte ==
+      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,
@@ -600,10 +692,11 @@ static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
   image->channel_map[MagentaPixelChannel].traits=traits;
 }
 
-static inline void SetPixelMetaChannels(Image *image,
-  const size_t number_meta_channels)
+static inline void SetPixelMask(const Image *restrict image,
+  const Quantum mask,Quantum *restrict pixel)
 {
-  image->number_meta_channels=number_meta_channels;
+  if (image->channel_map[MaskPixelChannel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[MaskPixelChannel].offset]=mask;
 }
 
 static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
@@ -611,6 +704,13 @@ static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
   image->metacontent_extent=extent;
 }
 
+static inline void SetPixelOpacity(const Image *restrict image,
+  const Quantum alpha,Quantum *restrict pixel)
+{
+  if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
+}
+
 static inline void SetPixelRed(const Image *restrict image,const Quantum red,
   Quantum *restrict pixel)
 {
@@ -644,51 +744,6 @@ static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
   image->channel_map[YPixelChannel].traits=traits;
 }
 
-static inline Quantum GetPixelIntensity(const Image *restrict image,
-  const Quantum *restrict pixel)
-{
-#if !defined(MAGICKCORE_HDRI_SUPPORT)
-  if ((pixel[image->channel_map[RedPixelChannel].offset] ==
-       pixel[image->channel_map[GreenPixelChannel].offset]) &&
-      (pixel[image->channel_map[GreenPixelChannel].offset] ==
-       pixel[image->channel_map[BluePixelChannel].offset]))
-    return(pixel[image->channel_map[RedPixelChannel].offset]);
-  return((Quantum) (0.299*pixel[image->channel_map[RedPixelChannel].offset]+
-    0.587*pixel[image->channel_map[GreenPixelChannel].offset]+0.114*
-    pixel[image->channel_map[BluePixelChannel].offset]+0.5));
-#else
-  {
-    double
-      alpha,
-      beta;
-
-    alpha=pixel[image->channel_map[RedPixelChannel].offset]-(double)
-      pixel[image->channel_map[GreenPixelChannel].offset];
-    beta=pixel[image->channel_map[GreenPixelChannel].offset]-(double)
-      pixel[image->channel_map[BluePixelChannel].offset];
-    if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
-      return(pixel[image->channel_map[RedPixelChannel].offset]);
-    return((Quantum) (0.299*pixel[image->channel_map[RedPixelChannel].offset]+
-      0.587*pixel[image->channel_map[GreenPixelChannel].offset]+0.114*
-      pixel[image->channel_map[BluePixelChannel].offset]));
-  }
-#endif
-}
-
-static inline Quantum GetPixelLuminance(const Image *restrict image,
-  const Quantum *restrict pixel)
-{
-#if !defined(MAGICKCORE_HDRI_SUPPORT)
-  return((Quantum) (0.21267*pixel[image->channel_map[RedPixelChannel].offset]+
-    0.71516*pixel[image->channel_map[GreenPixelChannel].offset]+0.07217*
-    pixel[image->channel_map[BluePixelChannel].offset]+0.5));
-#else
-  return((Quantum) (0.21267*pixel[image->channel_map[RedPixelChannel].offset]+
-    0.71516*pixel[image->channel_map[GreenPixelChannel].offset]+0.07217*
-    pixel[image->channel_map[BluePixelChannel].offset]));
-#endif
-}
-
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif