From fa84114a917ab92aea6805ae8041e3cdae1b3a20 Mon Sep 17 00:00:00 2001 From: dirk Date: Mon, 9 Jun 2014 08:22:13 +0000 Subject: [PATCH] Added method to quickly export pixels. --- Magick++/lib/Image.cpp | 56 +++++++++++++++++++++++++++++++++++ Magick++/lib/Magick++/Image.h | 5 ++++ 2 files changed, 61 insertions(+) diff --git a/Magick++/lib/Image.cpp b/Magick++/lib/Image.cpp index 5bb7d9fcb..29406f1c4 100644 --- a/Magick++/lib/Image.cpp +++ b/Magick++/lib/Image.cpp @@ -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 diff --git a/Magick++/lib/Magick++/Image.h b/Magick++/lib/Magick++/Image.h index edb70e995..2a955581b 100644 --- a/Magick++/lib/Magick++/Image.h +++ b/Magick++/lib/Magick++/Image.h @@ -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); -- 2.40.0