]> granicus.if.org Git - imagemagick/commitdiff
Added method to quickly export pixels.
authordirk <dirk@git.imagemagick.org>
Mon, 9 Jun 2014 08:22:13 +0000 (08:22 +0000)
committerdirk <dirk@git.imagemagick.org>
Mon, 9 Jun 2014 08:22:13 +0000 (08:22 +0000)
Magick++/lib/Image.cpp
Magick++/lib/Magick++/Image.h

index 5bb7d9fcb01c9c82ab7f136dba36e4da33454534..29406f1c4473e86fc8ff5e2f4cf8b5121a7ac7c9 100644 (file)
@@ -2818,6 +2818,62 @@ void Magick::Image::erase(void)
   ThrowPPException;
 }
 
+void *Magick::Image::exportPixels(const ::ssize_t x_,const ::ssize_t y_,
+  const size_t width_,const size_t height_,std::string map_,
+  const StorageType type_)
+{
+  size_t
+    size;
+
+  void
+    *result;
+
+  result=(void *) NULL;
+  if ((x_ < 0) || (width_ < 0) || (y_ < 0) || (height_ < 0) ||
+      (x_ > image()->columns) || (width_ + x_ > image()->columns) ||
+      (y_ > image()->rows) || (height_ + y_ > image()->rows) ||
+      (map_.length() == 0))
+    return(result);
+
+  switch(type_)
+  {
+    case CharPixel:
+      size=sizeof(unsigned char);
+      break;
+    case DoublePixel:
+      size=sizeof(double);
+      break;
+    case FloatPixel:
+      size=sizeof(float);
+      break;
+    case LongPixel:
+      size=sizeof(unsigned int);
+      break;
+    case LongLongPixel:
+      size=sizeof(MagickSizeType);
+      break;
+    case QuantumPixel:
+      size=sizeof(Quantum);
+      break;
+    case ShortPixel:
+      size=sizeof(unsigned short);
+      break;
+    default:
+      throwExceptionExplicit(OptionError,"Invalid type");
+      return(result);
+  }
+
+  result=AcquireMagickMemory(width_*height_*map_.length()*size);
+
+  GetPPException;
+  MagickCore::ExportImagePixels(image(),x_,y_,width_,height_,map_.c_str(),
+    type_,result,&exceptionInfo);
+  if (exceptionInfo.severity != UndefinedException)
+    result=RelinquishMagickMemory(result);
+  ThrowPPException;
+  return(result);
+}
+
 void Magick::Image::extent(const Geometry &geometry_ )
 {
   MagickCore::Image
index edb70e995ac11b3bf6cae6734abe1bb146a857da..2a955581b738de31d3969dc4b565bdd6597b025d 100644 (file)
@@ -878,6 +878,11 @@ namespace Magick
     // Erase image to current "background color"
     void erase(void);
 
+    // Returns a copy of the pixels at the specified location
+    void *exportPixels(const ::ssize_t x_,const ::ssize_t y_,
+      const size_t width_,const size_t height_,std::string map_,
+      const StorageType type_);
+
     // Extend the image as defined by the geometry.
     void extent(const Geometry &geometry_);
     void extent(const Geometry &geometry_,const Color &backgroundColor);