]> granicus.if.org Git - imagemagick/blobdiff - Magick++/lib/Image.cpp
(no commit message)
[imagemagick] / Magick++ / lib / Image.cpp
index d31bc162029df93787bc798bab66a4a17e5c6611..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;
 
@@ -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) SetPixelChannelMapMask( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   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_, &exceptionInfo);
-  (void) SetPixelChannelMapMask( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -951,10 +951,12 @@ void Magick::Image::erase ( void )
 //
 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 );
@@ -971,14 +973,15 @@ void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravit
   RectangleInfo geometry;
 
   SetGeometry(image(), &geometry);
+  geometry.width = geometry_.width();
+  geometry.height = geometry_.height();
   GravityAdjustGeometry(image()->columns, image()->rows, gravity_, &geometry);
-  extent ( 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)
@@ -1201,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) SetPixelChannelMapMask( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -1258,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_, &exceptionInfo );
-  (void) SetPixelChannelMapMask( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -1374,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) SetPixelChannelMapMask( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
 }
@@ -1398,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 )
 {
@@ -1605,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) SetPixelChannelMapMask( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
 }
@@ -1628,10 +1645,10 @@ 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) SetPixelChannelMapMask( image(), channel_mask );
-  (void) CompositeImage( image(), crop_image, image()->matte != MagickFalse ?
+  (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);
@@ -1674,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) SetPixelChannelMapMask( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   throwImageException();
   (void) DestroyExceptionInfo( &exceptionInfo );
 }
@@ -1999,13 +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_,
                          &exceptionInfo );
-  (void) SetPixelChannelMapMask( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -2076,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) SetPixelChannelMapMask( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -2290,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_,
@@ -2298,7 +2315,7 @@ void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
                              amount_,
                              threshold_,
                              &exceptionInfo );
-  (void) SetPixelChannelMapMask( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -2339,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);
@@ -2356,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);
@@ -2375,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);
@@ -3374,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;
@@ -3767,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;
@@ -3775,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) SetPixelChannelMapMask( 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;
@@ -3785,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) SetPixelChannelMapMask( 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;
@@ -3795,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) SetPixelChannelMapMask( 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;
@@ -3805,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) SetPixelChannelMapMask( image(), channel_mask );
+  (void) SetPixelChannelMask( image(), channel_mask );
 
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );