]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/enhance.c
(no commit message)
[imagemagick] / MagickCore / enhance.c
index bff00dbc2e9931d0700d9945e2f15126027f2427..bf1817f97f5cd0e2188746db1bbb017734438477 100644 (file)
 %
 %  The format of the AutoGammaImage method is:
 %
-%      MagickBooleanType AutoGammaImage(Image *image)
-%      MagickBooleanType AutoGammaImageChannel(Image *image,
-%        const ChannelType channel)
+%      MagickBooleanType AutoGammaImage(Image *image,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o image: The image to auto-level
 %
-%    o channel: The channels to auto-level.  If the special 'SyncChannels'
-%      flag is set all given channels is adjusted in the same way using the
-%      mean average of those channels.
+%    o exception: return any errors or warnings in this structure.
 %
 */
-
-MagickExport MagickBooleanType AutoGammaImage(Image *image)
-{
-  return(AutoGammaImageChannel(image,DefaultChannels));
-}
-
-MagickExport MagickBooleanType AutoGammaImageChannel(Image *image,
-  const ChannelType channel)
+MagickExport MagickBooleanType AutoGammaImage(Image *image,
+  ExceptionInfo *exception)
 {
-  MagickStatusType
-    status;
-
   double
     gamma,
     log_mean,
     mean,
     sans;
 
-  log_mean=log(0.5);
+  MagickStatusType
+    status;
 
-  if ((channel & SyncChannels) != 0 )
+  register ssize_t
+    i;
+
+  log_mean=log(0.5);
+  if (image->sync != MagickFalse)
     {
       /*
-        Apply gamma correction equally accross all given channels
+        Apply gamma correction equally across all given channels.
       */
-      (void) GetImageChannelMean(image,channel,&mean,&sans,&image->exception);
+      (void) GetImageMean(image,&mean,&sans,exception);
       gamma=log(mean*QuantumScale)/log_mean;
-      return(LevelImageChannel(image,channel,0.0,(double)QuantumRange,gamma));
+      return(LevelImage(image,0.0,(double) QuantumRange,gamma,exception));
     }
-
   /*
     Auto-gamma each channel separately.
   */
   status=MagickTrue;
-  if ((channel & RedChannel) != 0)
-    {
-      (void) GetImageChannelMean(image,RedChannel,&mean,&sans,
-        &image->exception);
-      gamma=log(mean*QuantumScale)/log_mean;
-      status=status && LevelImageChannel(image,RedChannel,0.0,(double)
-        QuantumRange, gamma);
-    }
-  if ((channel & GreenChannel) != 0)
-    {
-      (void) GetImageChannelMean(image,GreenChannel,&mean,&sans,
-        &image->exception);
-      gamma=log(mean*QuantumScale)/log_mean;
-      status=status && LevelImageChannel(image,GreenChannel,0.0,(double)
-        QuantumRange,gamma);
-    }
-  if ((channel & BlueChannel) != 0)
-    {
-      (void) GetImageChannelMean(image,BlueChannel,&mean,&sans,
-        &image->exception);
-      gamma=log(mean*QuantumScale)/log_mean;
-      status=status && LevelImageChannel(image,BlueChannel,0.0,(double)
-        QuantumRange,gamma);
-    }
-  if (((channel & BlackChannel) != 0) &&
-      (image->colorspace == CMYKColorspace))
-    {
-      (void) GetImageChannelMean(image,BlackChannel,&mean,&sans,
-        &image->exception);
-      gamma=log(mean*QuantumScale)/log_mean;
-      status=status && LevelImageChannel(image,BlackChannel,0.0,(double)
-        QuantumRange,gamma);
-    }
-  if (((channel & OpacityChannel) != 0) &&
-      (image->matte == MagickTrue))
-    {
-      (void) GetImageChannelMean(image,OpacityChannel,&mean,&sans,
-        &image->exception);
-      gamma=log(mean*QuantumScale)/log_mean;
-      status=status && LevelImageChannel(image,OpacityChannel,0.0,(double)
-        QuantumRange,gamma);
-    }
+  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+  {
+    ChannelType
+      channel_mask;
+
+    PixelTrait
+      traits;
+
+    traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
+    if ((traits & UpdatePixelTrait) == 0)
+      continue;
+    channel_mask=SetPixelChannelMask(image,(ChannelType) i);
+    status=GetImageMean(image,&mean,&sans,exception);
+    gamma=log(mean*QuantumScale)/log_mean;
+    status&=LevelImage(image,0.0,(double) QuantumRange,gamma,exception);
+    (void) SetPixelChannelMask(image,channel_mask);
+    if (status == MagickFalse)
+      break;
+  }
   return(status != 0 ? MagickTrue : MagickFalse);
 }
 \f
@@ -197,32 +165,19 @@ MagickExport MagickBooleanType AutoGammaImageChannel(Image *image,
 %
 %  The format of the LevelImage method is:
 %
-%      MagickBooleanType AutoLevelImage(Image *image)
-%      MagickBooleanType AutoLevelImageChannel(Image *image,
-%        const ChannelType channel)
+%      MagickBooleanType AutoLevelImage(Image *image,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o image: The image to auto-level
 %
-%    o channel: The channels to auto-level.  If the special 'SyncChannels'
-%      flag is set the min/max/mean value of all given channels is used for
-%      all given channels, to all channels in the same way.
+%    o exception: return any errors or warnings in this structure.
 %
 */
-
-MagickExport MagickBooleanType AutoLevelImage(Image *image)
+MagickExport MagickBooleanType AutoLevelImage(Image *image,
+  ExceptionInfo *exception)
 {
-  return(AutoLevelImageChannel(image,DefaultChannels));
-}
-
-MagickExport MagickBooleanType AutoLevelImageChannel(Image *image,
-  const ChannelType channel)
-{
-  /*
-    This is simply a convenience function around a Min/Max Histogram Stretch
-  */
-  return MinMaxStretchImage(image, channel, 0.0, 0.0);
+  return(MinMaxStretchImage(image,0.0,0.0,exception));
 }
 \f
 /*
@@ -236,50 +191,35 @@ MagickExport MagickBooleanType AutoLevelImageChannel(Image *image,
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  Use BrightnessContrastImage() to change the brightness and/or contrast of
-%  an image.  It converts the brightness and contrast parameters into slope
-%  and intercept and calls a polynomical function to apply to the image.
+%  BrightnessContrastImage() changes the brightness and/or contrast of an
+%  image.  It converts the brightness and contrast parameters into slope and
+%  intercept and calls a polynomical function to apply to the image.
 %
 %  The format of the BrightnessContrastImage method is:
 %
 %      MagickBooleanType BrightnessContrastImage(Image *image,
-%        const double brightness,const double contrast)
-%      MagickBooleanType BrightnessContrastImageChannel(Image *image,
-%        const ChannelType channel,const double brightness,
-%        const double contrast)
+%        const double brightness,const double contrast,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o image: the image.
 %
-%    o channel: the channel.
-%
 %    o brightness: the brightness percent (-100 .. 100).
 %
 %    o contrast: the contrast percent (-100 .. 100).
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
-
 MagickExport MagickBooleanType BrightnessContrastImage(Image *image,
-  const double brightness,const double contrast)
-{
-  MagickBooleanType
-    status;
-
-  status=BrightnessContrastImageChannel(image,DefaultChannels,brightness,
-    contrast);
-  return(status);
-}
-
-MagickExport MagickBooleanType BrightnessContrastImageChannel(Image *image,
-  const ChannelType channel,const double brightness,const double contrast)
+  const double brightness,const double contrast,ExceptionInfo *exception)
 {
 #define BrightnessContastImageTag  "BrightnessContast/Image"
 
   double
     alpha,
-    intercept,
     coefficients[2],
+    intercept,
     slope;
 
   MagickBooleanType
@@ -299,8 +239,183 @@ MagickExport MagickBooleanType BrightnessContrastImageChannel(Image *image,
   intercept=brightness/100.0+((100-brightness)/200.0)*(1.0-slope);
   coefficients[0]=slope;
   coefficients[1]=intercept;
-  status=FunctionImageChannel(image,channel,PolynomialFunction,2,coefficients,
-    &image->exception);
+  status=FunctionImage(image,PolynomialFunction,2,coefficients,exception);
+  return(status);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%     C l u t I m a g e                                                       %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  ClutImage() replaces each color value in the given image, by using it as an
+%  index to lookup a replacement color value in a Color Look UP Table in the
+%  form of an image.  The values are extracted along a diagonal of the CLUT
+%  image so either a horizontal or vertial gradient image can be used.
+%
+%  Typically this is used to either re-color a gray-scale image according to a
+%  color gradient in the CLUT image, or to perform a freeform histogram
+%  (level) adjustment according to the (typically gray-scale) gradient in the
+%  CLUT image.
+%
+%  When the 'channel' mask includes the matte/alpha transparency channel but
+%  one image has no such channel it is assumed that that image is a simple
+%  gray-scale image that will effect the alpha channel values, either for
+%  gray-scale coloring (with transparent or semi-transparent colors), or
+%  a histogram adjustment of existing alpha channel values.   If both images
+%  have matte channels, direct and normal indexing is applied, which is rarely
+%  used.
+%
+%  The format of the ClutImage method is:
+%
+%      MagickBooleanType ClutImage(Image *image,Image *clut_image,
+%        ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image: the image, which is replaced by indexed CLUT values
+%
+%    o clut_image: the color lookup table image for replacement color values.
+%
+%    o channel: the channel.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport MagickBooleanType ClutImage(Image *image,const Image *clut_image,
+  ExceptionInfo *exception)
+{
+#define ClutImageTag  "Clut/Image"
+
+  CacheView
+    *clut_view,
+    *image_view;
+
+  double
+    *clut_map;
+
+  MagickBooleanType
+    status;
+
+  MagickOffsetType
+    progress;
+
+  register ssize_t
+    x;
+
+  ssize_t
+    adjust,
+    y;
+
+  assert(image != (Image *) NULL);
+  assert(image->signature == MagickSignature);
+  if (image->debug != MagickFalse)
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+  assert(clut_image != (Image *) NULL);
+  assert(clut_image->signature == MagickSignature);
+  if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
+    return(MagickFalse);
+  clut_map=(double *) AcquireQuantumMemory(MaxMap+1UL,GetPixelChannels(image)*
+    sizeof(*clut_map));
+  if (clut_map == (double *) NULL)
+    ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
+      image->filename);
+  /*
+    Clut image.
+  */
+  status=MagickTrue;
+  progress=0;
+  adjust=(ssize_t) (clut_image->interpolate == IntegerInterpolatePixel ? 0 : 1);
+  clut_view=AcquireCacheView(clut_image);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+  #pragma omp parallel for schedule(dynamic,4)
+#endif
+  for (x=0; x <= (ssize_t) MaxMap; x++)
+  {
+    register ssize_t
+      i;
+
+    for (i=0; i < (ssize_t) GetPixelChannels(clut_image); i++)
+      (void) InterpolatePixelChannel(clut_image,clut_view,(PixelChannel) i,
+        UndefinedInterpolatePixel,QuantumScale*x*(clut_image->columns-adjust),
+        QuantumScale*x*(clut_image->rows-adjust),clut_map+x*
+        GetPixelChannels(clut_image)+i,exception);
+  }
+  clut_view=DestroyCacheView(clut_view);
+  image_view=AcquireCacheView(image);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+  #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
+#endif
+  for (y=0; y < (ssize_t) image->rows; y++)
+  {
+    register Quantum
+      *restrict q;
+
+    register ssize_t
+      x;
+
+    if (status == MagickFalse)
+      continue;
+    q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
+    if (q == (Quantum *) NULL)
+      {
+        status=MagickFalse;
+        continue;
+      }
+    for (x=0; x < (ssize_t) image->columns; x++)
+    {
+      register ssize_t
+        i;
+
+      for (i=0; i < (ssize_t) GetPixelChannels(clut_image); i++)
+      {
+        PixelChannel
+          channel;
+
+        PixelTrait 
+          clut_traits,
+          traits;
+
+        clut_traits=GetPixelChannelMapTraits(clut_image,(PixelChannel) i);
+        if (clut_traits == UndefinedPixelTrait)
+          continue;
+        channel=GetPixelChannelMapChannel(clut_image,(PixelChannel) i);
+        traits=GetPixelChannelMapTraits(clut_image,channel);
+        if (traits == UndefinedPixelTrait)
+          continue;
+        if ((traits & UpdatePixelTrait) == 0)
+          continue;
+        q[channel]=ClampToQuantum(clut_map[ScaleQuantumToMap(q[channel])*
+          GetPixelChannels(clut_image)+channel]);
+      }
+      q+=GetPixelChannels(image);
+    }
+    if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+      status=MagickFalse;
+    if (image->progress_monitor != (MagickProgressMonitor) NULL)
+      {
+        MagickBooleanType
+          proceed;
+
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+  #pragma omp critical (MagickCore_ClutImage)
+#endif
+        proceed=SetImageProgress(image,ClutImageTag,progress++,image->rows);
+        if (proceed == MagickFalse)
+          status=MagickFalse;
+      }
+  }
+  image_view=DestroyCacheView(image_view);
+  clut_map=(double *) RelinquishMagickMemory(clut_map);
+  if ((clut_image->matte != MagickFalse) &&
+      ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0))
+    (void) SetImageAlphaChannel(image,ActivateAlphaChannel,exception);
   return(status);
 }
 \f
@@ -338,7 +453,7 @@ MagickExport MagickBooleanType BrightnessContrastImageChannel(Image *image,
 %  The format of the ColorDecisionListImage method is:
 %
 %      MagickBooleanType ColorDecisionListImage(Image *image,
-%        const char *color_correction_collection)
+%        const char *color_correction_collection,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -346,9 +461,11 @@ MagickExport MagickBooleanType BrightnessContrastImageChannel(Image *image,
 %
 %    o color_correction_collection: the color correction collection in XML.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 MagickExport MagickBooleanType ColorDecisionListImage(Image *image,
-  const char *color_correction_collection)
+  const char *color_correction_collection,ExceptionInfo *exception)
 {
 #define ColorDecisionListCorrectImageTag  "ColorDecisionList/Image"
 
@@ -384,9 +501,6 @@ MagickExport MagickBooleanType ColorDecisionListImage(Image *image,
     *content,
     *p;
 
-  ExceptionInfo
-    *exception;
-
   MagickBooleanType
     status;
 
@@ -417,7 +531,7 @@ MagickExport MagickBooleanType ColorDecisionListImage(Image *image,
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   if (color_correction_collection == (const char *) NULL)
     return(MagickFalse);
-  ccc=NewXMLTree((const char *) color_correction_collection,&image->exception);
+  ccc=NewXMLTree((const char *) color_correction_collection,exception);
   if (ccc == (XMLTreeInfo *) NULL)
     return(MagickFalse);
   cc=GetXMLTreeChild(ccc,"ColorCorrection");
@@ -595,14 +709,14 @@ MagickExport MagickBooleanType ColorDecisionListImage(Image *image,
 #endif
   for (i=0; i <= (ssize_t) MaxMap; i++)
   {
-    cdl_map[i].red=ClampToQuantum((MagickRealType) ScaleMapToQuantum((
-      MagickRealType) (MaxMap*(pow(color_correction.red.slope*i/MaxMap+
+    cdl_map[i].red=ClampToQuantum((MagickRealType) ScaleMapToQuantum(
+      (MagickRealType) (MaxMap*(pow(color_correction.red.slope*i/MaxMap+
       color_correction.red.offset,color_correction.red.power)))));
-    cdl_map[i].green=ClampToQuantum((MagickRealType) ScaleMapToQuantum((
-      MagickRealType) (MaxMap*(pow(color_correction.green.slope*i/MaxMap+
+    cdl_map[i].green=ClampToQuantum((MagickRealType) ScaleMapToQuantum(
+      (MagickRealType) (MaxMap*(pow(color_correction.green.slope*i/MaxMap+
       color_correction.green.offset,color_correction.green.power)))));
-    cdl_map[i].blue=ClampToQuantum((MagickRealType) ScaleMapToQuantum((
-      MagickRealType) (MaxMap*(pow(color_correction.blue.slope*i/MaxMap+
+    cdl_map[i].blue=ClampToQuantum((MagickRealType) ScaleMapToQuantum(
+      (MagickRealType) (MaxMap*(pow(color_correction.blue.slope*i/MaxMap+
       color_correction.blue.offset,color_correction.blue.power)))));
   }
   if (image->storage_class == PseudoClass)
@@ -620,13 +734,15 @@ MagickExport MagickBooleanType ColorDecisionListImage(Image *image,
 
         luma=0.2126*image->colormap[i].red+0.7152*image->colormap[i].green+
           0.0722*image->colormap[i].blue;
-        image->colormap[i].red=ClampToQuantum(luma+color_correction.saturation*
-          cdl_map[ScaleQuantumToMap(image->colormap[i].red)].red-luma);
+        image->colormap[i].red=ClampToQuantum(luma+
+          color_correction.saturation*cdl_map[ScaleQuantumToMap(
+          image->colormap[i].red)].red-luma);
         image->colormap[i].green=ClampToQuantum(luma+
           color_correction.saturation*cdl_map[ScaleQuantumToMap(
           image->colormap[i].green)].green-luma);
-        image->colormap[i].blue=ClampToQuantum(luma+color_correction.saturation*
-          cdl_map[ScaleQuantumToMap(image->colormap[i].blue)].blue-luma);
+        image->colormap[i].blue=ClampToQuantum(luma+
+          color_correction.saturation*cdl_map[ScaleQuantumToMap(
+          image->colormap[i].blue)].blue-luma);
       }
     }
   /*
@@ -634,7 +750,6 @@ MagickExport MagickBooleanType ColorDecisionListImage(Image *image,
   */
   status=MagickTrue;
   progress=0;
-  exception=(&image->exception);
   image_view=AcquireCacheView(image);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
@@ -696,198 +811,6 @@ MagickExport MagickBooleanType ColorDecisionListImage(Image *image,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%     C l u t I m a g e                                                       %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  ClutImage() replaces each color value in the given image, by using it as an
-%  index to lookup a replacement color value in a Color Look UP Table in the
-%  form of an image.  The values are extracted along a diagonal of the CLUT
-%  image so either a horizontal or vertial gradient image can be used.
-%
-%  Typically this is used to either re-color a gray-scale image according to a
-%  color gradient in the CLUT image, or to perform a freeform histogram
-%  (level) adjustment according to the (typically gray-scale) gradient in the
-%  CLUT image.
-%
-%  When the 'channel' mask includes the matte/alpha transparency channel but
-%  one image has no such channel it is assumed that that image is a simple
-%  gray-scale image that will effect the alpha channel values, either for
-%  gray-scale coloring (with transparent or semi-transparent colors), or
-%  a histogram adjustment of existing alpha channel values.   If both images
-%  have matte channels, direct and normal indexing is applied, which is rarely
-%  used.
-%
-%  The format of the ClutImage method is:
-%
-%      MagickBooleanType ClutImage(Image *image,Image *clut_image)
-%      MagickBooleanType ClutImageChannel(Image *image,
-%        const ChannelType channel,Image *clut_image)
-%
-%  A description of each parameter follows:
-%
-%    o image: the image, which is replaced by indexed CLUT values
-%
-%    o clut_image: the color lookup table image for replacement color values.
-%
-%    o channel: the channel.
-%
-*/
-
-MagickExport MagickBooleanType ClutImage(Image *image,const Image *clut_image)
-{
-  return(ClutImageChannel(image,DefaultChannels,clut_image));
-}
-
-MagickExport MagickBooleanType ClutImageChannel(Image *image,
-  const ChannelType channel,const Image *clut_image)
-{
-#define ClampAlphaPixelComponent(pixel) ClampToQuantum((pixel)->alpha)
-#define ClampBlackPixelComponent(pixel) ClampToQuantum((pixel)->black)
-#define ClampBluePixelComponent(pixel) ClampToQuantum((pixel)->blue)
-#define ClampGreenPixelComponent(pixel) ClampToQuantum((pixel)->green)
-#define ClampRedPixelComponent(pixel) ClampToQuantum((pixel)->red)
-#define ClutImageTag  "Clut/Image"
-
-  CacheView
-    *clut_view,
-    *image_view;
-
-  ExceptionInfo
-    *exception;
-
-  MagickBooleanType
-    status;
-
-  MagickOffsetType
-    progress;
-
-  PixelInfo
-    *clut_map;
-
-  register ssize_t
-    i;
-
-  ssize_t
-    adjust,
-    y;
-
-  assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
-  if (image->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  assert(clut_image != (Image *) NULL);
-  assert(clut_image->signature == MagickSignature);
-  if (SetImageStorageClass(image,DirectClass) == MagickFalse)
-    return(MagickFalse);
-  clut_map=(PixelInfo *) AcquireQuantumMemory(MaxMap+1UL,
-    sizeof(*clut_map));
-  if (clut_map == (PixelInfo *) NULL)
-    ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
-      image->filename);
-  /*
-    Clut image.
-  */
-  status=MagickTrue;
-  progress=0;
-  adjust=(ssize_t) (clut_image->interpolate == IntegerInterpolatePixel ? 0 : 1);
-  exception=(&image->exception);
-  clut_view=AcquireCacheView(clut_image);
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4)
-#endif
-  for (i=0; i <= (ssize_t) MaxMap; i++)
-  {
-    GetPixelInfo(clut_image,clut_map+i);
-    (void) InterpolatePixelInfo(clut_image,clut_view,
-      UndefinedInterpolatePixel,QuantumScale*i*(clut_image->columns-adjust),
-      QuantumScale*i*(clut_image->rows-adjust),clut_map+i,exception);
-  }
-  clut_view=DestroyCacheView(clut_view);
-  image_view=AcquireCacheView(image);
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
-#endif
-  for (y=0; y < (ssize_t) image->rows; y++)
-  {
-    PixelInfo
-      pixel;
-
-    register Quantum
-      *restrict q;
-
-    register ssize_t
-      x;
-
-    if (status == MagickFalse)
-      continue;
-    q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
-    if (q == (const Quantum *) NULL)
-      {
-        status=MagickFalse;
-        continue;
-      }
-    GetPixelInfo(image,&pixel);
-    for (x=0; x < (ssize_t) image->columns; x++)
-    {
-      SetPixelInfo(image,q,&pixel);
-      if ((channel & RedChannel) != 0)
-        SetPixelRed(image,ClampRedPixelComponent(clut_map+
-          ScaleQuantumToMap(GetPixelRed(image,q))),q);
-      if ((channel & GreenChannel) != 0)
-        SetPixelGreen(image,ClampGreenPixelComponent(clut_map+
-          ScaleQuantumToMap(GetPixelGreen(image,q))),q);
-      if ((channel & BlueChannel) != 0)
-        SetPixelBlue(image,ClampBluePixelComponent(clut_map+
-          ScaleQuantumToMap(GetPixelBlue(image,q))),q);
-      if (((channel & BlackChannel) != 0) &&
-          (image->colorspace == CMYKColorspace))
-        SetPixelBlack(image,ClampBlackPixelComponent(clut_map+
-          ScaleQuantumToMap(GetPixelBlack(image,q))),q);
-      if ((channel & OpacityChannel) != 0)
-        {
-          if (clut_image->matte == MagickFalse)
-            SetPixelAlpha(image,GetPixelInfoIntensity(clut_map+
-              ScaleQuantumToMap((Quantum) GetPixelAlpha(image,q))),q);
-          else
-            if (image->matte == MagickFalse)
-              SetPixelAlpha(image,ClampAlphaPixelComponent(clut_map+
-                ScaleQuantumToMap((Quantum) GetPixelInfoIntensity(&pixel))),q);
-            else
-              SetPixelAlpha(image,ClampAlphaPixelComponent(clut_map+
-                ScaleQuantumToMap(GetPixelAlpha(image,q))),q);
-        }
-      q+=GetPixelChannels(image);
-    }
-    if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
-      status=MagickFalse;
-    if (image->progress_monitor != (MagickProgressMonitor) NULL)
-      {
-        MagickBooleanType
-          proceed;
-
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_ClutImageChannel)
-#endif
-        proceed=SetImageProgress(image,ClutImageTag,progress++,image->rows);
-        if (proceed == MagickFalse)
-          status=MagickFalse;
-      }
-  }
-  image_view=DestroyCacheView(image_view);
-  clut_map=(PixelInfo *) RelinquishMagickMemory(clut_map);
-  if ((clut_image->matte != MagickFalse) && ((channel & OpacityChannel) != 0))
-    (void) SetImageAlphaChannel(image,ActivateAlphaChannel);
-  return(status);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
 %     C o n t r a s t I m a g e                                               %
 %                                                                             %
 %                                                                             %
@@ -901,7 +824,7 @@ MagickExport MagickBooleanType ClutImageChannel(Image *image,
 %  The format of the ContrastImage method is:
 %
 %      MagickBooleanType ContrastImage(Image *image,
-%        const MagickBooleanType sharpen)
+%        const MagickBooleanType sharpen,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -909,6 +832,8 @@ MagickExport MagickBooleanType ClutImageChannel(Image *image,
 %
 %    o sharpen: Increase or decrease image contrast.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 
 static void Contrast(const int sign,Quantum *red,Quantum *green,Quantum *blue)
@@ -939,16 +864,13 @@ static void Contrast(const int sign,Quantum *red,Quantum *green,Quantum *blue)
 }
 
 MagickExport MagickBooleanType ContrastImage(Image *image,
-  const MagickBooleanType sharpen)
+  const MagickBooleanType sharpen,ExceptionInfo *exception)
 {
 #define ContrastImageTag  "Contrast/Image"
 
   CacheView
     *image_view;
 
-  ExceptionInfo
-    *exception;
-
   int
     sign;
 
@@ -983,7 +905,6 @@ MagickExport MagickBooleanType ContrastImage(Image *image,
   */
   status=MagickTrue;
   progress=0;
-  exception=(&image->exception);
   image_view=AcquireCacheView(image);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
@@ -1050,27 +971,22 @@ MagickExport MagickBooleanType ContrastImage(Image *image,
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  The ContrastStretchImage() is a simple image enhancement technique that
-%  attempts to improve the contrast in an image by `stretching' the range of
-%  intensity values it contains to span a desired range of values. It differs
-%  from the more sophisticated histogram equalization in that it can only
-%  apply %  a linear scaling function to the image pixel values.  As a result
-%  the `enhancement' is less harsh.
+%  ContrastStretchImage() is a simple image enhancement technique that attempts
+%  to improve the contrast in an image by `stretching' the range of intensity
+%  values it contains to span a desired range of values. It differs from the
+%  more sophisticated histogram equalization in that it can only apply a
+%  linear scaling function to the image pixel values.  As a result the
+%  `enhancement' is less harsh.
 %
 %  The format of the ContrastStretchImage method is:
 %
 %      MagickBooleanType ContrastStretchImage(Image *image,
-%        const char *levels)
-%      MagickBooleanType ContrastStretchImageChannel(Image *image,
-%        const size_t channel,const double black_point,
-%        const double white_point)
+%        const char *levels,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o image: the image.
 %
-%    o channel: the channel.
-%
 %    o black_point: the black point.
 %
 %    o white_point: the white point.
@@ -1078,48 +994,11 @@ MagickExport MagickBooleanType ContrastImage(Image *image,
 %    o levels: Specify the levels where the black and white points have the
 %      range of 0 to number-of-pixels (e.g. 1%, 10x90%, etc.).
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
-
 MagickExport MagickBooleanType ContrastStretchImage(Image *image,
-  const char *levels)
-{
-  double
-    black_point,
-    white_point;
-
-  GeometryInfo
-    geometry_info;
-
-  MagickBooleanType
-    status;
-
-  MagickStatusType
-    flags;
-
-  /*
-    Parse levels.
-  */
-  if (levels == (char *) NULL)
-    return(MagickFalse);
-  flags=ParseGeometry(levels,&geometry_info);
-  black_point=geometry_info.rho;
-  white_point=(double) image->columns*image->rows;
-  if ((flags & SigmaValue) != 0)
-    white_point=geometry_info.sigma;
-  if ((flags & PercentValue) != 0)
-    {
-      black_point*=(double) QuantumRange/100.0;
-      white_point*=(double) QuantumRange/100.0;
-    }
-  if ((flags & SigmaValue) == 0)
-    white_point=(double) image->columns*image->rows-black_point;
-  status=ContrastStretchImageChannel(image,DefaultChannels,black_point,
-    white_point);
-  return(status);
-}
-
-MagickExport MagickBooleanType ContrastStretchImageChannel(Image *image,
-  const ChannelType channel,const double black_point,const double white_point)
+  const double black_point,const double white_point,ExceptionInfo *exception)
 {
 #define MaxRange(color)  ((MagickRealType) ScaleQuantumToMap((Quantum) (color)))
 #define ContrastStretchImageTag  "ContrastStretch/Image"
@@ -1127,23 +1006,17 @@ MagickExport MagickBooleanType ContrastStretchImageChannel(Image *image,
   CacheView
     *image_view;
 
-  double
-    intensity;
-
-  ExceptionInfo
-    *exception;
-
   MagickBooleanType
     status;
 
   MagickOffsetType
     progress;
 
-  PixelInfo
-    black,
+  double
+    *black,
     *histogram,
     *stretch_map,
-    white;
+    *white;
 
   register ssize_t
     i;
@@ -1158,20 +1031,32 @@ MagickExport MagickBooleanType ContrastStretchImageChannel(Image *image,
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  histogram=(PixelInfo *) AcquireQuantumMemory(MaxMap+1UL,
-    sizeof(*histogram));
-  stretch_map=(PixelInfo *) AcquireQuantumMemory(MaxMap+1UL,
-    sizeof(*stretch_map));
-  if ((histogram == (PixelInfo *) NULL) ||
-      (stretch_map == (PixelInfo *) NULL))
-    ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
-      image->filename);
+  black=(double *) AcquireQuantumMemory(GetPixelChannels(image),sizeof(*black));
+  white=(double *) AcquireQuantumMemory(GetPixelChannels(image),sizeof(*white));
+  histogram=(double *) AcquireQuantumMemory(MaxMap+1UL,
+    GetPixelChannels(image)*sizeof(*histogram));
+  stretch_map=(double *) AcquireQuantumMemory(MaxMap+1UL,
+    GetPixelChannels(image)*sizeof(*stretch_map));
+  if ((black == (double *) NULL) || (white == (double *) NULL) ||
+      (histogram == (double *) NULL) || (stretch_map == (double *) NULL))
+    {
+      if (stretch_map != (double *) NULL)
+        stretch_map=(double *) RelinquishMagickMemory(stretch_map);
+      if (histogram != (double *) NULL)
+        histogram=(double *) RelinquishMagickMemory(histogram);
+      if (white != (double *) NULL)
+        white=(double *) RelinquishMagickMemory(white);
+      if (black != (double *) NULL)
+        black=(double *) RelinquishMagickMemory(black);
+      ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
+        image->filename);
+    }
   /*
     Form histogram.
   */
   status=MagickTrue;
-  exception=(&image->exception);
-  (void) ResetMagickMemory(histogram,0,(MaxMap+1)*sizeof(*histogram));
+  (void) ResetMagickMemory(histogram,0,(MaxMap+1)*GetPixelChannels(image)*
+    sizeof(*histogram));
   image_view=AcquireCacheView(image);
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -1189,264 +1074,135 @@ MagickExport MagickBooleanType ContrastStretchImageChannel(Image *image,
         status=MagickFalse;
         continue;
       }
-    if (channel == DefaultChannels)
-      for (x=0; x < (ssize_t) image->columns; x++)
-      {
-        Quantum
-          intensity;
-
-        intensity=GetPixelIntensity(image,p);
-        histogram[ScaleQuantumToMap(intensity)].red++;
-        histogram[ScaleQuantumToMap(intensity)].green++;
-        histogram[ScaleQuantumToMap(intensity)].blue++;
-        histogram[ScaleQuantumToMap(intensity)].black++;
-        p+=GetPixelChannels(image);
-      }
-    else
-      for (x=0; x < (ssize_t) image->columns; x++)
+    for (x=0; x < (ssize_t) image->columns; x++)
+    {
+      register ssize_t
+        i;
+
+      for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        if ((channel & RedChannel) != 0)
-          histogram[ScaleQuantumToMap(GetPixelRed(image,p))].red++;
-        if ((channel & GreenChannel) != 0)
-          histogram[ScaleQuantumToMap(GetPixelGreen(image,p))].green++;
-        if ((channel & BlueChannel) != 0)
-          histogram[ScaleQuantumToMap(GetPixelBlue(image,p))].blue++;
-        if (((channel & BlackChannel) != 0) &&
-            (image->colorspace == CMYKColorspace))
-          histogram[ScaleQuantumToMap(GetPixelBlack(image,p))].black++;
-        if ((channel & OpacityChannel) != 0)
-          histogram[ScaleQuantumToMap(GetPixelAlpha(image,p))].alpha++;
-        p+=GetPixelChannels(image);
+        PixelTrait
+          traits;
+
+        traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
+        if ((traits & UpdatePixelTrait) == 0)
+          continue;
+        histogram[GetPixelChannels(image)*ScaleQuantumToMap(p[i])+i]++;
       }
+      p+=GetPixelChannels(image);
+    }
   }
   /*
     Find the histogram boundaries by locating the black/white levels.
   */
-  black.red=0.0;
-  white.red=MaxRange(QuantumRange);
-  if ((channel & RedChannel) != 0)
-    {
-      intensity=0.0;
-      for (i=0; i <= (ssize_t) MaxMap; i++)
-      {
-        intensity+=histogram[i].red;
-        if (intensity > black_point)
-          break;
-      }
-      black.red=(MagickRealType) i;
-      intensity=0.0;
-      for (i=(ssize_t) MaxMap; i != 0; i--)
-      {
-        intensity+=histogram[i].red;
-        if (intensity > ((double) image->columns*image->rows-white_point))
-          break;
-      }
-      white.red=(MagickRealType) i;
-    }
-  black.green=0.0;
-  white.green=MaxRange(QuantumRange);
-  if ((channel & GreenChannel) != 0)
-    {
-      intensity=0.0;
-      for (i=0; i <= (ssize_t) MaxMap; i++)
-      {
-        intensity+=histogram[i].green;
-        if (intensity > black_point)
-          break;
-      }
-      black.green=(MagickRealType) i;
-      intensity=0.0;
-      for (i=(ssize_t) MaxMap; i != 0; i--)
-      {
-        intensity+=histogram[i].green;
-        if (intensity > ((double) image->columns*image->rows-white_point))
-          break;
-      }
-      white.green=(MagickRealType) i;
-    }
-  black.blue=0.0;
-  white.blue=MaxRange(QuantumRange);
-  if ((channel & BlueChannel) != 0)
-    {
-      intensity=0.0;
-      for (i=0; i <= (ssize_t) MaxMap; i++)
-      {
-        intensity+=histogram[i].blue;
-        if (intensity > black_point)
-          break;
-      }
-      black.blue=(MagickRealType) i;
-      intensity=0.0;
-      for (i=(ssize_t) MaxMap; i != 0; i--)
-      {
-        intensity+=histogram[i].blue;
-        if (intensity > ((double) image->columns*image->rows-white_point))
-          break;
-      }
-      white.blue=(MagickRealType) i;
-    }
-  black.alpha=0.0;
-  white.alpha=MaxRange(QuantumRange);
-  if ((channel & OpacityChannel) != 0)
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+  #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
+#endif
+  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+  {
+    double
+      intensity;
+
+    register ssize_t
+      j;
+
+    black[i]=0.0;
+    white[i]=MaxRange(QuantumRange);
+    intensity=0.0;
+    for (j=0; j <= (ssize_t) MaxMap; j++)
     {
-      intensity=0.0;
-      for (i=0; i <= (ssize_t) MaxMap; i++)
-      {
-        intensity+=histogram[i].alpha;
-        if (intensity > black_point)
-          break;
-      }
-      black.alpha=(MagickRealType) i;
-      intensity=0.0;
-      for (i=(ssize_t) MaxMap; i != 0; i--)
-      {
-        intensity+=histogram[i].alpha;
-        if (intensity > ((double) image->columns*image->rows-white_point))
-          break;
-      }
-      white.alpha=(MagickRealType) i;
+      intensity+=histogram[GetPixelChannels(image)*j+i];
+      if (intensity > black_point)
+        break;
     }
-  black.black=0.0;
-  white.black=MaxRange(QuantumRange);
-  if (((channel & BlackChannel) != 0) && (image->colorspace == CMYKColorspace))
+    black[i]=(MagickRealType) j;
+    intensity=0.0;
+    for (j=(ssize_t) MaxMap; j != 0; j--)
     {
-      intensity=0.0;
-      for (i=0; i <= (ssize_t) MaxMap; i++)
-      {
-        intensity+=histogram[i].black;
-        if (intensity > black_point)
-          break;
-      }
-      black.black=(MagickRealType) i;
-      intensity=0.0;
-      for (i=(ssize_t) MaxMap; i != 0; i--)
-      {
-        intensity+=histogram[i].black;
-        if (intensity > ((double) image->columns*image->rows-white_point))
-          break;
-      }
-      white.black=(MagickRealType) i;
+      intensity+=histogram[GetPixelChannels(image)*j+i];
+      if (intensity > ((double) image->columns*image->rows-white_point))
+        break;
     }
-  histogram=(PixelInfo *) RelinquishMagickMemory(histogram);
+    white[i]=(MagickRealType) j;
+  }
+  histogram=(double *) RelinquishMagickMemory(histogram);
   /*
     Stretch the histogram to create the stretched image mapping.
   */
-  (void) ResetMagickMemory(stretch_map,0,(MaxMap+1)*sizeof(*stretch_map));
+  (void) ResetMagickMemory(stretch_map,0,(MaxMap+1)*GetPixelChannels(image)*
+    sizeof(*stretch_map));
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
 #endif
-  for (i=0; i <= (ssize_t) MaxMap; i++)
+  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
   {
-    if ((channel & RedChannel) != 0)
-      {
-        if (i < (ssize_t) black.red)
-          stretch_map[i].red=0.0;
-        else
-          if (i > (ssize_t) white.red)
-            stretch_map[i].red=(MagickRealType) QuantumRange;
-          else
-            if (black.red != white.red)
-              stretch_map[i].red=(MagickRealType) ScaleMapToQuantum(
-                (MagickRealType) (MaxMap*(i-black.red)/(white.red-black.red)));
-      }
-    if ((channel & GreenChannel) != 0)
-      {
-        if (i < (ssize_t) black.green)
-          stretch_map[i].green=0.0;
-        else
-          if (i > (ssize_t) white.green)
-            stretch_map[i].green=(MagickRealType) QuantumRange;
-          else
-            if (black.green != white.green)
-              stretch_map[i].green=(MagickRealType) ScaleMapToQuantum(
-                (MagickRealType) (MaxMap*(i-black.green)/(white.green-
-                black.green)));
-      }
-    if ((channel & BlueChannel) != 0)
-      {
-        if (i < (ssize_t) black.blue)
-          stretch_map[i].blue=0.0;
-        else
-          if (i > (ssize_t) white.blue)
-            stretch_map[i].blue=(MagickRealType) QuantumRange;
-          else
-            if (black.blue != white.blue)
-              stretch_map[i].blue=(MagickRealType) ScaleMapToQuantum(
-                (MagickRealType) (MaxMap*(i-black.blue)/(white.blue-
-                black.blue)));
-      }
-    if ((channel & OpacityChannel) != 0)
-      {
-        if (i < (ssize_t) black.alpha)
-          stretch_map[i].alpha=0.0;
-        else
-          if (i > (ssize_t) white.alpha)
-            stretch_map[i].alpha=(MagickRealType) QuantumRange;
-          else
-            if (black.alpha != white.alpha)
-              stretch_map[i].alpha=(MagickRealType) ScaleMapToQuantum(
-                (MagickRealType) (MaxMap*(i-black.alpha)/(white.alpha-
-                black.alpha)));
-      }
-    if (((channel & BlackChannel) != 0) &&
-        (image->colorspace == CMYKColorspace))
-      {
-        if (i < (ssize_t) black.black)
-          stretch_map[i].black=0.0;
+    register ssize_t
+      j;
+
+    for (j=0; j <= (ssize_t) MaxMap; j++)
+    {
+      if (j < (ssize_t) black[i])
+        stretch_map[GetPixelChannels(image)*j+i]=0.0;
+      else
+        if (j > (ssize_t) white[i])
+          stretch_map[GetPixelChannels(image)*j+i]=(MagickRealType)
+            QuantumRange;
         else
-          if (i > (ssize_t) white.black)
-            stretch_map[i].black=(MagickRealType) QuantumRange;
-          else
-            if (black.black != white.black)
-              stretch_map[i].black=(MagickRealType) ScaleMapToQuantum(
-                (MagickRealType) (MaxMap*(i-black.black)/(white.black-
-                black.black)));
-      }
+          if (black[i] != white[i])
+            stretch_map[GetPixelChannels(image)*j+i]=(MagickRealType)
+              ScaleMapToQuantum((MagickRealType) (MaxMap*(j-black[i])/
+              (white[i]-black[i])));
+    }
   }
-  /*
-    Stretch the image.
-  */
-  if (((channel & OpacityChannel) != 0) || (((channel & BlackChannel) != 0) &&
-      (image->colorspace == CMYKColorspace)))
-    image->storage_class=DirectClass;
   if (image->storage_class == PseudoClass)
     {
+      register ssize_t
+        j;
+
       /*
-        Stretch colormap.
+        Stretch-contrast colormap.
       */
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
 #endif
-      for (i=0; i < (ssize_t) image->colors; i++)
+      for (j=0; j < (ssize_t) image->colors; j++)
       {
-        if ((channel & RedChannel) != 0)
+        if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
           {
-            if (black.red != white.red)
+            i=GetPixelChannelMapChannel(image,RedPixelChannel);
+            if (black[i] != white[i])
               image->colormap[i].red=ClampToQuantum(stretch_map[
-                ScaleQuantumToMap(image->colormap[i].red)].red);
+                GetPixelChannels(image)*ScaleQuantumToMap(
+                image->colormap[i].red)]+i);
           }
-        if ((channel & GreenChannel) != 0)
+        if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
           {
-            if (black.green != white.green)
-              image->colormap[i].green=ClampToQuantum(stretch_map[
-                ScaleQuantumToMap(image->colormap[i].green)].green);
+            i=GetPixelChannelMapChannel(image,GreenPixelChannel);
+            if (black[i] != white[i])
+              image->colormap[i].red=ClampToQuantum(stretch_map[
+                GetPixelChannels(image)*ScaleQuantumToMap(
+                image->colormap[i].red)]+i);
           }
-        if ((channel & BlueChannel) != 0)
+        if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
           {
-            if (black.blue != white.blue)
-              image->colormap[i].blue=ClampToQuantum(stretch_map[
-                ScaleQuantumToMap(image->colormap[i].blue)].blue);
+            i=GetPixelChannelMapChannel(image,BluePixelChannel);
+            if (black[i] != white[i])
+              image->colormap[i].red=ClampToQuantum(stretch_map[
+                GetPixelChannels(image)*ScaleQuantumToMap(
+                image->colormap[i].red)]+i);
           }
-        if ((channel & OpacityChannel) != 0)
+        if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
           {
-            if (black.alpha != white.alpha)
-              image->colormap[i].alpha=ClampToQuantum(stretch_map[
-                ScaleQuantumToMap(image->colormap[i].alpha)].alpha);
+            i=GetPixelChannelMapChannel(image,AlphaPixelChannel);
+            if (black[i] != white[i])
+              image->colormap[i].red=ClampToQuantum(stretch_map[
+                GetPixelChannels(image)*ScaleQuantumToMap(
+                image->colormap[i].red)]+i);
           }
       }
     }
   /*
-    Stretch image.
+    Stretch-contrast image.
   */
   status=MagickTrue;
   progress=0;
@@ -1471,37 +1227,21 @@ MagickExport MagickBooleanType ContrastStretchImageChannel(Image *image,
       }
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      if ((channel & RedChannel) != 0)
-        {
-          if (black.red != white.red)
-            SetPixelRed(image,ClampToQuantum(stretch_map[ScaleQuantumToMap(
-              GetPixelRed(image,q))].red),q);
-        }
-      if ((channel & GreenChannel) != 0)
-        {
-          if (black.green != white.green)
-            SetPixelGreen(image,ClampToQuantum(stretch_map[ScaleQuantumToMap(
-              GetPixelGreen(image,q))].green),q);
-        }
-      if ((channel & BlueChannel) != 0)
-        {
-          if (black.blue != white.blue)
-            SetPixelBlue(image,ClampToQuantum(stretch_map[ScaleQuantumToMap(
-              GetPixelBlue(image,q))].blue),q);
-        }
-      if (((channel & BlackChannel) != 0) &&
-          (image->colorspace == CMYKColorspace))
-        {
-          if (black.black != white.black)
-            SetPixelBlack(image,ClampToQuantum(stretch_map[ScaleQuantumToMap(
-              GetPixelBlack(image,q))].black),q);
-        }
-      if ((channel & OpacityChannel) != 0)
-        {
-          if (black.alpha != white.alpha)
-            SetPixelAlpha(image,ClampToQuantum(stretch_map[ScaleQuantumToMap(
-              GetPixelAlpha(image,q))].alpha),q);
-        }
+      register ssize_t
+        i;
+
+      for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+      {
+        PixelTrait
+          traits;
+
+        traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
+        if ((traits & UpdatePixelTrait) == 0)
+          continue;
+        if (black[i] != white[i])
+          q[i]=ClampToQuantum(stretch_map[GetPixelChannels(image)*
+            ScaleQuantumToMap(q[i])+i]);
+      }
       q+=GetPixelChannels(image);
     }
     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
@@ -1512,7 +1252,7 @@ MagickExport MagickBooleanType ContrastStretchImageChannel(Image *image,
           proceed;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_ContrastStretchImageChannel)
+  #pragma omp critical (MagickCore_ContrastStretchImage)
 #endif
         proceed=SetImageProgress(image,ContrastStretchImageTag,progress++,
           image->rows);
@@ -1521,7 +1261,9 @@ MagickExport MagickBooleanType ContrastStretchImageChannel(Image *image,
       }
   }
   image_view=DestroyCacheView(image_view);
-  stretch_map=(PixelInfo *) RelinquishMagickMemory(stretch_map);
+  stretch_map=(double *) RelinquishMagickMemory(stretch_map);
+  white=(double *) RelinquishMagickMemory(white);
+  black=(double *) RelinquishMagickMemory(black);
   return(status);
 }
 \f
@@ -1616,9 +1358,8 @@ MagickExport Image *EnhanceImage(const Image *image,ExceptionInfo *exception)
     exception);
   if (enhance_image == (Image *) NULL)
     return((Image *) NULL);
-  if (SetImageStorageClass(enhance_image,DirectClass) == MagickFalse)
+  if (SetImageStorageClass(enhance_image,DirectClass,exception) == MagickFalse)
     {
-      InheritException(exception,&enhance_image->exception);
       enhance_image=DestroyImage(enhance_image);
       return((Image *) NULL);
     }
@@ -1738,8 +1479,6 @@ MagickExport Image *EnhanceImage(const Image *image,ExceptionInfo *exception)
 %  The format of the EqualizeImage method is:
 %
 %      MagickBooleanType EqualizeImage(Image *image)
-%      MagickBooleanType EqualizeImageChannel(Image *image,
-%        const ChannelType channel)
 %
 %  A description of each parameter follows:
 %
@@ -1748,14 +1487,7 @@ MagickExport Image *EnhanceImage(const Image *image,ExceptionInfo *exception)
 %    o channel: the channel.
 %
 */
-
 MagickExport MagickBooleanType EqualizeImage(Image *image)
-{
-  return(EqualizeImageChannel(image,DefaultChannels));
-}
-
-MagickExport MagickBooleanType EqualizeImageChannel(Image *image,
-  const ChannelType channel)
 {
 #define EqualizeImageTag  "Equalize/Image"
 
@@ -1828,16 +1560,16 @@ MagickExport MagickBooleanType EqualizeImageChannel(Image *image,
       break;
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      if ((channel & RedChannel) != 0)
+      if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
         histogram[ScaleQuantumToMap(GetPixelRed(image,p))].red++;
-      if ((channel & GreenChannel) != 0)
+      if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
         histogram[ScaleQuantumToMap(GetPixelGreen(image,p))].green++;
-      if ((channel & BlueChannel) != 0)
+      if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
         histogram[ScaleQuantumToMap(GetPixelBlue(image,p))].blue++;
-      if (((channel & BlackChannel) != 0) &&
+      if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
           (image->colorspace == CMYKColorspace))
         histogram[ScaleQuantumToMap(GetPixelBlack(image,p))].black++;
-      if ((channel & OpacityChannel) != 0)
+      if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
         histogram[ScaleQuantumToMap(GetPixelAlpha(image,p))].alpha++;
       p+=GetPixelChannels(image);
     }
@@ -1848,16 +1580,16 @@ MagickExport MagickBooleanType EqualizeImageChannel(Image *image,
   (void) ResetMagickMemory(&intensity,0,sizeof(intensity));
   for (i=0; i <= (ssize_t) MaxMap; i++)
   {
-    if ((channel & RedChannel) != 0)
+    if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
       intensity.red+=histogram[i].red;
-    if ((channel & GreenChannel) != 0)
+    if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
       intensity.green+=histogram[i].green;
-    if ((channel & BlueChannel) != 0)
+    if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
       intensity.blue+=histogram[i].blue;
-    if (((channel & BlackChannel) != 0) &&
+    if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
         (image->colorspace == CMYKColorspace))
       intensity.black+=histogram[i].black;
-    if ((channel & OpacityChannel) != 0)
+    if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
       intensity.alpha+=histogram[i].alpha;
     map[i]=intensity;
   }
@@ -1869,21 +1601,25 @@ MagickExport MagickBooleanType EqualizeImageChannel(Image *image,
 #endif
   for (i=0; i <= (ssize_t) MaxMap; i++)
   {
-    if (((channel & RedChannel) != 0) && (white.red != black.red))
+    if (((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) &&
+        (white.red != black.red))
       equalize_map[i].red=(MagickRealType) ScaleMapToQuantum((MagickRealType)
         ((MaxMap*(map[i].red-black.red))/(white.red-black.red)));
-    if (((channel & GreenChannel) != 0) && (white.green != black.green))
+    if (((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) &&
+        (white.green != black.green))
       equalize_map[i].green=(MagickRealType) ScaleMapToQuantum((MagickRealType)
         ((MaxMap*(map[i].green-black.green))/(white.green-black.green)));
-    if (((channel & BlueChannel) != 0) && (white.blue != black.blue))
+    if (((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) &&
+        (white.blue != black.blue))
       equalize_map[i].blue=(MagickRealType) ScaleMapToQuantum((MagickRealType)
         ((MaxMap*(map[i].blue-black.blue))/(white.blue-black.blue)));
-    if ((((channel & BlackChannel) != 0) &&
+    if ((((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
         (image->colorspace == CMYKColorspace)) &&
         (white.black != black.black))
       equalize_map[i].black=(MagickRealType) ScaleMapToQuantum((MagickRealType)
         ((MaxMap*(map[i].black-black.black))/(white.black-black.black)));
-    if (((channel & OpacityChannel) != 0) && (white.alpha != black.alpha))
+    if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
+        (white.alpha != black.alpha))
       equalize_map[i].alpha=(MagickRealType) ScaleMapToQuantum(
         (MagickRealType) ((MaxMap*(map[i].alpha-black.alpha))/
         (white.alpha-black.alpha)));
@@ -1900,16 +1636,19 @@ MagickExport MagickBooleanType EqualizeImageChannel(Image *image,
 #endif
       for (i=0; i < (ssize_t) image->colors; i++)
       {
-        if (((channel & RedChannel) != 0) && (white.red != black.red))
+        if (((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) &&
+            (white.red != black.red))
           image->colormap[i].red=ClampToQuantum(equalize_map[
             ScaleQuantumToMap(image->colormap[i].red)].red);
-        if (((channel & GreenChannel) != 0) && (white.green != black.green))
+        if (((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) &&
+            (white.green != black.green))
           image->colormap[i].green=ClampToQuantum(equalize_map[
             ScaleQuantumToMap(image->colormap[i].green)].green);
-        if (((channel & BlueChannel) != 0) && (white.blue != black.blue))
+        if (((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) &&
+            (white.blue != black.blue))
           image->colormap[i].blue=ClampToQuantum(equalize_map[
             ScaleQuantumToMap(image->colormap[i].blue)].blue);
-        if (((channel & OpacityChannel) != 0) &&
+        if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
             (white.alpha != black.alpha))
           image->colormap[i].alpha=ClampToQuantum(equalize_map[
             ScaleQuantumToMap(image->colormap[i].alpha)].alpha);
@@ -1943,21 +1682,25 @@ MagickExport MagickBooleanType EqualizeImageChannel(Image *image,
       }
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      if (((channel & RedChannel) != 0) && (white.red != black.red))
+      if (((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) &&
+          (white.red != black.red))
         SetPixelRed(image,ClampToQuantum(equalize_map[
           ScaleQuantumToMap(GetPixelRed(image,q))].red),q);
-      if (((channel & GreenChannel) != 0) && (white.green != black.green))
+      if (((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) &&
+          (white.green != black.green))
         SetPixelGreen(image,ClampToQuantum(equalize_map[
           ScaleQuantumToMap(GetPixelGreen(image,q))].green),q);
-      if (((channel & BlueChannel) != 0) && (white.blue != black.blue))
+      if (((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) &&
+          (white.blue != black.blue))
         SetPixelBlue(image,ClampToQuantum(equalize_map[
           ScaleQuantumToMap(GetPixelBlue(image,q))].blue),q);
-      if ((((channel & BlackChannel) != 0) &&
+      if ((((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
           (image->colorspace == CMYKColorspace)) &&
           (white.black != black.black))
         SetPixelBlack(image,ClampToQuantum(equalize_map[
           ScaleQuantumToMap(GetPixelBlack(image,q))].black),q);
-      if (((channel & OpacityChannel) != 0) && (white.alpha != black.alpha))
+      if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
+          (white.alpha != black.alpha))
         SetPixelAlpha(image,ClampToQuantum(equalize_map[
           ScaleQuantumToMap(GetPixelAlpha(image,q))].alpha),q);
       q+=GetPixelChannels(image);
@@ -1970,7 +1713,7 @@ MagickExport MagickBooleanType EqualizeImageChannel(Image *image,
           proceed;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_EqualizeImageChannel)
+  #pragma omp critical (MagickCore_EqualizeImage)
 #endif
         proceed=SetImageProgress(image,EqualizeImageTag,progress++,image->rows);
         if (proceed == MagickFalse)
@@ -2004,72 +1747,26 @@ MagickExport MagickBooleanType EqualizeImageChannel(Image *image,
 %
 %  The format of the GammaImage method is:
 %
-%      MagickBooleanType GammaImage(Image *image,const char *level)
-%      MagickBooleanType GammaImageChannel(Image *image,
-%        const ChannelType channel,const double gamma)
+%      MagickBooleanType GammaImage(Image *image,const double gamma,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o image: the image.
 %
-%    o channel: the channel.
-%
 %    o level: the image gamma as a string (e.g. 1.6,1.2,1.0).
 %
 %    o gamma: the image gamma.
 %
 */
-MagickExport MagickBooleanType GammaImage(Image *image,const char *level)
-{
-  GeometryInfo
-    geometry_info;
-
-  PixelInfo
-    gamma;
-
-  MagickStatusType
-    flags,
-    status;
-
-  assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
-  if (image->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  if (level == (char *) NULL)
-    return(MagickFalse);
-  flags=ParseGeometry(level,&geometry_info);
-  gamma.red=geometry_info.rho;
-  gamma.green=geometry_info.sigma;
-  if ((flags & SigmaValue) == 0)
-    gamma.green=gamma.red;
-  gamma.blue=geometry_info.xi;
-  if ((flags & XiValue) == 0)
-    gamma.blue=gamma.red;
-  if ((gamma.red == 1.0) && (gamma.green == 1.0) && (gamma.blue == 1.0))
-    return(MagickTrue);
-  if ((gamma.red == gamma.green) && (gamma.green == gamma.blue))
-    status=GammaImageChannel(image,(const ChannelType) (RedChannel |
-      GreenChannel | BlueChannel),(double) gamma.red);
-  else
-    {
-      status=GammaImageChannel(image,RedChannel,(double) gamma.red);
-      status|=GammaImageChannel(image,GreenChannel,(double) gamma.green);
-      status|=GammaImageChannel(image,BlueChannel,(double) gamma.blue);
-    }
-  return(status != 0 ? MagickTrue : MagickFalse);
-}
-
-MagickExport MagickBooleanType GammaImageChannel(Image *image,
-  const ChannelType channel,const double gamma)
+MagickExport MagickBooleanType GammaImage(Image *image,const double gamma,
+  ExceptionInfo *exception)
 {
 #define GammaCorrectImageTag  "GammaCorrect/Image"
 
   CacheView
     *image_view;
 
-  ExceptionInfo
-    *exception;
-
   MagickBooleanType
     status;
 
@@ -2100,8 +1797,8 @@ MagickExport MagickBooleanType GammaImageChannel(Image *image,
       image->filename);
   (void) ResetMagickMemory(gamma_map,0,(MaxMap+1)*sizeof(*gamma_map));
   if (gamma != 0.0)
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4)
+#if defined(MAGICKCORE_OPENMP_SUPPORT) && (MaxMap > 256)
+  #pragma omp parallel for
 #endif
     for (i=0; i <= (ssize_t) MaxMap; i++)
       gamma_map[i]=ClampToQuantum((MagickRealType) ScaleMapToQuantum((
@@ -2116,16 +1813,16 @@ MagickExport MagickBooleanType GammaImageChannel(Image *image,
 #endif
       for (i=0; i < (ssize_t) image->colors; i++)
       {
-        if ((channel & RedChannel) != 0)
+        if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
           image->colormap[i].red=gamma_map[
             ScaleQuantumToMap(image->colormap[i].red)];
-        if ((channel & GreenChannel) != 0)
+        if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
           image->colormap[i].green=gamma_map[
             ScaleQuantumToMap(image->colormap[i].green)];
-        if ((channel & BlueChannel) != 0)
+        if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
           image->colormap[i].blue=gamma_map[
             ScaleQuantumToMap(image->colormap[i].blue)];
-        if ((channel & OpacityChannel) != 0)
+        if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
           image->colormap[i].alpha=gamma_map[
             ScaleQuantumToMap(image->colormap[i].alpha)];
       }
@@ -2135,7 +1832,6 @@ MagickExport MagickBooleanType GammaImageChannel(Image *image,
   */
   status=MagickTrue;
   progress=0;
-  exception=(&image->exception);
   image_view=AcquireCacheView(image);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
@@ -2158,43 +1854,20 @@ MagickExport MagickBooleanType GammaImageChannel(Image *image,
       }
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      if (channel == DefaultChannels)
-        {
-          SetPixelRed(image,gamma_map[
-            ScaleQuantumToMap(GetPixelRed(image,q))],q);
-          SetPixelGreen(image,gamma_map[
-            ScaleQuantumToMap(GetPixelGreen(image,q))],q);
-          SetPixelBlue(image,gamma_map[ScaleQuantumToMap(
-            GetPixelBlue(image,q))],q);
-        }
-      else
-        {
-          if ((channel & RedChannel) != 0)
-            SetPixelRed(image,gamma_map[ScaleQuantumToMap(
-              GetPixelRed(image,q))],q);
-          if ((channel & GreenChannel) != 0)
-            SetPixelGreen(image,gamma_map[
-              ScaleQuantumToMap(GetPixelGreen(image,q))],q);
-          if ((channel & BlueChannel) != 0)
-            SetPixelBlue(image,gamma_map[
-              ScaleQuantumToMap(GetPixelBlue(image,q))],q);
-          if ((channel & OpacityChannel) != 0)
-            {
-              if (image->matte == MagickFalse)
-                SetPixelAlpha(image,gamma_map[
-                  ScaleQuantumToMap(GetPixelAlpha(image,q))],q);
-              else
-                SetPixelAlpha(image,gamma_map[
-                  ScaleQuantumToMap(GetPixelAlpha(image,q))],q);
-            }
-        }
+      register ssize_t
+        i;
+
+      for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+      {
+        PixelTrait
+          traits;
+
+        traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
+        if ((traits & UpdatePixelTrait) != 0)
+          q[i]=gamma_map[ScaleQuantumToMap(q[i])];
+      }
       q+=GetPixelChannels(image);
     }
-    if (((channel & BlackChannel) != 0) &&
-        (image->colorspace == CMYKColorspace))
-      for (x=0; x < (ssize_t) image->columns; x++)
-        SetPixelBlack(image,gamma_map[ScaleQuantumToMap(
-          GetPixelBlack(image,q))],q);
     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
       status=MagickFalse;
     if (image->progress_monitor != (MagickProgressMonitor) NULL)
@@ -2203,7 +1876,7 @@ MagickExport MagickBooleanType GammaImageChannel(Image *image,
           proceed;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_GammaImageChannel)
+  #pragma omp critical (MagickCore_GammaImage)
 #endif
         proceed=SetImageProgress(image,GammaCorrectImageTag,progress++,
           image->rows);
@@ -2238,8 +1911,6 @@ MagickExport MagickBooleanType GammaImageChannel(Image *image,
 %  The format of the HaldClutImage method is:
 %
 %      MagickBooleanType HaldClutImage(Image *image,Image *hald_image)
-%      MagickBooleanType HaldClutImageChannel(Image *image,
-%        const ChannelType channel,Image *hald_image)
 %
 %  A description of each parameter follows:
 %
@@ -2247,8 +1918,6 @@ MagickExport MagickBooleanType GammaImageChannel(Image *image,
 %
 %    o hald_image: the color lookup table image for replacement color values.
 %
-%    o channel: the channel.
-%
 */
 
 static inline size_t MagickMin(const size_t x,const size_t y)
@@ -2260,12 +1929,6 @@ static inline size_t MagickMin(const size_t x,const size_t y)
 
 MagickExport MagickBooleanType HaldClutImage(Image *image,
   const Image *hald_image)
-{
-  return(HaldClutImageChannel(image,DefaultChannels,hald_image));
-}
-
-MagickExport MagickBooleanType HaldClutImageChannel(Image *image,
-  const ChannelType channel,const Image *hald_image)
 {
 #define HaldClutImageTag  "Clut/Image"
 
@@ -2310,10 +1973,11 @@ MagickExport MagickBooleanType HaldClutImageChannel(Image *image,
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(hald_image != (Image *) NULL);
   assert(hald_image->signature == MagickSignature);
-  if (SetImageStorageClass(image,DirectClass) == MagickFalse)
+  exception=(&image->exception);
+  if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
     return(MagickFalse);
   if (image->matte == MagickFalse)
-    (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
+    (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
   /*
     Hald clut image.
   */
@@ -2325,7 +1989,6 @@ MagickExport MagickBooleanType HaldClutImageChannel(Image *image,
   cube_size=level*level;
   width=(double) hald_image->columns;
   GetPixelInfo(hald_image,&zero);
-  exception=(&image->exception);
   image_view=AcquireCacheView(image);
   hald_view=AcquireCacheView(hald_image);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
@@ -2393,20 +2056,20 @@ MagickExport MagickBooleanType HaldClutImageChannel(Image *image,
         pixel2.alpha,point.y,&pixel4);
       CompositePixelInfoAreaBlend(&pixel3,pixel3.alpha,&pixel4,
         pixel4.alpha,point.z,&pixel);
-      if ((channel & RedChannel) != 0)
+      if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
         SetPixelRed(image,
           ClampToQuantum(pixel.red),q);
-      if ((channel & GreenChannel) != 0)
+      if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
         SetPixelGreen(image,
           ClampToQuantum(pixel.green),q);
-      if ((channel & BlueChannel) != 0)
+      if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
         SetPixelBlue(image,
           ClampToQuantum(pixel.blue),q);
-      if (((channel & BlackChannel) != 0) &&
+      if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
           (image->colorspace == CMYKColorspace))
         SetPixelBlack(image,
           ClampToQuantum(pixel.black),q);
-      if (((channel & OpacityChannel) != 0) && (image->matte != MagickFalse))
+      if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) && (image->matte != MagickFalse))
         SetPixelAlpha(image,
           ClampToQuantum(pixel.alpha),q);
       q+=GetPixelChannels(image);
@@ -2419,7 +2082,7 @@ MagickExport MagickBooleanType HaldClutImageChannel(Image *image,
           proceed;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_HaldClutImageChannel)
+  #pragma omp critical (MagickCore_HaldClutImage)
 #endif
         proceed=SetImageProgress(image,HaldClutImageTag,progress++,image->rows);
         if (proceed == MagickFalse)
@@ -2454,113 +2117,29 @@ MagickExport MagickBooleanType HaldClutImageChannel(Image *image,
 %
 %  If a '!' flag is given, map black and white colors to the given levels
 %  rather than mapping those levels to black and white.  See
-%  LevelizeImageChannel() and LevelizeImageChannel(), below.
+%  LevelizeImage() below.
 %
 %  Gamma specifies a gamma correction to apply to the image.
 %
 %  The format of the LevelImage method is:
 %
-%      MagickBooleanType LevelImage(Image *image,const char *levels)
-%
-%  A description of each parameter follows:
-%
-%    o image: the image.
-%
-%    o levels: Specify the levels where the black and white points have the
-%      range of 0-QuantumRange, and gamma has the range 0-10 (e.g. 10x90%+2).
-%      A '!' flag inverts the re-mapping.
-%
-*/
-
-MagickExport MagickBooleanType LevelImage(Image *image,const char *levels)
-{
-  double
-    black_point,
-    gamma,
-    white_point;
-
-  GeometryInfo
-    geometry_info;
-
-  MagickBooleanType
-    status;
-
-  MagickStatusType
-    flags;
-
-  /*
-    Parse levels.
-  */
-  if (levels == (char *) NULL)
-    return(MagickFalse);
-  flags=ParseGeometry(levels,&geometry_info);
-  black_point=geometry_info.rho;
-  white_point=(double) QuantumRange;
-  if ((flags & SigmaValue) != 0)
-    white_point=geometry_info.sigma;
-  gamma=1.0;
-  if ((flags & XiValue) != 0)
-    gamma=geometry_info.xi;
-  if ((flags & PercentValue) != 0)
-    {
-      black_point*=(double) image->columns*image->rows/100.0;
-      white_point*=(double) image->columns*image->rows/100.0;
-    }
-  if ((flags & SigmaValue) == 0)
-    white_point=(double) QuantumRange-black_point;
-  if ((flags & AspectValue ) == 0)
-    status=LevelImageChannel(image,DefaultChannels,black_point,white_point,
-      gamma);
-  else
-    status=LevelizeImage(image,black_point,white_point,gamma);
-  return(status);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%     L e v e l i z e I m a g e                                               %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  LevelizeImage() applies the normal level operation to the image, spreading
-%  out the values between the black and white points over the entire range of
-%  values.  Gamma correction is also applied after the values has been mapped.
-%
-%  It is typically used to improve image contrast, or to provide a controlled
-%  linear threshold for the image. If the black and white points are set to
-%  the minimum and maximum values found in the image, the image can be
-%  normalized.  or by swapping black and white values, negate the image.
-%
-%  The format of the LevelizeImage method is:
-%
-%      MagickBooleanType LevelizeImage(Image *image,const double black_point,
-%        const double white_point,const double gamma)
-%      MagickBooleanType LevelizeImageChannel(Image *image,
-%        const ChannelType channel,const double black_point,
-%        const double white_point,const double gamma)
+%      MagickBooleanType LevelImage(Image *image,const double black_point,
+%        const double white_point,const double gamma,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o image: the image.
 %
-%    o channel: the channel.
-%
-%    o black_point: The level which is to be mapped to zero (black)
+%    o black_point: The level to map zero (black) to.
 %
-%    o white_point: The level which is to be mapped to QuantiumRange (white)
+%    o white_point: The level to map QuantumRange (white) to.
 %
-%    o gamma: adjust gamma by this factor before mapping values.
-%             use 1.0 for purely linear stretching of image color values
+%    o exception: return any errors or warnings in this structure.
 %
 */
-MagickExport MagickBooleanType LevelImageChannel(Image *image,
-  const ChannelType channel,const double black_point,const double white_point,
-  const double gamma)
+MagickExport MagickBooleanType LevelImage(Image *image,
+  const double black_point,const double white_point,const double gamma,
+  ExceptionInfo *exception)
 {
 #define LevelImageTag  "Level/Image"
 #define LevelQuantum(x) (ClampToQuantum((MagickRealType) QuantumRange* \
@@ -2569,9 +2148,6 @@ MagickExport MagickBooleanType LevelImageChannel(Image *image,
   CacheView
     *image_view;
 
-  ExceptionInfo
-    *exception;
-
   MagickBooleanType
     status;
 
@@ -2604,13 +2180,13 @@ MagickExport MagickBooleanType LevelImageChannel(Image *image,
       /*
         Level colormap.
       */
-      if ((channel & RedChannel) != 0)
+      if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
         image->colormap[i].red=LevelQuantum(image->colormap[i].red);
-      if ((channel & GreenChannel) != 0)
+      if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
         image->colormap[i].green=LevelQuantum(image->colormap[i].green);
-      if ((channel & BlueChannel) != 0)
+      if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
         image->colormap[i].blue=LevelQuantum(image->colormap[i].blue);
-      if ((channel & OpacityChannel) != 0)
+      if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
         image->colormap[i].alpha=LevelQuantum(image->colormap[i].alpha);
       }
   /*
@@ -2618,7 +2194,6 @@ MagickExport MagickBooleanType LevelImageChannel(Image *image,
   */
   status=MagickTrue;
   progress=0;
-  exception=(&image->exception);
   image_view=AcquireCacheView(image);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
@@ -2641,23 +2216,18 @@ MagickExport MagickBooleanType LevelImageChannel(Image *image,
       }
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      if ((channel & RedChannel) != 0)
-        SetPixelRed(image,LevelQuantum(
-          GetPixelRed(image,q)),q);
-      if ((channel & GreenChannel) != 0)
-        SetPixelGreen(image,
-          LevelQuantum(GetPixelGreen(image,q)),q);
-      if ((channel & BlueChannel) != 0)
-        SetPixelBlue(image,
-          LevelQuantum(GetPixelBlue(image,q)),q);
-      if (((channel & OpacityChannel) != 0) &&
+      if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
+        SetPixelRed(image,LevelQuantum(GetPixelRed(image,q)),q);
+      if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
+        SetPixelGreen(image,LevelQuantum(GetPixelGreen(image,q)),q);
+      if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
+        SetPixelBlue(image,LevelQuantum(GetPixelBlue(image,q)),q);
+      if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
           (image->matte == MagickTrue))
-        SetPixelAlpha(image,
-          LevelQuantum(GetPixelAlpha(image,q)),q);
-      if (((channel & BlackChannel) != 0) &&
+        SetPixelAlpha(image,LevelQuantum(GetPixelAlpha(image,q)),q);
+      if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
           (image->colorspace == CMYKColorspace))
-        SetPixelBlack(image,
-          LevelQuantum(GetPixelBlack(image,q)),q);
+        SetPixelBlack(image,LevelQuantum(GetPixelBlack(image,q)),q);
       q+=GetPixelChannels(image);
     }
     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
@@ -2668,7 +2238,7 @@ MagickExport MagickBooleanType LevelImageChannel(Image *image,
           proceed;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_LevelImageChannel)
+  #pragma omp critical (MagickCore_LevelImage)
 #endif
         proceed=SetImageProgress(image,LevelImageTag,progress++,image->rows);
         if (proceed == MagickFalse)
@@ -2690,12 +2260,12 @@ MagickExport MagickBooleanType LevelImageChannel(Image *image,
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  LevelizeImageChannel() applies the reversed LevelImage() operation to just
+%  LevelizeImage() applies the reversed LevelImage() operation to just
 %  the specific channels specified.  It compresses the full range of color
 %  values, so that they lie between the given black and white points. Gamma is
 %  applied before the values are mapped.
 %
-%  LevelizeImageChannel() can be called with by using a +level command line
+%  LevelizeImage() can be called with by using a +level command line
 %  API option, or using a '!' on a -level or LevelImage() geometry string.
 %
 %  It can be used for example de-contrast a greyscale image to the exact
@@ -2703,43 +2273,28 @@ MagickExport MagickBooleanType LevelImageChannel(Image *image,
 %  you can convert a gray-scale image to any linear color gradient, according
 %  to those levels.
 %
-%  The format of the LevelizeImageChannel method is:
+%  The format of the LevelizeImage method is:
 %
-%      MagickBooleanType LevelizeImageChannel(Image *image,
-%        const ChannelType channel,const char *levels)
+%      MagickBooleanType LevelizeImage(Image *image,const double black_point,
+%        const double white_point,const double gamma)
 %
 %  A description of each parameter follows:
 %
 %    o image: the image.
 %
-%    o channel: the channel.
-%
 %    o black_point: The level to map zero (black) to.
 %
-%    o white_point: The level to map QuantiumRange (white) to.
+%    o white_point: The level to map QuantumRange (white) to.
 %
 %    o gamma: adjust gamma by this factor before mapping values.
 %
 */
-
 MagickExport MagickBooleanType LevelizeImage(Image *image,
   const double black_point,const double white_point,const double gamma)
-{
-  MagickBooleanType
-    status;
-
-  status=LevelizeImageChannel(image,DefaultChannels,black_point,white_point,
-    gamma);
-  return(status);
-}
-
-MagickExport MagickBooleanType LevelizeImageChannel(Image *image,
-  const ChannelType channel,const double black_point,const double white_point,
-  const double gamma)
 {
 #define LevelizeImageTag  "Levelize/Image"
 #define LevelizeValue(x) (ClampToQuantum(((MagickRealType) \
-  pow((double)(QuantumScale*(x)),1.0/gamma))*(white_point-black_point)+ \
+  pow((double) (QuantumScale*(x)),1.0/gamma))*(white_point-black_point)+ \
   black_point))
 
   CacheView
@@ -2776,13 +2331,13 @@ MagickExport MagickBooleanType LevelizeImageChannel(Image *image,
       /*
         Level colormap.
       */
-      if ((channel & RedChannel) != 0)
+      if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
         image->colormap[i].red=LevelizeValue(image->colormap[i].red);
-      if ((channel & GreenChannel) != 0)
+      if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
         image->colormap[i].green=LevelizeValue(image->colormap[i].green);
-      if ((channel & BlueChannel) != 0)
+      if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
         image->colormap[i].blue=LevelizeValue(image->colormap[i].blue);
-      if ((channel & OpacityChannel) != 0)
+      if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
         image->colormap[i].alpha=LevelizeValue(image->colormap[i].alpha);
     }
   /*
@@ -2813,16 +2368,16 @@ MagickExport MagickBooleanType LevelizeImageChannel(Image *image,
       }
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      if ((channel & RedChannel) != 0)
+      if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
         SetPixelRed(image,LevelizeValue(GetPixelRed(image,q)),q);
-      if ((channel & GreenChannel) != 0)
+      if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
         SetPixelGreen(image,LevelizeValue(GetPixelGreen(image,q)),q);
-      if ((channel & BlueChannel) != 0)
+      if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
         SetPixelBlue(image,LevelizeValue(GetPixelBlue(image,q)),q);
-      if (((channel & BlackChannel) != 0) &&
+      if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
           (image->colorspace == CMYKColorspace))
         SetPixelBlack(image,LevelizeValue(GetPixelBlack(image,q)),q);
-      if (((channel & OpacityChannel) != 0) &&
+      if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
           (image->matte == MagickTrue))
         SetPixelAlpha(image,LevelizeValue(GetPixelAlpha(image,q)),q);
       q+=GetPixelChannels(image);
@@ -2835,7 +2390,7 @@ MagickExport MagickBooleanType LevelizeImageChannel(Image *image,
           proceed;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_LevelizeImageChannel)
+  #pragma omp critical (MagickCore_LevelizeImage)
 #endif
         proceed=SetImageProgress(image,LevelizeImageTag,progress++,image->rows);
         if (proceed == MagickFalse)
@@ -2857,7 +2412,7 @@ MagickExport MagickBooleanType LevelizeImageChannel(Image *image,
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  LevelImageColor() maps the given color to "black" and "white" values,
+%  LevelImageColors() maps the given color to "black" and "white" values,
 %  linearly spreading out the colors, and level values on a channel by channel
 %  bases, as per LevelImage().  The given colors allows you to specify
 %  different level ranges for each of the color channels separately.
@@ -2868,21 +2423,16 @@ MagickExport MagickBooleanType LevelizeImageChannel(Image *image,
 %  appropriatally.  This effectivally maps a greyscale gradient into the given
 %  color gradient.
 %
-%  The format of the LevelColorsImageChannel method is:
+%  The format of the LevelImageColors method is:
 %
-%    MagickBooleanType LevelColorsImage(Image *image,
-%      const PixelInfo *black_color,
-%      const PixelInfo *white_color,const MagickBooleanType invert)
-%    MagickBooleanType LevelColorsImageChannel(Image *image,
-%      const ChannelType channel,const PixelInfo *black_color,
-%      const PixelInfo *white_color,const MagickBooleanType invert)
+%    MagickBooleanType LevelImageColors(Image *image,
+%      const PixelInfo *black_color,const PixelInfo *white_color,
+%      const MagickBooleanType invert)
 %
 %  A description of each parameter follows:
 %
 %    o image: the image.
 %
-%    o channel: the channel.
-%
 %    o black_color: The color to map black to/from
 %
 %    o white_point: The color to map white to/from
@@ -2890,23 +2440,13 @@ MagickExport MagickBooleanType LevelizeImageChannel(Image *image,
 %    o invert: if true map the colors (levelize), rather than from (level)
 %
 */
-
-MagickExport MagickBooleanType LevelColorsImage(Image *image,
+MagickExport MagickBooleanType LevelImageColors(Image *image,
   const PixelInfo *black_color,const PixelInfo *white_color,
   const MagickBooleanType invert)
 {
-  MagickBooleanType
-    status;
+  ChannelType
+    channel_mask;
 
-  status=LevelColorsImageChannel(image,DefaultChannels,black_color,white_color,
-    invert);
-  return(status);
-}
-
-MagickExport MagickBooleanType LevelColorsImageChannel(Image *image,
-  const ChannelType channel,const PixelInfo *black_color,
-  const PixelInfo *white_color,const MagickBooleanType invert)
-{
   MagickStatusType
     status;
 
@@ -2920,43 +2460,81 @@ MagickExport MagickBooleanType LevelColorsImageChannel(Image *image,
   status=MagickFalse;
   if (invert == MagickFalse)
     {
-      if ((channel & RedChannel) != 0)
-        status|=LevelImageChannel(image,RedChannel,
-          black_color->red,white_color->red,(double) 1.0);
-      if ((channel & GreenChannel) != 0)
-        status|=LevelImageChannel(image,GreenChannel,
-          black_color->green,white_color->green,(double) 1.0);
-      if ((channel & BlueChannel) != 0)
-        status|=LevelImageChannel(image,BlueChannel,
-          black_color->blue,white_color->blue,(double) 1.0);
-      if (((channel & BlackChannel) != 0) &&
+      if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
+        {
+          channel_mask=SetPixelChannelMask(image,RedChannel);
+          status|=LevelImage(image,black_color->red,white_color->red,1.0,
+            &image->exception);
+          (void) SetPixelChannelMask(image,channel_mask);
+        }
+      if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
+        {
+          channel_mask=SetPixelChannelMask(image,GreenChannel);
+          status|=LevelImage(image,black_color->green,white_color->green,1.0,
+            &image->exception);
+          (void) SetPixelChannelMask(image,channel_mask);
+        }
+      if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
+        {
+          channel_mask=SetPixelChannelMask(image,BlueChannel);
+          status|=LevelImage(image,black_color->blue,white_color->blue,1.0,
+            &image->exception);
+          (void) SetPixelChannelMask(image,channel_mask);
+        }
+      if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
           (image->colorspace == CMYKColorspace))
-        status|=LevelImageChannel(image,BlackChannel,
-          black_color->black,white_color->black,(double) 1.0);
-      if (((channel & OpacityChannel) != 0) &&
+        {
+          channel_mask=SetPixelChannelMask(image,BlackChannel);
+          status|=LevelImage(image,black_color->black,white_color->black,1.0,
+            &image->exception);
+          (void) SetPixelChannelMask(image,channel_mask);
+        }
+      if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
           (image->matte == MagickTrue))
-        status|=LevelImageChannel(image,OpacityChannel,
-          black_color->alpha,white_color->alpha,(double) 1.0);
+        {
+          channel_mask=SetPixelChannelMask(image,AlphaChannel);
+          status|=LevelImage(image,black_color->alpha,white_color->alpha,1.0,
+            &image->exception);
+          (void) SetPixelChannelMask(image,channel_mask);
+        }
     }
   else
     {
-      if ((channel & RedChannel) != 0)
-        status|=LevelizeImageChannel(image,RedChannel,
-          black_color->red,white_color->red,(double) 1.0);
-      if ((channel & GreenChannel) != 0)
-        status|=LevelizeImageChannel(image,GreenChannel,
-          black_color->green,white_color->green,(double) 1.0);
-      if ((channel & BlueChannel) != 0)
-        status|=LevelizeImageChannel(image,BlueChannel,
-          black_color->blue,white_color->blue,(double) 1.0);
-      if (((channel & BlackChannel) != 0) &&
+      if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
+        {
+          channel_mask=SetPixelChannelMask(image,RedChannel);
+          status|=LevelizeImage(image,black_color->red,white_color->red,1.0);
+          (void) SetPixelChannelMask(image,channel_mask);
+        }
+      if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
+        {
+          channel_mask=SetPixelChannelMask(image,GreenChannel);
+          status|=LevelizeImage(image,black_color->green,white_color->green,
+            1.0);
+          (void) SetPixelChannelMask(image,channel_mask);
+        }
+      if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
+        {
+          channel_mask=SetPixelChannelMask(image,BlueChannel);
+          status|=LevelizeImage(image,black_color->blue,white_color->blue,1.0);
+          (void) SetPixelChannelMask(image,channel_mask);
+        }
+      if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
           (image->colorspace == CMYKColorspace))
-        status|=LevelizeImageChannel(image,BlackChannel,
-          black_color->black,white_color->black,(double) 1.0);
-      if (((channel & OpacityChannel) != 0) &&
+        {
+          channel_mask=SetPixelChannelMask(image,BlackChannel);
+          status|=LevelizeImage(image,black_color->black,white_color->black,
+            1.0);
+          (void) SetPixelChannelMask(image,channel_mask);
+        }
+      if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
           (image->matte == MagickTrue))
-        status|=LevelizeImageChannel(image,OpacityChannel,
-          black_color->alpha,white_color->alpha,(double) 1.0);
+        {
+          channel_mask=SetPixelChannelMask(image,AlphaChannel);
+          status|=LevelizeImage(image,black_color->alpha,white_color->alpha,
+            1.0);
+          (void) SetPixelChannelMask(image,channel_mask);
+        }
     }
   return(status == 0 ? MagickFalse : MagickTrue);
 }
@@ -2972,8 +2550,8 @@ MagickExport MagickBooleanType LevelColorsImageChannel(Image *image,
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  The LinearStretchImage() discards any pixels below the black point and
-%  above the white point and levels the remaining pixels.
+%  LinearStretchImage() discards any pixels below the black point and above
+%  the white point and levels the remaining pixels.
 %
 %  The format of the LinearStretchImage method is:
 %
@@ -3059,8 +2637,7 @@ MagickExport MagickBooleanType LinearStretchImage(Image *image,
       break;
   }
   histogram=(MagickRealType *) RelinquishMagickMemory(histogram);
-  status=LevelImageChannel(image,DefaultChannels,(double) black,(double) white,
-    1.0);
+  status=LevelImage(image,(double) black,(double) white,1.0,&image->exception);
   return(status);
 }
 \f
@@ -3362,44 +2939,28 @@ MagickExport MagickBooleanType ModulateImage(Image *image,const char *modulate)
 %  NegateImage() negates the colors in the reference image.  The grayscale
 %  option means that only grayscale values within the image are negated.
 %
-%  The format of the NegateImageChannel method is:
+%  The format of the NegateImage method is:
 %
 %      MagickBooleanType NegateImage(Image *image,
-%        const MagickBooleanType grayscale)
-%      MagickBooleanType NegateImageChannel(Image *image,
-%        const ChannelType channel,const MagickBooleanType grayscale)
+%        const MagickBooleanType grayscale,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o image: the image.
 %
-%    o channel: the channel.
-%
 %    o grayscale: If MagickTrue, only negate grayscale pixels within the image.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
-
 MagickExport MagickBooleanType NegateImage(Image *image,
-  const MagickBooleanType grayscale)
-{
-  MagickBooleanType
-    status;
-
-  status=NegateImageChannel(image,DefaultChannels,grayscale);
-  return(status);
-}
-
-MagickExport MagickBooleanType NegateImageChannel(Image *image,
-  const ChannelType channel,const MagickBooleanType grayscale)
+  const MagickBooleanType grayscale,ExceptionInfo *exception)
 {
 #define NegateImageTag  "Negate/Image"
 
   CacheView
     *image_view;
 
-  ExceptionInfo
-    *exception;
-
   MagickBooleanType
     status;
 
@@ -3430,13 +2991,13 @@ MagickExport MagickBooleanType NegateImageChannel(Image *image,
           if ((image->colormap[i].red != image->colormap[i].green) ||
               (image->colormap[i].green != image->colormap[i].blue))
             continue;
-        if ((channel & RedChannel) != 0)
+        if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
           image->colormap[i].red=(Quantum) QuantumRange-
             image->colormap[i].red;
-        if ((channel & GreenChannel) != 0)
+        if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
           image->colormap[i].green=(Quantum) QuantumRange-
             image->colormap[i].green;
-        if ((channel & BlueChannel) != 0)
+        if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
           image->colormap[i].blue=(Quantum) QuantumRange-
             image->colormap[i].blue;
       }
@@ -3446,7 +3007,6 @@ MagickExport MagickBooleanType NegateImageChannel(Image *image,
   */
   status=MagickTrue;
   progress=0;
-  exception=(&image->exception);
   image_view=AcquireCacheView(image);
   if (grayscale != MagickFalse)
     {
@@ -3475,23 +3035,23 @@ MagickExport MagickBooleanType NegateImageChannel(Image *image,
           }
         for (x=0; x < (ssize_t) image->columns; x++)
         {
-          if ((GetPixelRed(image,q) != GetPixelGreen(image,q)) ||
-              (GetPixelGreen(image,q) != GetPixelBlue(image,q)))
+          register ssize_t
+            i;
+
+          if (IsPixelGray(image,q) != MagickFalse)
             {
               q+=GetPixelChannels(image);
               continue;
             }
-          if ((channel & RedChannel) != 0)
-            SetPixelRed(image,QuantumRange-GetPixelRed(image,q),q);
-          if ((channel & GreenChannel) != 0)
-            SetPixelGreen(image,QuantumRange-GetPixelGreen(image,q),q);
-          if ((channel & BlueChannel) != 0)
-            SetPixelBlue(image,QuantumRange-GetPixelBlue(image,q),q);
-          if (((channel & BlackChannel) != 0) &&
-              (image->colorspace == CMYKColorspace))
-            SetPixelBlack(image,QuantumRange-GetPixelBlack(image,q),q);
-          if ((channel & OpacityChannel) != 0)
-            SetPixelAlpha(image,QuantumRange-GetPixelAlpha(image,q),q);
+          for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+          {
+            PixelTrait 
+              traits;
+
+            traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
+            if ((traits & UpdatePixelTrait) != 0)
+              q[i]=QuantumRange-q[i];
+          }
           q+=GetPixelChannels(image);
         }
         sync=SyncCacheViewAuthenticPixels(image_view,exception);
@@ -3503,7 +3063,7 @@ MagickExport MagickBooleanType NegateImageChannel(Image *image,
               proceed;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_NegateImageChannel)
+  #pragma omp critical (MagickCore_NegateImage)
 #endif
             proceed=SetImageProgress(image,NegateImageTag,progress++,
               image->rows);
@@ -3538,17 +3098,18 @@ MagickExport MagickBooleanType NegateImageChannel(Image *image,
       }
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      if ((channel & RedChannel) != 0)
-        SetPixelRed(image,QuantumRange-GetPixelRed(image,q),q);
-      if ((channel & GreenChannel) != 0)
-        SetPixelGreen(image,QuantumRange-GetPixelGreen(image,q),q);
-      if ((channel & BlueChannel) != 0)
-        SetPixelBlue(image,QuantumRange-GetPixelBlue(image,q),q);
-      if (((channel & BlackChannel) != 0) &&
-          (image->colorspace == CMYKColorspace))
-        SetPixelBlack(image,QuantumRange-GetPixelBlack(image,q),q);
-      if ((channel & OpacityChannel) != 0)
-        SetPixelAlpha(image,QuantumRange-GetPixelAlpha(image,q),q);
+      register ssize_t
+        i;
+
+      for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+      {
+        PixelTrait 
+          traits;
+
+        traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
+        if ((traits & UpdatePixelTrait) != 0)
+          q[i]=QuantumRange-q[i];
+      }
       q+=GetPixelChannels(image);
     }
     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
@@ -3559,7 +3120,7 @@ MagickExport MagickBooleanType NegateImageChannel(Image *image,
           proceed;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_NegateImageChannel)
+  #pragma omp critical (MagickCore_NegateImage)
 #endif
         proceed=SetImageProgress(image,NegateImageTag,progress++,image->rows);
         if (proceed == MagickFalse)
@@ -3581,35 +3142,22 @@ MagickExport MagickBooleanType NegateImageChannel(Image *image,
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  The NormalizeImage() method enhances the contrast of a color image by
-%  mapping the darkest 2 percent of all pixel to black and the brightest
-%  1 percent to white.
+%  NormalizeImage() enhances the contrast of a color image by mapping the
+%  darkest 2 percent of all pixel to black and the brightest 1 percent to white.
 %
 %  The format of the NormalizeImage method is:
 %
-%      MagickBooleanType NormalizeImage(Image *image)
-%      MagickBooleanType NormalizeImageChannel(Image *image,
-%        const ChannelType channel)
+%      MagickBooleanType NormalizeImage(Image *image,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o image: the image.
 %
-%    o channel: the channel.
+%    o exception: return any errors or warnings in this structure.
 %
 */
-
-MagickExport MagickBooleanType NormalizeImage(Image *image)
-{
-  MagickBooleanType
-    status;
-
-  status=NormalizeImageChannel(image,DefaultChannels);
-  return(status);
-}
-
-MagickExport MagickBooleanType NormalizeImageChannel(Image *image,
-  const ChannelType channel)
+MagickExport MagickBooleanType NormalizeImage(Image *image,
+  ExceptionInfo *exception)
 {
   double
     black_point,
@@ -3617,7 +3165,7 @@ MagickExport MagickBooleanType NormalizeImageChannel(Image *image,
 
   black_point=(double) image->columns*image->rows*0.0015;
   white_point=(double) image->columns*image->rows*0.9995;
-  return(ContrastStretchImageChannel(image,channel,black_point,white_point));
+  return(ContrastStretchImage(image,black_point,white_point,exception));
 }
 \f
 /*
@@ -3644,16 +3192,11 @@ MagickExport MagickBooleanType NormalizeImageChannel(Image *image,
 %
 %      MagickBooleanType SigmoidalContrastImage(Image *image,
 %        const MagickBooleanType sharpen,const char *levels)
-%      MagickBooleanType SigmoidalContrastImageChannel(Image *image,
-%        const ChannelType channel,const MagickBooleanType sharpen,
-%        const double contrast,const double midpoint)
 %
 %  A description of each parameter follows:
 %
 %    o image: the image.
 %
-%    o channel: the channel.
-%
 %    o sharpen: Increase or decrease image contrast.
 %
 %    o alpha: strength of the contrast, the larger the number the more
@@ -3662,32 +3205,8 @@ MagickExport MagickBooleanType NormalizeImageChannel(Image *image,
 %    o beta: midpoint of the function as a color value 0 to QuantumRange.
 %
 */
-
 MagickExport MagickBooleanType SigmoidalContrastImage(Image *image,
-  const MagickBooleanType sharpen,const char *levels)
-{
-  GeometryInfo
-    geometry_info;
-
-  MagickBooleanType
-    status;
-
-  MagickStatusType
-    flags;
-
-  flags=ParseGeometry(levels,&geometry_info);
-  if ((flags & SigmaValue) == 0)
-    geometry_info.sigma=1.0*QuantumRange/2.0;
-  if ((flags & PercentValue) != 0)
-    geometry_info.sigma=1.0*QuantumRange*geometry_info.sigma/100.0;
-  status=SigmoidalContrastImageChannel(image,DefaultChannels,sharpen,
-    geometry_info.rho,geometry_info.sigma);
-  return(status);
-}
-
-MagickExport MagickBooleanType SigmoidalContrastImageChannel(Image *image,
-  const ChannelType channel,const MagickBooleanType sharpen,
-  const double contrast,const double midpoint)
+  const MagickBooleanType sharpen,const double contrast,const double midpoint)
 {
 #define SigmoidalContrastImageTag  "SigmoidalContrast/Image"
 
@@ -3760,16 +3279,16 @@ MagickExport MagickBooleanType SigmoidalContrastImageChannel(Image *image,
 #endif
       for (i=0; i < (ssize_t) image->colors; i++)
       {
-        if ((channel & RedChannel) != 0)
+        if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
           image->colormap[i].red=ClampToQuantum(sigmoidal_map[
             ScaleQuantumToMap(image->colormap[i].red)]);
-        if ((channel & GreenChannel) != 0)
+        if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
           image->colormap[i].green=ClampToQuantum(sigmoidal_map[
             ScaleQuantumToMap(image->colormap[i].green)]);
-        if ((channel & BlueChannel) != 0)
+        if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
           image->colormap[i].blue=ClampToQuantum(sigmoidal_map[
             ScaleQuantumToMap(image->colormap[i].blue)]);
-        if ((channel & OpacityChannel) != 0)
+        if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
           image->colormap[i].alpha=ClampToQuantum(sigmoidal_map[
             ScaleQuantumToMap(image->colormap[i].alpha)]);
       }
@@ -3802,20 +3321,20 @@ MagickExport MagickBooleanType SigmoidalContrastImageChannel(Image *image,
       }
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      if ((channel & RedChannel) != 0)
+      if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
         SetPixelRed(image,ClampToQuantum(sigmoidal_map[ScaleQuantumToMap(
           GetPixelRed(image,q))]),q);
-      if ((channel & GreenChannel) != 0)
+      if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
         SetPixelGreen(image,ClampToQuantum(sigmoidal_map[ScaleQuantumToMap(
           GetPixelGreen(image,q))]),q);
-      if ((channel & BlueChannel) != 0)
+      if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
         SetPixelBlue(image,ClampToQuantum(sigmoidal_map[ScaleQuantumToMap(
           GetPixelBlue(image,q))]),q);
-      if (((channel & BlackChannel) != 0) &&
+      if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
           (image->colorspace == CMYKColorspace))
         SetPixelBlack(image,ClampToQuantum(sigmoidal_map[ScaleQuantumToMap(
           GetPixelBlack(image,q))]),q);
-      if ((channel & OpacityChannel) != 0)
+      if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
         SetPixelAlpha(image,ClampToQuantum(sigmoidal_map[ScaleQuantumToMap(
           GetPixelAlpha(image,q))]),q);
       q+=GetPixelChannels(image);
@@ -3828,7 +3347,7 @@ MagickExport MagickBooleanType SigmoidalContrastImageChannel(Image *image,
           proceed;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_SigmoidalContrastImageChannel)
+  #pragma omp critical (MagickCore_SigmoidalContrastImage)
 #endif
         proceed=SetImageProgress(image,SigmoidalContrastImageTag,progress++,
           image->rows);