From: dirk Date: Sat, 7 Dec 2013 19:19:26 +0000 (+0000) Subject: Code cleanup and refactoring. X-Git-Tag: 7.0.1-0~3056 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1940fe06f035ea32a4ec4df61f6897396877aa3c;p=imagemagick Code cleanup and refactoring. --- diff --git a/Magick++/lib/Color.cpp b/Magick++/lib/Color.cpp index 5176ffae7..3ec83b3d9 100644 --- a/Magick++/lib/Color.cpp +++ b/Magick++/lib/Color.cpp @@ -16,7 +16,7 @@ using namespace std; #include "Magick++/Color.h" #include "Magick++/Exception.h" -int Magick::operator == (const Magick::Color &left_, +MagickPPExport int Magick::operator == (const Magick::Color &left_, const Magick::Color &right_) { return((left_.isValid() == right_.isValid()) && @@ -25,19 +25,19 @@ int Magick::operator == (const Magick::Color &left_, (left_.quantumBlue() == right_.quantumBlue())); } -int Magick::operator != (const Magick::Color &left_, +MagickPPExport int Magick::operator != (const Magick::Color &left_, const Magick::Color &right_) { return(!(left_ == right_)); } -int Magick::operator > (const Magick::Color &left_, +MagickPPExport int Magick::operator > (const Magick::Color &left_, const Magick::Color &right_) { return(!(left_ < right_ ) && (left_ != right_ )); } -int Magick::operator < ( const Magick::Color &left_, +MagickPPExport int Magick::operator < ( const Magick::Color &left_, const Magick::Color &right_) { if(left_.quantumRed() < right_.quantumRed()) @@ -53,13 +53,13 @@ int Magick::operator < ( const Magick::Color &left_, return(false); } -int Magick::operator >= (const Magick::Color &left_, +MagickPPExport int Magick::operator >= (const Magick::Color &left_, const Magick::Color &right_) { return((left_ > right_) || (left_ == right_)); } -int Magick::operator <= ( const Magick::Color &left_, +MagickPPExport int Magick::operator <= ( const Magick::Color &left_, const Magick::Color &right_) { return((left_ < right_) || (left_ == right_)); diff --git a/Magick++/lib/Image.cpp b/Magick++/lib/Image.cpp index 2bf8375df..ca244826f 100644 --- a/Magick++/lib/Image.cpp +++ b/Magick++/lib/Image.cpp @@ -26,5041 +26,4449 @@ using namespace std; #define AbsoluteValue(x) ((x) < 0 ? -(x) : (x)) #define DegreesToRadians(x) (MagickPI*(x)/180.0) -MagickPPExport const char *Magick::borderGeometryDefault = "6x6+0+0"; -MagickPPExport const char *Magick::frameGeometryDefault = "25x25+6+6"; -MagickPPExport const char *Magick::raiseGeometryDefault = "6x6+0+0"; +#define GetPPException \ + ExceptionInfo \ + exceptionInfo; \ + GetExceptionInfo(&exceptionInfo) +#define ClonePPDrawException(wand) \ + ExceptionInfo \ + *exceptionInfo; \ + exceptionInfo=DrawCloneExceptionInfo(wand) +#define RestorePPChannelMask \ + SetPixelChannelMask(image(),channel_mask) +#define SetPPChannelMask(channel) \ + ChannelType \ + channel_mask; \ + channel_mask=SetImageChannelMask(image(),channel) +#define ThrowPPDrawException \ + throwException(*exceptionInfo); \ + (void) DestroyExceptionInfo(exceptionInfo) +#define ThrowPPException \ + throwException(exceptionInfo); \ + (void) DestroyExceptionInfo(&exceptionInfo) + +MagickPPExport const char *Magick::borderGeometryDefault="6x6+0+0"; +MagickPPExport const char *Magick::frameGeometryDefault="25x25+6+6"; +MagickPPExport const char *Magick::raiseGeometryDefault="6x6+0+0"; static bool magick_initialized=false; -// -// Explicit template instantiations -// - -// -// Friend functions to compare Image objects -// - -MagickPPExport int Magick::operator == ( const Magick::Image& left_, - const Magick::Image& right_ ) +MagickPPExport int Magick::operator == (const Magick::Image &left_, + const Magick::Image &right_) { // If image pixels and signature are the same, then the image is identical - return ( ( left_.rows() == right_.rows() ) && - ( left_.columns() == right_.columns() ) && - ( left_.signature() == right_.signature() ) - ); + return((left_.rows() == right_.rows()) && + (left_.columns() == right_.columns()) && + (left_.signature() == right_.signature())); } -MagickPPExport int Magick::operator != ( const Magick::Image& left_, - const Magick::Image& right_ ) + +MagickPPExport int Magick::operator != (const Magick::Image &left_, + const Magick::Image &right_) { - return ( ! (left_ == right_) ); + return(!(left_ == right_)); } -MagickPPExport int Magick::operator > ( const Magick::Image& left_, - const Magick::Image& right_ ) + +MagickPPExport int Magick::operator > (const Magick::Image &left_, + const Magick::Image &right_) { - return ( !( left_ < right_ ) && ( left_ != right_ ) ); + return(!(left_ < right_) && (left_ != right_)); } -MagickPPExport int Magick::operator < ( const Magick::Image& left_, - const Magick::Image& right_ ) + +MagickPPExport int Magick::operator < (const Magick::Image &left_, + const Magick::Image &right_) { // If image pixels are less, then image is smaller - return ( ( left_.rows() * left_.columns() ) < - ( right_.rows() * right_.columns() ) - ); + return((left_.rows() * left_.columns()) < + (right_.rows() * right_.columns())); } -MagickPPExport int Magick::operator >= ( const Magick::Image& left_, - const Magick::Image& right_ ) + +MagickPPExport int Magick::operator >= (const Magick::Image &left_, + const Magick::Image &right_) { - return ( ( left_ > right_ ) || ( left_ == right_ ) ); + return((left_ > right_) || (left_ == right_)); } -MagickPPExport int Magick::operator <= ( const Magick::Image& left_, - const Magick::Image& right_ ) + +MagickPPExport int Magick::operator <= (const Magick::Image &left_, + const Magick::Image &right_) { - return ( ( left_ < right_ ) || ( left_ == right_ ) ); + return((left_ < right_) || ( left_ == right_)); } -// -// Image object implementation -// +MagickPPExport void Magick::InitializeMagick(const char *path_) +{ + MagickCore::MagickCoreGenesis(path_,MagickFalse); + if (!magick_initialized) + magick_initialized=true; +} -// Construct from image file or image specification -Magick::Image::Image ( const std::string &imageSpec_ ) - : _imgRef(new ImageRef) +MagickPPExport void Magick::TerminateMagick(void) { - try - { - // Initialize, Allocate and Read images - read( imageSpec_ ); - } - catch ( const Warning & /*warning_*/ ) - { - // FIXME: need a way to report warnings in constructor - } - catch ( const Error & /*error_*/ ) + if (magick_initialized) { - // Release resources - delete _imgRef; - throw; + magick_initialized=false; + MagickCore::MagickCoreTerminus(); } } -// Construct a blank image canvas of specified size and color -Magick::Image::Image ( const Geometry &size_, - const Color &color_ ) +Magick::Image::Image(void) : _imgRef(new ImageRef) { - // xc: prefix specifies an X11 color string - std::string imageSpec("xc:"); - imageSpec += color_; +} +Magick::Image::Image(const Blob &blob_) + : _imgRef(new ImageRef) +{ try - { - // Set image size - size( size_ ); - - // Initialize, Allocate and Read images - read( imageSpec ); - } - catch ( const Warning & /*warning_*/ ) - { - // FIXME: need a way to report warnings in constructor - } - catch ( const Error & /*error_*/ ) - { - // Release resources - delete _imgRef; - throw; - } + { + // Initialize, Allocate and Read images + read(blob_); + } + catch(const Warning &/*warning_*/) + { + // FIXME: need a way to report warnings in constructor + } + catch (const Error &/*error_*/) + { + // Release resources + delete _imgRef; + throw; + } } -// Construct Image from in-memory BLOB -Magick::Image::Image ( const Blob &blob_ ) +Magick::Image::Image(const Blob &blob_,const Geometry &size_) : _imgRef(new ImageRef) { try - { - // Initialize, Allocate and Read images - read( blob_ ); - } - catch ( const Warning & /*warning_*/ ) - { - // FIXME: need a way to report warnings in constructor - } - catch ( const Error & /*error_*/ ) - { - // Release resources - delete _imgRef; - throw; - } + { + // Read from Blob + read(blob_, size_); + } + catch(const Warning &/*warning_*/) + { + // FIXME: need a way to report warnings in constructor + } + catch(const Error &/*error_*/) + { + // Release resources + delete _imgRef; + throw; + } } -// Construct Image of specified size from in-memory BLOB -Magick::Image::Image ( const Blob &blob_, - const Geometry &size_ ) +Magick::Image::Image(const Blob &blob_,const Geometry &size_, + const size_t depth_) : _imgRef(new ImageRef) { try - { - // Read from Blob - read( blob_, size_ ); - } - catch ( const Warning & /*warning_*/ ) - { - // FIXME: need a way to report warnings in constructor - } - catch ( const Error & /*error_*/ ) - { - // Release resources - delete _imgRef; - throw; - } + { + // Read from Blob + read(blob_,size_,depth_); + } + catch(const Warning &/*warning_*/) + { + // FIXME: need a way to report warnings in constructor + } + catch(const Error &/*error_*/) + { + // Release resources + delete _imgRef; + throw; + } } -// Construct Image of specified size and depth from in-memory BLOB -Magick::Image::Image ( const Blob &blob_, - const Geometry &size_, - const size_t depth_ ) +Magick::Image::Image(const Blob &blob_,const Geometry &size_, + const size_t depth_,const std::string &magick_) : _imgRef(new ImageRef) { try - { - // Read from Blob - read( blob_, size_, depth_ ); - } - catch ( const Warning & /*warning_*/ ) - { - // FIXME: need a way to report warnings in constructor - } - catch ( const Error & /*error_*/ ) - { - // Release resources - delete _imgRef; - throw; - } + { + // Read from Blob + read(blob_,size_,depth_,magick_); + } + catch(const Warning &/*warning_*/) + { + // FIXME: need a way to report warnings in constructor + } + catch(const Error &/*error_*/) + { + // Release resources + delete _imgRef; + throw; + } } -// Construct Image of specified size, depth, and format from in-memory BLOB -Magick::Image::Image ( const Blob &blob_, - const Geometry &size_, - const size_t depth_, - const std::string &magick_ ) +Magick::Image::Image(const Blob &blob_,const Geometry &size_, + const std::string &magick_) : _imgRef(new ImageRef) { try - { - // Read from Blob - read( blob_, size_, depth_, magick_ ); - } - catch ( const Warning & /*warning_*/ ) - { - // FIXME: need a way to report warnings in constructor - } - catch ( const Error & /*error_*/ ) - { - // Release resources - delete _imgRef; - throw; - } + { + // Read from Blob + read(blob_,size_,magick_); + } + catch(const Warning &/*warning_*/) + { + // FIXME: need a way to report warnings in constructor + } + catch(const Error &/*error_*/) + { + // Release resources + delete _imgRef; + throw; + } } -// Construct Image of specified size, and format from in-memory BLOB -Magick::Image::Image ( const Blob &blob_, - const Geometry &size_, - const std::string &magick_ ) +Magick::Image::Image(const Geometry &size_,const Color &color_) : _imgRef(new ImageRef) { + // xc: prefix specifies an X11 color string + std::string imageSpec("xc:"); + imageSpec+=color_; + try - { - // Read from Blob - read( blob_, size_, magick_ ); - } - catch ( const Warning & /*warning_*/ ) - { - // FIXME: need a way to report warnings in constructor - } - catch ( const Error & /*error_*/ ) - { - // Release resources - delete _imgRef; - throw; - } + { + // Set image size + size(size_); + + // Initialize, Allocate and Read images + read(imageSpec); + } + catch(const Warning &/*warning_*/) + { + // FIXME: need a way to report warnings in constructor + } + catch(const Error & /*error_*/) + { + // Release resources + delete _imgRef; + throw; + } +} + +Magick::Image::Image(const Image &image_) + : _imgRef(image_._imgRef) +{ + Lock(&_imgRef->_mutexLock); + + // Increase reference count + ++_imgRef->_refCount; } -// Construct an image based on an array of raw pixels, of specified -// type and mapping, in memory -Magick::Image::Image ( const size_t width_, - const size_t height_, - const std::string &map_, - const StorageType type_, - const void *pixels_ ) +Magick::Image::Image(const size_t width_,const size_t height_, + const std::string &map_,const StorageType type_,const void *pixels_) : _imgRef(new ImageRef) { try - { - read( width_, height_, map_.c_str(), type_, pixels_ ); - } - catch ( const Warning & /*warning_*/ ) - { - // FIXME: need a way to report warnings in constructor - } - catch ( const Error & /*error_*/ ) - { - // Release resources - delete _imgRef; - throw; - } + { + read(width_,height_,map_.c_str(),type_,pixels_); + } + catch(const Warning &/*warning_*/) + { + // FIXME: need a way to report warnings in constructor + } + catch(const Error &/*error_*/) + { + // Release resources + delete _imgRef; + throw; + } } -// Default constructor -Magick::Image::Image ( void ) +Magick::Image::Image(const std::string &imageSpec_) : _imgRef(new ImageRef) { + try + { + // Initialize, Allocate and Read images + read(imageSpec_); + } + catch(const Warning &/*warning_*/) + { + // FIXME: need a way to report warnings in constructor + } + catch(const Error &/*error_*/) + { + // Release resources + delete _imgRef; + throw; + } } -// Destructor -/* virtual */ Magick::Image::~Image() { - bool doDelete = false; + bool + doDelete=false; + { - Lock( &_imgRef->_mutexLock ); - if ( --_imgRef->_refCount == 0 ) - doDelete = true; + Lock(&_imgRef->_mutexLock); + if (--_imgRef->_refCount == 0) + doDelete=true; } - if ( doDelete ) + if (doDelete) + delete _imgRef; + + _imgRef=0; +} + +Magick::Image& Magick::Image::operator=(const Magick::Image &image_) +{ + if(this != &image_) { - delete _imgRef; + bool + doDelete=false; + + { + Lock(&image_._imgRef->_mutexLock); + ++image_._imgRef->_refCount; + } + + { + Lock(&_imgRef->_mutexLock); + if (--_imgRef->_refCount == 0) + doDelete=true; + } + + if (doDelete) + { + // Delete old image reference with associated image and options. + delete _imgRef; + _imgRef=0; + } + // Use new image reference + _imgRef=image_._imgRef; } - _imgRef = 0; -} - -// Adaptive-blur image -void Magick::Image::adaptiveBlur ( const double radius_, const double sigma_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - AdaptiveBlurImage( constImage(), radius_, sigma_, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -void Magick::Image::adaptiveResize ( const Geometry &geometry_ ) -{ - ssize_t x = 0; - ssize_t y = 0; - size_t width = columns(); - size_t height = rows(); - - ParseMetaGeometry( static_cast(geometry_).c_str(), - &x, &y, - &width, &height ); - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - AdaptiveResizeImage( constImage(), width, height, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -void Magick::Image::adaptiveSharpen ( const double radius_, - const double sigma_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - AdaptiveSharpenImage( constImage(), radius_, sigma_, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + + return(*this); } -void Magick::Image::adaptiveSharpenChannel ( const ChannelType channel_, - const double radius_, - const double sigma_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_); - MagickCore::Image* newImage = - AdaptiveSharpenImage( constImage(), radius_, sigma_, &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); +void Magick::Image::adjoin(const bool flag_) +{ + modifyImage(); + options()->adjoin(flag_); } -// Local adaptive threshold image -// http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm -// Width x height define the size of the pixel neighborhood -// offset = constant to subtract from pixel neighborhood mean -void Magick::Image::adaptiveThreshold ( const size_t width_, - const size_t height_, - const ssize_t offset_ ) +bool Magick::Image::adjoin(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - AdaptiveThresholdImage( constImage(), width_, height_, offset_, - &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->adjoin()); } -// Add noise to image -void Magick::Image::addNoise ( const NoiseType noiseType_ ) +void Magick::Image::alpha(const bool matteFlag_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - AddNoiseImage ( constImage(), noiseType_, 1.0, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + modifyImage(); + + // If matte channel is requested, but image doesn't already have a + // matte channel, then create an opaque matte channel. Likewise, if + // the image already has a matte channel but a matte channel is not + // desired, then set the matte channel to opaque. + GetPPException; + if ((matteFlag_ && !constImage()->alpha_trait) || + (constImage()->alpha_trait && !matteFlag_)) + SetImageAlpha(image(),OpaqueAlpha,&exceptionInfo); + ThrowPPException; + + image()->alpha_trait=matteFlag_ ? BlendPixelTrait : UndefinedPixelTrait; } -void Magick::Image::addNoiseChannel ( const ChannelType channel_, - const NoiseType noiseType_ ) +bool Magick::Image::alpha(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_); - MagickCore::Image* newImage = - AddNoiseImage ( constImage(), noiseType_, 1.0, &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + if (constImage()->alpha_trait == BlendPixelTrait) + return(true); + else + return(false); } -// Affine Transform image -void Magick::Image::affineTransform ( const DrawableAffine &affine_ ) +void Magick::Image::alphaColor(const Color &alphaColor_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); + modifyImage(); - AffineMatrix _affine; - _affine.sx = affine_.sx(); - _affine.sy = affine_.sy(); - _affine.rx = affine_.rx(); - _affine.ry = affine_.ry(); - _affine.tx = affine_.tx(); - _affine.ty = affine_.ty(); + if (alphaColor_.isValid()) + { + image()->matte_color=alphaColor_; + options()->matteColor(alphaColor_); + } + else + { + // Set to default matte color + Color tmpColor("#BDBDBD"); + image()->matte_color=tmpColor; + options()->matteColor(tmpColor); + } +} - MagickCore::Image* newImage = - AffineTransformImage( constImage(), &_affine, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); +Magick::Color Magick::Image::alphaColor(void) const +{ + return(Color(ClampToQuantum(constImage()->matte_color.red), + ClampToQuantum(constImage()->matte_color.green), + ClampToQuantum(constImage()->matte_color.blue))); } -// Set or attenuate the alpha channel. If the image pixels are -// opaque then they are set to the specified alpha value, otherwise -// they are blended with the supplied alpha value. The value of -// alpha_ ranges from 0 (completely opaque) to QuantumRange. The defines -// OpaqueAlpha and TransparentAlpha are available to specify -// completely opaque or completely transparent, respectively. -void Magick::Image::alpha ( const unsigned int alpha_ ) +void Magick::Image::antiAlias(const bool flag_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - SetImageAlpha( image(), alpha_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + options()->antiAlias(static_cast(flag_)); } -void Magick::Image::alphaChannel ( AlphaChannelOption alphaOption_ ) +bool Magick::Image::antiAlias(void) { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - SetImageAlphaChannel( image(), alphaOption_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(static_cast(options()->antiAlias())); } -// Annotate using specified text, and placement location -void Magick::Image::annotate ( const std::string &text_, - const Geometry &location_ ) +void Magick::Image::animationDelay(const size_t delay_) { - annotate ( text_, location_, NorthWestGravity, 0.0 ); + modifyImage(); + image()->delay=delay_; } -// Annotate using specified text, bounding area, and placement gravity -void Magick::Image::annotate ( const std::string &text_, - const Geometry &boundingArea_, - const GravityType gravity_ ) +size_t Magick::Image::animationDelay(void) const { - annotate ( text_, boundingArea_, gravity_, 0.0 ); + return(constImage()->delay); } -// Annotate with text using specified text, bounding area, placement -// gravity, and rotation. -void Magick::Image::annotate ( const std::string &text_, - const Geometry &boundingArea_, - const GravityType gravity_, - const double degrees_ ) +void Magick::Image::animationIterations(const size_t iterations_) { modifyImage(); + image()->iterations=iterations_; +} - DrawInfo *drawInfo - = options()->drawInfo(); - - drawInfo->text = const_cast(text_.c_str()); - - char boundingArea[MaxTextExtent]; - - drawInfo->geometry = 0; - if ( boundingArea_.isValid() ) - { - if ( boundingArea_.width() == 0 || boundingArea_.height() == 0 ) - { - FormatLocaleString( boundingArea, MaxTextExtent, "%+.20g%+.20g", - (double) boundingArea_.xOff(), (double) boundingArea_.yOff() ); - } - else - { - (void) CopyMagickString( boundingArea, string(boundingArea_).c_str(), - MaxTextExtent); - } - drawInfo->geometry = boundingArea; - } - - drawInfo->gravity = gravity_; - - AffineMatrix oaffine = drawInfo->affine; - if ( degrees_ != 0.0) - { - AffineMatrix affine; - affine.sx=1.0; - affine.rx=0.0; - affine.ry=0.0; - affine.sy=1.0; - affine.tx=0.0; - affine.ty=0.0; - - AffineMatrix current = drawInfo->affine; - affine.sx=cos(DegreesToRadians(fmod(degrees_,360.0))); - affine.rx=sin(DegreesToRadians(fmod(degrees_,360.0))); - affine.ry=(-sin(DegreesToRadians(fmod(degrees_,360.0)))); - affine.sy=cos(DegreesToRadians(fmod(degrees_,360.0))); - - drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx; - drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx; - drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy; - drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy; - drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty - +current.tx; - } - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - AnnotateImage( image(), drawInfo, &exceptionInfo ); - - // Restore original values - drawInfo->affine = oaffine; - drawInfo->text = 0; - drawInfo->geometry = 0; - - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); +size_t Magick::Image::animationIterations(void) const +{ + return(constImage()->iterations); } -// Annotate with text (bounding area is entire image) and placement gravity. -void Magick::Image::annotate ( const std::string &text_, - const GravityType gravity_ ) +void Magick::Image::backgroundColor(const Color &backgroundColor_) { modifyImage(); - DrawInfo *drawInfo - = options()->drawInfo(); - - drawInfo->text = const_cast(text_.c_str()); - - drawInfo->gravity = gravity_; - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - AnnotateImage( image(), drawInfo, &exceptionInfo ); + if (backgroundColor_.isValid()) + image()->background_color=backgroundColor_; + else + image()->background_color=Color(); - drawInfo->gravity = NorthWestGravity; - drawInfo->text = 0; + options()->backgroundColor(backgroundColor_); +} - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); +Magick::Color Magick::Image::backgroundColor(void) const +{ + return(constOptions()->backgroundColor()); } -void Magick::Image::artifact ( const std::string &name_, - const std::string &value_ ) +void Magick::Image::backgroundTexture(const std::string &backgroundTexture_) { modifyImage(); - (void) SetImageArtifact ( image(), name_.c_str(), value_.c_str() ); + options()->backgroundTexture(backgroundTexture_); } -std::string Magick::Image::artifact ( const std::string &name_ ) +std::string Magick::Image::backgroundTexture(void) const { - const char *value = GetImageArtifact ( image(), name_.c_str() ); - if (value) - return std::string( value ); - return std::string( ); + return(constOptions()->backgroundTexture()); } -void Magick::Image::autoGamma ( void ) +size_t Magick::Image::baseColumns(void) const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - AutoGammaImage( image(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constImage()->magick_columns); } -void Magick::Image::autoGammaChannel ( const ChannelType channel_ ) +std::string Magick::Image::baseFilename(void) const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - AutoGammaImage( image(), &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(std::string(constImage()->magick_filename)); } -void Magick::Image::autoLevel ( void ) +size_t Magick::Image::baseRows(void) const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - AutoLevelImage( image(), &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constImage()->magick_rows); } -void Magick::Image::autoLevelChannel ( const ChannelType channel_ ) +void Magick::Image::borderColor(const Color &borderColor_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - AutoLevelImage( image(), &exceptionInfo); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + + if (borderColor_.isValid()) + image()->border_color=borderColor_; + else + image()->border_color=Color(); + + options()->borderColor(borderColor_); } -void Magick::Image::autoOrient ( void ) +Magick::Color Magick::Image::borderColor(void) const { - if (image()->orientation == UndefinedOrientation || - image()->orientation == TopLeftOrientation) - return; - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - AutoOrientImage( constImage(), image()->orientation, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->borderColor()); } -void Magick::Image::blackThreshold ( const std::string &threshold_ ) +Magick::Geometry Magick::Image::boundingBox(void) const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - BlackThresholdImage( image(), threshold_.c_str(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + RectangleInfo + bbox; + + GetPPException; + bbox=GetImageBoundingBox(constImage(),&exceptionInfo); + ThrowPPException; + return(Geometry(bbox)); } -void Magick::Image::blackThresholdChannel ( const ChannelType channel_, - const std::string &threshold_ ) +void Magick::Image::boxColor(const Color &boxColor_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - BlackThresholdImage( image(), threshold_.c_str(), &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + options()->boxColor(boxColor_); } -void Magick::Image::blueShift ( const double factor_ ) +Magick::Color Magick::Image::boxColor(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - BlueShiftImage( constImage(), factor_, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->boxColor()); } -// Blur image -void Magick::Image::blur ( const double radius_, const double sigma_ ) +void Magick::Image::cacheThreshold(const MagickSizeType threshold_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - BlurImage( constImage(), radius_, sigma_, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + SetMagickResourceLimit(MemoryResource, threshold_); } -void Magick::Image::blurChannel ( const ChannelType channel_, - const double radius_, const double sigma_ ) +void Magick::Image::channelDepth(const size_t depth_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - MagickCore::Image* newImage = - BlurImage( constImage(), radius_, sigma_, &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + modifyImage(); + GetPPException; + SetImageDepth(image(),depth_,&exceptionInfo); + ThrowPPException; } -// Add border to image -// Only uses width & height -void Magick::Image::border( const Geometry &geometry_ ) +size_t Magick::Image::channelDepth() { - RectangleInfo borderInfo = geometry_; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - BorderImage( image(), &borderInfo, image()->compose, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + size_t + channel_depth; + + GetPPException; + channel_depth=GetImageDepth(constImage(),&exceptionInfo); + ThrowPPException; + return(channel_depth); } -void Magick::Image::brightnessContrast ( const double brightness_, - const double contrast_ ) +size_t Magick::Image::channels() const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - BrightnessContrastImage( image(), brightness_, contrast_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constImage()->number_channels); } -void Magick::Image::brightnessContrastChannel ( const ChannelType channel_, - const double brightness_, - const double contrast_ ) +void Magick::Image::classType(const ClassType class_) { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - BrightnessContrastImage( image(), brightness_, contrast_, &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + if (classType() == PseudoClass && class_ == DirectClass) + { + // Use SyncImage to synchronize the DirectClass pixels with the + // color map and then set to DirectClass type. + modifyImage(); + GetPPException; + SyncImage(image(),&exceptionInfo); + ThrowPPException; + image()->colormap=(PixelInfo *)RelinquishMagickMemory(image()->colormap); + image()->storage_class=static_cast(DirectClass); + return; + } + + if (classType() == DirectClass && class_ == PseudoClass) + { + // Quantize to create PseudoClass color map + modifyImage(); + quantizeColors(MaxColormapSize); + quantize(); + image()->storage_class=static_cast(PseudoClass); + } } -// Extract channel from image -void Magick::Image::channel ( const ChannelType channel_ ) +Magick::ClassType Magick::Image::classType(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - SeparateImage( image(), channel_, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return static_cast(constImage()->storage_class); } -// Set or obtain modulus channel depth -void Magick::Image::channelDepth ( const size_t depth_ ) +void Magick::Image::clipMask(const Magick::Image &clipMask_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - SetImageDepth( image(), depth_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + + GetPPException; + if (clipMask_.isValid()) + SetImageMask(image(),clipMask_.constImage(),&exceptionInfo); + else + SetImageMask(image(),0,&exceptionInfo); + ThrowPPException; } -size_t Magick::Image::channelDepth ( ) +Magick::Image Magick::Image::clipMask(void) const { - size_t channel_depth; + MagickCore::Image + *image; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - channel_depth=GetImageDepth( constImage(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - return channel_depth; + GetPPException; + image=GetImageMask(constImage(),&exceptionInfo); + ThrowPPException; + if (image == (MagickCore::Image *) NULL) + return(Magick::Image()); + else + return(Magick::Image(image)); } -// Charcoal-effect image -void Magick::Image::charcoal ( const double radius_, const double sigma_ ) +void Magick::Image::colorFuzz(const double fuzz_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - CharcoalImage( image(), radius_, sigma_, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + modifyImage(); + image()->fuzz=fuzz_; + options()->colorFuzz(fuzz_); } -// Chop image -void Magick::Image::chop ( const Geometry &geometry_ ) +double Magick::Image::colorFuzz(void) const { - RectangleInfo chopInfo = geometry_; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - ChopImage( image(), &chopInfo, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->colorFuzz()); } -// contains one or more color corrections and applies the correction to the -// image. -void Magick::Image::cdl ( const std::string &cdl_ ) +void Magick::Image::colorMapSize(const size_t entries_) { + if (entries_ >MaxColormapSize) + throwExceptionExplicit(OptionError, + "Colormap entries must not exceed MaxColormapSize"); + modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - (void) ColorDecisionListImage( image(), cdl_.c_str(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + GetPPException; + AcquireImageColormap(image(),entries_,&exceptionInfo); + ThrowPPException; } -void Magick::Image::clamp ( void ) +size_t Magick::Image::colorMapSize(void) const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ClampImage( image(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + if (!constImage()->colormap) + throwExceptionExplicit(OptionError,"Image does not contain a colormap"); + + return(constImage()->colors); } -void Magick::Image::clampChannel ( const ChannelType channel_ ) +void Magick::Image::colorSpace(const ColorspaceType colorSpace_) { + if (image()->colorspace == colorSpace_) + return; + modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - ClampImage( image(), &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + GetPPException; + TransformImageColorspace(image(),colorSpace_,&exceptionInfo); + ThrowPPException; } -void Magick::Image::clip ( void ) +Magick::ColorspaceType Magick::Image::colorSpace(void) const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ClipImage( image(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return (constImage()->colorspace); } -void Magick::Image::clipPath ( const std::string pathname_, - const bool inside_ ) +void Magick::Image::colorSpaceType(const ColorspaceType colorSpace_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ClipImagePath( image(), pathname_.c_str(), (MagickBooleanType) inside_, - &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + GetPPException; + SetImageColorspace(image(),colorSpace_,&exceptionInfo); + ThrowPPException; + options()->colorspaceType(colorSpace_); } -void Magick::Image::clut ( const Image &clutImage_, - const PixelInterpolateMethod method ) +Magick::ColorspaceType Magick::Image::colorSpaceType(void) const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ClutImage( image(), clutImage_.constImage(), method, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->colorspaceType()); +} + +size_t Magick::Image::columns(void) const +{ + return(constImage()->columns); } -void Magick::Image::clutChannel ( const ChannelType channel_, - const Image &clutImage_, - const PixelInterpolateMethod method) +void Magick::Image::comment(const std::string &comment_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - ClutImage( image(), clutImage_.constImage(), method, &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + GetPPException; + SetImageProperty(image(),"Comment",NULL,&exceptionInfo); + if (comment_.length() > 0) + SetImageProperty(image(),"Comment",comment_.c_str(),&exceptionInfo); + ThrowPPException; } -// Colorize -void Magick::Image::colorize ( const unsigned int alphaRed_, - const unsigned int alphaGreen_, - const unsigned int alphaBlue_, - const Color &penColor_ ) +std::string Magick::Image::comment(void) const { - if ( !penColor_.isValid() ) - throwExceptionExplicit( OptionError, "Pen color argument is invalid" ); + const char + *value; - char blend[MaxTextExtent]; - FormatLocaleString( blend, MaxTextExtent, "%u/%u/%u", - alphaRed_, alphaGreen_, alphaBlue_ ); + GetPPException; + value=GetImageProperty(constImage(),"Comment",&exceptionInfo); + ThrowPPException; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - PixelInfo target; - GetPixelInfo(image(),&target); - PixelInfo pixel=static_cast(penColor_); - target.red=pixel.red; - target.green=pixel.green; - target.blue=pixel.blue; - target.alpha=pixel.alpha; - MagickCore::Image* newImage = - ColorizeImage ( image(), blend, &target, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -void Magick::Image::colorize ( const unsigned int alpha_, - const Color &penColor_ ) -{ - colorize( alpha_, alpha_, alpha_, penColor_ ); -} - -// Apply a color matrix to the image channels. The user supplied -// matrix may be of order 1 to 6 (1x1 through 6x6). -void Magick::Image::colorMatrix ( const size_t order_, - const double *color_matrix_ ) -{ - KernelInfo - *kernel_info; + if (value) + return(std::string(value)); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - kernel_info=AcquireKernelInfo((const char *) NULL); - kernel_info->width=order_; - kernel_info->height=order_; - kernel_info->values=(MagickRealType *) AcquireAlignedMemory(order_, - order_*sizeof(*kernel_info->values)); - if (kernel_info->values != (MagickRealType *) NULL) - { - for (ssize_t i=0; i < (ssize_t) (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); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(std::string()); // Intentionally no exception } -// Compare current image with another image -// Sets meanErrorPerPixel, normalizedMaxError, and normalizedMeanError -// in the current image. False is returned if the images are identical. -bool Magick::Image::compare ( const Image &reference_ ) +void Magick::Image::compose(const CompositeOperator compose_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - modifyImage(); - Image ref = reference_; - ref.modifyImage(); - bool status = - static_cast(IsImagesEqual(image(), ref.image(), &exceptionInfo)); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - return status; -} -double Magick::Image::compare ( const Image &reference_, - const MetricType metric_) -{ - double distortion = 0.0; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - GetImageDistortion(image(), reference_.constImage(), metric_, &distortion, - &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - return distortion; + image()->compose=compose_; } -double Magick::Image::compareChannel ( const ChannelType channel_, - const Image &reference_, - const MetricType metric_) +Magick::CompositeOperator Magick::Image::compose(void) const { - double distortion = 0.0; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - GetImageDistortion(image(), reference_.constImage(), metric_, &distortion, - &exceptionInfo); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - return distortion; -} - -Magick::Image Magick::Image::compare ( const Image &reference_, - const MetricType metric_, - double *distortion ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = CompareImages(image(), reference_.constImage(), - metric_, distortion, &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - if (newImage == (MagickCore::Image *) NULL) - return Magick::Image(); - else - return Magick::Image( newImage ); -} - -Magick::Image Magick::Image::compareChannel ( const ChannelType channel_, - const Image &reference_, - const MetricType metric_, - double *distortion ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - MagickCore::Image* newImage = CompareImages(image(), reference_.constImage(), - metric_, distortion, &exceptionInfo); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - if (newImage == (MagickCore::Image *) NULL) - return Magick::Image(); - else - return Magick::Image( newImage ); + return(constImage()->compose); } -// Composite two images -void Magick::Image::composite ( const Image &compositeImage_, - const ssize_t xOffset_, - const ssize_t yOffset_, - const CompositeOperator compose_ ) +void Magick::Image::compressType(const CompressionType compressType_) { - // Image supplied as compositeImage is composited with current image and - // results in updating current image. modifyImage(); - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - CompositeImage( image(), compositeImage_.constImage(), compose_, MagickFalse, - xOffset_, yOffset_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + image()->compression=compressType_; + options()->compressType(compressType_); } -void Magick::Image::composite ( const Image &compositeImage_, - const Geometry &offset_, - const CompositeOperator compose_ ) +Magick::CompressionType Magick::Image::compressType(void) const { - modifyImage(); - - ssize_t x = offset_.xOff(); - ssize_t y = offset_.yOff(); - size_t width = columns(); - size_t height = rows(); - - ParseMetaGeometry ( static_cast(offset_).c_str(), - &x, &y, - &width, &height ); - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - CompositeImage( image(), compositeImage_.constImage(), compose_, MagickFalse, - x, y, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constImage()->compression); } -void Magick::Image::composite ( const Image &compositeImage_, - const GravityType gravity_, - const CompositeOperator compose_ ) +void Magick::Image::debug(const bool flag_) { modifyImage(); - - RectangleInfo geometry; - - SetGeometry(compositeImage_.constImage(), &geometry); - GravityAdjustGeometry(columns(), rows(), gravity_, &geometry); - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - CompositeImage( image(), compositeImage_.constImage(), compose_, MagickFalse, - geometry.x, geometry.y, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + options()->debug(flag_); } -// Contrast image -void Magick::Image::contrast ( const size_t sharpen_ ) +bool Magick::Image::debug(void) const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ContrastImage ( image(), (MagickBooleanType) sharpen_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->debug()); } -void Magick::Image::contrastStretch ( const double black_point_, - const double white_point_ ) +void Magick::Image::density(const Geometry &density_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ContrastStretchImage ( image(), black_point_, white_point_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + options()->density(density_); + if (density_.isValid()) + { + image()->resolution.x=density_.width(); + if (density_.height() != 0) + image()->resolution.y=density_.height(); + else + image()->resolution.y=density_.width(); + } + else + { + // Reset to default + image()->resolution.x=0; + image()->resolution.y=0; + } } -void Magick::Image::contrastStretchChannel ( const ChannelType channel_, - const double black_point_, - const double white_point_ ) +Magick::Geometry Magick::Image::density(void) const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - ContrastStretchImage ( image(), black_point_, white_point_, &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} + if (isValid()) + { + ssize_t + x_resolution=72, + y_resolution=72; -// Convolve image. Applies a general image convolution kernel to the image. -// order_ represents the number of columns and rows in the filter kernel. -// kernel_ is an array of doubles representing the convolution kernel. -void Magick::Image::convolve ( const size_t order_, - const double *kernel_ ) -{ - KernelInfo - *kernel_info; + if (constImage()->resolution.x > 0.0) + x_resolution=static_cast(constImage()->resolution.x + 0.5); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - kernel_info=AcquireKernelInfo((const char *) NULL); - kernel_info->width=order_; - kernel_info->height=order_; - kernel_info->values=(MagickRealType *) AcquireAlignedMemory(order_, - order_*sizeof(*kernel_info->values)); - if (kernel_info->values != (MagickRealType *) NULL) - { - for (ssize_t i=0; i < (ssize_t) (order_*order_); i++) - kernel_info->values[i]=kernel_[i]; - MagickCore::Image* newImage = - ConvolveImage ( image(), kernel_info, &exceptionInfo ); - replaceImage( newImage ); + if (constImage()->resolution.y > 0.0) + y_resolution=static_cast(constImage()->resolution.y + 0.5); + + return(Geometry(x_resolution,y_resolution)); } - kernel_info=DestroyKernelInfo(kernel_info); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} -// Crop image -void Magick::Image::crop ( const Geometry &geometry_ ) -{ - RectangleInfo cropInfo = geometry_; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - CropImage( image(), &cropInfo, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->density()); } -// Cycle Color Map -void Magick::Image::cycleColormap ( const ssize_t amount_ ) +void Magick::Image::depth(const size_t depth_) { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - CycleColormapImage( image(), amount_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} + size_t + depth = depth_; + + if (depth > MAGICKCORE_QUANTUM_DEPTH) + depth=MAGICKCORE_QUANTUM_DEPTH; -void Magick::Image::decipher ( const std::string &passphrase_ ) -{ modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - DecipherImage( image(), passphrase_.c_str(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + image()->depth=depth; + options()->depth(depth); } -// Despeckle -void Magick::Image::despeckle ( void ) +size_t Magick::Image::depth(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - DespeckleImage( image(), &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constImage()->depth); } -void Magick::Image::deskew ( const double threshold_ ) +std::string Magick::Image::directory(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - DeskewImage( image(), threshold_, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + if (constImage()->directory) + return(std::string(constImage()->directory)); + + throwExceptionExplicit(CorruptImageWarning, + "Image does not contain a directory"); + + return(std::string()); } -// Display image -void Magick::Image::display( void ) +void Magick::Image::endian(const Magick::EndianType endian_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - DisplayImages( imageInfo(), image(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + modifyImage(); + options()->endian(endian_); + image()->endian=endian_; } -// Distort image. distorts an image using various distortion methods, by -// mapping color lookups of the source image to a new destination image -// usally of the same size as the source image, unless 'bestfit' is set to -// true. -void Magick::Image::distort ( const DistortImageMethod method_, - const size_t number_arguments_, - const double *arguments_, - const bool bestfit_ ) +Magick::EndianType Magick::Image::endian(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = DistortImage ( image(), method_, - number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse, - &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constImage()->endian); } -// Draw on image using single drawable -void Magick::Image::draw ( const Magick::Drawable &drawable_ ) +void Magick::Image::exifProfile(const Magick::Blob &exifProfile_) { modifyImage(); - DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image()); - - if(wand) + if (exifProfile_.data() != 0) { - drawable_.operator()(wand); - - DrawRender(wand); - - wand=DestroyDrawingWand(wand); + StringInfo + *exif_profile; + + exif_profile=AcquireStringInfo(exifProfile_.length()); + SetStringInfoDatum(exif_profile,(unsigned char *) exifProfile_.data()); + GetPPException; + (void) SetImageProfile(image(),"exif",exif_profile,&exceptionInfo); + exif_profile=DestroyStringInfo(exif_profile); + ThrowPPException; } - - throwImageException(); } -// Draw on image using a drawable list -void Magick::Image::draw ( const std::list &drawable_ ) +Magick::Blob Magick::Image::exifProfile(void) const { - modifyImage(); + const StringInfo + *exif_profile; - DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image()); - - if(wand) - { - for( std::list::const_iterator p = drawable_.begin(); - p != drawable_.end(); p++ ) - { - p->operator()(wand); - } + exif_profile=GetImageProfile(constImage(),"exif"); + if (exif_profile == (StringInfo *) NULL) + return(Blob()); + return(Blob(GetStringInfoDatum(exif_profile), + GetStringInfoLength(exif_profile))); +} - DrawRender(wand); +void Magick::Image::fileName(const std::string &fileName_) +{ + modifyImage(); - wand=DestroyDrawingWand(wand); - } + fileName_.copy(image()->filename,sizeof(image()->filename)-1); + image()->filename[fileName_.length()]=0; // Null terminate - throwImageException(); + options()->fileName(fileName_); } -// Hilight edges in image -void Magick::Image::edge ( const double radius_ ) +std::string Magick::Image::fileName(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - EdgeImage( image(), radius_, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->fileName()); } -// Emboss image (hilight edges) -void Magick::Image::emboss ( const double radius_, const double sigma_ ) +MagickCore::MagickSizeType Magick::Image::fileSize(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - EmbossImage( image(), radius_, sigma_, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(GetBlobSize(constImage())); } -void Magick::Image::encipher ( const std::string &passphrase_ ) +void Magick::Image::fillColor(const Magick::Color &fillColor_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - EncipherImage( image(), passphrase_.c_str(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + options()->fillColor(fillColor_); } -// Enhance image (minimize noise) -void Magick::Image::enhance ( void ) +Magick::Color Magick::Image::fillColor(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - EnhanceImage( image(), &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->fillColor()); } -// Equalize image (histogram equalization) -void Magick::Image::equalize ( void ) +void Magick::Image::fillRule(const Magick::FillRule &fillRule_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); modifyImage(); - EqualizeImage( image(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + options()->fillRule(fillRule_); } -// Erase image to current "background color" -void Magick::Image::erase ( void ) +Magick::FillRule Magick::Image::fillRule(void) const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - SetImageBackgroundColor( image(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return constOptions()->fillRule(); } -// Extends image as defined by the geometry. -void Magick::Image::extent ( const Geometry &geometry_ ) +void Magick::Image::fillPattern(const Image &fillPattern_) { 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 ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + if (fillPattern_.isValid()) + options()->fillPattern(fillPattern_.constImage()); + else + options()->fillPattern(static_cast(NULL)); } -void Magick::Image::extent ( const Geometry &geometry_, - const Color &backgroundColor_ ) +Magick::Image Magick::Image::fillPattern(void) const { - backgroundColor ( backgroundColor_ ); - extent ( geometry_ ); -} + // FIXME: This is inordinately innefficient + const MagickCore::Image + *tmpTexture; -void Magick::Image::extent ( const Geometry &geometry_, - const GravityType gravity_ ) -{ - RectangleInfo geometry; + Image + texture; - SetGeometry(image(), &geometry); - geometry.width = geometry_.width(); - geometry.height = geometry_.height(); - GravityAdjustGeometry(image()->columns, image()->rows, gravity_, &geometry); - extent ( geometry ); -} + tmpTexture=constOptions()->fillPattern(); -void Magick::Image::extent ( const Geometry &geometry_, - const Color &backgroundColor_, - const GravityType gravity_ ) -{ - backgroundColor ( backgroundColor_ ); - extent ( geometry_, gravity_ ); + if (tmpTexture) + { + MagickCore::Image + *image; + + GetPPException; + image=CloneImage(tmpTexture,0,0,MagickTrue,&exceptionInfo); + texture.replaceImage(image); + ThrowPPException; + } + return(texture); } -// Flip image (reflect each scanline in the vertical direction) -void Magick::Image::flip ( void ) +void Magick::Image::filterType(const Magick::FilterTypes filterType_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - FlipImage( image(), &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + modifyImage(); + image()->filter=filterType_; } -// Flood-fill color across pixels that match the color of the -// target pixel and are neighbors of the target pixel. -// Uses current fuzz setting when determining color match. -void Magick::Image::floodFillColor ( const ssize_t x_, - const ssize_t y_, - const Magick::Color &fillColor_ ) +Magick::FilterTypes Magick::Image::filterType(void) const { - floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) ); + return(constImage()->filter); } -void Magick::Image::floodFillColor ( const Geometry &point_, - const Magick::Color &fillColor_ ) +void Magick::Image::font(const std::string &font_) { - floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) ); + modifyImage(); + options()->font(font_); } -// Flood-fill color across pixels starting at target-pixel and -// stopping at pixels matching specified border color. -// Uses current fuzz setting when determining color match. -void Magick::Image::floodFillColor ( const ssize_t x_, - const ssize_t y_, - const Magick::Color &fillColor_, - const Magick::Color &borderColor_ ) +std::string Magick::Image::font(void) const { - floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_), - borderColor_ ); + return(constOptions()->font()); } -void Magick::Image::floodFillColor ( const Geometry &point_, - const Magick::Color &fillColor_, - const Magick::Color &borderColor_ ) +void Magick::Image::fontPointsize(const double pointSize_) { - floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_), - borderColor_ ); + modifyImage(); + options()->fontPointsize(pointSize_); } -// Floodfill pixels matching color (within fuzz factor) of target -// pixel(x,y) with replacement alpha value using method. -void Magick::Image::floodFillAlpha ( const ssize_t x_, - const ssize_t y_, - const unsigned int alpha_, - const PaintMethod method_ ) +double Magick::Image::fontPointsize(void) const { - modifyImage(); - PixelInfo target; - GetPixelInfo(image(),&target); - PixelInfo pixel=static_cast(pixelColor(x_,y_)); - target.red=pixel.red; - target.green=pixel.green; - target.blue=pixel.blue; - target.alpha=alpha_; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - FloodfillPaintImage ( image(), - options()->drawInfo(), // const DrawInfo *draw_info - &target, - static_cast(x_), static_cast(y_), - method_ == FloodfillMethod ? MagickFalse : MagickTrue, - &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->fontPointsize()); } -// Flood-fill texture across pixels that match the color of the -// target pixel and are neighbors of the target pixel. -// Uses current fuzz setting when determining color match. -void Magick::Image::floodFillTexture ( const ssize_t x_, - const ssize_t y_, - const Magick::Image &texture_ ) +std::string Magick::Image::format(void) const { - modifyImage(); + const MagickInfo + *magick_info; - // Set drawing pattern - options()->fillPattern(texture_.constImage()); + GetPPException; + magick_info=GetMagickInfo(constImage()->magick,&exceptionInfo); + ThrowPPException; - // Get pixel view - Pixels pixels(*this); - // Fill image - Quantum *p = pixels.get(x_, y_, 1, 1 ); - PixelInfo target; - GetPixelInfo(constImage(),&target); - target.red=GetPixelRed(constImage(),p); - target.green=GetPixelGreen(constImage(),p); - target.blue=GetPixelBlue(constImage(),p); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - if (p) - FloodfillPaintImage ( image(), // Image *image - options()->drawInfo(), // const DrawInfo *draw_info - &target, // const MagickPacket target - static_cast(x_), // const ssize_t x_offset - static_cast(y_), // const ssize_t y_offset - MagickFalse, // const PaintMethod method - &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + if ((magick_info != 0) && (*magick_info->description != '\0')) + return(std::string(magick_info->description)); + + throwExceptionExplicit(CorruptImageWarning,"Unrecognized image magick type"); + return(std::string()); } -void Magick::Image::floodFillTexture ( const Magick::Geometry &point_, - const Magick::Image &texture_ ) +double Magick::Image::gamma(void) const { - floodFillTexture( point_.xOff(), point_.yOff(), texture_ ); + return(constImage()->gamma); } -// Flood-fill texture across pixels starting at target-pixel and -// stopping at pixels matching specified border color. -// Uses current fuzz setting when determining color match. -void Magick::Image::floodFillTexture ( const ssize_t x_, - const ssize_t y_, - const Magick::Image &texture_, - const Magick::Color &borderColor_ ) +Magick::Geometry Magick::Image::geometry(void) const { - modifyImage(); + if (constImage()->geometry) + return Geometry(constImage()->geometry); - // Set drawing fill pattern - options()->fillPattern(texture_.constImage()); + throwExceptionExplicit(OptionWarning,"Image does not contain a geometry"); - PixelInfo target; - GetPixelInfo(constImage(),&target); - target.red=static_cast(borderColor_).red; - target.green=static_cast(borderColor_).green; - target.blue=static_cast(borderColor_).blue; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - FloodfillPaintImage ( image(), - options()->drawInfo(), - &target, - static_cast(x_), - static_cast(y_), - MagickTrue, &exceptionInfo); - - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(Geometry()); } -void Magick::Image::floodFillTexture ( const Magick::Geometry &point_, - const Magick::Image &texture_, - const Magick::Color &borderColor_ ) +void Magick::Image::gifDisposeMethod( + const MagickCore::DisposeType disposeMethod_) { - floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ ); + modifyImage(); + image()->dispose=disposeMethod_; } -// Flop image (reflect each scanline in the horizontal direction) -void Magick::Image::flop ( void ) +MagickCore::DisposeType Magick::Image::gifDisposeMethod(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - FlopImage( image(), &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constImage()->dispose); } -// Frame image -void Magick::Image::frame ( const Geometry &geometry_ ) +void Magick::Image::iccColorProfile(const Magick::Blob &colorProfile_) { - FrameInfo info; - - info.x = static_cast(geometry_.width()); - info.y = static_cast(geometry_.height()); - info.width = columns() + ( static_cast(info.x) << 1 ); - info.height = rows() + ( static_cast(info.y) << 1 ); - info.outer_bevel = geometry_.xOff(); - info.inner_bevel = geometry_.yOff(); + profile("icm",colorProfile_); +} - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - FrameImage( image(), &info, image()->compose, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -void Magick::Image::frame ( const size_t width_, - const size_t height_, - const ssize_t outerBevel_, - const ssize_t innerBevel_ ) +Magick::Blob Magick::Image::iccColorProfile(void) const { - FrameInfo info; - info.x = static_cast(width_); - info.y = static_cast(height_); - info.width = columns() + ( static_cast(info.x) << 1 ); - info.height = rows() + ( static_cast(info.y) << 1 ); - info.outer_bevel = static_cast(outerBevel_); - info.inner_bevel = static_cast(innerBevel_); + const StringInfo + *color_profile; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - FrameImage( image(), &info, image()->compose, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + color_profile=GetImageProfile(constImage(),"icc"); + if (color_profile == (StringInfo *) NULL) + return(Blob()); + return(Blob(GetStringInfoDatum(color_profile),GetStringInfoLength( + color_profile))); } -// Fx image. Applies a mathematical expression to the image. -void Magick::Image::fx ( const std::string expression ) +void Magick::Image::interlaceType(const Magick::InterlaceType interlace_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - FxImage ( image(), expression.c_str(), &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + modifyImage(); + image()->interlace=interlace_; + options()->interlaceType(interlace_); } -void Magick::Image::fx ( const std::string expression, - const Magick::ChannelType channel ) +Magick::InterlaceType Magick::Image::interlaceType(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel ); - MagickCore::Image* newImage = - FxImage ( image(), expression.c_str(), &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constImage()->interlace); } -// Gamma correct image -void Magick::Image::gamma ( const double gamma_ ) +void Magick::Image::iptcProfile(const Magick::Blob &iptcProfile_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); modifyImage(); - GammaImage ( image(), gamma_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + if (iptcProfile_.data() != 0) + { + StringInfo + *iptc_profile; + + iptc_profile=AcquireStringInfo(iptcProfile_.length()); + SetStringInfoDatum(iptc_profile,(unsigned char *) iptcProfile_.data()); + GetPPException; + (void) SetImageProfile(image(),"iptc",iptc_profile,&exceptionInfo); + iptc_profile=DestroyStringInfo(iptc_profile); + ThrowPPException; + } } -void Magick::Image::gamma ( const double gammaRed_, - const double gammaGreen_, - const double gammaBlue_ ) -{ - char gamma[MaxTextExtent + 1]; - FormatLocaleString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/", - gammaRed_, gammaGreen_, gammaBlue_); - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - modifyImage(); - GammaImage ( image(), atof(gamma), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Gaussian blur image -// The number of neighbor pixels to be included in the convolution -// mask is specified by 'width_'. The standard deviation of the -// gaussian bell curve is specified by 'sigma_'. -void Magick::Image::gaussianBlur ( const double width_, const double sigma_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - GaussianBlurImage( image(), width_, sigma_, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -void Magick::Image::gaussianBlurChannel ( const ChannelType channel_, - const double width_, - const double sigma_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - MagickCore::Image* newImage = - GaussianBlurImage( image(), width_, sigma_, &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Apply a color lookup table (Hald CLUT) to the image. -void Magick::Image::haldClut ( const Image &clutImage_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - modifyImage(); - (void) HaldClutImage( image(), clutImage_.constImage(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Implode image -void Magick::Image::implode ( const double factor_ ) +Magick::Blob Magick::Image::iptcProfile(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - ImplodeImage( image(), factor_, image()->interpolate, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} + const StringInfo + *iptc_profile; + + iptc_profile=GetImageProfile(constImage(),"iptc"); + if (iptc_profile == (StringInfo *) NULL) + return(Blob()); + return(Blob(GetStringInfoDatum(iptc_profile),GetStringInfoLength( + iptc_profile))); +} -// implements the inverse discrete Fourier transform (IFT) of the image either -// as a magnitude / phase or real / imaginary image pair. -void Magick::Image::inverseFourierTransform ( const Image &phase_ ) +void Magick::Image::isValid(const bool isValid_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - InverseFourierTransformImage( image(), phase_.constImage(), MagickTrue, - &exceptionInfo); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + if (!isValid_) + { + delete _imgRef; + _imgRef=new ImageRef; + } + else if (!isValid()) + { + // Construct with single-pixel black image to make + // image valid. This is an obvious hack. + size(Geometry(1,1)); + read("xc:black"); + } } -void Magick::Image::inverseFourierTransform ( const Image &phase_, - const bool magnitude_ ) +bool Magick::Image::isValid(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - InverseFourierTransformImage( image(), phase_.constImage(), - magnitude_ == true ? MagickTrue : MagickFalse, - &exceptionInfo); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} + return rows() && columns(); +} -// Level image. Adjust the levels of the image by scaling the colors -// falling between specified white and black points to the full -// available quantum range. The parameters provided represent the -// black, mid (gamma), and white points. The black point specifies -// the darkest color in the image. Colors darker than the black point -// are set to zero. Mid point (gamma) specifies a gamma correction to -// apply to the image. White point specifies the lightest color in the -// image. Colors brighter than the white point are set to the maximum -// quantum value. The black and white point have the valid range 0 to -// QuantumRange while gamma has a useful range of 0 to ten. -void Magick::Image::level ( const double blackPoint_, - const double whitePoint_, - const double gamma_ ) -{ - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - (void) LevelImage( image(), blackPoint_, whitePoint_, gamma_, - &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -void Magick::Image::levelChannel ( const ChannelType channel_, - const double blackPoint_, - const double whitePoint_, - const double gamma_ ) -{ - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - (void) LevelImage( image(), blackPoint_, whitePoint_, gamma_, - &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -void Magick::Image::levelColors ( const Color &blackColor_, - const Color &whiteColor_, - const bool invert_ ) -{ +void Magick::Image::label(const std::string &label_) +{ modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); + GetPPException; + SetImageProperty(image(),"Label",NULL,&exceptionInfo); + if (label_.length() > 0) + SetImageProperty(image(),"Label",label_.c_str(),&exceptionInfo); + ThrowPPException; +} - PixelInfo black; - GetPixelInfo(image(), &black); - PixelInfo pixel=static_cast(blackColor_); - black.red=pixel.red; - black.green=pixel.green; - black.blue=pixel.blue; - black.alpha=pixel.alpha; +std::string Magick::Image::label(void) const +{ + const char + *value; - PixelInfo white; - GetPixelInfo(image(), &white); - pixel=static_cast(whiteColor_); - white.red=pixel.red; - white.green=pixel.green; - white.blue=pixel.blue; - white.alpha=pixel.alpha; + GetPPException; + value=GetImageProperty(constImage(),"Label",&exceptionInfo); + ThrowPPException; + + if (value) + return(std::string(value)); - (void) LevelImageColors( image(), &black, &white, - invert_ == true ? MagickTrue : MagickFalse, - &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(std::string()); } -void Magick::Image::levelColorsChannel ( const ChannelType channel_, - const Color &blackColor_, - const Color &whiteColor_, - const bool invert_ ) +void Magick::Image::magick(const std::string &magick_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - PixelInfo black; - GetPixelInfo(image(), &black); - PixelInfo pixel=static_cast(blackColor_); - black.red=pixel.red; - black.green=pixel.green; - black.blue=pixel.blue; - black.alpha=pixel.alpha; + magick_.copy(image()->magick,sizeof(image()->magick)-1); + image()->magick[magick_.length()]=0; + + options()->magick(magick_); +} - PixelInfo white; - GetPixelInfo(image(), &white); - pixel=static_cast(whiteColor_); - white.red=pixel.red; - white.green=pixel.green; - white.blue=pixel.blue; - white.alpha=pixel.alpha; +std::string Magick::Image::magick(void) const +{ + if (*(constImage()->magick) != '\0') + return(std::string(constImage()->magick)); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - (void) LevelImageColors( image(), &black, &white, - invert_ == true ? MagickTrue : MagickFalse, - &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->magick()); } -void Magick::Image::linearStretch ( const double blackPoint_, - const double whitePoint_ ) +double Magick::Image::meanErrorPerPixel(void) const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - LinearStretchImage( image(), blackPoint_, whitePoint_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constImage()->error.mean_error_per_pixel); } -void Magick::Image::liquidRescale ( const Geometry &geometry_ ) +void Magick::Image::modulusDepth(const size_t depth_) { - ssize_t x = 0; - ssize_t y = 0; - size_t width = columns(); - size_t height = rows(); - - ParseMetaGeometry( static_cast(geometry_).c_str(), - &x, &y, - &width, &height ); - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = LiquidRescaleImage( image(), width, height, - x, y, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + modifyImage(); + GetPPException; + SetImageDepth(image(),depth_,&exceptionInfo); + ThrowPPException; + options()->depth(depth_); } -// Magnify image by integral size -void Magick::Image::magnify ( void ) +size_t Magick::Image::modulusDepth(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = MagnifyImage( image(), &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + size_t + depth; + + GetPPException; + depth=GetImageDepth(constImage(),&exceptionInfo); + ThrowPPException; + return(depth); } -// Remap image colors with closest color from reference image -void Magick::Image::map ( const Image &mapImage_, const bool dither_ ) +void Magick::Image::monochrome(const bool monochromeFlag_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); modifyImage(); - options()->quantizeDither( dither_ ); - RemapImage ( options()->quantizeInfo(), image(), - mapImage_.constImage(), &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + options()->monochrome(monochromeFlag_); } -// Floodfill designated area with replacement alpha value -void Magick::Image::alphaFloodfill ( const Color &target_, - const unsigned int alpha_, - const ssize_t x_, const ssize_t y_, - const Magick::PaintMethod method_ ) +bool Magick::Image::monochrome(void) const { - modifyImage(); - PixelInfo target; - GetPixelInfo(constImage(),&target); - target.red=static_cast(target_).red; - target.green=static_cast(target_).green; - target.blue=static_cast(target_).blue; - target.alpha=alpha_; - ChannelType channel_mask = SetImageChannelMask( image(), AlphaChannel ); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - FloodfillPaintImage ( image(), options()->drawInfo(), &target, x_, y_, - method_ == FloodfillMethod ? MagickFalse : MagickTrue, &exceptionInfo); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->monochrome()); } -// Filter image by replacing each pixel component with the median -// color in a circular neighborhood -void Magick::Image::medianFilter ( const double radius_ ) +Magick::Geometry Magick::Image::montageGeometry(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - StatisticImage ( image(), MedianStatistic, (size_t) radius_, - (size_t) radius_, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + if (constImage()->montage) + return Magick::Geometry(constImage()->montage); + + throwExceptionExplicit(CorruptImageWarning, + "Image does not contain a montage"); + + return(Magick::Geometry()); } -// Reduce image by integral size -void Magick::Image::minify ( void ) +double Magick::Image::normalizedMaxError(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - MinifyImage( image(), &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constImage()->error.normalized_maximum_error); } -// Modulate percent hue, saturation, and brightness of an image -void Magick::Image::modulate ( const double brightness_, - const double saturation_, - const double hue_ ) +double Magick::Image::normalizedMeanError(void) const { - char modulate[MaxTextExtent + 1]; - FormatLocaleString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f", - brightness_, saturation_, hue_); + return(constImage()->error.normalized_mean_error); +} - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); +void Magick::Image::orientation(const Magick::OrientationType orientation_) +{ modifyImage(); - ModulateImage( image(), modulate, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + image()->orientation=orientation_; } -// Motion blur image with specified blur factor -// The radius_ parameter specifies the radius of the Gaussian, in -// pixels, not counting the center pixel. The sigma_ parameter -// specifies the standard deviation of the Laplacian, in pixels. -// The angle_ parameter specifies the angle the object appears -// to be comming from (zero degrees is from the right). -void Magick::Image::motionBlur ( const double radius_, - const double sigma_, - const double angle_ ) +Magick::OrientationType Magick::Image::orientation(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - MotionBlurImage( image(), radius_, sigma_, angle_, &exceptionInfo); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constImage()->orientation); } -// Negate image. Set grayscale_ to true to effect grayscale values -// only -void Magick::Image::negate ( const bool grayscale_ ) +void Magick::Image::page(const Magick::Geometry &pageSize_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); modifyImage(); - NegateImage( image(), (MagickBooleanType) grayscale_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + options()->page(pageSize_); + image()->page=pageSize_; } -void Magick::Image::negateChannel ( const ChannelType channel_, - const bool grayscale_ ) +Magick::Geometry Magick::Image::page(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - modifyImage(); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - NegateImage( image(), (MagickBooleanType) grayscale_, &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(Geometry(constImage()->page.width,constImage()->page.height, + AbsoluteValue(constImage()->page.x),AbsoluteValue(constImage()->page.y), + constImage()->page.x < 0 ? true : false, + constImage()->page.y < 0 ? true : false)); } -// Normalize image -void Magick::Image::normalize ( void ) +void Magick::Image::quality(const size_t quality_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - NormalizeImage ( image(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + image()->quality=quality_; + options()->quality(quality_); } -// Oilpaint image -void Magick::Image::oilPaint ( const double radius_, const double sigma_ ) +size_t Magick::Image::quality(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - OilPaintImage( image(), radius_, sigma_, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constImage()->quality); } -// Change the color of an opaque pixel to the pen color. -void Magick::Image::opaque ( const Color &opaqueColor_, - const Color &penColor_ ) +void Magick::Image::quantizeColors(const size_t colors_) { - if ( !opaqueColor_.isValid() ) - throwExceptionExplicit( OptionError, "Opaque color argument is invalid" ); - - if ( !penColor_.isValid() ) - throwExceptionExplicit( OptionError, "Pen color argument is invalid" ); - modifyImage(); - std::string opaqueColor = opaqueColor_; - std::string penColor = penColor_; - - PixelInfo opaque; - PixelInfo pen; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - (void) QueryColorCompliance( std::string(opaqueColor_).c_str(), - AllCompliance, &opaque, &exceptionInfo ); - (void) QueryColorCompliance( std::string(penColor_).c_str(), - AllCompliance, &pen, &exceptionInfo ); - OpaquePaintImage ( image(), &opaque, &pen, MagickFalse, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + options()->quantizeColors(colors_); } -void Magick::Image::perceptible ( const double epsilon_ ) +size_t Magick::Image::quantizeColors(void) const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - PerceptibleImage( image(), epsilon_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->quantizeColors()); } -void Magick::Image::perceptibleChannel ( const ChannelType channel_, - const double epsilon_ ) +void Magick::Image::quantizeColorSpace( + const Magick::ColorspaceType colorSpace_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - PerceptibleImage( image(), epsilon_, &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + options()->quantizeColorSpace(colorSpace_); } -// Ping is similar to read except only enough of the image is read to -// determine the image columns, rows, and filesize. Access the -// columns(), rows(), and fileSize() attributes after invoking ping. -// The image data is not valid after calling ping. -void Magick::Image::ping ( const std::string &imageSpec_ ) +Magick::ColorspaceType Magick::Image::quantizeColorSpace(void) const { - options()->fileName( imageSpec_ ); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* image = - PingImage( imageInfo(), &exceptionInfo ); - replaceImage( image ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->quantizeColorSpace()); } -// Ping is similar to read except only enough of the image is read -// to determine the image columns, rows, and filesize. Access the -// columns(), rows(), and fileSize() attributes after invoking -// ping. The image data is not valid after calling ping. -void Magick::Image::ping ( const Blob& blob_ ) +void Magick::Image::quantizeDither(const bool ditherFlag_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* image = - PingBlob( imageInfo(), blob_.data(), blob_.length(), &exceptionInfo ); - replaceImage( image ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + modifyImage(); + options()->quantizeDither(ditherFlag_); } -void Magick::Image::polaroid ( const std::string &caption_, - const double angle_, - const PixelInterpolateMethod method_ ) +bool Magick::Image::quantizeDither(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* image = - PolaroidImage( constImage(), options()->drawInfo(), caption_.c_str(), - angle_, method_, &exceptionInfo ); - replaceImage( image ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->quantizeDither()); } -void Magick::Image::posterize ( const size_t levels_, - const DitherMethod method_ ) +void Magick::Image::quantizeTreeDepth(const size_t treeDepth_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - PosterizeImage( image(), levels_, method_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + options()->quantizeTreeDepth(treeDepth_); } -void Magick::Image::posterizeChannel ( const ChannelType channel_, - const size_t levels_, - const DitherMethod method_ ) +size_t Magick::Image::quantizeTreeDepth() const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - PosterizeImage( image(), levels_, method_, &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->quantizeTreeDepth()); } -// Execute a named process module using an argc/argv syntax similar to -// that accepted by a C 'main' routine. An exception is thrown if the -// requested process module doesn't exist, fails to load, or fails during -// execution. -void Magick::Image::process( std::string name_, - const ssize_t argc, - const char **argv ) +void Magick::Image::renderingIntent( + const Magick::RenderingIntent renderingIntent_) { modifyImage(); + image()->rendering_intent=renderingIntent_; +} - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - size_t status = - InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv, - &exceptionInfo ); - (void) status; - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); +Magick::RenderingIntent Magick::Image::renderingIntent(void) const +{ + return(static_cast(constImage()->rendering_intent)); } -// Quantize colors in image using current quantization settings -// Set measureError_ to true in order to measure quantization error -void Magick::Image::quantize ( const bool measureError_ ) +void Magick::Image::resolutionUnits( + const Magick::ResolutionType resolutionUnits_) { modifyImage(); - - if (measureError_) - options()->quantizeInfo()->measure_error=MagickTrue; - else - options()->quantizeInfo()->measure_error=MagickFalse; - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - QuantizeImage( options()->quantizeInfo(), image(), &exceptionInfo ); - - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + image()->units=resolutionUnits_; + options()->resolutionUnits(resolutionUnits_); } -// Apply an arithmetic or bitwise operator to the image pixel quantums. -void Magick::Image::quantumOperator ( const ChannelType channel_, - const MagickEvaluateOperator operator_, - double rvalue_) +Magick::ResolutionType Magick::Image::resolutionUnits(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - EvaluateImage( image(), operator_, rvalue_, &exceptionInfo); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->resolutionUnits()); } -void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_, - const size_t columns_, - const size_t rows_, - const ChannelType channel_, - const MagickEvaluateOperator operator_, - const double rvalue_) +size_t Magick::Image::rows(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - RectangleInfo geometry; - geometry.width = columns_; - geometry.height = rows_; - geometry.x = x_; - geometry.y = y_; - MagickCore::Image *crop_image = CropImage( image(), &geometry, - &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_); - EvaluateImage( crop_image, operator_, rvalue_, &exceptionInfo ); - 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 ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constImage()->rows); } -// Raise image (lighten or darken the edges of an image to give a 3-D -// raised or lowered effect) -void Magick::Image::raise ( const Geometry &geometry_ , - const bool raisedFlag_ ) +void Magick::Image::scene(const size_t scene_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - RectangleInfo raiseInfo = geometry_; modifyImage(); - RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + image()->scene=scene_; } - -// Random threshold image. -// -// Changes the value of individual pixels based on the intensity -// of each pixel compared to a random threshold. The result is a -// low-contrast, two color image. The thresholds_ argument is a -// geometry containing LOWxHIGH thresholds. If the string -// contains 2x2, 3x3, or 4x4, then an ordered dither of order 2, -// 3, or 4 will be performed instead. If a channel_ argument is -// specified then only the specified channel is altered. This is -// a very fast alternative to 'quantize' based dithering. -void Magick::Image::randomThreshold( const Geometry &thresholds_ ) -{ - randomThresholdChannel(thresholds_,DefaultChannels); -} -void Magick::Image::randomThresholdChannel( const Geometry &thresholds_, - const ChannelType channel_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - modifyImage(); - ChannelType channel_mask = SetImageChannelMask( image(), channel_); - (void) RandomThresholdImage( image(), - static_cast(thresholds_).c_str(), - &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - throwImageException(); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Read image into current object -void Magick::Image::read ( const std::string &imageSpec_ ) -{ - options()->fileName( imageSpec_ ); - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* image = - ReadImage( imageInfo(), &exceptionInfo ); - - // Ensure that multiple image frames were not read. - if ( image && image->next ) - { - // Destroy any extra image frames - MagickCore::Image* next = image->next; - image->next = 0; - next->previous = 0; - DestroyImageList( next ); - - } - replaceImage( image ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); +size_t Magick::Image::scene(void) const +{ + return(constImage()->scene); } -// Read image of specified size into current object -void Magick::Image::read ( const Geometry &size_, - const std::string &imageSpec_ ) +void Magick::Image::size(const Geometry &geometry_) { - size( size_ ); - read( imageSpec_ ); + modifyImage(); + options()->size(geometry_); + image()->rows=geometry_.height(); + image()->columns=geometry_.width(); } -// Read image from in-memory BLOB -void Magick::Image::read ( const Blob &blob_ ) +Magick::Geometry Magick::Image::size(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* image = - BlobToImage( imageInfo(), - static_cast(blob_.data()), - blob_.length(), &exceptionInfo ); - replaceImage( image ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(Magick::Geometry(constImage()->columns,constImage()->rows)); } -// Read image of specified size from in-memory BLOB -void Magick::Image::read ( const Blob &blob_, - const Geometry &size_ ) +void Magick::Image::strokeAntiAlias(const bool flag_) { - // Set image size - size( size_ ); - // Read from Blob - read( blob_ ); + modifyImage(); + options()->strokeAntiAlias(flag_); } -// Read image of specified size and depth from in-memory BLOB -void Magick::Image::read ( const Blob &blob_, - const Geometry &size_, - const size_t depth_ ) +bool Magick::Image::strokeAntiAlias(void) const { - // Set image size - size( size_ ); - // Set image depth - depth( depth_ ); - // Read from Blob - read( blob_ ); + return(constOptions()->strokeAntiAlias()); } -// Read image of specified size, depth, and format from in-memory BLOB -void Magick::Image::read ( const Blob &blob_, - const Geometry &size_, - const size_t depth_, - const std::string &magick_ ) +void Magick::Image::strokeColor(const Magick::Color &strokeColor_) { - // Set image size - size( size_ ); - // Set image depth - depth( depth_ ); - // Set image magick - magick( magick_ ); - // Set explicit image format - fileName( magick_ + ':'); - // Read from Blob - read( blob_ ); + modifyImage(); + options()->strokeColor(strokeColor_); } -// Read image of specified size, and format from in-memory BLOB -void Magick::Image::read ( const Blob &blob_, - const Geometry &size_, - const std::string &magick_ ) -{ - // Set image size - size( size_ ); - // Set image magick - magick( magick_ ); - // Set explicit image format - fileName( magick_ + ':'); - // Read from Blob - read( blob_ ); -} - -// Read image based on raw pixels in memory (ConstituteImage) -void Magick::Image::read ( const size_t width_, - const size_t height_, - const std::string &map_, - const StorageType type_, - const void *pixels_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* image = - ConstituteImage( width_, height_, map_.c_str(), type_, pixels_, - &exceptionInfo ); - replaceImage( image ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Reduce noise in image -void Magick::Image::reduceNoise ( const double order_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - StatisticImage( image(), NonpeakStatistic, (size_t) order_, (size_t) order_, - &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Resize image -void Magick::Image::resize( const Geometry &geometry_ ) +Magick::Color Magick::Image::strokeColor(void) const { - // Calculate new size. This code should be supported using binary arguments - // in the ImageMagick library. - ssize_t x = 0; - ssize_t y = 0; - size_t width = columns(); - size_t height = rows(); - - ParseMetaGeometry (static_cast(geometry_).c_str(), - &x, &y, - &width, &height ); - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - ResizeImage( image(), - width, - height, - image()->filter, - &exceptionInfo); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Roll image -void Magick::Image::roll ( const Geometry &roll_ ) -{ - ssize_t xOff = roll_.xOff(); - if ( roll_.xNegative() ) - xOff = 0 - xOff; - ssize_t yOff = roll_.yOff(); - if ( roll_.yNegative() ) - yOff = 0 - yOff; - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - RollImage( image(), xOff, yOff, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} -void Magick::Image::roll ( const size_t columns_, - const size_t rows_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - RollImage( image(), - static_cast(columns_), - static_cast(rows_), &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Rotate image -void Magick::Image::rotate ( const double degrees_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - RotateImage( image(), degrees_, &exceptionInfo); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Sample image -void Magick::Image::sample ( const Geometry &geometry_ ) -{ - ssize_t x = 0; - ssize_t y = 0; - size_t width = columns(); - size_t height = rows(); - - ParseMetaGeometry (static_cast(geometry_).c_str(), - &x, &y, - &width, &height ); - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - SampleImage( image(), width, height, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Scale image -void Magick::Image::scale ( const Geometry &geometry_ ) -{ - ssize_t x = 0; - ssize_t y = 0; - size_t width = columns(); - size_t height = rows(); - - ParseMetaGeometry (static_cast(geometry_).c_str(), - &x, &y, - &width, &height ); - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - ScaleImage( image(), width, height, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Segment (coalesce similar image components) by analyzing the -// histograms of the color components and identifying units that are -// homogeneous with the fuzzy c-means technique. -void Magick::Image::segment ( const double clusterThreshold_, - const double smoothingThreshold_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - modifyImage(); - SegmentImage ( image(), - options()->quantizeColorSpace(), - (MagickBooleanType) options()->verbose(), - clusterThreshold_, - smoothingThreshold_, &exceptionInfo ); - SyncImage( image(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Shade image using distant light source -void Magick::Image::shade ( const double azimuth_, - const double elevation_, - const bool colorShading_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - ShadeImage( image(), - colorShading_ == true ? MagickTrue : MagickFalse, - azimuth_, - elevation_, - &exceptionInfo); - replaceImage( newImage ); - throwException( exceptionInfo ); - (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_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - SharpenImage( image(), - radius_, - sigma_, - &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -void Magick::Image::sharpenChannel ( const ChannelType channel_, - const double radius_, const double sigma_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - MagickCore::Image* newImage = - SharpenImage( image(), - radius_, - sigma_, - &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Shave pixels from image edges. -void Magick::Image::shave ( const Geometry &geometry_ ) -{ - RectangleInfo shaveInfo = geometry_; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - ShaveImage( image(), - &shaveInfo, - &exceptionInfo); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Shear image -void Magick::Image::shear ( const double xShearAngle_, - const double yShearAngle_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - ShearImage( image(), - xShearAngle_, - yShearAngle_, - &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Contrast image -void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - modifyImage(); - (void) SigmoidalContrastImage( image(), (MagickBooleanType) sharpen_, contrast, midpoint, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Solarize image (similar to effect seen when exposing a photographic -// film to light during the development process) -void Magick::Image::solarize ( const double factor_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - modifyImage(); - SolarizeImage ( image(), factor_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} + return(constOptions()->strokeColor()); +} -// Sparse color image, given a set of coordinates, interpolates the colors -// found at those coordinates, across the whole image, using various methods. -// -void Magick::Image::sparseColor ( const ChannelType channel, - const SparseColorMethod method, - const size_t number_arguments, - const double *arguments ) +void Magick::Image::strokeDashArray(const double *strokeDashArray_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); + modifyImage(); + options()->strokeDashArray(strokeDashArray_); +} - ChannelType channel_mask = SetImageChannelMask( image(), channel ); - MagickCore::Image* newImage = SparseColorImage ( image(), method, - number_arguments, arguments, &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); +const double* Magick::Image::strokeDashArray(void) const +{ + return(constOptions()->strokeDashArray()); } -// Spread pixels randomly within image by specified ammount -void Magick::Image::spread ( const size_t amount_ ) +void Magick::Image::strokeDashOffset(const double strokeDashOffset_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - SpreadImage( image(), - amount_, - image()->interpolate, - &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + modifyImage(); + options()->strokeDashOffset(strokeDashOffset_); } -// Add a digital watermark to the image (based on second image) -void Magick::Image::stegano ( const Image &watermark_ ) +double Magick::Image::strokeDashOffset(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - SteganoImage( image(), - watermark_.constImage(), - &exceptionInfo); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->strokeDashOffset()); } -// Stereo image (left image is current image) -void Magick::Image::stereo ( const Image &rightImage_ ) +void Magick::Image::strokeLineCap(const Magick::LineCap lineCap_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - StereoImage( image(), - rightImage_.constImage(), - &exceptionInfo); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + modifyImage(); + options()->strokeLineCap(lineCap_); } -// Swirl image -void Magick::Image::swirl ( const double degrees_ ) +Magick::LineCap Magick::Image::strokeLineCap(void) const { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - SwirlImage( image(), degrees_, image()->interpolate, - &exceptionInfo); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->strokeLineCap()); } -// Texture image -void Magick::Image::texture ( const Image &texture_ ) +void Magick::Image::strokeLineJoin(const Magick::LineJoin lineJoin_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - TextureImage( image(), texture_.constImage(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + options()->strokeLineJoin(lineJoin_); } -// Threshold image -void Magick::Image::threshold ( const double threshold_ ) +Magick::LineJoin Magick::Image::strokeLineJoin(void) const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - BilevelImage( image(), threshold_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->strokeLineJoin()); } -// Transform image based on image geometry only -void Magick::Image::transform ( const Geometry &imageGeometry_ ) +void Magick::Image::strokeMiterLimit(const size_t strokeMiterLimit_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - TransformImage ( &(image()), 0, - std::string(imageGeometry_).c_str(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + options()->strokeMiterLimit(strokeMiterLimit_); } -// Transform image based on image and crop geometries -void Magick::Image::transform ( const Geometry &imageGeometry_, - const Geometry &cropGeometry_ ) + +size_t Magick::Image::strokeMiterLimit(void) const { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - TransformImage ( &(image()), std::string(cropGeometry_).c_str(), - std::string(imageGeometry_).c_str(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->strokeMiterLimit()); } -// Add matte image to image, setting pixels matching color to transparent -void Magick::Image::transparent ( const Color &color_ ) +void Magick::Image::strokePattern(const Image &strokePattern_) { - if ( !color_.isValid() ) - { - throwExceptionExplicit( OptionError, - "Color argument is invalid" ); - } - - std::string color = color_; - - PixelInfo target; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - (void) QueryColorCompliance(std::string(color_).c_str(),AllCompliance, - &target,&exceptionInfo); modifyImage(); - TransparentPaintImage ( image(), &target, TransparentAlpha, MagickFalse, - &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + if(strokePattern_.isValid()) + options()->strokePattern(strokePattern_.constImage()); + else + options()->strokePattern(static_cast(NULL)); } -// Add matte image to image, setting pixels matching color to transparent -void Magick::Image::transparentChroma(const Color &colorLow_, - const Color &colorHigh_) +Magick::Image Magick::Image::strokePattern(void) const { - if ( !colorLow_.isValid() || !colorHigh_.isValid() ) - { - throwExceptionExplicit( OptionError, - "Color argument is invalid" ); - } + // FIXME: This is inordinately innefficient + const MagickCore::Image + *tmpTexture; + + Image + texture; - std::string colorLow = colorLow_; - std::string colorHigh = colorHigh_; - - PixelInfo targetLow; - PixelInfo targetHigh; - 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 ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - - -// Trim edges that are the background color from the image -void Magick::Image::trim ( void ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - TrimImage( image(), &exceptionInfo); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Replace image with a sharpened version of the original image -// using the unsharp mask algorithm. -// radius_ -// the radius of the Gaussian, in pixels, not counting the -// center pixel. -// sigma_ -// the standard deviation of the Gaussian, in pixels. -// amount_ -// the percentage of the difference between the original and -// the blur image that is added back into the original. -// threshold_ -// the threshold in pixels needed to apply the diffence amount. -void Magick::Image::unsharpmask ( const double radius_, - const double sigma_, - const double amount_, - const double threshold_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - UnsharpMaskImage( image(), - radius_, - sigma_, - amount_, - threshold_, - &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -void Magick::Image::unsharpmaskChannel ( const ChannelType channel_, - const double radius_, - const double sigma_, - const double amount_, - const double threshold_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - MagickCore::Image* newImage = - UnsharpMaskImage( image(), - radius_, - sigma_, - amount_, - threshold_, - &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Map image pixels to a sine wave -void Magick::Image::wave ( const double amplitude_, const double wavelength_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - WaveImage( constImage(), amplitude_, wavelength_, image()->interpolate, - &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -void Magick::Image::whiteThreshold ( const std::string &threshold_ ) -{ - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - WhiteThresholdImage( image(), threshold_.c_str(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -void Magick::Image::whiteThresholdChannel ( const ChannelType channel_, - const std::string &threshold_ ) -{ - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ChannelType channel_mask = SetImageChannelMask( image(), channel_ ); - WhiteThresholdImage( image(), threshold_.c_str(), &exceptionInfo ); - SetPixelChannelMask( image(), channel_mask ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Write image to file -void Magick::Image::write ( const std::string &imageSpec_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - modifyImage(); - fileName( imageSpec_ ); - WriteImage( constImageInfo(), image(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Write image to in-memory BLOB -void Magick::Image::write ( Blob *blob_ ) -{ - modifyImage(); - size_t length = 2048; // Efficient size for small images - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - void* data = ImagesToBlob( constImageInfo(), image(), &length, - &exceptionInfo); - throwException( exceptionInfo ); - blob_->updateNoCopy( data, length, Blob::MallocAllocator ); - throwImageException(); - (void) DestroyExceptionInfo( &exceptionInfo ); + tmpTexture=constOptions()->strokePattern(); + + if (tmpTexture) + { + MagickCore::Image + *image; + + GetPPException; + image=CloneImage(tmpTexture,0,0,MagickTrue,&exceptionInfo); + texture.replaceImage(image); + ThrowPPException; + } + return(texture); } -void Magick::Image::write ( Blob *blob_, - const std::string &magick_ ) + +void Magick::Image::strokeWidth(const double strokeWidth_) { modifyImage(); - magick(magick_); - size_t length = 2048; // Efficient size for small images - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - void* data = ImagesToBlob( constImageInfo(), image(), &length, - &exceptionInfo ); - throwException( exceptionInfo ); - blob_->updateNoCopy( data, length, Blob::MallocAllocator ); - throwImageException(); - (void) DestroyExceptionInfo( &exceptionInfo ); + options()->strokeWidth(strokeWidth_); } -void Magick::Image::write ( Blob *blob_, - const std::string &magick_, - const size_t depth_ ) + +double Magick::Image::strokeWidth(void) const { - modifyImage(); - magick(magick_); - depth(depth_); - size_t length = 2048; // Efficient size for small images - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - void* data = ImagesToBlob( constImageInfo(), image(), &length, - &exceptionInfo ); - throwException( exceptionInfo ); - blob_->updateNoCopy( data, length, Blob::MallocAllocator ); - throwImageException(); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Write image to an array of pixels with storage type specified -// by user (ExportImagePixels), e.g. -// image.write( 0, 0, 640, 1, "RGB", 0, pixels ); -void Magick::Image::write ( const ssize_t x_, - const ssize_t y_, - const size_t columns_, - const size_t rows_, - const std::string &map_, - const StorageType type_, - void *pixels_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_, - pixels_, - &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + return(constOptions()->strokeWidth()); } -// Zoom image -void Magick::Image::zoom ( const Geometry &geometry_ ) +void Magick::Image::subImage(const size_t subImage_) { - // Calculate new size. This code should be supported using binary arguments - // in the ImageMagick library. - ssize_t x = 0; - ssize_t y = 0; - size_t width = columns(); - size_t height = rows(); - - ParseMetaGeometry (static_cast(geometry_).c_str(), - &x, &y, - &width, &height ); - - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - ResizeImage( constImage(), width, height, image()->filter, &exceptionInfo ); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + modifyImage(); + options()->subImage(subImage_); } -/* - * Methods for setting image attributes - * - */ +size_t Magick::Image::subImage(void) const +{ + return(constOptions()->subImage()); +} -// Join images into a single multi-image file -void Magick::Image::adjoin ( const bool flag_ ) +void Magick::Image::subRange(const size_t subRange_) { modifyImage(); - options()->adjoin( flag_ ); + options()->subRange(subRange_); } -bool Magick::Image::adjoin ( void ) const + +size_t Magick::Image::subRange(void) const { - return constOptions()->adjoin(); + return(constOptions()->subRange()); } -// Remove pixel aliasing -void Magick::Image::antiAlias( const bool flag_ ) +void Magick::Image::textEncoding(const std::string &encoding_) { modifyImage(); - options()->antiAlias( static_cast(flag_) ); + options()->textEncoding(encoding_); +} + +std::string Magick::Image::textEncoding(void) const +{ + return(constOptions()->textEncoding()); } -bool Magick::Image::antiAlias( void ) + +size_t Magick::Image::totalColors(void) const { - return static_cast( options()->antiAlias( ) ); + size_t + colors; + + GetPPException; + colors=GetNumberColors(constImage(),0,&exceptionInfo); + ThrowPPException; + return colors; } -// Animation inter-frame delay -void Magick::Image::animationDelay ( const size_t delay_ ) +void Magick::Image::transformRotation(const double angle_) { modifyImage(); - image()->delay = delay_; + options()->transformRotation(angle_); } -size_t Magick::Image::animationDelay ( void ) const + +void Magick::Image::transformSkewX(const double skewx_) { - return constImage()->delay; + modifyImage(); + options()->transformSkewX(skewx_); } -// Number of iterations to play animation -void Magick::Image::animationIterations ( const size_t iterations_ ) +void Magick::Image::transformSkewY(const double skewy_) { modifyImage(); - image()->iterations = iterations_; + options()->transformSkewY(skewy_); } -size_t Magick::Image::animationIterations ( void ) const + +Magick::ImageType Magick::Image::type(void) const { - return constImage()->iterations; + ImageType + image_type; + + GetPPException; + image_type=constOptions()->type(); + if (image_type == UndefinedType) + image_type=GetImageType(constImage(),&exceptionInfo); + ThrowPPException; + return image_type; } -// Access/Update a named image attribute -void Magick::Image::attribute ( const std::string name_, - const std::string value_ ) +void Magick::Image::type(const Magick::ImageType type_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - SetImageProperty( image(), name_.c_str(), value_.c_str(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + options()->type(type_); + GetPPException; + SetImageType(image(),type_,&exceptionInfo); + ThrowPPException; } -std::string Magick::Image::attribute ( const std::string name_ ) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - const char *value = GetImageProperty( constImage(), name_.c_str(), - &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - if ( value ) - return std::string( value ); +void Magick::Image::verbose(const bool verboseFlag_) +{ + modifyImage(); + options()->verbose(verboseFlag_); +} - return std::string(); // Intentionally no exception +bool Magick::Image::verbose(void) const +{ + return(constOptions()->verbose()); } -// Background color -void Magick::Image::backgroundColor ( const Color &backgroundColor_ ) +void Magick::Image::view(const std::string &view_) { modifyImage(); + options()->view(view_); +} - if ( backgroundColor_.isValid() ) - { - image()->background_color = backgroundColor_; - } - else - { - image()->background_color = Color(); - } +std::string Magick::Image::view(void) const +{ + return(constOptions()->view()); +} - options()->backgroundColor( backgroundColor_ ); +void Magick::Image::virtualPixelMethod( + const VirtualPixelMethod virtualPixelMethod_) +{ + modifyImage(); + GetPPException; + SetImageVirtualPixelMethod(image(),virtualPixelMethod_,&exceptionInfo); + ThrowPPException; } -Magick::Color Magick::Image::backgroundColor ( void ) const + +Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod(void) const { - return constOptions()->backgroundColor( ); + return(GetImageVirtualPixelMethod(constImage())); } -// Background fill texture -void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ ) +void Magick::Image::x11Display(const std::string &display_) { modifyImage(); - options()->backgroundTexture( backgroundTexture_ ); + options()->x11Display(display_); } -std::string Magick::Image::backgroundTexture ( void ) const + +std::string Magick::Image::x11Display(void) const { - return constOptions()->backgroundTexture( ); + return(constOptions()->x11Display()); } -// Original image columns -size_t Magick::Image::baseColumns ( void ) const +double Magick::Image::xResolution(void) const { - return constImage()->magick_columns; + return(constImage()->resolution.x); } -// Original image name -std::string Magick::Image::baseFilename ( void ) const +double Magick::Image::yResolution(void) const { - return std::string(constImage()->magick_filename); + return(constImage()->resolution.y); } -// Original image rows -size_t Magick::Image::baseRows ( void ) const +void Magick::Image::adaptiveBlur(const double radius_,const double sigma_) { - return constImage()->magick_rows; + MagickCore::Image + *newImage; + + GetPPException; + newImage=AdaptiveBlurImage(constImage(),radius_,sigma_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Border color -void Magick::Image::borderColor ( const Color &borderColor_ ) +void Magick::Image::adaptiveResize(const Geometry &geometry_) { - modifyImage(); + MagickCore::Image + *newImage; - if ( borderColor_.isValid() ) - { - image()->border_color = borderColor_; - } - else - { - image()->border_color = Color(); - } + size_t + height=rows(), + width=columns(); + + ssize_t + x=0, + y=0; + + ParseMetaGeometry(static_cast(geometry_).c_str(),&x,&y,&width, + &height); - options()->borderColor( borderColor_ ); + GetPPException; + newImage=AdaptiveResizeImage(constImage(),width,height,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -Magick::Color Magick::Image::borderColor ( void ) const + +void Magick::Image::adaptiveSharpen(const double radius_,const double sigma_) { - return constOptions()->borderColor( ); + MagickCore::Image + *newImage; + + GetPPException; + newImage=AdaptiveSharpenImage(constImage(),radius_,sigma_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Return smallest bounding box enclosing non-border pixels. The -// current fuzz value is used when discriminating between pixels. -// This is the crop bounding box used by crop(Geometry(0,0)); -Magick::Geometry Magick::Image::boundingBox ( void ) const +void Magick::Image::adaptiveSharpenChannel(const ChannelType channel_, + const double radius_,const double sigma_ ) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - return Geometry( bbox ); + MagickCore::Image + *newImage; + + GetPPException; + SetPPChannelMask(channel_); + newImage=AdaptiveSharpenImage(constImage(),radius_,sigma_,&exceptionInfo); + RestorePPChannelMask; + replaceImage(newImage); + ThrowPPException; } -// Text bounding-box base color -void Magick::Image::boxColor ( const Color &boxColor_ ) +void Magick::Image::adaptiveThreshold(const size_t width_,const size_t height_, + const ssize_t offset_) { - modifyImage(); - options()->boxColor( boxColor_ ); + + MagickCore::Image + *newImage; + + GetPPException; + newImage=AdaptiveThresholdImage(constImage(),width_,height_,offset_, + &exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -Magick::Color Magick::Image::boxColor ( void ) const + +void Magick::Image::addNoise(const NoiseType noiseType_) { - return constOptions()->boxColor( ); + MagickCore::Image + *newImage; + + GetPPException; + newImage=AddNoiseImage(constImage(),noiseType_,1.0,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Pixel cache threshold. Once this threshold is exceeded, all -// subsequent pixels cache operations are to/from disk. -// This setting is shared by all Image objects. -/* static */ -void Magick::Image::cacheThreshold ( const MagickSizeType threshold_ ) +void Magick::Image::addNoiseChannel(const ChannelType channel_, + const NoiseType noiseType_) { - SetMagickResourceLimit( MemoryResource, threshold_ ); + MagickCore::Image + *newImage; + + GetPPException; + SetPPChannelMask(channel_); + newImage=AddNoiseImage(constImage(),noiseType_,1.0,&exceptionInfo); + RestorePPChannelMask; + replaceImage(newImage); + ThrowPPException; } -size_t Magick::Image::channels() const +void Magick::Image::affineTransform(const DrawableAffine &affine_) { - return constImage()->number_channels; + AffineMatrix + _affine; + + MagickCore::Image + *newImage; + + _affine.sx=affine_.sx(); + _affine.sy=affine_.sy(); + _affine.rx=affine_.rx(); + _affine.ry=affine_.ry(); + _affine.tx=affine_.tx(); + _affine.ty=affine_.ty(); + + GetPPException; + newImage=AffineTransformImage(constImage(),&_affine,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -void Magick::Image::chromaBluePrimary ( const double x_, const double y_ ) +void Magick::Image::alpha(const unsigned int alpha_) { modifyImage(); - image()->chromaticity.blue_primary.x = x_; - image()->chromaticity.blue_primary.y = y_; + GetPPException; + SetImageAlpha(image(),alpha_,&exceptionInfo); + ThrowPPException; } -void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const + +void Magick::Image::alphaChannel(AlphaChannelOption alphaOption_) { - *x_ = constImage()->chromaticity.blue_primary.x; - *y_ = constImage()->chromaticity.blue_primary.y; + modifyImage(); + GetPPException; + SetImageAlphaChannel(image(),alphaOption_,&exceptionInfo); + ThrowPPException; } -void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ ) +void Magick::Image::alphaFloodfill(const Color &target_, + const unsigned int alpha_,const ssize_t x_,const ssize_t y_, + const Magick::PaintMethod method_) { + PixelInfo + target; + modifyImage(); - image()->chromaticity.green_primary.x = x_; - image()->chromaticity.green_primary.y = y_; + GetPixelInfo(constImage(),&target); + target.red=static_cast(target_).red; + target.green=static_cast(target_).green; + target.blue=static_cast(target_).blue; + target.alpha=alpha_; + GetPPException; + SetPPChannelMask(AlphaChannel); + FloodfillPaintImage(image(),options()->drawInfo(),&target,x_,y_, + method_ == FloodfillMethod ? MagickFalse : MagickTrue,&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; +} + +void Magick::Image::annotate(const std::string &text_, + const Geometry &location_) +{ + annotate(text_,location_,NorthWestGravity,0.0); } -void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const + +void Magick::Image::annotate(const std::string &text_, + const Geometry &boundingArea_,const GravityType gravity_) { - *x_ = constImage()->chromaticity.green_primary.x; - *y_ = constImage()->chromaticity.green_primary.y; + annotate(text_,boundingArea_,gravity_,0.0); } -void Magick::Image::chromaRedPrimary ( const double x_, const double y_ ) +void Magick::Image::annotate(const std::string &text_, + const Geometry &boundingArea_,const GravityType gravity_, + const double degrees_) { + AffineMatrix + oaffine; + + char + boundingArea[MaxTextExtent]; + + DrawInfo + *drawInfo; + modifyImage(); - image()->chromaticity.red_primary.x = x_; - image()->chromaticity.red_primary.y = y_; + + drawInfo=options()->drawInfo(); + drawInfo->text=const_cast(text_.c_str()); + drawInfo->geometry=0; + + if (boundingArea_.isValid()) + { + if (boundingArea_.width() == 0 || boundingArea_.height() == 0) + { + FormatLocaleString(boundingArea,MaxTextExtent,"%+.20g%+.20g", + (double) boundingArea_.xOff(),(double) boundingArea_.yOff()); + } + else + { + (void) CopyMagickString(boundingArea,string(boundingArea_).c_str(), + MaxTextExtent); + } + drawInfo->geometry=boundingArea; + } + + drawInfo->gravity=gravity_; + + oaffine=drawInfo->affine; + if (degrees_ != 0.0) + { + AffineMatrix + affine, + current; + + affine.sx=1.0; + affine.rx=0.0; + affine.ry=0.0; + affine.sy=1.0; + affine.tx=0.0; + affine.ty=0.0; + + current=drawInfo->affine; + affine.sx=cos(DegreesToRadians(fmod(degrees_,360.0))); + affine.rx=sin(DegreesToRadians(fmod(degrees_,360.0))); + affine.ry=(-sin(DegreesToRadians(fmod(degrees_,360.0)))); + affine.sy=cos(DegreesToRadians(fmod(degrees_,360.0))); + + drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx; + drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx; + drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy; + drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy; + drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty + +current.tx; + } + + GetPPException; + AnnotateImage(image(),drawInfo,&exceptionInfo); + + // Restore original values + drawInfo->affine=oaffine; + drawInfo->text=0; + drawInfo->geometry=0; + + ThrowPPException; } -void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const + +void Magick::Image::annotate(const std::string &text_, + const GravityType gravity_) { - *x_ = constImage()->chromaticity.red_primary.x; - *y_ = constImage()->chromaticity.red_primary.y; + DrawInfo + *drawInfo; + + modifyImage(); + + drawInfo=options()->drawInfo(); + drawInfo->text=const_cast(text_.c_str()); + drawInfo->gravity=gravity_; + + GetPPException; + AnnotateImage(image(),drawInfo,&exceptionInfo); + + drawInfo->gravity=NorthWestGravity; + drawInfo->text=0; + + ThrowPPException; } -void Magick::Image::chromaWhitePoint ( const double x_, const double y_ ) +void Magick::Image::artifact(const std::string &name_,const std::string &value_) { modifyImage(); - image()->chromaticity.white_point.x = x_; - image()->chromaticity.white_point.y = y_; + (void) SetImageArtifact(image(),name_.c_str(),value_.c_str()); } -void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const + +std::string Magick::Image::artifact(const std::string &name_) { - *x_ = constImage()->chromaticity.white_point.x; - *y_ = constImage()->chromaticity.white_point.y; + const char + *value; + + value=GetImageArtifact(constImage(),name_.c_str()); + if (value) + return(std::string(value)); + return(std::string()); } -// Set image storage class -void Magick::Image::classType ( const ClassType class_ ) +void Magick::Image::attribute(const std::string name_,const std::string value_) { - if ( classType() == PseudoClass && class_ == DirectClass ) - { - // Use SyncImage to synchronize the DirectClass pixels with the - // color map and then set to DirectClass type. - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - SyncImage( image(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - image()->colormap = (PixelInfo *) - RelinquishMagickMemory( image()->colormap ); - image()->storage_class = static_cast(DirectClass); - return; - } + modifyImage(); + GetPPException; + SetImageProperty(image(),name_.c_str(),value_.c_str(),&exceptionInfo); + ThrowPPException; +} - if ( classType() == DirectClass && class_ == PseudoClass ) - { - // Quantize to create PseudoClass color map - modifyImage(); - quantizeColors(MaxColormapSize); - quantize(); - image()->storage_class = static_cast(PseudoClass); - } +std::string Magick::Image::attribute(const std::string name_) +{ + const char + *value; + + GetPPException; + value=GetImageProperty(constImage(),name_.c_str(),&exceptionInfo); + ThrowPPException; + + if (value) + return(std::string(value)); + + return(std::string()); // Intentionally no exception } -// Associate a clip mask with the image. The clip mask must be the -// same dimensions as the image. Pass an invalid image to unset an -// existing clip mask. -void Magick::Image::clipMask ( const Magick::Image & clipMask_ ) +void Magick::Image::autoGamma(void) { modifyImage(); + GetPPException; + AutoGammaImage(image(),&exceptionInfo); + ThrowPPException; +} - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - if( clipMask_.isValid() ) - { - // Set clip mask - SetImageMask( image(), clipMask_.constImage(), &exceptionInfo ); - } - else - { - // Unset existing clip mask - SetImageMask( image(), 0, &exceptionInfo ); - } - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); +void Magick::Image::autoGammaChannel(const ChannelType channel_) +{ + modifyImage(); + GetPPException; + SetPPChannelMask(channel_); + AutoGammaImage(image(),&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; } -Magick::Image Magick::Image::clipMask ( void ) const + +void Magick::Image::autoLevel(void) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* image = GetImageMask( constImage(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - if (image == (MagickCore::Image *) NULL) - return Magick::Image(); - else - return Magick::Image( image ); + modifyImage(); + GetPPException; + AutoLevelImage(image(),&exceptionInfo); + ThrowPPException; } -void Magick::Image::colorFuzz ( const double fuzz_ ) +void Magick::Image::autoLevelChannel(const ChannelType channel_) { modifyImage(); - image()->fuzz = fuzz_; - options()->colorFuzz( fuzz_ ); + GetPPException; + SetPPChannelMask(channel_); + AutoLevelImage(image(),&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; } -double Magick::Image::colorFuzz ( void ) const + +void Magick::Image::autoOrient(void) { - return constOptions()->colorFuzz( ); + MagickCore::Image + *newImage; + + if (image()->orientation == UndefinedOrientation || + image()->orientation == TopLeftOrientation) + return; + + GetPPException; + newImage=AutoOrientImage(constImage(),image()->orientation,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Set color in colormap at index -void Magick::Image::colorMap ( const size_t index_, - const Color &color_ ) +void Magick::Image::blackThreshold(const std::string &threshold_) { - MagickCore::Image* imageptr = image(); + modifyImage(); + GetPPException; + BlackThresholdImage(image(),threshold_.c_str(),&exceptionInfo); + ThrowPPException; +} - if (index_ > (MaxColormapSize-1) ) - throwExceptionExplicit( OptionError, - "Colormap index must be less than MaxColormapSize" ); - - if ( !color_.isValid() ) - throwExceptionExplicit( OptionError, - "Color argument is invalid"); +void Magick::Image::blackThresholdChannel(const ChannelType channel_, + const std::string &threshold_) +{ modifyImage(); + GetPPException; + SetPPChannelMask(channel_); + BlackThresholdImage(image(),threshold_.c_str(),&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; +} - // Ensure that colormap size is large enough - if ( colorMapSize() < (index_+1) ) - colorMapSize( index_ + 1 ); +void Magick::Image::blueShift(const double factor_) +{ + MagickCore::Image + *newImage; - // Set color at index in colormap - (imageptr->colormap)[index_] = color_; + GetPPException; + newImage=BlueShiftImage(constImage(),factor_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::blur(const double radius_,const double sigma_) +{ + MagickCore::Image + *newImage; + + GetPPException; + newImage=BlurImage(constImage(),radius_,sigma_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Return color in colormap at index -Magick::Color Magick::Image::colorMap ( const size_t index_ ) const + +void Magick::Image::blurChannel(const ChannelType channel_, + const double radius_,const double sigma_) { - const MagickCore::Image* imageptr = constImage(); + MagickCore::Image + *newImage; - if ( !imageptr->colormap ) - throwExceptionExplicit( OptionError, - "Image does not contain a colormap"); + GetPPException; + SetPPChannelMask(channel_); + newImage=BlurImage(constImage(),radius_,sigma_,&exceptionInfo); + RestorePPChannelMask; + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::border(const Geometry &geometry_) +{ + MagickCore::Image + *newImage; - if ( index_ > imageptr->colors-1 ) - throwExceptionExplicit( OptionError, - "Index out of range"); + RectangleInfo + borderInfo=geometry_; - return Magick::Color( (imageptr->colormap)[index_] ); + GetPPException; + newImage=BorderImage(constImage(),&borderInfo,image()->compose, + &exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Colormap size (number of colormap entries) -void Magick::Image::colorMapSize ( const size_t entries_ ) +void Magick::Image::brightnessContrast(const double brightness_, + const double contrast_) { - if (entries_ >MaxColormapSize ) - throwExceptionExplicit( OptionError, - "Colormap entries must not exceed MaxColormapSize" ); + modifyImage(); + GetPPException; + BrightnessContrastImage(image(),brightness_,contrast_,&exceptionInfo); + ThrowPPException; +} +void Magick::Image::brightnessContrastChannel(const ChannelType channel_, + const double brightness_,const double contrast_) +{ modifyImage(); + GetPPException; + SetPPChannelMask(channel_); + BrightnessContrastImage(image(),brightness_,contrast_,&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; +} - MagickCore::Image* imageptr = image(); +void Magick::Image::channel(const ChannelType channel_) +{ + MagickCore::Image + *newImage; - if( !imageptr->colormap ) - { - // Allocate colormap - imageptr->colormap = - static_cast(AcquireMagickMemory(entries_*sizeof(PixelInfo))); - imageptr->colors = 0; - } - else if ( entries_ > imageptr->colors ) - { - // Re-allocate colormap - imageptr->colormap=(PixelInfo *) - ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelInfo)); - } + GetPPException; + newImage=SeparateImage(image(),channel_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; +} - // Initialize any new colormap entries as all black - Color black(0,0,0); - for( size_t i=imageptr->colors; i<(entries_-1); i++ ) - (imageptr->colormap)[i] = black; +void Magick::Image::charcoal(const double radius_,const double sigma_) +{ + MagickCore::Image + *newImage; - imageptr->colors = entries_; + GetPPException; + newImage=CharcoalImage(image(),radius_,sigma_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -size_t Magick::Image::colorMapSize ( void ) const + +void Magick::Image::chop(const Geometry &geometry_) { - const MagickCore::Image* imageptr = constImage(); + MagickCore::Image + *newImage; - if ( !imageptr->colormap ) - throwExceptionExplicit( OptionError, - "Image does not contain a colormap"); + RectangleInfo + chopInfo=geometry_; - return imageptr->colors; + GetPPException; + newImage=ChopImage(image(),&chopInfo,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Image colorspace -void Magick::Image::colorSpace( const ColorspaceType colorSpace_ ) +void Magick::Image::chromaBluePrimary(const double x_,const double y_) { - if ( image()->colorspace == colorSpace_ ) - return; - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - TransformImageColorspace(image(), colorSpace_, &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + image()->chromaticity.blue_primary.x=x_; + image()->chromaticity.blue_primary.y=y_; } -Magick::ColorspaceType Magick::Image::colorSpace ( void ) const + +void Magick::Image::chromaBluePrimary(double *x_,double *y_) const { - return constImage()->colorspace; + *x_=constImage()->chromaticity.blue_primary.x; + *y_=constImage()->chromaticity.blue_primary.y; } -// Set image colorspace type. -void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ ) +void Magick::Image::chromaGreenPrimary(const double x_,const double y_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - SetImageColorspace(image(), colorSpace_, &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - options()->colorspaceType( colorSpace_ ); + image()->chromaticity.green_primary.x=x_; + image()->chromaticity.green_primary.y=y_; } -Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const + +void Magick::Image::chromaGreenPrimary(double *x_,double *y_) const { - return constOptions()->colorspaceType(); + *x_=constImage()->chromaticity.green_primary.x; + *y_=constImage()->chromaticity.green_primary.y; } - -// Comment string -void Magick::Image::comment ( const std::string &comment_ ) +void Magick::Image::chromaRedPrimary(const double x_,const double y_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - SetImageProperty( image(), "Comment", NULL, &exceptionInfo ); - if ( comment_.length() > 0 ) - SetImageProperty( image(), "Comment", comment_.c_str(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + image()->chromaticity.red_primary.x=x_; + image()->chromaticity.red_primary.y=y_; } -std::string Magick::Image::comment ( void ) const -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - const char *value = GetImageProperty( constImage(), "Comment", - &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - if ( value ) - return std::string( value ); - - return std::string(); // Intentionally no exception +void Magick::Image::chromaRedPrimary(double *x_,double *y_) const +{ + *x_=constImage()->chromaticity.red_primary.x; + *y_=constImage()->chromaticity.red_primary.y; } -// Composition operator to be used when composition is implicitly used -// (such as for image flattening). -void Magick::Image::compose (const CompositeOperator compose_) +void Magick::Image::chromaWhitePoint(const double x_,const double y_) { - image()->compose=compose_; + modifyImage(); + image()->chromaticity.white_point.x=x_; + image()->chromaticity.white_point.y=y_; } -Magick::CompositeOperator Magick::Image::compose ( void ) const +void Magick::Image::chromaWhitePoint(double *x_,double *y_) const { - return constImage()->compose; + *x_=constImage()->chromaticity.white_point.x; + *y_=constImage()->chromaticity.white_point.y; } -// Compression algorithm -void Magick::Image::compressType ( const CompressionType compressType_ ) +void Magick::Image::cdl(const std::string &cdl_) { modifyImage(); - image()->compression = compressType_; - options()->compressType( compressType_ ); + GetPPException; + (void) ColorDecisionListImage(image(),cdl_.c_str(),&exceptionInfo); + ThrowPPException; } -Magick::CompressionType Magick::Image::compressType ( void ) const + +void Magick::Image::clamp(void) { - return constImage()->compression; + modifyImage(); + GetPPException; + ClampImage(image(),&exceptionInfo); + ThrowPPException; } -// Enable printing of debug messages from ImageMagick -void Magick::Image::debug ( const bool flag_ ) +void Magick::Image::clampChannel(const ChannelType channel_) { modifyImage(); - options()->debug( flag_ ); + GetPPException; + SetPPChannelMask(channel_); + ClampImage(image(),&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; } -bool Magick::Image::debug ( void ) const + +void Magick::Image::clip(void) { - return constOptions()->debug(); + modifyImage(); + GetPPException; + ClipImage(image(),&exceptionInfo); + ThrowPPException; } -// Tagged image format define (set/access coder-specific option) The -// magick_ option specifies the coder the define applies to. The key_ -// option provides the key specific to that coder. The value_ option -// provides the value to set (if any). See the defineSet() method if the -// key must be removed entirely. -void Magick::Image::defineValue ( const std::string &magick_, - const std::string &key_, - const std::string &value_ ) +void Magick::Image::clipPath(const std::string pathname_,const bool inside_) { modifyImage(); - std::string format = magick_ + ":" + key_; - std::string option = value_; - (void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() ); + GetPPException; + ClipImagePath(image(),pathname_.c_str(),(MagickBooleanType) inside_, + &exceptionInfo); + ThrowPPException; } -std::string Magick::Image::defineValue ( const std::string &magick_, - const std::string &key_ ) const + +void Magick::Image::clut(const Image &clutImage_, + const PixelInterpolateMethod method) { - std::string definition = magick_ + ":" + key_; - const char *option = - GetImageOption ( constImageInfo(), definition.c_str() ); - if (option) - return std::string( option ); - return std::string( ); + modifyImage(); + GetPPException; + ClutImage(image(),clutImage_.constImage(),method,&exceptionInfo); + ThrowPPException; } -// Tagged image format define. Similar to the defineValue() method -// except that passing the flag_ value 'true' creates a value-less -// define with that format and key. Passing the flag_ value 'false' -// removes any existing matching definition. The method returns 'true' -// if a matching key exists, and 'false' if no matching key exists. -void Magick::Image::defineSet ( const std::string &magick_, - const std::string &key_, - bool flag_ ) +void Magick::Image::clutChannel(const ChannelType channel_, + const Image &clutImage_,const PixelInterpolateMethod method) { modifyImage(); - std::string definition = magick_ + ":" + key_; - if (flag_) - { - (void) SetImageOption ( imageInfo(), definition.c_str(), "" ); - } - else - { - DeleteImageOption( imageInfo(), definition.c_str() ); - } + GetPPException; + SetPPChannelMask(channel_); + ClutImage(image(),clutImage_.constImage(),method,&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; } -bool Magick::Image::defineSet ( const std::string &magick_, - const std::string &key_ ) const + +void Magick::Image::colorize(const unsigned int alpha_,const Color &penColor_) { - std::string key = magick_ + ":" + key_; - const char *option = - GetImageOption ( constImageInfo(), key.c_str() ); - if (option) - return true; - return false; + colorize(alpha_,alpha_,alpha_,penColor_); } -// Pixel resolution -void Magick::Image::density ( const Geometry &density_ ) +void Magick::Image::colorize(const unsigned int alphaRed_, + const unsigned int alphaGreen_,const unsigned int alphaBlue_, + const Color &penColor_) { - modifyImage(); - options()->density( density_ ); - if ( density_.isValid() ) - { - image()->resolution.x = density_.width(); - if ( density_.height() != 0 ) - { - image()->resolution.y = density_.height(); - } - else - { - image()->resolution.y = density_.width(); - } - } - else - { - // Reset to default - image()->resolution.x = 0; - image()->resolution.y = 0; - } + char + blend[MaxTextExtent]; + + MagickCore::Image + *newImage; + + PixelInfo + pixel, + target; + + if (!penColor_.isValid()) + throwExceptionExplicit(OptionError,"Pen color argument is invalid"); + + FormatLocaleString(blend,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_, + alphaBlue_); + + GetPixelInfo(image(),&target); + pixel=static_cast(penColor_); + target.red=pixel.red; + target.green=pixel.green; + target.blue=pixel.blue; + target.alpha=pixel.alpha; + GetPPException; + newImage=ColorizeImage(image(),blend,&target,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -Magick::Geometry Magick::Image::density ( void ) const + +void Magick::Image::colorMap(const size_t index_,const Color &color_) { - if (isValid()) - { - ssize_t x_resolution=72; - ssize_t y_resolution=72; + MagickCore::Image + *imageptr; - if (constImage()->resolution.x > 0.0) - x_resolution=static_cast(constImage()->resolution.x + 0.5); + imageptr=image(); - if (constImage()->resolution.y > 0.0) - y_resolution=static_cast(constImage()->resolution.y + 0.5); + if (index_ > (MaxColormapSize-1)) + throwExceptionExplicit(OptionError, + "Colormap index must be less than MaxColormapSize"); - return Geometry(x_resolution,y_resolution); - } + if (!color_.isValid()) + throwExceptionExplicit(OptionError,"Color argument is invalid"); + + modifyImage(); + + // Ensure that colormap size is large enough + if (colorMapSize() < (index_+1)) + colorMapSize(index_+1); + + // Set color at index in colormap + (imageptr->colormap)[index_]=color_; +} + +Magick::Color Magick::Image::colorMap(const size_t index_) const +{ + if (!constImage()->colormap) + throwExceptionExplicit(OptionError,"Image does not contain a colormap"); + + if (index_ > constImage()->colors-1) + throwExceptionExplicit(OptionError,"Index out of range"); + + return(Magick::Color((constImage()->colormap)[index_])); +} - return constOptions()->density( ); +void Magick::Image::colorMatrix(const size_t order_, + const double *color_matrix_) +{ + KernelInfo + *kernel_info; + + GetPPException; + kernel_info=AcquireKernelInfo((const char *) NULL); + kernel_info->width=order_; + kernel_info->height=order_; + kernel_info->values=(MagickRealType *) AcquireAlignedMemory(order_, + order_*sizeof(*kernel_info->values)); + if (kernel_info->values != (MagickRealType *) NULL) + { + MagickCore::Image + *newImage; + + for (ssize_t i=0; i < (ssize_t) (order_*order_); i++) + kernel_info->values[i]=color_matrix_[i]; + newImage=ColorMatrixImage(image(),kernel_info,&exceptionInfo); + replaceImage(newImage); + } + kernel_info=DestroyKernelInfo(kernel_info); + ThrowPPException; +} + +bool Magick::Image::compare(const Image &reference_) +{ + bool + status; + + Image + ref=reference_; + + GetPPException; + modifyImage(); + ref.modifyImage(); + status=static_cast(IsImagesEqual(image(),ref.image(),&exceptionInfo)); + ThrowPPException; + return(status); +} + +double Magick::Image::compare(const Image &reference_,const MetricType metric_) +{ + double + distortion=0.0; + + GetPPException; + GetImageDistortion(image(),reference_.constImage(),metric_,&distortion, + &exceptionInfo); + ThrowPPException; + return(distortion); +} + +double Magick::Image::compareChannel(const ChannelType channel_, + const Image &reference_,const MetricType metric_) +{ + double + distortion=0.0; + + GetPPException; + SetPPChannelMask(channel_); + GetImageDistortion(image(),reference_.constImage(),metric_,&distortion, + &exceptionInfo); + RestorePPChannelMask; + ThrowPPException; + return(distortion); +} + +Magick::Image Magick::Image::compare(const Image &reference_, + const MetricType metric_,double *distortion) +{ + MagickCore::Image + *newImage; + + GetPPException; + newImage=CompareImages(image(),reference_.constImage(),metric_,distortion, + &exceptionInfo); + ThrowPPException; + if (newImage == (MagickCore::Image *) NULL) + return(Magick::Image()); + else + return(Magick::Image(newImage)); +} + +Magick::Image Magick::Image::compareChannel(const ChannelType channel_, + const Image &reference_,const MetricType metric_,double *distortion) +{ + MagickCore::Image + *newImage; + + GetPPException; + SetPPChannelMask(channel_); + newImage=CompareImages(image(),reference_.constImage(),metric_,distortion, + &exceptionInfo); + RestorePPChannelMask; + ThrowPPException; + if (newImage == (MagickCore::Image *) NULL) + return(Magick::Image()); + else + return(Magick::Image(newImage)); +} + +void Magick::Image::composite(const Image &compositeImage_, + const Geometry &offset_,const CompositeOperator compose_) +{ + size_t + height=rows(), + width=columns(); + + ssize_t + x=offset_.xOff(), + y=offset_.yOff(); + + ParseMetaGeometry(static_cast(offset_).c_str(),&x,&y,&width, + &height); + + modifyImage(); + GetPPException; + CompositeImage(image(),compositeImage_.constImage(),compose_,MagickFalse, + x,y,&exceptionInfo); + ThrowPPException; +} + +void Magick::Image::composite(const Image &compositeImage_, + const GravityType gravity_,const CompositeOperator compose_) +{ + RectangleInfo + geometry; + + modifyImage(); + SetGeometry(compositeImage_.constImage(),&geometry); + GravityAdjustGeometry(columns(),rows(),gravity_,&geometry); + + GetPPException; + CompositeImage(image(),compositeImage_.constImage(),compose_,MagickFalse, + geometry.x,geometry.y,&exceptionInfo); + ThrowPPException; +} + +void Magick::Image::composite(const Image &compositeImage_, + const ssize_t xOffset_,const ssize_t yOffset_, + const CompositeOperator compose_) +{ + // Image supplied as compositeImage is composited with current image and + // results in updating current image. + modifyImage(); + GetPPException; + CompositeImage(image(),compositeImage_.constImage(),compose_,MagickFalse, + xOffset_,yOffset_,&exceptionInfo); + ThrowPPException; +} + +void Magick::Image::contrast(const size_t sharpen_) +{ + modifyImage(); + GetPPException; + ContrastImage(image(),(MagickBooleanType) sharpen_,&exceptionInfo); + ThrowPPException; +} + +void Magick::Image::contrastStretch(const double blackPoint_, + const double whitePoint_) +{ + modifyImage(); + GetPPException; + ContrastStretchImage(image(),blackPoint_,whitePoint_,&exceptionInfo); + ThrowPPException; +} + +void Magick::Image::contrastStretchChannel(const ChannelType channel_, + const double blackPoint_,const double whitePoint_) +{ + modifyImage(); + GetPPException; + SetPPChannelMask(channel_); + ContrastStretchImage(image(),blackPoint_,whitePoint_,&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; +} + +void Magick::Image::convolve(const size_t order_,const double *kernel_) +{ + KernelInfo + *kernel_info; + + GetPPException; + kernel_info=AcquireKernelInfo((const char *) NULL); + kernel_info->width=order_; + kernel_info->height=order_; + kernel_info->values=(MagickRealType *) AcquireAlignedMemory(order_, + order_*sizeof(*kernel_info->values)); + if (kernel_info->values != (MagickRealType *) NULL) + { + MagickCore::Image + *newImage; + + for (ssize_t i=0; i < (ssize_t) (order_*order_); i++) + kernel_info->values[i]=kernel_[i]; + newImage=ConvolveImage(image(),kernel_info,&exceptionInfo); + replaceImage(newImage); + } + kernel_info=DestroyKernelInfo(kernel_info); + ThrowPPException; +} + +void Magick::Image::crop(const Geometry &geometry_) +{ + MagickCore::Image + *newImage; + + RectangleInfo + cropInfo=geometry_; + + GetPPException; + newImage=CropImage(constImage(),&cropInfo,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::cycleColormap(const ssize_t amount_) +{ + modifyImage(); + GetPPException; + CycleColormapImage(image(),amount_,&exceptionInfo); + ThrowPPException; +} + +void Magick::Image::decipher(const std::string &passphrase_) +{ + modifyImage(); + GetPPException; + DecipherImage(image(),passphrase_.c_str(),&exceptionInfo); + ThrowPPException; +} + +void Magick::Image::defineSet(const std::string &magick_, + const std::string &key_,bool flag_) +{ + std::string + definition; + + modifyImage(); + definition=magick_ + ":" + key_; + if (flag_) + (void) SetImageOption(imageInfo(),definition.c_str(),""); + else + DeleteImageOption(imageInfo(),definition.c_str()); +} + +bool Magick::Image::defineSet(const std::string &magick_, + const std::string &key_ ) const +{ + const char + *option; + + std::string + key; + + key=magick_ + ":" + key_; + option=GetImageOption(constImageInfo(),key.c_str()); + if (option) + return(true); + return(false); +} + +void Magick::Image::defineValue(const std::string &magick_, + const std::string &key_,const std::string &value_) +{ + std::string + format, + option; + + modifyImage(); + format=magick_ + ":" + key_; + option=value_; + (void) SetImageOption(imageInfo(),format.c_str(),option.c_str()); +} + +std::string Magick::Image::defineValue(const std::string &magick_, + const std::string &key_) const +{ + const char + *option; + + std::string + definition; + + definition=magick_ + ":" + key_; + option=GetImageOption(constImageInfo(),definition.c_str()); + if (option) + return(std::string(option)); + return(std::string()); +} + +void Magick::Image::deskew(const double threshold_) +{ + MagickCore::Image + *newImage; + + GetPPException; + newImage=DeskewImage(constImage(),threshold_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::despeckle(void) +{ + MagickCore::Image + *newImage; + + GetPPException; + newImage=DespeckleImage(constImage(),&exceptionInfo); + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::display(void) +{ + GetPPException; + DisplayImages(imageInfo(),image(),&exceptionInfo); + ThrowPPException; +} + +void Magick::Image::distort(const DistortImageMethod method_, + const size_t numberArguments_,const double *arguments_,const bool bestfit_) +{ + MagickCore::Image + *newImage; + + GetPPException; + newImage=DistortImage(constImage(), method_,numberArguments_,arguments_, + bestfit_ == true ? MagickTrue : MagickFalse,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::draw(const Magick::Drawable &drawable_) +{ + DrawingWand + *wand; + + modifyImage(); + + wand=DrawAllocateWand(options()->drawInfo(),image()); + + if(wand) + { + drawable_.operator()(wand); + + DrawRender(wand); + + ClonePPDrawException(wand); + wand=DestroyDrawingWand(wand); + ThrowPPDrawException; + } +} + +void Magick::Image::draw(const std::list &drawable_) +{ + DrawingWand + *wand; + + modifyImage(); + + wand=DrawAllocateWand(options()->drawInfo(),image()); + + if(wand) + { + for (std::list::const_iterator p = drawable_.begin(); + p != drawable_.end(); p++ ) + { + p->operator()(wand); + if (DrawGetExceptionType(wand) != UndefinedException) + break; + } + + if (DrawGetExceptionType(wand) == UndefinedException) + DrawRender(wand); + + ClonePPDrawException(wand); + wand=DestroyDrawingWand(wand); + ThrowPPDrawException; + } +} + +void Magick::Image::edge(const double radius_) +{ + MagickCore::Image + *newImage; + + GetPPException; + newImage=EdgeImage(constImage(),radius_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::emboss(const double radius_,const double sigma_) +{ + MagickCore::Image + *newImage; + + GetPPException; + newImage=EmbossImage(constImage(),radius_,sigma_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::encipher(const std::string &passphrase_) +{ + modifyImage(); + GetPPException; + EncipherImage(image(),passphrase_.c_str(),&exceptionInfo); + ThrowPPException; +} + +void Magick::Image::enhance(void) +{ + MagickCore::Image + *newImage; + + GetPPException; + newImage=EnhanceImage(constImage(),&exceptionInfo); + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::equalize(void) +{ + modifyImage(); + GetPPException; + EqualizeImage(image(),&exceptionInfo); + ThrowPPException; +} + +void Magick::Image::erase(void) +{ + modifyImage(); + GetPPException; + SetImageBackgroundColor(image(),&exceptionInfo); + ThrowPPException; +} + +void Magick::Image::extent(const Geometry &geometry_ ) +{ + MagickCore::Image + *newImage; + + RectangleInfo + extentInfo=geometry_; + + modifyImage(); + extentInfo.x=geometry_.xOff(); + extentInfo.y=geometry_.yOff(); + GetPPException; + newImage=ExtentImage(image(),&extentInfo,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::extent(const Geometry &geometry_, + const Color &backgroundColor_) +{ + backgroundColor(backgroundColor_); + extent(geometry_); +} + +void Magick::Image::extent(const Geometry &geometry_, + const Color &backgroundColor_,const GravityType gravity_) +{ + backgroundColor(backgroundColor_); + extent(geometry_,gravity_); +} + +void Magick::Image::extent(const Geometry &geometry_, + const GravityType gravity_) +{ + 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::flip(void) +{ + MagickCore::Image + *newImage; + + GetPPException; + newImage=FlipImage(constImage(),&exceptionInfo); + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::floodFillAlpha(const ssize_t x_,const ssize_t y_, + const unsigned int alpha_,const PaintMethod method_) +{ + PixelInfo + pixel, + target; + + modifyImage(); + GetPixelInfo(image(),&target); + pixel=static_cast(pixelColor(x_,y_)); + target.red=pixel.red; + target.green=pixel.green; + target.blue=pixel.blue; + target.alpha=alpha_; + + GetPPException; + FloodfillPaintImage(image(),options()->drawInfo(),&target, + static_cast(x_), static_cast(y_), + method_ == FloodfillMethod ? MagickFalse : MagickTrue,&exceptionInfo); + ThrowPPException; +} + +void Magick::Image::floodFillColor(const Geometry &point_, + const Magick::Color &fillColor_) +{ + floodFillTexture(point_,Image(Geometry(1,1),fillColor_)); +} + +void Magick::Image::floodFillColor(const ssize_t x_,const ssize_t y_, + const Magick::Color &fillColor_) +{ + floodFillTexture(x_,y_,Image(Geometry(1,1),fillColor_)); +} + +void Magick::Image::floodFillColor(const Geometry &point_, + const Magick::Color &fillColor_,const Magick::Color &borderColor_) +{ + floodFillTexture(point_,Image(Geometry(1,1),fillColor_),borderColor_); +} + +void Magick::Image::floodFillColor(const ssize_t x_,const ssize_t y_, + const Magick::Color &fillColor_,const Magick::Color &borderColor_) +{ + floodFillTexture(x_,y_,Image(Geometry(1,1),fillColor_),borderColor_); +} + +void Magick::Image::floodFillTexture(const Magick::Geometry &point_, + const Magick::Image &texture_) +{ + floodFillTexture(point_.xOff(),point_.yOff(),texture_); +} + +void Magick::Image::floodFillTexture(const ssize_t x_,const ssize_t y_, + const Magick::Image &texture_) +{ + Quantum + *p; + + modifyImage(); + + // Set drawing pattern + options()->fillPattern(texture_.constImage()); + + // Get pixel view + Pixels pixels(*this); + // Fill image + p=pixels.get(x_,y_,1,1); + + if (p) + { + PixelInfo + target; + + GetPixelInfo(constImage(),&target); + target.red=GetPixelRed(constImage(),p); + target.green=GetPixelGreen(constImage(),p); + target.blue=GetPixelBlue(constImage(),p); + GetPPException; + FloodfillPaintImage(image(),options()->drawInfo(),&target, + static_cast(x_),static_cast(y_),MagickFalse, + &exceptionInfo); + ThrowPPException; + } +} + +void Magick::Image::floodFillTexture(const Magick::Geometry &point_, + const Magick::Image &texture_,const Magick::Color &borderColor_) +{ + floodFillTexture(point_.xOff(),point_.yOff(),texture_,borderColor_); +} + +void Magick::Image::floodFillTexture(const ssize_t x_,const ssize_t y_, + const Magick::Image &texture_,const Magick::Color &borderColor_) +{ + PixelInfo + target; + + modifyImage(); + + // Set drawing fill pattern + options()->fillPattern(texture_.constImage()); + + GetPixelInfo(constImage(),&target); + target.red=static_cast(borderColor_).red; + target.green=static_cast(borderColor_).green; + target.blue=static_cast(borderColor_).blue; + GetPPException; + FloodfillPaintImage(image(),options()->drawInfo(),&target, + static_cast(x_),static_cast(y_),MagickTrue, + &exceptionInfo); + ThrowPPException; +} + +void Magick::Image::flop(void) +{ + MagickCore::Image + *newImage; + + GetPPException; + newImage=FlopImage(constImage(),&exceptionInfo); + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::fontTypeMetrics(const std::string &text_, + TypeMetric *metrics) +{ + DrawInfo + *drawInfo; + + drawInfo=options()->drawInfo(); + drawInfo->text=const_cast(text_.c_str()); + GetPPException; + GetTypeMetrics(image(),drawInfo,&(metrics->_typeMetric),&exceptionInfo); + drawInfo->text=0; + ThrowPPException; +} + +void Magick::Image::frame(const Geometry &geometry_) +{ + FrameInfo + info; + + MagickCore::Image + *newImage; + + info.x=static_cast(geometry_.width()); + info.y=static_cast(geometry_.height()); + info.width=columns() + (static_cast(info.x) << 1); + info.height=rows() + (static_cast(info.y) << 1); + info.outer_bevel=geometry_.xOff(); + info.inner_bevel=geometry_.yOff(); + + GetPPException; + newImage=FrameImage(constImage(),&info,image()->compose,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::frame(const size_t width_,const size_t height_, + const ssize_t outerBevel_,const ssize_t innerBevel_) +{ + FrameInfo + info; + + MagickCore::Image + *newImage; + + info.x=static_cast(width_); + info.y=static_cast(height_); + info.width=columns() + (static_cast(info.x) << 1); + info.height=rows() + (static_cast(info.y) << 1); + info.outer_bevel=static_cast(outerBevel_); + info.inner_bevel=static_cast(innerBevel_); + + GetPPException; + newImage=FrameImage(constImage(),&info,image()->compose,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::fx(const std::string expression_) +{ + MagickCore::Image + *newImage; + + GetPPException; + newImage=FxImage(constImage(),expression_.c_str(),&exceptionInfo); + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::fx(const std::string expression_, + const Magick::ChannelType channel_) +{ + MagickCore::Image + *newImage; + + GetPPException; + SetPPChannelMask(channel_); + newImage=FxImage(constImage(),expression_.c_str(),&exceptionInfo); + RestorePPChannelMask; + replaceImage(newImage); + ThrowPPException; +} + +void Magick::Image::gamma(const double gamma_) +{ + modifyImage(); + GetPPException; + GammaImage(image(),gamma_,&exceptionInfo); + ThrowPPException; } -// Image depth (bits allocated to red/green/blue components) -void Magick::Image::depth ( const size_t depth_ ) +void Magick::Image::gamma(const double gammaRed_,const double gammaGreen_, + const double gammaBlue_) { - size_t depth = depth_; + char + gamma[MaxTextExtent + 1]; - if (depth > MAGICKCORE_QUANTUM_DEPTH) - depth=MAGICKCORE_QUANTUM_DEPTH; + FormatLocaleString(gamma,MaxTextExtent,"%3.6f/%3.6f/%3.6f/",gammaRed_, + gammaGreen_,gammaBlue_); modifyImage(); - image()->depth=depth; - options()->depth( depth ); + GetPPException; + GammaImage(image(),atof(gamma),&exceptionInfo); + ThrowPPException; } -size_t Magick::Image::depth ( void ) const + +void Magick::Image::gaussianBlur(const double width_,const double sigma_) { - return constImage()->depth; + MagickCore::Image + *newImage; + + GetPPException; + newImage=GaussianBlurImage(constImage(),width_,sigma_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -std::string Magick::Image::directory ( void ) const +void Magick::Image::gaussianBlurChannel(const ChannelType channel_, + const double width_,const double sigma_) { - if ( constImage()->directory ) - return std::string( constImage()->directory ); - - throwExceptionExplicit( CorruptImageWarning, - "Image does not contain a directory"); + MagickCore::Image + *newImage; - return std::string(); + GetPPException; + SetPPChannelMask(channel_); + newImage=GaussianBlurImage(constImage(),width_,sigma_,&exceptionInfo); + RestorePPChannelMask; + replaceImage(newImage); + ThrowPPException; } -// Endianness (little like Intel or big like SPARC) for image -// formats which support endian-specific options. -void Magick::Image::endian ( const Magick::EndianType endian_ ) +const Magick::Quantum *Magick::Image::getConstPixels(const ssize_t x_, + const ssize_t y_,const size_t columns_,const size_t rows_) const { - modifyImage(); - options()->endian( endian_ ); - image()->endian = endian_; + const Quantum + *p; + + GetPPException; + p=(*GetVirtualPixels)(constImage(),x_, y_,columns_, rows_,&exceptionInfo); + ThrowPPException; + return(p); } -Magick::EndianType Magick::Image::endian ( void ) const + +const void *Magick::Image::getConstMetacontent(void) const { - return constImage()->endian; + const void + *result; + + result=GetVirtualMetacontent(constImage()); + + if(!result) + throwExceptionExplicit(OptionError,"Unable to retrieve meta content."); + + return(result); } -// EXIF profile (BLOB) -void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ ) +void *Magick::Image::getMetacontent(void ) { - modifyImage(); - if ( exifProfile_.data() != 0 ) - { - StringInfo * exif_profile = AcquireStringInfo( exifProfile_.length() ); - SetStringInfoDatum(exif_profile ,(unsigned char *) exifProfile_.data()); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - (void) SetImageProfile( image(), "exif", exif_profile, &exceptionInfo); - exif_profile =DestroyStringInfo( exif_profile ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - } + void + *result; + + result=GetAuthenticMetacontent(image()); + + if(!result) + throwExceptionExplicit(OptionError,"Unable to retrieve meta content."); + + return(result); } -Magick::Blob Magick::Image::exifProfile( void ) const -{ - const StringInfo * exif_profile = GetImageProfile( constImage(), "exif" ); - if ( exif_profile == (StringInfo *) NULL) - return Blob( 0, 0 ); - return Blob(GetStringInfoDatum(exif_profile),GetStringInfoLength(exif_profile)); -} -// Image file name -void Magick::Image::fileName ( const std::string &fileName_ ) +Magick::Quantum *Magick::Image::getPixels(const ssize_t x_,const ssize_t y_, + const size_t columns_,const size_t rows_) { + Quantum + *result; + modifyImage(); + GetPPException; + result=(*GetAuthenticPixels)(image(),x_, y_,columns_,rows_,&exceptionInfo); + ThrowPPException; - fileName_.copy( image()->filename, - sizeof(image()->filename) - 1 ); - image()->filename[ fileName_.length() ] = 0; // Null terminate - - options()->fileName( fileName_ ); - + return(result); } -std::string Magick::Image::fileName ( void ) const + +void Magick::Image::haldClut(const Image &clutImage_) { - return constOptions()->fileName( ); + modifyImage(); + GetPPException; + (void) HaldClutImage(image(),clutImage_.constImage(),&exceptionInfo); + ThrowPPException; } -// Image file size -off_t Magick::Image::fileSize ( void ) const +void Magick::Image::implode(const double factor_) { - return (off_t) GetBlobSize( constImage() ); + MagickCore::Image + *newImage; + + GetPPException; + newImage=ImplodeImage(constImage(),factor_,image()->interpolate, + &exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Color to use when drawing inside an object -void Magick::Image::fillColor ( const Magick::Color &fillColor_ ) +void Magick::Image::inverseFourierTransform(const Image &phase_) { - modifyImage(); - options()->fillColor(fillColor_); + inverseFourierTransform(phase_,true); } -Magick::Color Magick::Image::fillColor ( void ) const + +void Magick::Image::inverseFourierTransform(const Image &phase_, + const bool magnitude_) { - return constOptions()->fillColor(); + MagickCore::Image + *newImage; + + GetPPException; + newImage=InverseFourierTransformImage(constImage(),phase_.constImage(), + magnitude_ == true ? MagickTrue : MagickFalse,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Rule to use when filling drawn objects -void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ ) +void Magick::Image::level(const double blackPoint_,const double whitePoint_, + const double gamma_) { modifyImage(); - options()->fillRule(fillRule_); -} -Magick::FillRule Magick::Image::fillRule ( void ) const -{ - return constOptions()->fillRule(); + GetPPException; + (void) LevelImage(image(),blackPoint_,whitePoint_,gamma_,&exceptionInfo); + ThrowPPException; } -// Pattern to use while filling drawn objects. -void Magick::Image::fillPattern ( const Image &fillPattern_ ) +void Magick::Image::levelChannel(const ChannelType channel_, + const double blackPoint_,const double whitePoint_,const double gamma_) { modifyImage(); - if(fillPattern_.isValid()) - options()->fillPattern( fillPattern_.constImage() ); - else - options()->fillPattern( static_cast(NULL) ); + GetPPException; + SetPPChannelMask(channel_); + (void) LevelImage(image(),blackPoint_,whitePoint_,gamma_,&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; } -Magick::Image Magick::Image::fillPattern ( void ) const + +void Magick::Image::levelColors(const Color &blackColor_, + const Color &whiteColor_,const bool invert_) { - // FIXME: This is inordinately innefficient - Image texture; - - const MagickCore::Image* tmpTexture = constOptions()->fillPattern( ); + PixelInfo + black, + pixel, + white; - if ( tmpTexture ) - { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* image = - CloneImage( tmpTexture, - 0, // columns - 0, // rows - MagickTrue, // orphan - &exceptionInfo); - texture.replaceImage( image ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - } - return texture; + modifyImage(); + + GetPixelInfo(image(),&black); + pixel=static_cast(blackColor_); + black.red=pixel.red; + black.green=pixel.green; + black.blue=pixel.blue; + black.alpha=pixel.alpha; + + GetPixelInfo(image(),&white); + pixel=static_cast(whiteColor_); + white.red=pixel.red; + white.green=pixel.green; + white.blue=pixel.blue; + white.alpha=pixel.alpha; + + GetPPException; + (void) LevelImageColors(image(),&black,&white,invert_ == true ? + MagickTrue : MagickFalse,&exceptionInfo); + ThrowPPException; } -// Filter used by zoom -void Magick::Image::filterType ( const Magick::FilterTypes filterType_ ) +void Magick::Image::levelColorsChannel(const ChannelType channel_, + const Color &blackColor_,const Color &whiteColor_,const bool invert_) { + PixelInfo + black, + pixel, + white; + modifyImage(); - image()->filter = filterType_; + + GetPixelInfo(image(),&black); + pixel=static_cast(blackColor_); + black.red=pixel.red; + black.green=pixel.green; + black.blue=pixel.blue; + black.alpha=pixel.alpha; + + GetPixelInfo(image(),&white); + pixel=static_cast(whiteColor_); + white.red=pixel.red; + white.green=pixel.green; + white.blue=pixel.blue; + white.alpha=pixel.alpha; + + GetPPException; + SetPPChannelMask(channel_); + (void) LevelImageColors(image(),&black,&white,invert_ == true ? + MagickTrue : MagickFalse,&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; } -Magick::FilterTypes Magick::Image::filterType ( void ) const + +void Magick::Image::linearStretch(const double blackPoint_, + const double whitePoint_) { - return constImage()->filter; + modifyImage(); + GetPPException; + LinearStretchImage(image(),blackPoint_,whitePoint_,&exceptionInfo); + ThrowPPException; } -// Font name -void Magick::Image::font ( const std::string &font_ ) +void Magick::Image::liquidRescale(const Geometry &geometry_) { - modifyImage(); - options()->font( font_ ); + MagickCore::Image + *newImage; + + size_t + height=rows(), + width=columns(); + + ssize_t + x=0, + y=0; + + ParseMetaGeometry(static_cast(geometry_).c_str(),&x,&y,&width, + &height); + + GetPPException; + newImage=LiquidRescaleImage(image(),width,height,x,y,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -std::string Magick::Image::font ( void ) const + +void Magick::Image::magnify(void) { - return constOptions()->font( ); + MagickCore::Image + *newImage; + + GetPPException; + newImage=MagnifyImage(constImage(),&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Font point size -void Magick::Image::fontPointsize ( const double pointSize_ ) +void Magick::Image::map(const Image &mapImage_,const bool dither_) { modifyImage(); - options()->fontPointsize( pointSize_ ); + GetPPException; + options()->quantizeDither(dither_); + RemapImage(options()->quantizeInfo(),image(),mapImage_.constImage(), + &exceptionInfo); + ThrowPPException; } -double Magick::Image::fontPointsize ( void ) const + +void Magick::Image::medianFilter(const double radius_) { - return constOptions()->fontPointsize( ); + MagickCore::Image + *newImage; + + GetPPException; + newImage=StatisticImage(image(),MedianStatistic,(size_t) radius_, + (size_t) radius_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Font type metrics -void Magick::Image::fontTypeMetrics( const std::string &text_, - TypeMetric *metrics ) +void Magick::Image::minify(void) { - DrawInfo *drawInfo = options()->drawInfo(); - drawInfo->text = const_cast(text_.c_str()); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - GetTypeMetrics( image(), drawInfo, &(metrics->_typeMetric), &exceptionInfo ); - drawInfo->text = 0; - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + MagickCore::Image + *newImage; + + GetPPException; + newImage=MinifyImage(constImage(),&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Image format string -std::string Magick::Image::format ( void ) const +void Magick::Image::modulate(const double brightness_,const double saturation_, + const double hue_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - const MagickInfo * magick_info - = GetMagickInfo( constImage()->magick, &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + char + modulate[MaxTextExtent + 1]; - if (( magick_info != 0 ) && - ( *magick_info->description != '\0' )) - return std::string(magick_info->description); + FormatLocaleString(modulate,MaxTextExtent,"%3.6f,%3.6f,%3.6f",brightness_, + saturation_,hue_); - throwExceptionExplicit( CorruptImageWarning, - "Unrecognized image magick type" ); - return std::string(); + modifyImage(); + GetPPException; + ModulateImage(image(),modulate,&exceptionInfo); + ThrowPPException; } -// Gamma adjustment -double Magick::Image::gamma ( void ) const +void Magick::Image::motionBlur(const double radius_,const double sigma_, + const double angle_) { - return constImage()->gamma; + MagickCore::Image + *newImage; + + GetPPException; + newImage=MotionBlurImage(constImage(),radius_,sigma_,angle_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -Magick::Geometry Magick::Image::geometry ( void ) const +void Magick::Image::negate(const bool grayscale_) { - if ( constImage()->geometry ) - { - return Geometry(constImage()->geometry); - } - - throwExceptionExplicit( OptionWarning, - "Image does not contain a geometry"); + modifyImage(); + GetPPException; + NegateImage(image(),(MagickBooleanType) grayscale_,&exceptionInfo); + ThrowPPException; +} - return Geometry(); +void Magick::Image::negateChannel(const ChannelType channel_, + const bool grayscale_) +{ + modifyImage(); + GetPPException; + SetPPChannelMask(channel_); + NegateImage(image(),(MagickBooleanType) grayscale_,&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; } -void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ ) +void Magick::Image::normalize(void) { modifyImage(); - image()->dispose = (DisposeType) disposeMethod_; + GetPPException; + NormalizeImage(image(),&exceptionInfo); + ThrowPPException; } -size_t Magick::Image::gifDisposeMethod ( void ) const + +void Magick::Image::oilPaint(const double radius_,const double sigma_) { - // FIXME: It would be better to return an enumeration - return constImage()->dispose; + MagickCore::Image + *newImage; + + GetPPException; + newImage=OilPaintImage(constImage(),radius_,sigma_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// ICC ICM color profile (BLOB) -void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ ) +void Magick::Image::opaque(const Color &opaqueColor_,const Color &penColor_) { - profile("icm",colorProfile_); + std::string + opaqueColor, + penColor; + + PixelInfo + opaque, + pen; + + if (!opaqueColor_.isValid()) + throwExceptionExplicit(OptionError,"Opaque color argument is invalid"); + + if (!penColor_.isValid()) + throwExceptionExplicit(OptionError,"Pen color argument is invalid"); + + modifyImage(); + opaqueColor=opaqueColor_; + penColor=penColor_; + + GetPPException; + (void) QueryColorCompliance(opaqueColor.c_str(),AllCompliance,&opaque, + &exceptionInfo); + (void) QueryColorCompliance(penColor.c_str(),AllCompliance,&pen, + &exceptionInfo); + OpaquePaintImage(image(),&opaque,&pen,MagickFalse,&exceptionInfo); + ThrowPPException; } -Magick::Blob Magick::Image::iccColorProfile( void ) const + +void Magick::Image::perceptible(const double epsilon_) { - const StringInfo * color_profile = GetImageProfile( constImage(), "icc" ); - if ( color_profile == (StringInfo *) NULL) - return Blob( 0, 0 ); - return Blob( GetStringInfoDatum(color_profile), GetStringInfoLength(color_profile) ); + modifyImage(); + GetPPException; + PerceptibleImage(image(),epsilon_,&exceptionInfo); + ThrowPPException; } -void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ ) +void Magick::Image::perceptibleChannel(const ChannelType channel_, + const double epsilon_) { modifyImage(); - image()->interlace = interlace_; - options()->interlaceType ( interlace_ ); + GetPPException; + SetPPChannelMask(channel_); + PerceptibleImage(image(),epsilon_,&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; } -Magick::InterlaceType Magick::Image::interlaceType ( void ) const + +void Magick::Image::ping(const std::string &imageSpec_) { - return constImage()->interlace; + MagickCore::Image + *newImage; + + GetPPException; + options()->fileName(imageSpec_); + newImage=PingImage(imageInfo(),&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// IPTC profile (BLOB) -void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ ) +void Magick::Image::ping(const Blob& blob_) { - modifyImage(); - if ( iptcProfile_.data() != 0 ) - { - StringInfo * iptc_profile = AcquireStringInfo( iptcProfile_.length() ); - SetStringInfoDatum(iptc_profile ,(unsigned char *) iptcProfile_.data()); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - (void) SetImageProfile( image(), "iptc", iptc_profile, &exceptionInfo); - iptc_profile =DestroyStringInfo( iptc_profile ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - } + MagickCore::Image + *newImage; + + GetPPException; + newImage=PingBlob(imageInfo(),blob_.data(),blob_.length(),&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -Magick::Blob Magick::Image::iptcProfile( void ) const + +void Magick::Image::pixelColor(const ssize_t x_,const ssize_t y_, + const Color &color_) { - const StringInfo * iptc_profile = GetImageProfile( constImage(), "iptc" ); - if ( iptc_profile == (StringInfo *) NULL) - return Blob( 0, 0 ); - return Blob( GetStringInfoDatum(iptc_profile), GetStringInfoLength(iptc_profile)); + PixelInfo + packet; + + Quantum + *pixel; + + // Test arguments to ensure they are within the image. + if (y_ > (ssize_t) rows() || x_ > (ssize_t) columns()) + throwExceptionExplicit(OptionError,"Access outside of image boundary"); + + modifyImage(); + + // Set image to DirectClass + classType(DirectClass ); + + // Get pixel view + Pixels pixels(*this); + // Set pixel value + pixel=pixels.get(x_, y_, 1, 1 ); + packet=color_; + MagickCore::SetPixelInfoPixel(constImage(),&packet,pixel); + // Tell ImageMagick that pixels have been updated + pixels.sync(); } -// Does object contain valid image? -void Magick::Image::isValid ( const bool isValid_ ) +Magick::Color Magick::Image::pixelColor(const ssize_t x_, + const ssize_t y_) const { - if ( !isValid_ ) - { - delete _imgRef; - _imgRef = new ImageRef; - } - else if ( !isValid() ) + const Quantum + *pixel; + + pixel=getConstPixels(x_,y_,1,1); + if (pixel) { - // Construct with single-pixel black image to make - // image valid. This is an obvious hack. - size( Geometry(1,1) ); - read( "xc:#000000" ); + PixelInfo + packet; + + MagickCore::GetPixelInfoPixel(constImage(),pixel,&packet); + return(Color(packet)); } + + return(Color()); // invalid } -bool Magick::Image::isValid ( void ) const +void Magick::Image::polaroid(const std::string &caption_,const double angle_, + const PixelInterpolateMethod method_) { - if ( rows() && columns() ) - return true; + MagickCore::Image + *newImage; - return false; + GetPPException; + newImage=PolaroidImage(constImage(),options()->drawInfo(),caption_.c_str(), + angle_,method_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Label image -void Magick::Image::label ( const std::string &label_ ) +void Magick::Image::posterize(const size_t levels_,const DitherMethod method_) { modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - SetImageProperty ( image(), "Label", NULL, &exceptionInfo ); - if ( label_.length() > 0 ) - SetImageProperty ( image(), "Label", label_.c_str(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + GetPPException; + PosterizeImage(image(),levels_,method_,&exceptionInfo); + ThrowPPException; } -std::string Magick::Image::label ( void ) const -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - const char *value = GetImageProperty( constImage(), "Label", &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - - if ( value ) - return std::string( value ); - return std::string(); +void Magick::Image::posterizeChannel(const ChannelType channel_, + const size_t levels_,const DitherMethod method_) +{ + modifyImage(); + GetPPException; + SetPPChannelMask(channel_); + PosterizeImage(image(),levels_,method_,&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; } -void Magick::Image::magick ( const std::string &magick_ ) +void Magick::Image::process(std::string name_,const ssize_t argc, + const char **argv) { modifyImage(); - magick_.copy( image()->magick, - sizeof(image()->magick) - 1 ); - image()->magick[ magick_.length() ] = 0; - - options()->magick( magick_ ); + GetPPException; + (void) InvokeDynamicImageFilter(name_.c_str(),&image(),argc,argv, + &exceptionInfo); + ThrowPPException; } -std::string Magick::Image::magick ( void ) const -{ - if ( *(constImage()->magick) != '\0' ) - return std::string(constImage()->magick); - return constOptions()->magick( ); +void Magick::Image::profile(const std::string name_, + const Magick::Blob &profile_) +{ + modifyImage(); + GetPPException; + (void) ProfileImage(image(),name_.c_str(),(unsigned char *)profile_.data(), + profile_.length(),&exceptionInfo); + ThrowPPException; } -void Magick::Image::matte ( const bool matteFlag_ ) +Magick::Blob Magick::Image::profile(const std::string name_) const { - modifyImage(); + const StringInfo + *profile; - // If matte channel is requested, but image doesn't already have a - // matte channel, then create an opaque matte channel. Likewise, if - // the image already has a matte channel but a matte channel is not - // desired, then set the matte channel to opaque. - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - if ((matteFlag_ && !constImage()->alpha_trait) || - (constImage()->alpha_trait && !matteFlag_)) - SetImageAlpha(image(),OpaqueAlpha,&exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + profile=GetImageProfile(constImage(),name_.c_str()); - image()->alpha_trait = matteFlag_ ? BlendPixelTrait : UndefinedPixelTrait; -} -bool Magick::Image::matte ( void ) const -{ - if ( constImage()->alpha_trait == BlendPixelTrait ) - return true; - else - return false; + if (profile == (StringInfo *) NULL) + return(Blob()); + return(Blob((void*) GetStringInfoDatum(profile),GetStringInfoLength( + profile))); } -void Magick::Image::matteColor ( const Color &matteColor_ ) +void Magick::Image::quantize(const bool measureError_) { modifyImage(); - - if ( matteColor_.isValid() ) - { - image()->matte_color = matteColor_; - options()->matteColor( matteColor_ ); - } + + if (measureError_) + options()->quantizeInfo()->measure_error=MagickTrue; else - { - // Set to default matte color - Color tmpColor( "#BDBDBD" ); - image()->matte_color = tmpColor; - options()->matteColor( tmpColor ); - } + options()->quantizeInfo()->measure_error=MagickFalse; + + GetPPException; + QuantizeImage(options()->quantizeInfo(),image(),&exceptionInfo); + ThrowPPException; } -Magick::Color Magick::Image::matteColor ( void ) const + +void Magick::Image::quantumOperator(const ChannelType channel_, + const MagickEvaluateOperator operator_,double rvalue_) { - return Color( ClampToQuantum( constImage()->matte_color.red ), - ClampToQuantum( constImage()->matte_color.green ), - ClampToQuantum( constImage()->matte_color.blue ) ); + GetPPException; + SetPPChannelMask(channel_); + EvaluateImage(image(),operator_,rvalue_,&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; } -double Magick::Image::meanErrorPerPixel ( void ) const +void Magick::Image::quantumOperator(const ssize_t x_,const ssize_t y_, + const size_t columns_,const size_t rows_,const ChannelType channel_, + const MagickEvaluateOperator operator_,const double rvalue_) { - return(constImage()->error.mean_error_per_pixel); + RectangleInfo + geometry; + + MagickCore::Image + *cropImage; + + geometry.width = columns_; + geometry.height = rows_; + geometry.x = x_; + geometry.y = y_; + + GetPPException; + cropImage=CropImage(image(),&geometry,&exceptionInfo); + SetPPChannelMask(channel_); + EvaluateImage(cropImage,operator_,rvalue_,&exceptionInfo); + RestorePPChannelMask; + (void) CompositeImage(image(),cropImage,image()->alpha_trait == + BlendPixelTrait ? OverCompositeOp : CopyCompositeOp,MagickFalse, + geometry.x,geometry.y,&exceptionInfo ); + cropImage=DestroyImageList(cropImage); + ThrowPPException; } -// Image modulus depth (minimum number of bits required to support -// red/green/blue components without loss of accuracy) -void Magick::Image::modulusDepth ( const size_t depth_ ) +void Magick::Image::raise(const Geometry &geometry_,const bool raisedFlag_) { + RectangleInfo + raiseInfo=geometry_; + + GetPPException; modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - SetImageDepth( image(), depth_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - options()->depth( depth_ ); + RaiseImage(image(),&raiseInfo,raisedFlag_ == true ? MagickTrue : MagickFalse, + &exceptionInfo); + ThrowPPException; } -size_t Magick::Image::modulusDepth ( void ) const + +void Magick::Image::randomThreshold(const Geometry &thresholds_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - size_t depth=GetImageDepth( constImage(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - return depth; + GetPPException; + (void) RandomThresholdImage(image(),static_cast( + thresholds_).c_str(),&exceptionInfo); + ThrowPPException; } -void Magick::Image::monochrome ( const bool monochromeFlag_ ) +void Magick::Image::randomThresholdChannel(const ChannelType channel_, + const Geometry &thresholds_) { modifyImage(); - options()->monochrome( monochromeFlag_ ); -} -bool Magick::Image::monochrome ( void ) const -{ - return constOptions()->monochrome( ); + GetPPException; + SetPPChannelMask(channel_); + (void) RandomThresholdImage(image(),static_cast( + thresholds_).c_str(),&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; } -Magick::Geometry Magick::Image::montageGeometry ( void ) const +void Magick::Image::read(const Blob &blob_) { - if ( constImage()->montage ) - return Magick::Geometry(constImage()->montage); - - throwExceptionExplicit( CorruptImageWarning, - "Image does not contain a montage" ); + MagickCore::Image + *newImage; - return Magick::Geometry(); + GetPPException; + newImage=BlobToImage(imageInfo(),static_cast(blob_.data()), + blob_.length(),&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -double Magick::Image::normalizedMaxError ( void ) const +void Magick::Image::read(const Blob &blob_,const Geometry &size_) { - return(constImage()->error.normalized_maximum_error); + size(size_); + read(blob_); } -double Magick::Image::normalizedMeanError ( void ) const +void Magick::Image::read(const Blob &blob_,const Geometry &size_, + const size_t depth_) { - return constImage()->error.normalized_mean_error; + size(size_); + depth(depth_); + read(blob_); } -// Image orientation -void Magick::Image::orientation ( const Magick::OrientationType orientation_ ) +void Magick::Image::read(const Blob &blob_,const Geometry &size_, + const size_t depth_,const std::string &magick_) { - modifyImage(); - image()->orientation = orientation_; + size(size_); + depth(depth_); + magick(magick_); + // Set explicit image format + fileName(magick_ + ':'); + read(blob_); } -Magick::OrientationType Magick::Image::orientation ( void ) const + +void Magick::Image::read(const Blob &blob_,const Geometry &size_, + const std::string &magick_) { - return constImage()->orientation; + size(size_); + magick(magick_); + // Set explicit image format + fileName(magick_ + ':'); + read(blob_); } -// Set the color of a pixel. -void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_, - const Color &color_ ) +void Magick::Image::read(const Geometry &size_,const std::string &imageSpec_) { - // Test arguments to ensure they are within the image. - if ( y_ > (ssize_t) rows() || x_ > (ssize_t) columns() ) - throwExceptionExplicit( OptionError, - "Access outside of image boundary" ); - - modifyImage(); - - // Set image to DirectClass - classType( DirectClass ); + size(size_); + read(imageSpec_); +} - // Get pixel view - Pixels pixels(*this); - // Set pixel value - Quantum *pixel = pixels.get(x_, y_, 1, 1 ); - PixelInfo packet = color_; - MagickCore::SetPixelInfoPixel(constImage(),&packet,pixel); - // Tell ImageMagick that pixels have been updated - pixels.sync(); +void Magick::Image::read(const size_t width_,const size_t height_, + const std::string &map_,const StorageType type_,const void *pixels_) +{ + MagickCore::Image + *newImage; - return; + GetPPException; + newImage=ConstituteImage(width_,height_,map_.c_str(),type_, pixels_, + &exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Get the color of a pixel -Magick::Color Magick::Image::pixelColor ( const ssize_t x_, - const ssize_t y_ ) const +void Magick::Image::read(const std::string &imageSpec_) { - const Quantum* pixel = getConstPixels( x_, y_, 1, 1 ); - if ( pixel ) + MagickCore::Image + *newImage; + + GetPPException; + options()->fileName(imageSpec_); + newImage=ReadImage(imageInfo(),&exceptionInfo); + + // Ensure that multiple image frames were not read. + if (newImage && newImage->next) { - PixelInfo packet; - MagickCore::GetPixelInfoPixel(constImage(),pixel,&packet); - return Color( packet ); - } + MagickCore::Image + *next; - return Color(); // invalid + // Destroy any extra image frames + next=newImage->next; + newImage->next=0; + next->previous=0; + DestroyImageList(next); + } + replaceImage(newImage); + ThrowPPException; } -// Preferred size and location of an image canvas. -void Magick::Image::page ( const Magick::Geometry &pageSize_ ) +void Magick::Image::readPixels(const Magick::QuantumType quantum_, + const unsigned char *source_) { - modifyImage(); - options()->page( pageSize_ ); - image()->page = pageSize_; + QuantumInfo + *quantum_info; + + quantum_info=AcquireQuantumInfo(imageInfo(),image()); + GetPPException; + ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info, + quantum_,source_,&exceptionInfo); + quantum_info=DestroyQuantumInfo(quantum_info); + ThrowPPException; } -Magick::Geometry Magick::Image::page ( void ) const + +void Magick::Image::reduceNoise(void) { - return Geometry( constImage()->page.width, - constImage()->page.height, - AbsoluteValue(constImage()->page.x), - AbsoluteValue(constImage()->page.y), - constImage()->page.x < 0 ? true : false, - constImage()->page.y < 0 ? true : false); + reduceNoise(3.0); } -// Add a named profile to an image or remove a named profile by -// passing an empty Blob (use default Blob constructor). -// Valid names are: -// "*", "8BIM", "ICM", "IPTC", or a generic profile name. -void Magick::Image::profile( const std::string name_, - const Magick::Blob &profile_ ) +void Magick::Image::reduceNoise(const double order_) { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ssize_t result = ProfileImage( image(), name_.c_str(), - (unsigned char *)profile_.data(), - profile_.length(), &exceptionInfo); - (void) result; - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + MagickCore::Image + *newImage; + GetPPException; + newImage=StatisticImage(constImage(),NonpeakStatistic,(size_t) order_, + (size_t) order_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Retrieve a named profile from the image. -// Valid names are: -// "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" or -// an existing generic profile name. -Magick::Blob Magick::Image::profile( const std::string name_ ) const +void Magick::Image::resize( const Geometry &geometry_ ) { - const StringInfo * profile = GetImageProfile( constImage(), name_.c_str() ); + MagickCore::Image + *newImage; + + size_t + height=rows(), + width=columns(); + + ssize_t + x=0, + y=0; + + // Calculate new size. This code should be supported using binary arguments + // in the ImageMagick library. + ParseMetaGeometry(static_cast(geometry_).c_str(),&x,&y,&width, + &height); - if ( profile == (StringInfo *) NULL) - return Blob( 0, 0 ); - return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile)); + GetPPException; + newImage=ResizeImage(constImage(),width,height,image()->filter, + &exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -void Magick::Image::quality ( const size_t quality_ ) +void Magick::Image::roll(const Geometry &roll_) { - modifyImage(); - image()->quality = quality_; - options()->quality( quality_ ); + MagickCore::Image + *newImage; + + ssize_t + xOff=roll_.xOff(), + yOff=roll_.yOff(); + + if (roll_.xNegative()) + xOff = 0 - xOff; + if (roll_.yNegative()) + yOff = 0 - yOff; + + GetPPException; + newImage=RollImage(constImage(),xOff,yOff,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -size_t Magick::Image::quality ( void ) const + +void Magick::Image::roll(const size_t columns_,const size_t rows_) { - return constImage()->quality; + MagickCore::Image + *newImage; + + GetPPException; + newImage=RollImage(constImage(),static_cast(columns_), + static_cast(rows_),&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -void Magick::Image::quantizeColors ( const size_t colors_ ) +void Magick::Image::rotate(const double degrees_) { - modifyImage(); - options()->quantizeColors( colors_ ); + MagickCore::Image + *newImage; + + GetPPException; + newImage=RotateImage(constImage(),degrees_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -size_t Magick::Image::quantizeColors ( void ) const + +void Magick::Image::sample(const Geometry &geometry_) { - return constOptions()->quantizeColors( ); + MagickCore::Image + *newImage; + + size_t + height=rows(), + width=columns(); + + ssize_t + x=0, + y=0; + + ParseMetaGeometry(static_cast(geometry_).c_str(),&x,&y,&width, + &height); + + GetPPException; + newImage=SampleImage(constImage(),width,height,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -void Magick::Image::quantizeColorSpace - ( const Magick::ColorspaceType colorSpace_ ) +Magick::Quantum *Magick::Image::setPixels(const ssize_t x_,const ssize_t y_, + const size_t columns_,const size_t rows_) { + Quantum + *result; + modifyImage(); - options()->quantizeColorSpace( colorSpace_ ); + GetPPException; + result=(*QueueAuthenticPixels)(image(),x_,y_,columns_,rows_,&exceptionInfo); + ThrowPPException; + return(result); } -Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const + +void Magick::Image::scale(const Geometry &geometry_) { - return constOptions()->quantizeColorSpace( ); + MagickCore::Image + *newImage; + + size_t + height=rows(), + width=columns(); + + ssize_t + x=0, + y=0; + + ParseMetaGeometry(static_cast(geometry_).c_str(),&x,&y,&width, + &height); + + GetPPException; + newImage=ScaleImage(constImage(),width,height,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -void Magick::Image::quantizeDither ( const bool ditherFlag_ ) +void Magick::Image::segment(const double clusterThreshold_, + const double smoothingThreshold_) { modifyImage(); - options()->quantizeDither( ditherFlag_ ); -} -bool Magick::Image::quantizeDither ( void ) const -{ - return constOptions()->quantizeDither( ); + GetPPException; + SegmentImage(image(),options()->quantizeColorSpace(), + (MagickBooleanType) options()->verbose(),clusterThreshold_, + smoothingThreshold_,&exceptionInfo); + SyncImage(image(),&exceptionInfo); + ThrowPPException; } -void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ ) +void Magick::Image::shade(const double azimuth_,const double elevation_, + const bool colorShading_) { - modifyImage(); - options()->quantizeTreeDepth( treeDepth_ ); + MagickCore::Image + *newImage; + + GetPPException; + newImage=ShadeImage(constImage(),colorShading_ == true ? + MagickTrue : MagickFalse,azimuth_,elevation_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -size_t Magick::Image::quantizeTreeDepth ( void ) const + +void Magick::Image::shadow(const double percent_opacity_,const double sigma_, + const ssize_t x_,const ssize_t y_) { - return constOptions()->quantizeTreeDepth( ); + MagickCore::Image + *newImage; + + GetPPException; + newImage=ShadowImage(constImage(),percent_opacity_, sigma_,x_, y_, + &exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -void Magick::Image::renderingIntent - ( const Magick::RenderingIntent renderingIntent_ ) +void Magick::Image::sharpen(const double radius_,const double sigma_) { - modifyImage(); - image()->rendering_intent = renderingIntent_; + MagickCore::Image + *newImage; + + GetPPException; + newImage=SharpenImage(constImage(),radius_,sigma_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const + +void Magick::Image::sharpenChannel(const ChannelType channel_, + const double radius_,const double sigma_) { - return static_cast(constImage()->rendering_intent); + MagickCore::Image + *newImage; + + GetPPException; + SetPPChannelMask(channel_); + newImage=SharpenImage(constImage(),radius_,sigma_,&exceptionInfo); + RestorePPChannelMask; + replaceImage(newImage); + ThrowPPException; } -void Magick::Image::resolutionUnits - ( const Magick::ResolutionType resolutionUnits_ ) +void Magick::Image::shave(const Geometry &geometry_) { - modifyImage(); - image()->units = resolutionUnits_; - options()->resolutionUnits( resolutionUnits_ ); + MagickCore::Image + *newImage; + + RectangleInfo + shaveInfo=geometry_; + + GetPPException; + newImage=ShaveImage(constImage(),&shaveInfo,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const + +void Magick::Image::shear(const double xShearAngle_,const double yShearAngle_) { - return constOptions()->resolutionUnits( ); + MagickCore::Image + *newImage; + + GetPPException; + newImage=ShearImage(constImage(),xShearAngle_,yShearAngle_,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -void Magick::Image::scene ( const size_t scene_ ) +void Magick::Image::sigmoidalContrast(const size_t sharpen_, + const double contrast,const double midpoint) { modifyImage(); - image()->scene = scene_; -} -size_t Magick::Image::scene ( void ) const -{ - return constImage()->scene; + GetPPException; + (void) SigmoidalContrastImage(image(),(MagickBooleanType) sharpen_,contrast, + midpoint,&exceptionInfo); + ThrowPPException; } -std::string Magick::Image::signature ( const bool force_ ) const +std::string Magick::Image::signature(const bool force_) const { - Lock( &_imgRef->_mutexLock ); + const char + *property; + + Lock(&_imgRef->_mutexLock); // Re-calculate image signature if necessary - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - if ( force_ || - !GetImageProperty(constImage(), "Signature", &exceptionInfo) || - constImage()->taint ) - { - SignatureImage( const_cast(constImage()), &exceptionInfo ); - } + GetPPException; + if (force_ || !GetImageProperty(constImage(),"Signature",&exceptionInfo) || + constImage()->taint) + SignatureImage(const_cast(constImage()), + &exceptionInfo); - const char *property = GetImageProperty(constImage(), "Signature", - &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + property=GetImageProperty(constImage(),"Signature",&exceptionInfo); + ThrowPPException; - return std::string( property ); + return(std::string(property)); } -void Magick::Image::size ( const Geometry &geometry_ ) +void Magick::Image::solarize(const double factor_) { modifyImage(); - options()->size( geometry_ ); - image()->rows = geometry_.height(); - image()->columns = geometry_.width(); + GetPPException; + SolarizeImage(image(),factor_,&exceptionInfo); + ThrowPPException; +} + +void Magick::Image::sparseColor(const ChannelType channel_, + const SparseColorMethod method_,const size_t numberArguments_, + const double *arguments_) +{ + MagickCore::Image + *newImage; + + GetPPException; + SetPPChannelMask(channel_); + newImage=SparseColorImage(constImage(),method_,numberArguments_,arguments_, + &exceptionInfo); + RestorePPChannelMask; + replaceImage(newImage); + ThrowPPException; } -Magick::Geometry Magick::Image::size ( void ) const + +void Magick::Image::splice(const Geometry &geometry_) { - return Magick::Geometry( constImage()->columns, constImage()->rows ); + MagickCore::Image + *newImage; + + RectangleInfo + spliceInfo=geometry_; + + GetPPException; + newImage=SpliceImage(constImage(),&spliceInfo,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Splice image -void Magick::Image::splice( const Geometry &geometry_ ) +void Magick::Image::spread(const size_t amount_) { - RectangleInfo spliceInfo = geometry_; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* newImage = - SpliceImage( image(), &spliceInfo, &exceptionInfo); - replaceImage( newImage ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + MagickCore::Image + *newImage; + + GetPPException; + newImage=SpreadImage(constImage(),amount_,image()->interpolate, + &exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Obtain image statistics. Statistics are normalized to the range of -// 0.0 to 1.0 and are output to the specified ImageStatistics -// structure. -void Magick::Image::statistics ( ImageStatistics *statistics ) +void Magick::Image::statistics(ImageStatistics *statistics) { double maximum, minimum; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); + GetPPException; - ChannelType channel_mask = SetImageChannelMask( image(), RedChannel); - (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo); + SetPPChannelMask(RedChannel); + (void) GetImageRange(constImage(),&minimum,&maximum,&exceptionInfo); statistics->red.minimum=minimum; statistics->red.maximum=maximum; - (void) GetImageMean( image(),&statistics->red.mean, + (void) GetImageMean(constImage(),&statistics->red.mean, &statistics->red.standard_deviation,&exceptionInfo); - (void) GetImageKurtosis( image(),&statistics->red.kurtosis, + (void) GetImageKurtosis(constImage(),&statistics->red.kurtosis, &statistics->red.skewness,&exceptionInfo); - SetPixelChannelMask( image(), channel_mask ); - channel_mask = SetImageChannelMask( image(), GreenChannel); - (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo); + (void) SetImageChannelMask(image(),GreenChannel); + (void) GetImageRange(constImage(),&minimum,&maximum,&exceptionInfo); statistics->green.minimum=minimum; statistics->green.maximum=maximum; - (void) GetImageMean( image(),&statistics->green.mean, + (void) GetImageMean(constImage(),&statistics->green.mean, &statistics->green.standard_deviation,&exceptionInfo); - (void) GetImageKurtosis( image(),&statistics->green.kurtosis, + (void) GetImageKurtosis(constImage(),&statistics->green.kurtosis, &statistics->green.skewness,&exceptionInfo); - SetPixelChannelMask( image(), channel_mask ); - channel_mask = SetImageChannelMask( image(), GreenChannel); - (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo); + (void) SetImageChannelMask(image(),GreenChannel); + (void) GetImageRange(constImage(),&minimum,&maximum,&exceptionInfo); statistics->blue.minimum=minimum; statistics->blue.maximum=maximum; - (void) GetImageMean( image(),&statistics->blue.mean, + (void) GetImageMean(constImage(),&statistics->blue.mean, &statistics->blue.standard_deviation,&exceptionInfo); - (void) GetImageKurtosis( image(),&statistics->blue.kurtosis, + (void) GetImageKurtosis(constImage(),&statistics->blue.kurtosis, &statistics->blue.skewness,&exceptionInfo); - SetPixelChannelMask( image(), channel_mask ); - channel_mask = SetImageChannelMask( image(), AlphaChannel); - (void) GetImageRange( image(),&minimum,&maximum,&exceptionInfo); + (void) SetImageChannelMask(image(),AlphaChannel); + (void) GetImageRange(constImage(),&minimum,&maximum,&exceptionInfo); statistics->alpha.minimum=minimum; statistics->alpha.maximum=maximum; - (void) GetImageMean( image(),&statistics->alpha.mean, + (void) GetImageMean(constImage(),&statistics->alpha.mean, &statistics->alpha.standard_deviation,&exceptionInfo); - (void) GetImageKurtosis( image(),&statistics->alpha.kurtosis, + (void) GetImageKurtosis(constImage(),&statistics->alpha.kurtosis, &statistics->alpha.skewness,&exceptionInfo); - SetPixelChannelMask( image(), channel_mask ); - - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} - -// Strip strips an image of all profiles and comments. -void Magick::Image::strip ( void ) -{ - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - StripImage( image(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + RestorePPChannelMask; + ThrowPPException; } -// enabled/disable stroke anti-aliasing -void Magick::Image::strokeAntiAlias ( const bool flag_ ) -{ - modifyImage(); - options()->strokeAntiAlias(flag_); -} -bool Magick::Image::strokeAntiAlias ( void ) const +void Magick::Image::stegano(const Image &watermark_) { - return constOptions()->strokeAntiAlias(); -} + MagickCore::Image + *newImage; -// Color to use when drawing object outlines -void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ ) -{ - modifyImage(); - options()->strokeColor(strokeColor_); -} -Magick::Color Magick::Image::strokeColor ( void ) const -{ - return constOptions()->strokeColor(); + GetPPException; + newImage=SteganoImage(constImage(),watermark_.constImage(),&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// dash pattern for drawing vector objects (default one) -void Magick::Image::strokeDashArray ( const double* strokeDashArray_ ) +void Magick::Image::stereo(const Image &rightImage_) { - modifyImage(); - options()->strokeDashArray( strokeDashArray_ ); -} + MagickCore::Image + *newImage; -const double* Magick::Image::strokeDashArray ( void ) const -{ - return constOptions()->strokeDashArray( ); + GetPPException; + newImage=StereoImage(constImage(),rightImage_.constImage(),&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// dash offset for drawing vector objects (default one) -void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ ) +void Magick::Image::strip(void) { modifyImage(); - options()->strokeDashOffset( strokeDashOffset_ ); + GetPPException; + StripImage(image(),&exceptionInfo); + ThrowPPException; } -double Magick::Image::strokeDashOffset ( void ) const +void Magick::Image::swirl(const double degrees_) { - return constOptions()->strokeDashOffset( ); -} + MagickCore::Image + *newImage; -// Specify the shape to be used at the end of open subpaths when they -// are stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap, -// and SquareCap. -void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ ) -{ - modifyImage(); - options()->strokeLineCap( lineCap_ ); + GetPPException; + newImage=SwirlImage(constImage(),degrees_,image()->interpolate, + &exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -Magick::LineCap Magick::Image::strokeLineCap ( void ) const + +void Magick::Image::syncPixels(void) { - return constOptions()->strokeLineCap( ); + GetPPException; + (*SyncAuthenticPixels)(image(),&exceptionInfo); + ThrowPPException; } -// Specify the shape to be used at the corners of paths (or other -// vector shapes) when they are stroked. Values of LineJoin are -// UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin. -void Magick::Image::strokeLineJoin ( const Magick::LineJoin lineJoin_ ) +void Magick::Image::texture(const Image &texture_) { modifyImage(); - options()->strokeLineJoin( lineJoin_ ); -} -Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const -{ - return constOptions()->strokeLineJoin( ); + GetPPException; + TextureImage(image(),texture_.constImage(),&exceptionInfo); + ThrowPPException; } -// Specify miter limit. When two line segments meet at a sharp angle -// and miter joins have been specified for 'lineJoin', it is possible -// for the miter to extend far beyond the thickness of the line -// stroking the path. The miterLimit' imposes a limit on the ratio of -// the miter length to the 'lineWidth'. The default value of this -// parameter is 4. -void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ ) +void Magick::Image::threshold(const double threshold_) { modifyImage(); - options()->strokeMiterLimit( strokeMiterLimit_ ); -} -size_t Magick::Image::strokeMiterLimit ( void ) const -{ - return constOptions()->strokeMiterLimit( ); + GetPPException; + BilevelImage(image(),threshold_,&exceptionInfo); + ThrowPPException; } -// Pattern to use while stroking drawn objects. -void Magick::Image::strokePattern ( const Image &strokePattern_ ) +void Magick::Image::transform(const Geometry &imageGeometry_) { modifyImage(); - if(strokePattern_.isValid()) - options()->strokePattern( strokePattern_.constImage() ); - else - options()->strokePattern( static_cast(NULL) ); -} -Magick::Image Magick::Image::strokePattern ( void ) const -{ - // FIXME: This is inordinately innefficient - Image texture; - - const MagickCore::Image* tmpTexture = constOptions()->strokePattern( ); - - if ( tmpTexture ) - { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - MagickCore::Image* image = - CloneImage( tmpTexture, - 0, // columns - 0, // rows - MagickTrue, // orphan - &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - texture.replaceImage( image ); - } - return texture; + GetPPException; + TransformImage(&(image()),0,std::string(imageGeometry_).c_str(), + &exceptionInfo); + ThrowPPException; } -// Stroke width for drawing lines, circles, ellipses, etc. -void Magick::Image::strokeWidth ( const double strokeWidth_ ) +void Magick::Image::transform(const Geometry &imageGeometry_, + const Geometry &cropGeometry_) { modifyImage(); - options()->strokeWidth( strokeWidth_ ); -} -double Magick::Image::strokeWidth ( void ) const -{ - return constOptions()->strokeWidth( ); + GetPPException; + TransformImage(&(image()),std::string(cropGeometry_).c_str(),std::string( + imageGeometry_).c_str(), &exceptionInfo); + ThrowPPException; } -void Magick::Image::subImage ( const size_t subImage_ ) +void Magick::Image::transformOrigin(const double x_,const double y_) { modifyImage(); - options()->subImage( subImage_ ); -} -size_t Magick::Image::subImage ( void ) const -{ - return constOptions()->subImage( ); + options()->transformOrigin(x_,y_); } -void Magick::Image::subRange ( const size_t subRange_ ) +void Magick::Image::transformReset(void) { modifyImage(); - options()->subRange( subRange_ ); -} -size_t Magick::Image::subRange ( void ) const -{ - return constOptions()->subRange( ); + options()->transformReset(); } -// Annotation text encoding (e.g. "UTF-16") -void Magick::Image::textEncoding ( const std::string &encoding_ ) +void Magick::Image::transformScale(const double sx_,const double sy_) { modifyImage(); - options()->textEncoding( encoding_ ); -} -std::string Magick::Image::textEncoding ( void ) const -{ - return constOptions()->textEncoding( ); + options()->transformScale(sx_,sy_); } -size_t Magick::Image::totalColors ( void ) const +void Magick::Image::transparent(const Color &color_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - size_t colors = GetNumberColors( constImage(), 0, &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - return colors; -} + PixelInfo + target; -// Origin of coordinate system to use when annotating with text or drawing -void Magick::Image::transformOrigin ( const double x_, const double y_ ) -{ - modifyImage(); - options()->transformOrigin( x_, y_ ); -} + std::string + color; -// Rotation to use when annotating with text or drawing -void Magick::Image::transformRotation ( const double angle_ ) -{ - modifyImage(); - options()->transformRotation( angle_ ); -} + if (!color_.isValid()) + throwExceptionExplicit(OptionError,"Color argument is invalid"); -// Reset transformation parameters to default -void Magick::Image::transformReset ( void ) -{ + color=color_; + GetPPException; + (void) QueryColorCompliance(color.c_str(),AllCompliance,&target, + &exceptionInfo); modifyImage(); - options()->transformReset(); + TransparentPaintImage(image(),&target,TransparentAlpha,MagickFalse, + &exceptionInfo); + ThrowPPException; } -// Scale to use when annotating with text or drawing -void Magick::Image::transformScale ( const double sx_, const double sy_ ) +void Magick::Image::transparentChroma(const Color &colorLow_, + const Color &colorHigh_) { - modifyImage(); - options()->transformScale( sx_, sy_ ); -} + std::string + colorHigh, + colorLow; -// Skew to use in X axis when annotating with text or drawing -void Magick::Image::transformSkewX ( const double skewx_ ) -{ - modifyImage(); - options()->transformSkewX( skewx_ ); -} + PixelInfo + targetHigh, + targetLow; -// Skew to use in Y axis when annotating with text or drawing -void Magick::Image::transformSkewY ( const double skewy_ ) -{ - modifyImage(); - options()->transformSkewY( skewy_ ); -} + if (!colorLow_.isValid() || !colorHigh_.isValid()) + throwExceptionExplicit(OptionError,"Color argument is invalid"); -// Image representation type -Magick::ImageType Magick::Image::type ( void ) const -{ + colorLow=colorLow_; + colorHigh=colorHigh_; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ImageType image_type = constOptions()->type(); - if ( image_type == UndefinedType ) - image_type= GetImageType( constImage(), &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - return image_type; -} -void Magick::Image::type ( const Magick::ImageType type_) -{ - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); + GetPPException; + (void) QueryColorCompliance(colorLow.c_str(),AllCompliance,&targetLow, + &exceptionInfo); + (void) QueryColorCompliance(colorHigh.c_str(),AllCompliance,&targetHigh, + &exceptionInfo); modifyImage(); - options()->type( type_ ); - SetImageType( image(), type_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + TransparentPaintImageChroma(image(),&targetLow,&targetHigh,TransparentAlpha, + MagickFalse,&exceptionInfo); + ThrowPPException; } -void Magick::Image::verbose ( const bool verboseFlag_ ) +void Magick::Image::trim(void) { - modifyImage(); - options()->verbose( verboseFlag_ ); -} -bool Magick::Image::verbose ( void ) const -{ - return constOptions()->verbose( ); -} + MagickCore::Image + *newImage; -void Magick::Image::view ( const std::string &view_ ) -{ - modifyImage(); - options()->view( view_ ); -} -std::string Magick::Image::view ( void ) const -{ - return constOptions()->view( ); + GetPPException; + newImage=TrimImage(constImage(),&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Virtual pixel method -void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ ) +void Magick::Image::unsharpmask(const double radius_,const double sigma_, + const double amount_,const double threshold_) { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - SetImageVirtualPixelMethod( image(), virtual_pixel_method_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); -} -Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const -{ - return GetImageVirtualPixelMethod( constImage() ); -} + MagickCore::Image + *newImage; -void Magick::Image::x11Display ( const std::string &display_ ) -{ - modifyImage(); - options()->x11Display( display_ ); -} -std::string Magick::Image::x11Display ( void ) const -{ - return constOptions()->x11Display( ); + GetPPException; + newImage=UnsharpMaskImage(constImage(),radius_,sigma_,amount_,threshold_, + &exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -double Magick::Image::xResolution ( void ) const -{ - return constImage()->resolution.x; -} -double Magick::Image::yResolution ( void ) const +void Magick::Image::unsharpmaskChannel(const ChannelType channel_, + const double radius_,const double sigma_,const double amount_, + const double threshold_) { - return constImage()->resolution.y; + MagickCore::Image + *newImage; + + GetPPException; + SetPPChannelMask(channel_); + newImage=UnsharpMaskImage(constImage(),radius_,sigma_,amount_,threshold_, + &exceptionInfo); + RestorePPChannelMask; + replaceImage(newImage); + ThrowPPException; } -// Copy Constructor -Magick::Image::Image( const Image & image_ ) - : _imgRef(image_._imgRef) +void Magick::Image::wave(const double amplitude_,const double wavelength_) { - Lock( &_imgRef->_mutexLock ); + MagickCore::Image + *newImage; - // Increase reference count - ++_imgRef->_refCount; + GetPPException; + newImage=WaveImage(constImage(),amplitude_,wavelength_,image()->interpolate, + &exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Assignment operator -Magick::Image& Magick::Image::operator=( const Magick::Image &image_ ) +void Magick::Image::whiteThreshold(const std::string &threshold_) { - if( this != &image_ ) - { - { - Lock( &image_._imgRef->_mutexLock ); - ++image_._imgRef->_refCount; - } - - bool doDelete = false; - { - Lock( &_imgRef->_mutexLock ); - if ( --_imgRef->_refCount == 0 ) - doDelete = true; - } - - if ( doDelete ) - { - // Delete old image reference with associated image and options. - delete _imgRef; - _imgRef = 0; - } - // Use new image reference - _imgRef = image_._imgRef; - } - - return *this; + modifyImage(); + GetPPException; + WhiteThresholdImage(image(),threshold_.c_str(),&exceptionInfo); + ThrowPPException; } -////////////////////////////////////////////////////////////////////// -// -// Low-level Pixel Access Routines -// -// Also see the Pixels class, which provides support for multiple -// cache views. The low-level pixel access routines in the Image -// class are provided in order to support backward compatability. -// -////////////////////////////////////////////////////////////////////// - -// Transfers read-only pixels from the image to the pixel cache as -// defined by the specified region -const Magick::Quantum* Magick::Image::getConstPixels - ( const ssize_t x_, const ssize_t y_, - const size_t columns_, - const size_t rows_ ) const +void Magick::Image::whiteThresholdChannel(const ChannelType channel_, + const std::string &threshold_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - const Quantum* p = (*GetVirtualPixels)( constImage(), - x_, y_, - columns_, rows_, - &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - return p; + modifyImage(); + GetPPException; + SetPPChannelMask(channel_); + WhiteThresholdImage(image(),threshold_.c_str(),&exceptionInfo); + RestorePPChannelMask; + ThrowPPException; } -// Obtain read-only pixel associated pixels channels -const void* Magick::Image::getConstMetacontent ( void ) const +void Magick::Image::write(Blob *blob_) { - const void* result = GetVirtualMetacontent( constImage() ); + size_t + length=2048; // Efficient size for small images - if( !result ) - throwImageException(); + void + *data; - return result; + modifyImage(); + GetPPException; + data=ImagesToBlob(constImageInfo(),image(),&length,&exceptionInfo); + ThrowPPException; + blob_->updateNoCopy(data,length,Blob::MallocAllocator); } -// Obtain image pixel associated pixels channels -void* Magick::Image::getMetacontent ( void ) +void Magick::Image::write(Blob *blob_,const std::string &magick_) { - void* result = GetAuthenticMetacontent( image() ); + size_t + length=2048; // Efficient size for small images - if( !result ) - throwImageException(); + void + *data; - return ( result ); + modifyImage(); + magick(magick_); + GetPPException; + data=ImagesToBlob(constImageInfo(),image(),&length,&exceptionInfo); + ThrowPPException; + blob_->updateNoCopy(data,length,Blob::MallocAllocator); } -// Transfers pixels from the image to the pixel cache as defined -// by the specified region. Modified pixels may be subsequently -// transferred back to the image via syncPixels. -Magick::Quantum* Magick::Image::getPixels ( const ssize_t x_, const ssize_t y_, - const size_t columns_, - const size_t rows_ ) +void Magick::Image::write(Blob *blob_,const std::string &magick_, + const size_t depth_) { - modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - Quantum* result = (*GetAuthenticPixels)( image(), - x_, y_, - columns_, rows_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + size_t + length=2048; // Efficient size for small images - return result; -} + void + *data; -// Allocates a pixel cache region to store image pixels as defined -// by the region rectangle. This area is subsequently transferred -// from the pixel cache to the image via syncPixels. -Magick::Quantum* Magick::Image::setPixels ( const ssize_t x_, const ssize_t y_, - const size_t columns_, - const size_t rows_ ) -{ modifyImage(); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - Quantum* result = (*QueueAuthenticPixels)( image(), - x_, y_, - columns_, rows_, &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - - return result; + magick(magick_); + depth(depth_); + GetPPException; + data=ImagesToBlob(constImageInfo(),image(),&length,&exceptionInfo); + ThrowPPException; + blob_->updateNoCopy(data,length,Blob::MallocAllocator); } -// Transfers the image cache pixels to the image. -void Magick::Image::syncPixels ( void ) +void Magick::Image::write(const ssize_t x_,const ssize_t y_, + const size_t columns_,const size_t rows_,const std::string &map_, + const StorageType type_,void *pixels_) { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - (*SyncAuthenticPixels)( image(), &exceptionInfo ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + GetPPException; + ExportImagePixels(image(),x_,y_,columns_,rows_,map_.c_str(),type_,pixels_, + &exceptionInfo); + ThrowPPException; } -// Transfers one or more pixel components from a buffer or file -// into the image pixel cache of an image. -// Used to support image decoders. -void Magick::Image::readPixels ( const Magick::QuantumType quantum_, - const unsigned char *source_ ) +void Magick::Image::write(const std::string &imageSpec_) { - QuantumInfo - *quantum_info; - - quantum_info=AcquireQuantumInfo(imageInfo(),image()); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info, - quantum_,source_, &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - quantum_info=DestroyQuantumInfo(quantum_info); + modifyImage(); + fileName(imageSpec_); + GetPPException; + WriteImage(constImageInfo(),image(),&exceptionInfo); + ThrowPPException; } -// Transfers one or more pixel components from the image pixel -// cache to a buffer or file. -// Used to support image encoders. -void Magick::Image::writePixels ( const Magick::QuantumType quantum_, - unsigned char *destination_ ) +void Magick::Image::writePixels(const Magick::QuantumType quantum_, + unsigned char *destination_) { QuantumInfo *quantum_info; quantum_info=AcquireQuantumInfo(imageInfo(),image()); - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); + GetPPException; ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info, quantum_,destination_, &exceptionInfo); quantum_info=DestroyQuantumInfo(quantum_info); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + ThrowPPException; } -///////////////////////////////////////////////////////////////////// -// -// No end-user methods beyond this point -// -///////////////////////////////////////////////////////////////////// +void Magick::Image::zoom(const Geometry &geometry_) +{ + MagickCore::Image + *newImage; + size_t + height=rows(), + width=columns(); -// -// Construct using existing image and default options -// -Magick::Image::Image ( MagickCore::Image* image_ ) - : _imgRef(new ImageRef( image_)) -{ + ssize_t + x=0, + y=0; + + ParseMetaGeometry(static_cast(geometry_).c_str(),&x,&y,&width, + &height); + + GetPPException; + newImage=ResizeImage(constImage(),width,height,image()->filter,&exceptionInfo); + replaceImage(newImage); + ThrowPPException; } -// Get Magick::Options* -Magick::Options* Magick::Image::options( void ) +Magick::Image::Image(MagickCore::Image *image_) + : _imgRef(new ImageRef(image_)) { - return _imgRef->options(); } -const Magick::Options* Magick::Image::constOptions( void ) const + +MagickCore::Image *&Magick::Image::image(void) { - return _imgRef->options(); + return(_imgRef->image()); } -// Get MagickCore::Image* -MagickCore::Image*& Magick::Image::image( void ) +const MagickCore::Image *Magick::Image::constImage(void) const { - return _imgRef->image(); + return(_imgRef->image()); } -const MagickCore::Image* Magick::Image::constImage( void ) const + +MagickCore::ImageInfo *Magick::Image::imageInfo(void) { - return _imgRef->image(); + return(_imgRef->options()->imageInfo()); } -// Get ImageInfo * -MagickCore::ImageInfo* Magick::Image::imageInfo( void ) +const MagickCore::ImageInfo *Magick::Image::constImageInfo(void) const { - return _imgRef->options()->imageInfo(); + return(_imgRef->options()->imageInfo()); } -const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const + +Magick::Options *Magick::Image::options(void) { - return _imgRef->options()->imageInfo(); + return(_imgRef->options()); } -// Get QuantizeInfo * -MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void ) +const Magick::Options *Magick::Image::constOptions(void) const { - return _imgRef->options()->quantizeInfo(); + return(_imgRef->options()); } -const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const + +MagickCore::QuantizeInfo *Magick::Image::quantizeInfo(void) { - return _imgRef->options()->quantizeInfo(); + return(_imgRef->options()->quantizeInfo()); } -// -// Replace current image -// -MagickCore::Image * Magick::Image::replaceImage - ( MagickCore::Image* replacement_ ) +const MagickCore::QuantizeInfo *Magick::Image::constQuantizeInfo(void) const { - MagickCore::Image* image; - - if( replacement_ ) - image = replacement_; - else - { - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - image = AcquireImage(constImageInfo(), &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - } - - { - Lock( &_imgRef->_mutexLock ); - - if ( _imgRef->_refCount == 1 ) - { - // We own the image, just replace it, and de-register - _imgRef->id( -1 ); - _imgRef->image(image); - } - else - { - // We don't own the image, dereference and replace with copy - --_imgRef->_refCount; - _imgRef = new ImageRef( image, constOptions() ); - } - } - - return _imgRef->_image; + return(_imgRef->options()->quantizeInfo()); } -// -// Prepare to modify image or image options -// Replace current image and options with copy if reference count > 1 -// -void Magick::Image::modifyImage( void ) +void Magick::Image::modifyImage(void) { { - Lock( &_imgRef->_mutexLock ); - if ( _imgRef->_refCount == 1 ) + Lock(&_imgRef->_mutexLock); + if (_imgRef->_refCount == 1) { // De-register image and return - _imgRef->id( -1 ); + _imgRef->id(-1); return; } } - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); - replaceImage( CloneImage( image(), - 0, // columns - 0, // rows - MagickTrue, // orphan - &exceptionInfo) ); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); - return; -} - -// -// Test for an ImageMagick reported error and throw exception if one -// has been reported. Secretly resets image->exception back to default -// state even though this method is const. -// -void Magick::Image::throwImageException( void ) const -{ - // Throw C++ exception while resetting Image exception to default state + GetPPException; + replaceImage(CloneImage(image(),0,0,MagickTrue,&exceptionInfo)); + ThrowPPException; } -// Register image with image registry or obtain registration id -ssize_t Magick::Image::registerId( void ) +ssize_t Magick::Image::registerId(void) { - Lock( &_imgRef->_mutexLock ); - if( _imgRef->id() < 0 ) + Lock(&_imgRef->_mutexLock); + if ( _imgRef->id() < 0) { - char id[MaxTextExtent]; - ExceptionInfo exceptionInfo; - GetExceptionInfo( &exceptionInfo ); + char + id[MaxTextExtent]; + + GetPPException; _imgRef->id(_imgRef->id()+1); sprintf(id,"%.20g\n",(double) _imgRef->id()); - SetImageRegistry(ImageRegistryType, id, image(), &exceptionInfo); - throwException( exceptionInfo ); - (void) DestroyExceptionInfo( &exceptionInfo ); + SetImageRegistry(ImageRegistryType,id,image(),&exceptionInfo); + ThrowPPException; } - return _imgRef->id(); + return(_imgRef->id()); } -// Unregister image from image registry -void Magick::Image::unregisterId( void ) +MagickCore::Image *Magick::Image::replaceImage(MagickCore::Image *replacement_) { - modifyImage(); - _imgRef->id( -1 ); -} - -// -// Create a local wrapper around MagickCoreTerminus -// -namespace Magick -{ - extern "C" { - void MagickPlusPlusDestroyMagick(void); - } -} + MagickCore::Image + *image; -void Magick::MagickPlusPlusDestroyMagick(void) -{ - if (magick_initialized) + if (replacement_) + image = replacement_; + else { - magick_initialized=false; - MagickCore::MagickCoreTerminus(); + GetPPException; + image=AcquireImage(constImageInfo(),&exceptionInfo); + ThrowPPException; } -} - -// C library initialization routine -void MagickPPExport Magick::InitializeMagick(const char *path_) -{ - MagickCore::MagickCoreGenesis(path_,MagickFalse); - if (!magick_initialized) - magick_initialized=true; -} - -// -// Cleanup class to ensure that ImageMagick singletons are destroyed -// so as to avoid any resemblence to a memory leak (which seems to -// confuse users) -// -namespace Magick -{ - class MagickCleanUp { - public: - MagickCleanUp( void ); - ~MagickCleanUp( void ); - }; - - // The destructor for this object is invoked when the destructors for - // static objects in this translation unit are invoked. - static MagickCleanUp magickCleanUpGuard; -} - -Magick::MagickCleanUp::MagickCleanUp ( void ) -{ - // Don't even think about invoking InitializeMagick here! -} - -Magick::MagickCleanUp::~MagickCleanUp ( void ) -{ - MagickPlusPlusDestroyMagick(); -} - -void Magick::Image::reduceNoise(void) -{ - reduceNoise(3.0); -} + Lock(&_imgRef->_mutexLock); -Magick::ClassType Magick::Image::classType(void) const -{ - return static_cast(constImage()->storage_class); -} + if (_imgRef->_refCount == 1) + { + // We own the image, just replace it, and de-register + _imgRef->id(-1); + _imgRef->image(image); + } + else + { + // We don't own the image, dereference and replace with copy + --_imgRef->_refCount; + _imgRef=new ImageRef(image,constOptions()); + } + } -size_t Magick::Image::columns(void) const -{ - return constImage()->columns; + return(_imgRef->_image); } -size_t Magick::Image::rows(void) const +void Magick::Image::unregisterId(void) { - return constImage()->rows; + modifyImage(); + _imgRef->id(-1); } \ No newline at end of file diff --git a/Magick++/lib/Magick++/Color.h b/Magick++/lib/Magick++/Color.h index 3fb683226..20c0fec74 100644 --- a/Magick++/lib/Magick++/Color.h +++ b/Magick++/lib/Magick++/Color.h @@ -15,17 +15,17 @@ namespace Magick class MagickPPExport Color; // Compare two Color objects regardless of LHS/RHS - int MagickPPExport operator == + MagickPPExport int operator == (const Magick::Color& left_,const Magick::Color& right_); - int MagickPPExport operator != + MagickPPExport int operator != (const Magick::Color& left_,const Magick::Color& right_); - int MagickPPExport operator > + MagickPPExport int operator > (const Magick::Color& left_,const Magick::Color& right_); - int MagickPPExport operator < + MagickPPExport int operator < (const Magick::Color& left_,const Magick::Color& right_); - int MagickPPExport operator >= + MagickPPExport int operator >= (const Magick::Color& left_,const Magick::Color& right_); - int MagickPPExport operator <= + MagickPPExport int operator <= (const Magick::Color& left_,const Magick::Color& right_); // Base color class stores RGBA components scaled to fit Quantum diff --git a/Magick++/lib/Magick++/Image.h b/Magick++/lib/Magick++/Image.h index 6a9eaaa4b..076dcdfcb 100644 --- a/Magick++/lib/Magick++/Image.h +++ b/Magick++/lib/Magick++/Image.h @@ -30,21 +30,22 @@ namespace Magick // Compare two Image objects regardless of LHS/RHS // Image sizes and signatures are used as basis of comparison - int MagickPPExport operator == + MagickPPExport int operator == (const Magick::Image &left_,const Magick::Image &right_); - int MagickPPExport operator != + MagickPPExport int operator != (const Magick::Image &left_,const Magick::Image &right_); - int MagickPPExport operator > + MagickPPExport int operator > (const Magick::Image &left_,const Magick::Image &right_); - int MagickPPExport operator < + MagickPPExport int operator < (const Magick::Image &left_,const Magick::Image &right_); - int MagickPPExport operator >= + MagickPPExport int operator >= (const Magick::Image &left_,const Magick::Image &right_); - int MagickPPExport operator <= + MagickPPExport int operator <= (const Magick::Image &left_,const Magick::Image &right_); // C library initialization routine - void MagickPPExport InitializeMagick(const char *path_); + MagickPPExport void InitializeMagick(const char *path_); + MagickPPExport void TerminateMagick(); // // Image is the representation of an image. In reality, it actually @@ -128,6 +129,14 @@ namespace Magick void adjoin(const bool flag_); bool adjoin(void) const; + // Image supports transparency (alpha channel) + void alpha(const bool alphaFlag_); + bool alpha(void) const; + + // Transparent color + void alphaColor(const Color &alphaColor_); + Color alphaColor(void) const; + // Anti-alias Postscript and TrueType fonts (default true) void antiAlias(const bool flag_); bool antiAlias(void); @@ -174,7 +183,7 @@ namespace Magick // Pixel cache threshold in bytes. Once this memory threshold // is exceeded, all subsequent pixels cache operations are to/from - // disk. This setting is shared by all Image objects. + // disk. This setting is shared by all Image objects. static void cacheThreshold(const MagickSizeType threshold_); // Set or obtain modulus channel depth @@ -211,8 +220,8 @@ namespace Magick void colorSpace(const ColorspaceType colorSpace_); ColorspaceType colorSpace(void) const; - void colorspaceType(const ColorspaceType colorSpace_); - ColorspaceType colorspaceType(void) const; + void colorSpaceType(const ColorspaceType colorSpace_); + ColorspaceType colorSpaceType(void) const; // Image width size_t columns(void) const; @@ -259,7 +268,7 @@ namespace Magick std::string fileName(void) const; // Number of bytes of the image on disk - off_t fileSize(void) const; + MagickSizeType fileSize(void) const; // Color to use when filling drawn objects void fillColor(const Color &fillColor_); @@ -295,8 +304,8 @@ namespace Magick Geometry geometry(void) const; // GIF disposal method - void gifDisposeMethod(const size_t disposeMethod_); - size_t gifDisposeMethod(void) const; + void gifDisposeMethod(const DisposeType disposeMethod_); + DisposeType gifDisposeMethod(void) const; // ICC color profile (BLOB) void iccColorProfile(const Blob &colorProfile_); @@ -315,20 +324,13 @@ namespace Magick bool isValid(void) const; // Image label + void label(const std::string &label_); std::string label(void) const; // File type magick identifier (.e.g "GIF") void magick(const std::string &magick_); std::string magick(void) const; - // Image supports transparency (matte channel) - void matte(const bool matteFlag_); - bool matte(void) const; - - // Transparent color - void matteColor(const Color &matteColor_); - Color matteColor(void) const; - // The mean error per pixel computed when an image is color reduced double meanErrorPerPixel(void) const; @@ -337,13 +339,13 @@ namespace Magick void modulusDepth(const size_t modulusDepth_); size_t modulusDepth(void) const; - // Tile size and offset within an image montage - Geometry montageGeometry(void) const; - // Transform image to black and white void monochrome(const bool monochromeFlag_); bool monochrome(void) const; + // Tile size and offset within an image montage + Geometry montageGeometry(void) const; + // The normalized max error per pixel computed when an image is // color reduced. double normalizedMaxError(void) const; @@ -746,9 +748,9 @@ namespace Magick // 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. - void contrastStretch(const double black_point_,const double white_point_); + void contrastStretch(const double blackPoint_,const double whitePoint_); void contrastStretchChannel(const ChannelType channel_, - const double black_point_,const double white_point_); + const double blackPoint_,const double whitePoint_); // Convolve image. Applies a user-specified convolution to the image. // order_ represents the number of columns and rows in the filter kernel. @@ -764,6 +766,15 @@ namespace Magick // Converts cipher pixels to plain pixels. void decipher(const std::string &passphrase_); + // Tagged image format define. Similar to the defineValue() method + // except that passing the flag_ value 'true' creates a value-less + // define with that format and key. Passing the flag_ value 'false' + // removes any existing matching definition. The method returns 'true' + // if a matching key exists, and 'false' if no matching key exists. + void defineSet(const std::string &magick_,const std::string &key_, + bool flag_); + bool defineSet(const std::string &magick_,const std::string &key_) const; + // Tagged image format define (set/access coder-specific option) The // magick_ option specifies the coder the define applies to. The key_ // option provides the key specific to that coder. The value_ option @@ -774,15 +785,6 @@ namespace Magick std::string defineValue(const std::string &magick_, const std::string &key_) const; - // Tagged image format define. Similar to the defineValue() method - // except that passing the flag_ value 'true' creates a value-less - // define with that format and key. Passing the flag_ value 'false' - // removes any existing matching definition. The method returns 'true' - // if a matching key exists, and 'false' if no matching key exists. - void defineSet(const std::string &magick_,const std::string &key_, - bool flag_); - bool defineSet(const std::string &magick_,const std::string &key_) const; - // Removes skew from the image. Skew is an artifact that occurs in scanned // images because of the camera being misaligned, imperfections in the // scanning or surface, or simply because the paper was not placed @@ -841,40 +843,40 @@ namespace Magick // Flip image (reflect each scanline in the vertical direction) void flip(void); + // Floodfill pixels matching color (within fuzz factor) of target + // pixel(x,y) with replacement alpha value using method. + void floodFillAlpha(const ::ssize_t x_,const ::ssize_t y_, + const unsigned int alpha_,const PaintMethod method_); + // Flood-fill color across pixels that match the color of the // target pixel and are neighbors of the target pixel. // Uses current fuzz setting when determining color match. + void floodFillColor(const Geometry &point_,const Color &fillColor_); void floodFillColor(const ::ssize_t x_,const ::ssize_t y_, const Color &fillColor_ ); - void floodFillColor(const Geometry &point_,const Color &fillColor_); - - // Floodfill pixels matching color (within fuzz factor) of target - // pixel(x,y) with replacement alpha value using method. - void floodFillAlpha(const ::ssize_t x_,const ::ssize_t y_, - const unsigned int alpha_,const PaintMethod method_); // Flood-fill color across pixels starting at target-pixel and // stopping at pixels matching specified border color. // Uses current fuzz setting when determining color match. - void floodFillColor(const ::ssize_t x_,const ::ssize_t y_, - const Color &fillColor_,const Color &borderColor_); void floodFillColor(const Geometry &point_,const Color &fillColor_, const Color &borderColor_); + void floodFillColor(const ::ssize_t x_,const ::ssize_t y_, + const Color &fillColor_,const Color &borderColor_); // Flood-fill texture across pixels that match the color of the // target pixel and are neighbors of the target pixel. // Uses current fuzz setting when determining color match. + void floodFillTexture(const Geometry &point_,const Image &texture_); void floodFillTexture(const ::ssize_t x_,const ::ssize_t y_, const Image &texture_); - void floodFillTexture(const Geometry &point_,const Image &texture_); // Flood-fill texture across pixels starting at target-pixel and // stopping at pixels matching specified border color. // Uses current fuzz setting when determining color match. - void floodFillTexture(const ::ssize_t x_,const ::ssize_t y_, - const Image &texture_,const Color &borderColor_); void floodFillTexture(const Geometry &point_,const Image &texture_, const Color &borderColor_); + void floodFillTexture(const ::ssize_t x_,const ::ssize_t y_, + const Image &texture_,const Color &borderColor_); // Flop image (reflect each scanline in the horizontal direction) void flop(void); @@ -889,8 +891,8 @@ namespace Magick const ::ssize_t innerBevel_=6,const ::ssize_t outerBevel_=6); // Applies a mathematical expression to the image. - void fx(const std::string expression); - void fx(const std::string expression,const Magick::ChannelType channel); + void fx(const std::string expression_); + void fx(const std::string expression_,const Magick::ChannelType channel_); // Gamma correct image void gamma(const double gamma_); @@ -934,9 +936,6 @@ namespace Magick void inverseFourierTransform(const Image &phase_); void inverseFourierTransform(const Image &phase_,const bool magnitude_); - // Label image - void label(const std::string &label_); - // Level image. Adjust the levels of the image by scaling the // colors falling between specified white and black points to the // full available quantum range. The parameters provided represent @@ -950,18 +949,6 @@ namespace Magick // has a useful range of 0 to ten. void level(const double blackPoint_,const double whitePoint_, const double gamma_=1.0); - - // Level image channel. Adjust the levels of the image channel by - // scaling the values falling between specified white and black - // points to the full available quantum range. The parameters - // provided represent the black, mid (gamma), and white points. - // The black point specifies the darkest color in the - // image. Colors darker than the black point are set to zero. Mid - // point (gamma) specifies a gamma correction to apply to the - // image. White point specifies the lightest color in the image. - // Colors brighter than the white point are set to the maximum - // quantum value. The black and white point have the valid range 0 - // to QuantumRange while mid (gamma) has a useful range of 0 to ten. void levelChannel(const ChannelType channel_,const double blackPoint_, const double whitePoint_,const double gamma_=1.0); @@ -1045,16 +1032,6 @@ namespace Magick void pixelColor(const ::ssize_t x_,const ::ssize_t y_,const Color &color_); Color pixelColor(const ::ssize_t x_,const ::ssize_t y_ ) const; - // Add or remove a named profile to/from the image. Remove the - // profile by passing an empty Blob (e.g. Blob()). Valid names are - // "*", "8BIM", "ICM", "IPTC", or a user/format-defined profile name. - void profile(const std::string name_,const Blob &colorProfile_); - - // Retrieve a named profile from the image. Valid names are: - // "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" - // or an existing user/format-defined profile name. - Blob profile(const std::string name_) const; - // Simulates a Polaroid picture. void polaroid(const std::string &caption_,const double angle_, const PixelInterpolateMethod method_); @@ -1070,6 +1047,16 @@ namespace Magick // execution. void process(std::string name_,const ::ssize_t argc_,const char **argv_); + // Add or remove a named profile to/from the image. Remove the + // profile by passing an empty Blob (e.g. Blob()). Valid names are + // "*", "8BIM", "ICM", "IPTC", or a user/format-defined profile name. + void profile(const std::string name_,const Blob &colorProfile_); + + // Retrieve a named profile from the image. Valid names are: + // "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" + // or an existing user/format-defined profile name. + Blob profile(const std::string name_) const; + // Quantize image (reduce number of colors) void quantize(const bool measureError_=false); @@ -1096,8 +1083,8 @@ namespace Magick // specified then only the specified channel is altered. This is // a very fast alternative to 'quantize' based dithering. void randomThreshold(const Geometry &thresholds_); - void randomThresholdChannel(const Geometry &thresholds_, - const ChannelType channel_); + void randomThresholdChannel(const ChannelType channel_, + const Geometry &thresholds_); // Read single image frame from in-memory BLOB void read(const Blob &blob_); @@ -1122,20 +1109,20 @@ namespace Magick // Read single image frame of specified size into current object void read(const Geometry &size_,const std::string &imageSpec_); - // Transfers one or more pixel components from a buffer or file - // into the image pixel cache of an image. - // Used to support image decoders. - void readPixels(const QuantumType quantum_,const unsigned char *source_); - // Read single image frame from an array of raw pixels, with // specified storage type (ConstituteImage), e.g. // image.read( 640, 480, "RGB", 0, pixels ); - void read( const size_t width_,const size_t height_, - const std::string &map_,const StorageType type_,const void *pixels_); + void read(const size_t width_,const size_t height_,const std::string &map_, + const StorageType type_,const void *pixels_); // Read single image frame into current object void read(const std::string &imageSpec_); + // Transfers one or more pixel components from a buffer or file + // into the image pixel cache of an image. + // Used to support image decoders. + void readPixels(const QuantumType quantum_,const unsigned char *source_); + // Reduce noise in image using a noise peak elimination filter void reduceNoise(void); void reduceNoise(const double order_); @@ -1160,9 +1147,6 @@ namespace Magick Quantum *setPixels(const ::ssize_t x_, const ::ssize_t y_, const size_t columns_,const size_t rows_); - // Transfers the image cache pixels to the image. - void syncPixels(void); - // Resize image by using simple ratio algorithm void scale(const Geometry &geometry_); @@ -1208,18 +1192,19 @@ namespace Magick // photographic film to light during the development process) void solarize(const double factor_=50.0); + // Sparse color image, given a set of coordinates, interpolates the colors + // found at those coordinates, across the whole image, using various + // methods. + void sparseColor(const ChannelType channel_, + const SparseColorMethod method_,const size_t numberArguments_, + const double *arguments_); + // Splice the background color into the image. void splice(const Geometry &geometry_); // Spread pixels randomly within image by specified ammount void spread(const size_t amount_=3); - // Sparse color image, given a set of coordinates, interpolates the colors - // found at those coordinates, across the whole image, using various - // methods. - void sparseColor(const ChannelType channel,const SparseColorMethod method, - const size_t numberArguments,const double *arguments); - void statistics(ImageStatistics *statistics); // Add a digital watermark to the image (based on second image) @@ -1235,6 +1220,9 @@ namespace Magick // Swirl image (image pixels are rotated by degrees) void swirl(const double degrees_); + // Transfers the image cache pixels to the image. + void syncPixels(void); + // Channel a texture on image background void texture(const Image &texture_); @@ -1301,7 +1289,7 @@ namespace Magick // Write single image frame to an array of pixels with storage // type specified by user (DispatchImage), e.g. - // image.write( 0, 0, 640, 1, "RGB", 0, pixels ); + // image.write( 0, 0, 640, 1, "RGB", 0, pixels ); void write(const ::ssize_t x_,const ::ssize_t y_,const size_t columns_, const size_t rows_,const std::string &map_,const StorageType type_, void *pixels_); @@ -1330,14 +1318,14 @@ namespace Magick MagickCore::Image *&image(void); const MagickCore::Image *constImage(void) const; - // Retrieve Options* - Options *options(void); - const Options *constOptions(void) const; - // Retrieve ImageInfo* MagickCore::ImageInfo *imageInfo(void); const MagickCore::ImageInfo *constImageInfo(void) const; + // Retrieve Options* + Options *options(void); + const Options *constOptions(void) const; + // Retrieve QuantizeInfo* MagickCore::QuantizeInfo *quantizeInfo(void); const MagickCore::QuantizeInfo *constQuantizeInfo(void) const; @@ -1346,14 +1334,11 @@ namespace Magick void modifyImage(void); // Register image with image registry or obtain registration id - ::ssize_t registerId( void ); + ::ssize_t registerId(void); // Replace current image (reference counted) MagickCore::Image *replaceImage(MagickCore::Image *replacement_); - // Test for ImageMagick error and throw exception if error - void throwImageException(void) const; - // Unregister image from image registry void unregisterId(void); diff --git a/Magick++/lib/Magick++/STL.h b/Magick++/lib/Magick++/STL.h index 8cdfa616e..35f033ed5 100644 --- a/Magick++/lib/Magick++/STL.h +++ b/Magick++/lib/Magick++/STL.h @@ -1496,12 +1496,12 @@ namespace Magick class MagickPPExport gifDisposeMethodImage : public std::unary_function { public: - gifDisposeMethodImage( const size_t disposeMethod_ ); + gifDisposeMethodImage( const DisposeType disposeMethod_ ); void operator()( Image &image_ ) const; private: - size_t _disposeMethod; + DisposeType _disposeMethod; }; // Type of interlacing to use @@ -1529,27 +1529,27 @@ namespace Magick }; // Image supports transparent color - class MagickPPExport matteImage : public std::unary_function + class MagickPPExport alphaFlagImage : public std::unary_function { public: - matteImage( const bool matteFlag_ ); + alphaFlagImage( const bool alphaFlag_ ); void operator()( Image &image_ ) const; private: - bool _matteFlag; + bool _alphaFlag; }; // Transparent color - class MagickPPExport matteColorImage : public std::unary_function + class MagickPPExport alphaColorImage : public std::unary_function { public: - matteColorImage( const Color &matteColor_ ); + alphaColorImage( const Color &alphaColor_ ); void operator()( Image &image_ ) const; private: - Color _matteColor; + Color _alphaColor; }; // Indicate that image is black and white diff --git a/Magick++/lib/Pixels.cpp b/Magick++/lib/Pixels.cpp index f42ad6d82..a347d0615 100644 --- a/Magick++/lib/Pixels.cpp +++ b/Magick++/lib/Pixels.cpp @@ -26,7 +26,7 @@ Magick::Pixels::Pixels(Magick::Image &image_) GetExceptionInfo(&_exception); if (!_view) - _image.throwImageException(); + throwExceptionExplicit(OptionError,"Empty view detected."); } Magick::Pixels::~Pixels(void) diff --git a/Magick++/lib/STL.cpp b/Magick++/lib/STL.cpp index ae5da9ffd..e5e21be5e 100644 --- a/Magick++/lib/STL.cpp +++ b/Magick++/lib/STL.cpp @@ -1332,7 +1332,7 @@ void Magick::fontPointsizeImage::operator()( Magick::Image &image_ ) const } // GIF disposal method -Magick::gifDisposeMethodImage::gifDisposeMethodImage( const size_t disposeMethod_ ) +Magick::gifDisposeMethodImage::gifDisposeMethodImage( const DisposeType disposeMethod_ ) : _disposeMethod( disposeMethod_ ) { } @@ -1362,23 +1362,23 @@ void Magick::magickImage::operator()( Magick::Image &image_ ) const } // Image supports transparent color -Magick::matteImage::matteImage( const bool matteFlag_ ) - : _matteFlag( matteFlag_ ) +Magick::alphaFlagImage::alphaFlagImage( const bool alphaFlag_ ) + : _alphaFlag( alphaFlag_ ) { } -void Magick::matteImage::operator()( Magick::Image &image_ ) const +void Magick::alphaFlagImage::operator()( Magick::Image &image_ ) const { - image_.matte( _matteFlag ); + image_.alpha( _alphaFlag ); } // Transparent color -Magick::matteColorImage::matteColorImage( const Color &matteColor_ ) - : _matteColor( matteColor_ ) +Magick::alphaColorImage::alphaColorImage( const Color &alphaColor_ ) + : _alphaColor( alphaColor_ ) { } -void Magick::matteColorImage::operator()( Magick::Image &image_ ) const +void Magick::alphaColorImage::operator()( Magick::Image &image_ ) const { - image_.matteColor( _matteColor ); + image_.alphaColor( _alphaColor ); } // Indicate that image is black and white diff --git a/MagickWand/drawing-wand.c b/MagickWand/drawing-wand.c index 53bee71d8..d76109265 100644 --- a/MagickWand/drawing-wand.c +++ b/MagickWand/drawing-wand.c @@ -936,6 +936,37 @@ WandExport MagickBooleanType DrawClearException(DrawingWand *wand) ClearMagickException(wand->exception); return(MagickTrue); } + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% D r a w C l o n e E x c e p t i o n I n f o % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% DrawCloneExceptionInfo() clones the ExceptionInfo structure within the wand. +% +% The format of the DrawCloneExceptionInfo method is: +% +% ExceptionInfo *DrawCloneExceptionInfo(DrawWand *wand) +% +% A description of each parameter follows: +% +% o wand: the drawing wand. +% +*/ +WandExport ExceptionInfo *DrawCloneExceptionInfo(const DrawingWand *wand) +{ + assert(wand != (DrawingWand *) NULL); + assert(wand->signature == WandSignature); + if (wand->exception == (ExceptionInfo*) NULL) + return (ExceptionInfo*) NULL; + return CloneExceptionInfo(wand->exception); +} /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/MagickWand/drawing-wand.h b/MagickWand/drawing-wand.h index ef2dda1ec..c5af07689 100644 --- a/MagickWand/drawing-wand.h +++ b/MagickWand/drawing-wand.h @@ -65,6 +65,9 @@ extern WandExport DrawingWand *DrawAllocateWand(const DrawInfo *,Image *), *NewDrawingWand(void); +extern WandExport ExceptionInfo + *DrawCloneExceptionInfo(const DrawingWand *wand); + extern WandExport ExceptionType DrawGetExceptionType(const DrawingWand *);