]> granicus.if.org Git - imagemagick/blobdiff - Magick++/lib/Image.cpp
(no commit message)
[imagemagick] / Magick++ / lib / Image.cpp
index 203ec963b6c1fb3392b19189d596340038691999..4daa9c0b2f42fab402679384d67afda74ba735a9 100644 (file)
@@ -8,12 +8,12 @@
 #define MAGICKCORE_IMPLEMENTATION  1
 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
 
+#include "Magick++/Include.h"
 #include <cstdlib>
 #include <string>
 #include <string.h>
 #include <errno.h>
 #include <math.h>
-#include "Magick++/Include.h"
 
 using namespace std;
 
@@ -300,7 +300,7 @@ void Magick::Image::adaptiveBlur( const double radius_, const double sigma_ )
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
   MagickCore::Image* newImage =
-    AdaptiveBlurImage( image(), radius_, sigma_, image()->bias, &exceptionInfo);
+    AdaptiveBlurImage( image(), radius_, sigma_, &exceptionInfo);
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -342,12 +342,12 @@ void Magick::Image::addNoiseChannel( const ChannelType channel_,
 {
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
-  ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
+  ChannelType channel_mask = SetImageChannelMask( image(), channel_);
   MagickCore::Image* newImage =
     AddNoiseImage ( image(),
                            noiseType_, 1.0,
                            &exceptionInfo );
-  (void) SetPixelChannelMap( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -487,7 +487,7 @@ void Magick::Image::blur( const double radius_, const double sigma_ )
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
   MagickCore::Image* newImage =
-    BlurImage( image(), radius_, sigma_, image()->bias, &exceptionInfo);
+    BlurImage( image(), radius_, sigma_, &exceptionInfo);
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -498,10 +498,10 @@ void Magick::Image::blurChannel( const ChannelType channel_,
 {
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
-  ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
+  ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
   MagickCore::Image* newImage =
-    BlurImage( image(), radius_, sigma_, image()->bias, &exceptionInfo);
-  (void) SetPixelChannelMap( image(), channel_mask );
+    BlurImage( image(), radius_, sigma_, &exceptionInfo);
+  (void) SetPixelChannelMask( image(), channel_mask );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -525,21 +525,24 @@ void Magick::Image::border( const Geometry &geometry_ )
 void Magick::Image::channel ( const ChannelType channel_ )
 {
   modifyImage();
-  ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
-  SeparateImage ( image(), &exceptionInfo );
+  MagickCore::Image* newImage =
+    SeparateImage( image(), channel_, &exceptionInfo);
+  replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
-  (void) SetPixelChannelMap( image(), channel_mask );
 }
 
 // Set or obtain modulus channel depth
 void Magick::Image::channelDepth ( const size_t depth_ )
 {
   modifyImage();
-  SetImageDepth( image(), depth_);
-  throwImageException();
+  ExceptionInfo exceptionInfo;
+  GetExceptionInfo( &exceptionInfo );
+  SetImageDepth( image(), depth_, &exceptionInfo);
+  throwException( exceptionInfo );
+  (void) DestroyExceptionInfo( &exceptionInfo );
 }
 size_t Magick::Image::channelDepth ( )
 {
@@ -560,7 +563,7 @@ void Magick::Image::charcoal( const double radius_, const double sigma_ )
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
   MagickCore::Image* newImage =
-    CharcoalImage( image(), radius_, sigma_, image()->bias, &exceptionInfo );
+    CharcoalImage( image(), radius_, sigma_, &exceptionInfo );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -640,12 +643,17 @@ void Magick::Image::colorMatrix (const size_t order_,
   kernel_info=AcquireKernelInfo((const char *) NULL);
   kernel_info->width=order_;
   kernel_info->height=order_;
-  kernel_info->values=(double *) color_matrix_;
-  MagickCore::Image* newImage =
-    ColorMatrixImage( image(), kernel_info, &exceptionInfo );
-  kernel_info->values=(double *) NULL;
+  kernel_info->values=(MagickRealType *)  AcquireAlignedMemory(order_,
+    order_*sizeof(*kernel_info->values));
+  if (kernel_info->values != (MagickRealType *) NULL)
+    {
+      for (ssize_t i=0; i < (order_*order_); i++)
+        kernel_info->values[i]=color_matrix_[i];
+      MagickCore::Image* newImage =
+        ColorMatrixImage( image(), kernel_info, &exceptionInfo );
+      replaceImage( newImage );
+    }
   kernel_info=DestroyKernelInfo(kernel_info);
-  replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
 }
@@ -680,8 +688,8 @@ void Magick::Image::composite ( const Image &compositeImage_,
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
   CompositeImage( image(),
-                 compose_,
                  compositeImage_.constImage(),
+                 compose_, MagickFalse,
                  xOffset_,
                   yOffset_, &exceptionInfo );
   throwException( exceptionInfo );
@@ -705,8 +713,8 @@ void Magick::Image::composite ( const Image &compositeImage_,
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
   CompositeImage( image(),
-                 compose_,
                  compositeImage_.constImage(),
+                 compose_, MagickFalse,
                  x, y, &exceptionInfo );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -725,8 +733,8 @@ void Magick::Image::composite ( const Image &compositeImage_,
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
   CompositeImage( image(),
-                 compose_,
                  compositeImage_.constImage(),
+                 compose_, MagickFalse,
                  geometry.x, geometry.y, &exceptionInfo );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -757,13 +765,17 @@ void Magick::Image::convolve ( const size_t order_,
   kernel_info=AcquireKernelInfo((const char *) NULL);
   kernel_info->width=order_;
   kernel_info->height=order_;
-  kernel_info->values=(double *) kernel_;
-  kernel_info->bias=image()->bias;
-  MagickCore::Image* newImage =
-    ConvolveImage ( image(), kernel_info, &exceptionInfo );
-  kernel_info->values=(double *) NULL;
+  kernel_info->values=(MagickRealType *)  AcquireAlignedMemory(order_,
+    order_*sizeof(*kernel_info->values));
+  if (kernel_info->values != (MagickRealType *) NULL)
+    {
+      for (ssize_t i=0; i < (order_*order_); i++)
+        kernel_info->values[i]=kernel_[i];
+      MagickCore::Image* newImage =
+        ConvolveImage ( image(), kernel_info, &exceptionInfo );
+      replaceImage( newImage );
+    }
   kernel_info=DestroyKernelInfo(kernel_info);
-  replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
 }
@@ -846,8 +858,7 @@ void Magick::Image::draw ( const Magick::Drawable &drawable_ )
     {
       drawable_.operator()(wand);
 
-      if( constImage()->exception.severity == UndefinedException)
-        DrawRender(wand);
+      DrawRender(wand);
 
       wand=DestroyDrawingWand(wand);
     }
@@ -868,12 +879,9 @@ void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
            p != drawable_.end(); p++ )
         {
           p->operator()(wand);
-          if( constImage()->exception.severity != UndefinedException)
-            break;
         }
 
-      if( constImage()->exception.severity == UndefinedException)
-        DrawRender(wand);
+      DrawRender(wand);
 
       wand=DestroyDrawingWand(wand);
     }
@@ -925,24 +933,30 @@ void Magick::Image::equalize ( void )
   modifyImage();
   EqualizeImage( image(), &exceptionInfo );
   throwException( exceptionInfo );
+  (void) DestroyExceptionInfo( &exceptionInfo );
 }
 
 // Erase image to current "background color"
 void Magick::Image::erase ( void )
 {
   modifyImage();
-  SetImageBackgroundColor( image() );
-  throwImageException();
+  ExceptionInfo exceptionInfo;
+  GetExceptionInfo( &exceptionInfo );
+  SetImageBackgroundColor( image(), &exceptionInfo );
+  throwException( exceptionInfo );
+  (void) DestroyExceptionInfo( &exceptionInfo );
 }
 
 // Extends image as defined by the geometry.
 //
 void Magick::Image::extent ( const Geometry &geometry_ )
 {
-  RectangleInfo extentInfo = geometry_;
   modifyImage();
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
+  RectangleInfo extentInfo = geometry_;
+  extentInfo.x = geometry_.xOff();
+  extentInfo.y = geometry_.yOff();
   MagickCore::Image* newImage =
     ExtentImage ( image(), &extentInfo, &exceptionInfo );
   replaceImage( newImage );
@@ -956,14 +970,18 @@ void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundC
 }
 void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ )
 {
-  image()->gravity  = gravity_;
-  extent ( geometry_ );
+  RectangleInfo geometry;
+
+  SetGeometry(image(), &geometry);
+  geometry.width = geometry_.width();
+  geometry.height = geometry_.height();
+  GravityAdjustGeometry(image()->columns, image()->rows, gravity_, &geometry);
+  extent ( geometry );
 }
 void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ )
 {
-  image()->gravity  = gravity_;
   backgroundColor ( backgroundColor_ );
-  extent ( geometry_ );
+  extent ( geometry_, gravity_ );
 }
 
 // Flip image (reflect each scanline in the vertical direction)
@@ -1186,10 +1204,10 @@ void Magick::Image::fx ( const std::string expression,
 {
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
-  ChannelType channel_mask = SetPixelChannelMask( image(), channel );
+  ChannelType channel_mask = SetImageChannelMask( image(), channel );
   MagickCore::Image* newImage =
     FxImage ( image(), expression.c_str(), &exceptionInfo );
-  (void) SetPixelChannelMap( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -1231,7 +1249,7 @@ void Magick::Image::gaussianBlur ( const double width_, const double sigma_ )
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
   MagickCore::Image* newImage =
-    GaussianBlurImage( image(), width_, sigma_, image()->bias, &exceptionInfo );
+    GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -1243,10 +1261,10 @@ void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
 {
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
-  ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
+  ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
   MagickCore::Image* newImage =
-    GaussianBlurImage( image(), width_, sigma_, image()->bias, &exceptionInfo );
-  (void) SetPixelChannelMap( image(), channel_mask );
+    GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
+  (void) SetPixelChannelMask( image(), channel_mask );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -1359,12 +1377,12 @@ void Magick::Image::matteFloodfill ( const Color &target_ ,
   target.green=static_cast<PixelInfo>(target_).green;
   target.blue=static_cast<PixelInfo>(target_).blue;
   target.alpha=alpha_;
-  ChannelType channel_mask = SetPixelChannelMask( image(), AlphaChannel );
+  ChannelType channel_mask = SetImageChannelMask( image(), AlphaChannel );
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
   FloodfillPaintImage ( image(), options()->drawInfo(), &target, x_, y_,
     method_ == FloodfillMethod ? MagickFalse : MagickTrue, &exceptionInfo);
-  (void) SetPixelChannelMap( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
 }
@@ -1383,6 +1401,20 @@ void Magick::Image::medianFilter ( const double radius_ )
   (void) DestroyExceptionInfo( &exceptionInfo );
 }
 
+// Merge layers
+void Magick::Image::mergeLayers( const LayerMethod layerMethod_ )
+{
+  ExceptionInfo exceptionInfo;
+  GetExceptionInfo( &exceptionInfo );
+  MagickCore::Image* newImage =
+    MergeImageLayers ( image(),
+        layerMethod_,
+        &exceptionInfo );
+  replaceImage( newImage );
+  throwException( exceptionInfo );
+  (void) DestroyExceptionInfo( &exceptionInfo );
+}
+
 // Reduce image by integral size
 void Magick::Image::minify ( void )
 {
@@ -1425,7 +1457,7 @@ void            Magick::Image::motionBlur ( const double radius_,
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
   MagickCore::Image* newImage =
-    MotionBlurImage( image(), radius_, sigma_, angle_, 0.0, &exceptionInfo);
+    MotionBlurImage( image(), radius_, sigma_, angle_, &exceptionInfo);
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -1554,12 +1586,14 @@ void Magick::Image::process( std::string name_, const ssize_t argc, const char *
 {
   modifyImage();
 
+  ExceptionInfo exceptionInfo;
+  GetExceptionInfo( &exceptionInfo );
   size_t status = 
     InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
-      &image()->exception );
-
-  if (status == false)
-    throwException( image()->exception );
+      &exceptionInfo );
+  (void) status;
+  throwException( exceptionInfo );
+  (void) DestroyExceptionInfo( &exceptionInfo );
 }
 
 // Quantize colors in image using current quantization settings
@@ -1588,9 +1622,9 @@ void Magick::Image::quantumOperator ( const ChannelType channel_,
 {
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
-  ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
+  ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
   EvaluateImage( image(), operator_, rvalue_, &exceptionInfo);
-  (void) SetPixelChannelMap( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
 }
@@ -1611,11 +1645,11 @@ void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
   geometry.y = y_;
   MagickCore::Image *crop_image = CropImage( image(), &geometry,
     &exceptionInfo );
-  ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
+  ChannelType channel_mask = SetImageChannelMask( image(), channel_);
   EvaluateImage( crop_image, operator_, rvalue_, &exceptionInfo );
-  (void) SetPixelChannelMap( image(), channel_mask );
-  (void) CompositeImage( image(), image()->matte != MagickFalse ?
-    OverCompositeOp : CopyCompositeOp, crop_image, geometry.x, geometry.y,
+  (void) SetPixelChannelMask( image(), channel_mask );
+  (void) CompositeImage( image(), crop_image, image()->alpha_trait == BlendPixelTrait ?
+    OverCompositeOp : CopyCompositeOp, MagickFalse, geometry.x, geometry.y,
     &exceptionInfo );
   crop_image = DestroyImageList(crop_image);
   throwException( exceptionInfo );
@@ -1657,11 +1691,11 @@ void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
   modifyImage();
-  ChannelType channel_mask = SetPixelChannelMask( image(), channel_);
+  ChannelType channel_mask = SetImageChannelMask( image(), channel_);
   (void) RandomThresholdImage( image(),
                                       static_cast<std::string>(thresholds_).c_str(),
                                       &exceptionInfo );
-  (void) SetPixelChannelMap( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   throwImageException();
   (void) DestroyExceptionInfo( &exceptionInfo );
 }
@@ -1688,8 +1722,6 @@ void Magick::Image::read ( const std::string &imageSpec_ )
     }
   replaceImage( image );
   throwException( exceptionInfo );
-  if ( image )
-    throwException( image->exception );
   (void) DestroyExceptionInfo( &exceptionInfo );
 }
 
@@ -1712,8 +1744,6 @@ void Magick::Image::read ( const Blob &blob_ )
                 blob_.length(), &exceptionInfo );
   replaceImage( image );
   throwException( exceptionInfo );
-  if ( image )
-    throwException( image->exception );
   (void) DestroyExceptionInfo( &exceptionInfo );
 }
 
@@ -1787,8 +1817,6 @@ void Magick::Image::read ( const size_t width_,
                      &exceptionInfo );
   replaceImage( image );
   throwException( exceptionInfo );
-  if ( image )
-    throwException( image->exception );
   (void) DestroyExceptionInfo( &exceptionInfo );
 }
 
@@ -1826,7 +1854,6 @@ void Magick::Image::resize( const Geometry &geometry_ )
                width,
                height,
                image()->filter,
-               1.0,
                &exceptionInfo);
   replaceImage( newImage );
   throwException( exceptionInfo );
@@ -1933,9 +1960,9 @@ void Magick::Image::segment ( const double clusterThreshold_,
                 (MagickBooleanType) options()->verbose(),
                 clusterThreshold_,
                 smoothingThreshold_, &exceptionInfo );
+  SyncImage( image(), &exceptionInfo );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
-  SyncImage( image() );
 }
 
 // Shade image using distant light source
@@ -1956,6 +1983,19 @@ void Magick::Image::shade ( const double azimuth_,
   (void) DestroyExceptionInfo( &exceptionInfo );
 }
 
+// Simulate an image shadow
+void Magick::Image::shadow( const double percent_opacity_, const double sigma_,
+  const ssize_t x_, const ssize_t y_ )
+{
+  ExceptionInfo exceptionInfo;
+  GetExceptionInfo( &exceptionInfo );
+  MagickCore::Image* newImage = ShadowImage( image(), percent_opacity_, sigma_,
+    x_, y_, &exceptionInfo );
+  replaceImage( newImage );
+  throwException( exceptionInfo );
+  (void) DestroyExceptionInfo( &exceptionInfo );
+}
+
 // Sharpen pixels in image
 void Magick::Image::sharpen ( const double radius_, const double sigma_ )
 {
@@ -1965,7 +2005,6 @@ void Magick::Image::sharpen ( const double radius_, const double sigma_ )
     SharpenImage( image(),
                   radius_,
                   sigma_,
-                  image()->bias,
                   &exceptionInfo );
   replaceImage( newImage );
   throwException( exceptionInfo );
@@ -1977,14 +2016,13 @@ void Magick::Image::sharpenChannel ( const ChannelType channel_,
 {
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
-  ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
+  ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
   MagickCore::Image* newImage =
     SharpenImage( image(),
                          radius_,
                          sigma_,
-                  image()->bias,
                          &exceptionInfo );
-  (void) SetPixelChannelMap( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -2055,10 +2093,10 @@ void Magick::Image::sparseColor ( const ChannelType channel,
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
 
-  ChannelType channel_mask = SetPixelChannelMask( image(), channel );
+  ChannelType channel_mask = SetImageChannelMask( image(), channel );
   MagickCore::Image* newImage = SparseColorImage ( image(), method,
     number_arguments, arguments, &exceptionInfo );
-  (void) SetPixelChannelMap( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -2178,10 +2216,10 @@ void Magick::Image::transparent ( const Color &color_ )
   std::string color = color_;
 
   PixelInfo target;
-  (void) QueryColorCompliance(std::string(color_).c_str(),AllCompliance,
-    &target,&image()->exception);
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
+  (void) QueryColorCompliance(std::string(color_).c_str(),AllCompliance,
+    &target,&exceptionInfo);
   modifyImage();
   TransparentPaintImage ( image(), &target, TransparentAlpha, MagickFalse,
     &exceptionInfo );
@@ -2204,12 +2242,12 @@ void Magick::Image::transparentChroma(const Color &colorLow_,
 
   PixelInfo targetLow;
   PixelInfo targetHigh;
-  (void) QueryColorCompliance(std::string(colorLow_).c_str(),
-    AllCompliance,&targetLow,&image()->exception);
-  (void) QueryColorCompliance(std::string(colorHigh_).c_str(),
-    AllCompliance,&targetHigh,&image()->exception);
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
+  (void) QueryColorCompliance(std::string(colorLow_).c_str(),
+    AllCompliance,&targetLow,&exceptionInfo);
+  (void) QueryColorCompliance(std::string(colorHigh_).c_str(),
+    AllCompliance,&targetHigh,&exceptionInfo);
   modifyImage();
   TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
     TransparentAlpha, MagickFalse, &exceptionInfo );
@@ -2269,7 +2307,7 @@ void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
 {
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
-  ChannelType channel_mask = SetPixelChannelMask( image(), channel_ );
+  ChannelType channel_mask = SetImageChannelMask( image(), channel_ );
   MagickCore::Image* newImage =
     UnsharpMaskImage( image(),
                              radius_,
@@ -2277,7 +2315,7 @@ void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
                              amount_,
                              threshold_,
                              &exceptionInfo );
-  (void) SetPixelChannelMap( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -2318,7 +2356,7 @@ void Magick::Image::write ( Blob *blob_ )
   size_t length = 2048; // Efficient size for small images
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
-  void* data = ImageToBlob( imageInfo(),
+  void* data = ImagesToBlob( imageInfo(),
                            image(),
                            &length,
                            &exceptionInfo);
@@ -2335,7 +2373,7 @@ void Magick::Image::write ( Blob *blob_,
   size_t length = 2048; // Efficient size for small images
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
-  void* data = ImageToBlob( imageInfo(),
+  void* data = ImagesToBlob( imageInfo(),
                            image(),
                            &length,
                            &exceptionInfo);
@@ -2354,7 +2392,7 @@ void Magick::Image::write ( Blob *blob_,
   size_t length = 2048; // Efficient size for small images
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
-  void* data = ImageToBlob( imageInfo(),
+  void* data = ImagesToBlob( imageInfo(),
                            image(),
                            &length,
                            &exceptionInfo);
@@ -2405,7 +2443,6 @@ void Magick::Image::zoom( const Geometry &geometry_ )
                width,
                height,
                image()->filter,
-               image()->blur,
                &exceptionInfo);
   replaceImage( newImage );
   throwException( exceptionInfo );
@@ -2647,7 +2684,11 @@ void Magick::Image::classType ( const ClassType class_ )
       // Use SyncImage to synchronize the DirectClass pixels with the
       // color map and then set to DirectClass type.
       modifyImage();
-      SyncImage( image() );
+      ExceptionInfo exceptionInfo;
+      GetExceptionInfo( &exceptionInfo );
+      SyncImage( image(), &exceptionInfo );
+      throwException( exceptionInfo );
+      (void) DestroyExceptionInfo( &exceptionInfo );
       image()->colormap = (PixelInfo *)
         RelinquishMagickMemory( image()->colormap );
       image()->storage_class = static_cast<MagickCore::ClassType>(DirectClass);
@@ -2676,12 +2717,12 @@ void Magick::Image::clipMask ( const Magick::Image & clipMask_ )
   if( clipMask_.isValid() )
     {
       // Set clip mask
-      SetImageClipMask( image(), clipMask_.constImage(), &exceptionInfo );
+      SetImageMask( image(), clipMask_.constImage(), &exceptionInfo );
     }
   else
     {
       // Unset existing clip mask
-      SetImageClipMask( image(), 0, &exceptionInfo );
+      SetImageMask( image(), 0, &exceptionInfo );
     }
    throwException( exceptionInfo );
    (void) DestroyExceptionInfo( &exceptionInfo );
@@ -2690,8 +2731,7 @@ Magick::Image Magick::Image::clipMask ( void  ) const
 {
    ExceptionInfo exceptionInfo;
    GetExceptionInfo( &exceptionInfo );
-   MagickCore::Image* image =
-     GetImageClipMask( constImage(), &exceptionInfo );
+   MagickCore::Image* image = GetImageMask( constImage(), &exceptionInfo );
    throwException( exceptionInfo );
    (void) DestroyExceptionInfo( &exceptionInfo );
    return Magick::Image( image );
@@ -2792,42 +2832,15 @@ size_t Magick::Image::colorMapSize ( void )
 // Image colorspace
 void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
 {
-  // Nothing to do?
   if ( image()->colorspace == colorSpace_ )
     return;
 
   modifyImage();
-
-  if ( colorSpace_ != RGBColorspace &&
-       colorSpace_ != sRGBColorspace &&
-       colorSpace_ != TransparentColorspace &&
-       colorSpace_ != GRAYColorspace )
-    {
-      if (image()->colorspace != RGBColorspace &&
-          image()->colorspace != sRGBColorspace &&
-          image()->colorspace != TransparentColorspace &&
-          image()->colorspace != GRAYColorspace)
-        {
-          /* Transform to RGB colorspace as intermediate step */
-          TransformRGBImage( image(), image()->colorspace );
-          throwImageException();
-        }
-      /* Transform to final non-RGB colorspace */
-      RGBTransformImage( image(), colorSpace_ );
-      throwImageException();
-      return;
-    }
-
-  if ( colorSpace_ == RGBColorspace ||
-       colorSpace_ == sRGBColorspace ||
-       colorSpace_ == TransparentColorspace ||
-       colorSpace_ == GRAYColorspace )
-    {
-      /* Transform to a RGB-type colorspace */
-      TransformRGBImage( image(), image()->colorspace );
-      throwImageException();
-      return;
-    }
+  ExceptionInfo exceptionInfo;
+  GetExceptionInfo( &exceptionInfo );
+  TransformImageColorspace(image(), colorSpace_, &exceptionInfo);
+  throwException( exceptionInfo );
+  (void) DestroyExceptionInfo( &exceptionInfo );
 }
 Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
 {
@@ -2838,6 +2851,11 @@ Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
 void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
 {
   modifyImage();
+  ExceptionInfo exceptionInfo;
+  GetExceptionInfo( &exceptionInfo );
+  SetImageColorspace(image(), colorSpace_, &exceptionInfo);
+  throwException( exceptionInfo );
+  (void) DestroyExceptionInfo( &exceptionInfo );
   options()->colorspaceType( colorSpace_ );
 }
 Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
@@ -2971,21 +2989,21 @@ void Magick::Image::density ( const Geometry &density_ )
   options()->density( density_ );
   if ( density_.isValid() )
     {
-      image()->x_resolution = density_.width();
+      image()->resolution.x = density_.width();
       if ( density_.height() != 0 )
         {
-          image()->y_resolution = density_.height();
+          image()->resolution.y = density_.height();
         }
       else
         {
-          image()->y_resolution = density_.width();
+          image()->resolution.y = density_.width();
         }
     }
   else
     {
       // Reset to default
-      image()->x_resolution = 0;
-      image()->y_resolution = 0;
+      image()->resolution.x = 0;
+      image()->resolution.y = 0;
     }
 }
 Magick::Geometry Magick::Image::density ( void ) const
@@ -2995,11 +3013,11 @@ Magick::Geometry Magick::Image::density ( void ) const
       ssize_t x_resolution=72;
       ssize_t y_resolution=72;
 
-      if (constImage()->x_resolution > 0.0)
-        x_resolution=static_cast<ssize_t>(constImage()->x_resolution + 0.5);
+      if (constImage()->resolution.x > 0.0)
+        x_resolution=static_cast<ssize_t>(constImage()->resolution.x + 0.5);
 
-      if (constImage()->y_resolution > 0.0)
-        y_resolution=static_cast<ssize_t>(constImage()->y_resolution + 0.5);
+      if (constImage()->resolution.y > 0.0)
+        y_resolution=static_cast<ssize_t>(constImage()->resolution.y + 0.5);
 
       return Geometry(x_resolution,y_resolution);
     }
@@ -3373,17 +3391,17 @@ void Magick::Image::matte ( const bool matteFlag_ )
   // desired, then set the matte channel to opaque.
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
-  if ((matteFlag_ && !constImage()->matte) ||
-      (constImage()->matte && !matteFlag_))
+  if ((matteFlag_ && !constImage()->alpha_trait) ||
+      (constImage()->alpha_trait && !matteFlag_))
     SetImageAlpha(image(),OpaqueAlpha,&exceptionInfo);
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
 
-  image()->matte = (MagickBooleanType) matteFlag_;
+  image()->alpha_trait = matteFlag_ ? BlendPixelTrait : UndefinedPixelTrait;
 }
 bool Magick::Image::matte ( void ) const
 {
-  if ( constImage()->matte )
+  if ( constImage()->alpha_trait == BlendPixelTrait )
     return true;
   else
     return false;
@@ -3408,9 +3426,9 @@ void Magick::Image::matteColor ( const Color &matteColor_ )
 }
 Magick::Color Magick::Image::matteColor ( void ) const
 {
-  return Color( constImage()->matte_color.red,
-               constImage()->matte_color.green,
-               constImage()->matte_color.blue );
+  return Color( ClampToQuantum( constImage()->matte_color.red ),
+               ClampToQuantum( constImage()->matte_color.green ),
+               ClampToQuantum( constImage()->matte_color.blue ) );
 }
 
 double Magick::Image::meanErrorPerPixel ( void ) const
@@ -3423,7 +3441,11 @@ double Magick::Image::meanErrorPerPixel ( void ) const
 void Magick::Image::modulusDepth ( const size_t depth_ )
 {
   modifyImage();
-  SetImageDepth( image(), depth_ );
+  ExceptionInfo exceptionInfo;
+  GetExceptionInfo( &exceptionInfo );
+  SetImageDepth( image(), depth_, &exceptionInfo );
+  throwException( exceptionInfo );
+  (void) DestroyExceptionInfo( &exceptionInfo );
   options()->depth( depth_ );
 }
 size_t Magick::Image::modulusDepth ( void ) const
@@ -3541,7 +3563,7 @@ void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
     // Set pixel value
   Quantum *pixel = pixels.get(x_, y_, 1, 1 );
   PixelInfo packet = color_;
-  MagickCore::SetPixelPixelInfo(constImage(),&packet,pixel);
+  MagickCore::SetPixelInfoPixel(constImage(),&packet,pixel);
   // Tell ImageMagick that pixels have been updated
   pixels.sync();
 
@@ -3552,9 +3574,6 @@ void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
 Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
                                          const ssize_t y_ ) const
 {
-  ClassType storage_class;
-  storage_class = classType();
-  // DirectClass
   const Quantum* pixel = getConstPixels( x_, y_, 1, 1 );
   if ( pixel )
     {
@@ -3596,6 +3615,7 @@ void Magick::Image::profile( const std::string name_,
   ssize_t result = ProfileImage( image(), name_.c_str(),
                              (unsigned char *)profile_.data(),
                              profile_.length(), &exceptionInfo);
+  (void) result;
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
 
@@ -3764,7 +3784,7 @@ void Magick::Image::statistics ( ImageStatistics *statistics )
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
 
-  ChannelType channel_mask = SetPixelChannelMask( image(), RedChannel);
+  ChannelType channel_mask = SetImageChannelMask( image(), RedChannel);
   (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
   statistics->red.minimum=minimum;
   statistics->red.maximum=maximum;
@@ -3772,9 +3792,9 @@ void Magick::Image::statistics ( ImageStatistics *statistics )
     &statistics->red.standard_deviation,&exceptionInfo);
   (void) GetImageKurtosis( image(),&statistics->red.kurtosis,
     &statistics->red.skewness,&exceptionInfo);
-  (void) SetPixelChannelMap( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
 
-  channel_mask = SetPixelChannelMask( image(), GreenChannel);
+  channel_mask = SetImageChannelMask( image(), GreenChannel);
   (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
   statistics->green.minimum=minimum;
   statistics->green.maximum=maximum;
@@ -3782,9 +3802,9 @@ void Magick::Image::statistics ( ImageStatistics *statistics )
     &statistics->green.standard_deviation,&exceptionInfo);
   (void) GetImageKurtosis( image(),&statistics->green.kurtosis,
     &statistics->green.skewness,&exceptionInfo);
-  (void) SetPixelChannelMap( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
 
-  channel_mask = SetPixelChannelMask( image(), GreenChannel);
+  channel_mask = SetImageChannelMask( image(), GreenChannel);
   (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
   statistics->blue.minimum=minimum;
   statistics->blue.maximum=maximum;
@@ -3792,9 +3812,9 @@ void Magick::Image::statistics ( ImageStatistics *statistics )
     &statistics->blue.standard_deviation,&exceptionInfo);
   (void) GetImageKurtosis( image(),&statistics->blue.kurtosis,
     &statistics->blue.skewness,&exceptionInfo);
-  (void) SetPixelChannelMap( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
 
-  channel_mask = SetPixelChannelMask( image(), AlphaChannel);
+  channel_mask = SetImageChannelMask( image(), AlphaChannel);
   (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo);
   statistics->alpha.minimum=minimum;
   statistics->alpha.maximum=maximum;
@@ -3802,7 +3822,7 @@ void Magick::Image::statistics ( ImageStatistics *statistics )
     &statistics->alpha.standard_deviation,&exceptionInfo);
   (void) GetImageKurtosis( image(),&statistics->alpha.kurtosis,
     &statistics->alpha.skewness,&exceptionInfo);
-  (void) SetPixelChannelMap( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
 
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -4082,8 +4102,11 @@ std::string Magick::Image::view ( void ) const
 void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
 {
   modifyImage();
-  SetImageVirtualPixelMethod( image(), virtual_pixel_method_ );
-  options()->virtualPixelMethod( virtual_pixel_method_ );
+  ExceptionInfo exceptionInfo;
+  GetExceptionInfo( &exceptionInfo );
+  SetImageVirtualPixelMethod( image(), virtual_pixel_method_, &exceptionInfo );
+  throwException( exceptionInfo );
+  (void) DestroyExceptionInfo( &exceptionInfo );
 }
 Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
 {
@@ -4102,11 +4125,11 @@ std::string Magick::Image::x11Display ( void ) const
 
 double Magick::Image::xResolution ( void ) const
 {
-  return constImage()->x_resolution;
+  return constImage()->resolution.x;
 }
 double Magick::Image::yResolution ( void ) const
 {
-  return constImage()->y_resolution;
+  return constImage()->resolution.y;
 }
 
 // Copy Constructor
@@ -4415,7 +4438,6 @@ void Magick::Image::modifyImage( void )
 void Magick::Image::throwImageException( void ) const
 {
   // Throw C++ exception while resetting Image exception to default state
-  throwException( const_cast<MagickCore::Image*>(constImage())->exception );
 }
 
 // Register image with image registry or obtain registration id