]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/pixel-accessor.h
Fix CLUT interpolation method
[imagemagick] / MagickCore / pixel-accessor.h
index 8720997264975459720228ff319835bacddaad76..78d9bcc31f13c12775602145af4f56100abd878d 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,126 +23,151 @@ extern "C" {
 #endif
 
 #include <math.h>
+#include <MagickCore/cache.h>
 #include <MagickCore/cache-view.h>
 #include <MagickCore/color.h>
 #include <MagickCore/image.h>
 
 #undef index
 
-static inline Quantum GetPixelAlpha(const Image *image,const Quantum *pixel)
+static inline Quantum GetPixelAlpha(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
-  return(pixel[image->channel_map[AlphaPixelChannel].channel]);
+  if (image->channel_map[AlphaPixelChannel].traits == UndefinedPixelTrait)
+    return(OpaqueAlpha);
+  return(pixel[image->channel_map[AlphaPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelAlphaTraits(const Image *image)
+static inline PixelTrait GetPixelAlphaTraits(const Image *restrict image)
 {
   return(image->channel_map[AlphaPixelChannel].traits);
 }
 
-static inline Quantum GetPixelBlack(const Image *image,const Quantum *pixel)
+static inline Quantum GetPixelBlack(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
-  return(pixel[image->channel_map[BlackPixelChannel].channel]);
+  if (image->channel_map[BlackPixelChannel].traits == UndefinedPixelTrait)
+    return(0);
+  return(pixel[image->channel_map[BlackPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelBlackTraits(const Image *image)
+static inline PixelTrait GetPixelBlackTraits(const Image *restrict image)
 {
   return(image->channel_map[BlackPixelChannel].traits);
 }
 
-static inline Quantum GetPixelBlue(const Image *image,const Quantum *pixel)
+static inline Quantum GetPixelBlue(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
-  return(pixel[image->channel_map[BluePixelChannel].channel]);
+  return(pixel[image->channel_map[BluePixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelBlueTraits(const Image *image)
+static inline PixelTrait GetPixelBlueTraits(const Image *restrict image)
 {
   return(image->channel_map[BluePixelChannel].traits);
 }
 
-static inline Quantum GetPixelCb(const Image *image,const Quantum *pixel)
+static inline Quantum GetPixelCb(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
-  return(pixel[image->channel_map[CbPixelChannel].channel]);
+  return(pixel[image->channel_map[CbPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelCbTraits(const Image *image)
+static inline PixelTrait GetPixelCbTraits(const Image *restrict image)
 {
   return(image->channel_map[CbPixelChannel].traits);
 }
 
-static inline Quantum GetPixelChannel(const Image *image,
-  const PixelChannel channel,const Quantum *pixel)
+static inline Quantum GetPixelChannel(const Image *restrict image,
+  const PixelChannel channel,const Quantum *restrict pixel)
 {
-  return(pixel[image->channel_map[channel].channel]);
+  if (image->channel_map[channel].traits == UndefinedPixelTrait)
+    return(0);
+  return(pixel[image->channel_map[channel].offset]);
 }
 
-static inline PixelChannel GetPixelChannelMapChannel(const Image *image,
+static inline PixelChannel GetPixelChannelMapChannel(
+  const Image *restrict image,const ssize_t offset)
+{
+  return(image->channel_map[offset].channel);
+}
+
+static inline ssize_t GetPixelChannelMapOffset(const Image *restrict image,
   const PixelChannel channel)
 {
-  return(image->channel_map[channel].channel);
+  return(image->channel_map[channel].offset);
 }
 
-static inline PixelTrait GetPixelChannelMapTraits(const Image *image,
+static inline PixelTrait GetPixelChannelMapTraits(const Image *restrict image,
   const PixelChannel channel)
 {
   return(image->channel_map[channel].traits);
 }
 
-static inline size_t GetPixelChannels(const Image *image)
+static inline size_t GetPixelChannels(const Image *restrict image)
 {
   return(image->number_channels);
 }
 
-static inline Quantum GetPixelCr(const Image *image,const Quantum *pixel)
+static inline Quantum GetPixelCr(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
-  return(pixel[image->channel_map[CrPixelChannel].channel]);
+  return(pixel[image->channel_map[CrPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelCrTraits(const Image *image)
+static inline PixelTrait GetPixelCrTraits(const Image *restrict image)
 {
   return(image->channel_map[CrPixelChannel].traits);
 }
 
-static inline Quantum GetPixelCyan(const Image *image,const Quantum *pixel)
+static inline Quantum GetPixelCyan(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
-  return(pixel[image->channel_map[CyanPixelChannel].channel]);
+  return(pixel[image->channel_map[CyanPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelCyanTraits(const Image *image)
+static inline PixelTrait GetPixelCyanTraits(const Image *restrict image)
 {
   return(image->channel_map[CyanPixelChannel].traits);
 }
 
-static inline Quantum GetPixelGray(const Image *image,const Quantum *pixel)
+static inline Quantum GetPixelGray(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
-  return(pixel[image->channel_map[GrayPixelChannel].channel]);
+  return(pixel[image->channel_map[GrayPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelGrayTraits(const Image *image)
+static inline PixelTrait GetPixelGrayTraits(const Image *restrict image)
 {
   return(image->channel_map[GrayPixelChannel].traits);
 }
 
-static inline Quantum GetPixelGreen(const Image *image,const Quantum *pixel)
+static inline Quantum GetPixelGreen(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
-  return(pixel[image->channel_map[GreenPixelChannel].channel]);
+  return(pixel[image->channel_map[GreenPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelGreenTraits(const Image *image)
+static inline PixelTrait GetPixelGreenTraits(const Image *restrict image)
 {
   return(image->channel_map[GreenPixelChannel].traits);
 }
 
-static inline Quantum GetPixelIndex(const Image *image,const Quantum *pixel)
+static inline Quantum GetPixelIndex(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
-  return(pixel[image->channel_map[IndexPixelChannel].channel]);
+  if (image->channel_map[IndexPixelChannel].traits == UndefinedPixelTrait)
+    return(0);
+  return(pixel[image->channel_map[IndexPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelIndexTraits(const Image *image)
+static inline PixelTrait GetPixelIndexTraits(const Image *restrict image)
 {
   return(image->channel_map[IndexPixelChannel].traits);
 }
 
-static inline Quantum GetPixelInfoIntensity(const PixelInfo *pixel_info)
+static inline Quantum GetPixelInfoIntensity(
+  const PixelInfo *restrict pixel_info)
 {
 #if !defined(MAGICKCORE_HDRI_SUPPORT)
   return((Quantum) (0.299*pixel_info->red+0.587*pixel_info->green+0.114*
@@ -153,7 +178,8 @@ static inline Quantum GetPixelInfoIntensity(const PixelInfo *pixel_info)
 #endif
 }
 
-static inline Quantum GetPixelInfoLuminance(const PixelInfo *pixel_info)
+static inline Quantum GetPixelInfoLuminance(
+  const PixelInfo *restrict pixel_info)
 {
   Quantum
     luminance;
@@ -168,89 +194,170 @@ static inline Quantum GetPixelInfoLuminance(const PixelInfo *pixel_info)
   return((Quantum) luminance);
 }
 
-static inline Quantum GetPixelMagenta(const Image *image,const Quantum *pixel)
+static inline Quantum GetPixelIntensity(const Image *restrict image,
+  const Quantum *restrict pixel)
+{
+#if !defined(MAGICKCORE_HDRI_SUPPORT)
+  if (image->colorspace == GRAYColorspace)
+    return(pixel[image->channel_map[GrayPixelChannel].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
+}
+
+static inline Quantum GetPixelMagenta(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
-  return(pixel[image->channel_map[MagentaPixelChannel].channel]);
+  return(pixel[image->channel_map[MagentaPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelMagentaTraits(const Image *image)
+static inline PixelTrait GetPixelMagentaTraits(const Image *restrict image)
 {
   return(image->channel_map[MagentaPixelChannel].traits);
 }
 
-static inline size_t GetPixelMetaChannels(const Image *image)
+static inline Quantum GetPixelMask(const Image *restrict image,
+  const Quantum *restrict pixel)
+{
+  if (image->channel_map[MaskPixelChannel].traits == UndefinedPixelTrait)
+    return(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);
 }
 
-static inline size_t GetPixelMetacontentExtent(const Image *image)
+static inline size_t GetPixelMetacontentExtent(const Image *restrict image)
 {
   return(image->metacontent_extent);
 }
 
-static inline Quantum GetPixelRed(const Image *image,const Quantum *pixel)
+static inline Quantum GetPixelOpacity(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
-  return(pixel[image->channel_map[RedPixelChannel].channel]);
+  if (image->channel_map[AlphaPixelChannel].traits == UndefinedPixelTrait)
+    return(QuantumRange-OpaqueAlpha);
+  return(QuantumRange-pixel[image->channel_map[AlphaPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelRedTraits(const Image *image)
+static inline Quantum GetPixelRed(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
-  return(image->channel_map[RedPixelChannel].traits);
+  return(pixel[image->channel_map[RedPixelChannel].offset]);
 }
 
-static inline void GetPixelInfoPixel(const Image *image,const Quantum *pixel,
-  PixelInfo *packet)
+static inline PixelTrait GetPixelRedTraits(const Image *restrict image)
 {
-  packet->red=(double) pixel[image->channel_map[RedPixelChannel].channel];
-  packet->green=(double) pixel[image->channel_map[GreenPixelChannel].channel];
-  packet->blue=(double) pixel[image->channel_map[BluePixelChannel].channel];
-  packet->alpha=(double) pixel[image->channel_map[AlphaPixelChannel].channel];
+  return(image->channel_map[RedPixelChannel].traits);
 }
 
-static inline PixelTrait GetPixelTraits(const Image *image,
+static inline void GetPixelInfoPixel(const Image *restrict image,
+  const Quantum *restrict pixel,PixelInfo *restrict pixel_info)
+{
+  pixel_info->red=(double)
+    pixel[image->channel_map[RedPixelChannel].offset];
+  pixel_info->green=(double)
+    pixel[image->channel_map[GreenPixelChannel].offset];
+  pixel_info->blue=(double)
+    pixel[image->channel_map[BluePixelChannel].offset];
+  pixel_info->black=0;
+  if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
+    pixel_info->black=(double)
+      pixel[image->channel_map[BlackPixelChannel].offset];
+  pixel_info->alpha=OpaqueAlpha;
+  if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
+    pixel_info->alpha=(double)
+      pixel[image->channel_map[AlphaPixelChannel].offset];
+  pixel_info->index=0;
+  if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
+    pixel_info->index=(double)
+      pixel[image->channel_map[IndexPixelChannel].offset];
+}
+
+static inline PixelTrait GetPixelTraits(const Image *restrict image,
   const PixelChannel channel)
 {
   return(image->channel_map[channel].traits);
 }
 
-static inline Quantum GetPixelY(const Image *image,const Quantum *pixel)
+static inline Quantum GetPixelY(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
-  return(pixel[image->channel_map[YPixelChannel].channel]);
+  return(pixel[image->channel_map[YPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelYTraits(const Image *image)
+static inline PixelTrait GetPixelYTraits(const Image *restrict image)
 {
   return(image->channel_map[YPixelChannel].traits);
 }
 
-static inline Quantum GetPixelYellow(const Image *image,const Quantum *pixel)
+static inline Quantum GetPixelYellow(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
-  return(pixel[image->channel_map[YellowPixelChannel].channel]);
+  return(pixel[image->channel_map[YellowPixelChannel].offset]);
 }
 
-static inline PixelTrait GetPixelYellowTraits(const Image *image)
+static inline PixelTrait GetPixelYellowTraits(const Image *restrict image)
 {
   return(image->channel_map[YellowPixelChannel].traits);
 }
 
-static inline MagickBooleanType IsPixelEquivalent(const Image *image,
-  const Quantum *p,const PixelInfo *q)
+static inline MagickBooleanType IsPixelEquivalent(const Image *restrict image,
+  const Quantum *restrict p,const PixelInfo *restrict q)
 {
-  if (((double) p[image->channel_map[RedPixelChannel].channel] == q->red) &&
-      ((double) p[image->channel_map[GreenPixelChannel].channel] == q->green) &&
-      ((double) p[image->channel_map[BluePixelChannel].channel] == q->blue))
+  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))
     return(MagickTrue);
   return(MagickFalse);
 }
 
-static inline MagickBooleanType IsPixelGray(const Image *image,
-  const Quantum *pixel)
+static inline MagickBooleanType IsPixelGray(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
 #if !defined(MAGICKCORE_HDRI_SUPPORT)
-  if ((pixel[image->channel_map[RedPixelChannel].channel] ==
-       pixel[image->channel_map[GreenPixelChannel].channel]) &&
-      (pixel[image->channel_map[GreenPixelChannel].channel] ==
-       pixel[image->channel_map[BluePixelChannel].channel]))
+  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(MagickTrue);
 #else
   {
@@ -258,10 +365,10 @@ static inline MagickBooleanType IsPixelGray(const Image *image,
       alpha,
       beta;
 
-    alpha=pixel[image->channel_map[RedPixelChannel].channel]-(double)
-      pixel[image->channel_map[GreenPixelChannel].channel];
-    beta=pixel[image->channel_map[GreenPixelChannel].channel]-(double)
-      pixel[image->channel_map[BluePixelChannel].channel];
+    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);
   }
@@ -269,8 +376,8 @@ static inline MagickBooleanType IsPixelGray(const Image *image,
   return(MagickFalse);
 }
 
-static inline MagickBooleanType IsPixelInfoEquivalent(const PixelInfo *p,
-  const PixelInfo *q)
+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))
@@ -296,16 +403,16 @@ static inline MagickBooleanType IsPixelInfoEquivalent(const PixelInfo *p,
   return(MagickTrue);
 }
 
-static inline MagickBooleanType IsPixelMonochrome(const Image *image,
-  const Quantum *pixel)
+static inline MagickBooleanType IsPixelMonochrome(const Image *restrict image,
+  const Quantum *restrict pixel)
 {
 #if !defined(MAGICKCORE_HDRI_SUPPORT)
-  if (((pixel[image->channel_map[RedPixelChannel].channel] == 0) ||
-      (pixel[image->channel_map[RedPixelChannel].channel] == (Quantum) QuantumRange)) &&
-      (pixel[image->channel_map[RedPixelChannel].channel] ==
-       pixel[image->channel_map[GreenPixelChannel].channel]) &&
-      (pixel[image->channel_map[GreenPixelChannel].channel] ==
-       pixel[image->channel_map[BluePixelChannel].channel]))
+  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]))
     return(MagickTrue);
 #else
   {
@@ -313,12 +420,12 @@ static inline MagickBooleanType IsPixelMonochrome(const Image *image,
       alpha,
       beta;
 
-    alpha=pixel[image->channel_map[RedPixelChannel].channel]-(double)
-      pixel[image->channel_map[GreenPixelChannel].channel];
-    beta=pixel[image->channel_map[GreenPixelChannel].channel]-(double)
-      pixel[image->channel_map[BluePixelChannel].channel];
-    if (((fabs(pixel[image->channel_map[RedPixelChannel].channel]) <= MagickEpsilon) ||
-         (fabs(pixel[image->channel_map[RedPixelChannel].channel]-QuantumRange) <= MagickEpsilon)) &&
+    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);
     }
@@ -326,10 +433,12 @@ static inline MagickBooleanType IsPixelMonochrome(const Image *image,
   return(MagickFalse);
 }
 
-static inline MagickBooleanType IsPixelInfoGray(const PixelInfo *pixel)
+static inline MagickBooleanType IsPixelInfoGray(
+  const PixelInfo *restrict pixel_info)
 {
 #if !defined(MAGICKCORE_HDRI_SUPPORT)
-  if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
+  if ((pixel_info->red == pixel_info->green) &&
+      (pixel_info->green == pixel_info->blue))
     return(MagickTrue);
 #else
   {
@@ -337,8 +446,8 @@ static inline MagickBooleanType IsPixelInfoGray(const PixelInfo *pixel)
       alpha,
       beta;
 
-    alpha=pixel->red-(double) pixel->green;
-    beta=pixel->green-(double) pixel->blue;
+    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);
   }
@@ -347,11 +456,12 @@ static inline MagickBooleanType IsPixelInfoGray(const PixelInfo *pixel)
 }
 
 static inline MagickBooleanType IsPixelInfoMonochrome(
-  const PixelInfo *pixel)
+  const PixelInfo *restrict pixel_info)
 {
 #if !defined(MAGICKCORE_HDRI_SUPPORT)
-  if (((pixel->red == 0) || (pixel->red == (Quantum) QuantumRange)) &&
-      (pixel->red == pixel->green) && (pixel->green == pixel->blue))
+  if (((pixel_info->red == 0) || (pixel_info->red == (Quantum) QuantumRange)) &&
+      (pixel_info->red == pixel_info->green) &&
+      (pixel_info->green == pixel_info->blue))
     return(MagickTrue);
 #else
   {
@@ -359,10 +469,10 @@ static inline MagickBooleanType IsPixelInfoMonochrome(
       alpha,
       beta;
 
-    alpha=pixel->red-(double) pixel->green;
-    beta=pixel->green-(double) pixel->blue;
-    if (((fabs(pixel->red) <= MagickEpsilon) ||
-         (fabs(pixel->red-QuantumRange) <= MagickEpsilon)) &&
+    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);
     }
@@ -370,23 +480,11 @@ static inline MagickBooleanType IsPixelInfoMonochrome(
   return(MagickFalse);
 }
 
-static inline void SetPacketPixelInfo(const Image *image,
-  const PixelInfo *pixel_info,PixelInfo *packet)
+static inline void SetPixelAlpha(const Image *restrict image,
+  const Quantum alpha,Quantum *restrict pixel)
 {
-  packet->red=pixel_info->red;
-  packet->green=pixel_info->green;
-  packet->blue=pixel_info->blue;
-  packet->alpha=pixel_info->alpha;
-  if (image->colorspace == CMYKColorspace)
-    packet->black=pixel_info->black;
-  if (image->storage_class == PseudoClass)
-    packet->index=pixel_info->index;
-}
-
-static inline void SetPixelAlpha(const Image *image,const Quantum alpha,
-  Quantum *pixel)
-{
-  pixel[image->channel_map[AlphaPixelChannel].channel]=alpha;
+  if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[AlphaPixelChannel].offset]=alpha;
 }
 
 static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
@@ -394,10 +492,11 @@ static inline void SetPixelAlphaTraits(Image *image,const PixelTrait traits)
   image->channel_map[AlphaPixelChannel].traits=traits;
 }
 
-static inline void SetPixelBlack(const Image *image,const Quantum black,
-  Quantum *pixel)
+static inline void SetPixelBlack(const Image *restrict image,
+  const Quantum black,Quantum *restrict pixel)
 {
-  pixel[image->channel_map[BlackPixelChannel].channel]=black;
+  if (image->channel_map[BlackPixelChannel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[BlackPixelChannel].offset]=black;
 }
 
 static inline void SetPixelBlackTraits(Image *image,const PixelTrait traits)
@@ -405,10 +504,10 @@ static inline void SetPixelBlackTraits(Image *image,const PixelTrait traits)
   image->channel_map[BlackPixelChannel].traits=traits;
 }
 
-static inline void SetPixelBlue(const Image *image,const Quantum blue,
-  Quantum *pixel)
+static inline void SetPixelBlue(const Image *restrict image,const Quantum blue,
+  Quantum *restrict pixel)
 {
-  pixel[image->channel_map[BluePixelChannel].channel]=blue;
+  pixel[image->channel_map[BluePixelChannel].offset]=blue;
 }
 
 static inline void SetPixelBlueTraits(Image *image,const PixelTrait traits)
@@ -416,10 +515,10 @@ static inline void SetPixelBlueTraits(Image *image,const PixelTrait traits)
   image->channel_map[BluePixelChannel].traits=traits;
 }
 
-static inline void SetPixelCb(const Image *image,const Quantum cb,
-  Quantum *pixel)
+static inline void SetPixelCb(const Image *restrict image,const Quantum cb,
+  Quantum *restrict pixel)
 {
-  pixel[image->channel_map[CbPixelChannel].channel]=cb;
+  pixel[image->channel_map[CbPixelChannel].offset]=cb;
 }
 
 static inline void SetPixelCbTraits(Image *image,const PixelTrait traits)
@@ -427,16 +526,26 @@ static inline void SetPixelCbTraits(Image *image,const PixelTrait traits)
   image->channel_map[CbPixelChannel].traits=traits;
 }
 
-static inline void SetPixelChannel(const Image *image,
-  const PixelChannel channel,const Quantum quantum,Quantum *pixel)
+static inline void SetPixelChannel(const Image *restrict image,
+  const PixelChannel channel,const Quantum quantum,Quantum *restrict pixel)
+{
+  if (image->channel_map[channel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[channel].offset]=quantum;
+}
+
+static inline void SetPixelChannelMapChannel(const Image *restrict image,
+  const PixelChannel channel,const ssize_t offset)
 {
-  pixel[image->channel_map[channel].channel]=quantum;
+  image->channel_map[offset].channel=channel;
+  image->channel_map[channel].offset=offset;
 }
 
-static inline void SetPixelChannelMapChannel(const Image *image,
-  const PixelChannel channel,const PixelChannel channels)
+static inline void SetPixelChannelMap(const Image *restrict image,
+  const PixelChannel channel,const PixelTrait traits,const ssize_t offset)
 {
-  image->channel_map[channel].channel=channels;
+  image->channel_map[offset].channel=channel;
+  image->channel_map[channel].offset=offset;
+  image->channel_map[channel].traits=traits;
 }
 
 static inline void SetPixelChannels(Image *image,const size_t number_channels)
@@ -456,10 +565,10 @@ static inline void SetPixelChannelMapTraits(Image *image,
   image->channel_map[channel].traits=traits;
 }
 
-static inline void SetPixelCr(const Image *image,const Quantum cr,
-  Quantum *pixel)
+static inline void SetPixelCr(const Image *restrict image,const Quantum cr,
+  Quantum *restrict pixel)
 {
-  pixel[image->channel_map[CrPixelChannel].channel]=cr;
+  pixel[image->channel_map[CrPixelChannel].offset]=cr;
 }
 
 static inline void SetPixelCrTraits(Image *image,const PixelTrait traits)
@@ -467,16 +576,16 @@ static inline void SetPixelCrTraits(Image *image,const PixelTrait traits)
   image->channel_map[CrPixelChannel].traits=traits;
 }
 
-static inline void SetPixelCyan(const Image *image,const Quantum cyan,
-  Quantum *pixel)
+static inline void SetPixelCyan(const Image *restrict image,const Quantum cyan,
+  Quantum *restrict pixel)
 {
-  pixel[image->channel_map[CyanPixelChannel].channel]=cyan;
+  pixel[image->channel_map[CyanPixelChannel].offset]=cyan;
 }
 
-static inline void SetPixelGray(const Image *image,const Quantum gray,
-  Quantum *pixel)
+static inline void SetPixelGray(const Image *restrict image,const Quantum gray,
+  Quantum *restrict pixel)
 {
-  pixel[image->channel_map[GrayPixelChannel].channel]=gray;
+  pixel[image->channel_map[GrayPixelChannel].offset]=gray;
 }
 
 static inline void SetPixelGrayTraits(Image *image,const PixelTrait traits)
@@ -484,10 +593,10 @@ static inline void SetPixelGrayTraits(Image *image,const PixelTrait traits)
   image->channel_map[GrayPixelChannel].traits=traits;
 }
 
-static inline void SetPixelGreen(const Image *image,const Quantum green,
-  Quantum *pixel)
+static inline void SetPixelGreen(const Image *restrict image,
+  const Quantum green,Quantum *restrict pixel)
 {
-  pixel[image->channel_map[GreenPixelChannel].channel]=green;
+  pixel[image->channel_map[GreenPixelChannel].offset]=green;
 }
 
 static inline void SetPixelGreenTraits(Image *image,const PixelTrait traits)
@@ -495,10 +604,11 @@ static inline void SetPixelGreenTraits(Image *image,const PixelTrait traits)
   image->channel_map[GreenPixelChannel].traits=traits;
 }
 
-static inline void SetPixelIndex(const Image *image,const Quantum index,
-  Quantum *pixel)
+static inline void SetPixelIndex(const Image *restrict image,
+  const Quantum index,Quantum *restrict pixel)
 {
-  pixel[image->channel_map[IndexPixelChannel].channel]=index;
+  if (image->channel_map[IndexPixelChannel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[IndexPixelChannel].offset]=index;
 }
 
 static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
@@ -506,29 +616,27 @@ static inline void SetPixelIndexTraits(Image *image,const PixelTrait traits)
   image->channel_map[IndexPixelChannel].traits=traits;
 }
 
-static inline void SetPixelInfo(const Image *image,const Quantum *pixel,
-  PixelInfo *pixel_info)
+static inline void SetPixelInfoPixel(const Image *restrict image,
+  const PixelInfo *restrict pixel_info,Quantum *restrict pixel)
 {
-  pixel_info->red=(MagickRealType)
-    pixel[image->channel_map[RedPixelChannel].channel];
-  pixel_info->green=(MagickRealType)
-    pixel[image->channel_map[GreenPixelChannel].channel];
-  pixel_info->blue=(MagickRealType)
-    pixel[image->channel_map[BluePixelChannel].channel];
-  if (image->colorspace == CMYKColorspace)
-    pixel_info->black=(MagickRealType)
-      pixel[image->channel_map[BlackPixelChannel].channel];
-  pixel_info->alpha=(MagickRealType)
-    pixel[image->channel_map[AlphaPixelChannel].channel];
-  if (image->storage_class == PseudoClass)
-    pixel_info->index=(MagickRealType)
-      pixel[image->channel_map[IndexPixelChannel].channel];
+  pixel[image->channel_map[RedPixelChannel].offset]=
+    ClampToQuantum(pixel_info->red);
+  pixel[image->channel_map[GreenPixelChannel].offset]=
+    ClampToQuantum(pixel_info->green);
+  pixel[image->channel_map[BluePixelChannel].offset]=
+    ClampToQuantum(pixel_info->blue);
+  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);
 }
 
-static inline void SetPixelMagenta(const Image *image,const Quantum magenta,
-  Quantum *pixel)
+static inline void SetPixelMagenta(const Image *restrict image,
+  const Quantum magenta,Quantum *restrict pixel)
 {
-  pixel[image->channel_map[MagentaPixelChannel].channel]=magenta;
+  pixel[image->channel_map[MagentaPixelChannel].offset]=magenta;
 }
 
 static inline void SetPixelMagentaTraits(Image *image,const PixelTrait traits)
@@ -536,10 +644,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)
@@ -547,37 +656,28 @@ static inline void SetPixelMetacontentExtent(Image *image,const size_t extent)
   image->metacontent_extent=extent;
 }
 
-static inline void SetPixelRed(const Image *image,const Quantum red,
-  Quantum *pixel)
+static inline void SetPixelOpacity(const Image *restrict image,
+  const Quantum alpha,Quantum *restrict pixel)
 {
-  pixel[image->channel_map[RedPixelChannel].channel]=red;
+  if (image->channel_map[AlphaPixelChannel].traits != UndefinedPixelTrait)
+    pixel[image->channel_map[AlphaPixelChannel].offset]=QuantumRange-alpha;
 }
 
-static inline void SetPixelRedTraits(Image *image,const PixelTrait traits)
+static inline void SetPixelRed(const Image *restrict image,const Quantum red,
+  Quantum *restrict pixel)
 {
-  image->channel_map[RedPixelChannel].traits=traits;
+  pixel[image->channel_map[RedPixelChannel].offset]=red;
 }
 
-static inline void SetPixelPixelInfo(const Image *image,
-  const PixelInfo *pixel_info,Quantum *pixel)
+static inline void SetPixelRedTraits(Image *image,const PixelTrait traits)
 {
-  pixel[image->channel_map[RedPixelChannel].channel]=
-    ClampToQuantum(pixel_info->red);
-  pixel[image->channel_map[GreenPixelChannel].channel]=
-    ClampToQuantum(pixel_info->green);
-  pixel[image->channel_map[BluePixelChannel].channel]=
-    ClampToQuantum(pixel_info->blue);
-  pixel[image->channel_map[AlphaPixelChannel].channel]=
-    ClampToQuantum(pixel_info->alpha);
-  if (image->colorspace == CMYKColorspace)
-    pixel[image->channel_map[BlackPixelChannel].channel]=
-      ClampToQuantum(pixel_info->black);
+  image->channel_map[RedPixelChannel].traits=traits;
 }
 
-static inline void SetPixelYellow(const Image *image,const Quantum yellow,
-  Quantum *pixel)
+static inline void SetPixelYellow(const Image *restrict image,
+  const Quantum yellow,Quantum *restrict pixel)
 {
-  pixel[image->channel_map[YellowPixelChannel].channel]=yellow;
+  pixel[image->channel_map[YellowPixelChannel].offset]=yellow;
 }
 
 static inline void SetPixelYellowTraits(Image *image,const PixelTrait traits)
@@ -585,9 +685,10 @@ static inline void SetPixelYellowTraits(Image *image,const PixelTrait traits)
   image->channel_map[YellowPixelChannel].traits=traits;
 }
 
-static inline void SetPixelY(const Image *image,const Quantum y,Quantum *pixel)
+static inline void SetPixelY(const Image *restrict image,const Quantum y,
+  Quantum *restrict pixel)
 {
-  pixel[image->channel_map[YPixelChannel].channel]=y;
+  pixel[image->channel_map[YPixelChannel].offset]=y;
 }
 
 static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
@@ -595,49 +696,6 @@ static inline void SetPixelYTraits(Image *image,const PixelTrait traits)
   image->channel_map[YPixelChannel].traits=traits;
 }
 
-static inline Quantum GetPixelIntensity(const Image *image,const Quantum *pixel)
-{
-#if !defined(MAGICKCORE_HDRI_SUPPORT)
-  if ((pixel[image->channel_map[RedPixelChannel].channel] ==
-       pixel[image->channel_map[GreenPixelChannel].channel]) &&
-      (pixel[image->channel_map[GreenPixelChannel].channel] ==
-       pixel[image->channel_map[BluePixelChannel].channel]))
-    return(pixel[image->channel_map[RedPixelChannel].channel]);
-  return((Quantum) (0.299*pixel[image->channel_map[RedPixelChannel].channel]+
-    0.587*pixel[image->channel_map[GreenPixelChannel].channel]+0.114*
-    pixel[image->channel_map[BluePixelChannel].channel]+0.5));
-#else
-  {
-    double
-      alpha,
-      beta;
-
-    alpha=pixel[image->channel_map[RedPixelChannel].channel]-(double)
-      pixel[image->channel_map[GreenPixelChannel].channel];
-    beta=pixel[image->channel_map[GreenPixelChannel].channel]-(double)
-      pixel[image->channel_map[BluePixelChannel].channel];
-    if ((fabs(alpha) <= MagickEpsilon) && (fabs(beta) <= MagickEpsilon))
-      return(pixel[image->channel_map[RedPixelChannel].channel]);
-    return((Quantum) (0.299*pixel[image->channel_map[RedPixelChannel].channel]+
-      0.587*pixel[image->channel_map[GreenPixelChannel].channel]+0.114*
-      pixel[image->channel_map[BluePixelChannel].channel]));
-  }
-#endif
-}
-
-static inline Quantum GetPixelLuminance(const Image *image,const Quantum *pixel)
-{
-#if !defined(MAGICKCORE_HDRI_SUPPORT)
-  return((Quantum) (0.21267*pixel[image->channel_map[RedPixelChannel].channel]+
-    0.71516*pixel[image->channel_map[GreenPixelChannel].channel]+0.07217*
-    pixel[image->channel_map[BluePixelChannel].channel]+0.5));
-#else
-  return((Quantum) (0.21267*pixel[image->channel_map[RedPixelChannel].channel]+
-    0.71516*pixel[image->channel_map[GreenPixelChannel].channel]+0.07217*
-    pixel[image->channel_map[BluePixelChannel].channel]));
-#endif
-}
-
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif