From be1bbacaa9919aa3754e3abae43557be13669657 Mon Sep 17 00:00:00 2001 From: dirk Date: Tue, 16 Dec 2014 11:56:14 +0000 Subject: [PATCH] Added new Point class for density in Image and Options. --- Magick++/demo/gravity.cpp | 2 +- Magick++/demo/zoom.cpp | 8 +- Magick++/lib/Geometry.cpp | 141 ++++++++++++++++++++++++++++++- Magick++/lib/Image.cpp | 22 ++--- Magick++/lib/Magick++/Geometry.h | 64 +++++++++++++- Magick++/lib/Magick++/Image.h | 4 +- Magick++/lib/Magick++/Options.h | 4 +- Magick++/lib/Magick++/STL.h | 4 +- Magick++/lib/Options.cpp | 10 +-- Magick++/lib/STL.cpp | 6 +- Magick++/tests/attributes.cpp | 4 +- 11 files changed, 234 insertions(+), 35 deletions(-) diff --git a/Magick++/demo/gravity.cpp b/Magick++/demo/gravity.cpp index c26251553..cb18ef6ce 100644 --- a/Magick++/demo/gravity.cpp +++ b/Magick++/demo/gravity.cpp @@ -45,7 +45,7 @@ int main( int /*argc*/, char ** argv) base.draw( DrawableLine( 300,100, 300,500 ) ); base.draw( DrawableLine( 100,300, 500,300 ) ); base.draw( DrawableRectangle( 100,100, 500,500 ) ); - base.density( Geometry(72,72) ); + base.density( Point(72,72) ); base.strokeColor(Color()); base.fillColor("#600"); base.fontPointsize( 30 ); diff --git a/Magick++/demo/zoom.cpp b/Magick++/demo/zoom.cpp index 8db2c8e3d..7f5f25bbe 100644 --- a/Magick++/demo/zoom.cpp +++ b/Magick++/demo/zoom.cpp @@ -47,10 +47,10 @@ int main(int argc,char **argv) }; { - Geometry density; Geometry geometry; - Geometry resample; Magick::FilterTypes filter(LanczosFilter); + Point density; + Point resample; ResizeAlgorithm resize_algorithm=Zoom; int argv_index=1; @@ -160,9 +160,9 @@ int main(int argc,char **argv) { geometry = Geometry(static_cast - (image.columns()*((double)resample.width()/density.width())+0.5), + (image.columns()*((double)resample.x()/density.x())+0.5), static_cast - (image.rows()*((double)resample.height()/density.height())+0.5)); + (image.rows()*((double)resample.y()/density.y())+0.5)); image.density(resample); } switch (resize_algorithm) diff --git a/Magick++/lib/Geometry.cpp b/Magick++/lib/Geometry.cpp index 966b62fdc..4ce2e4388 100644 --- a/Magick++/lib/Geometry.cpp +++ b/Magick++/lib/Geometry.cpp @@ -148,13 +148,13 @@ Magick::Geometry::~Geometry(void) { } -const Magick::Geometry& Magick::Geometry::operator=(const char * geometry_) +const Magick::Geometry& Magick::Geometry::operator=(const char *geometry_) { *this=std::string(geometry_); return(*this); } -Magick::Geometry& Magick::Geometry::operator=(const Geometry& geometry_) +Magick::Geometry& Magick::Geometry::operator=(const Geometry &geometry_) { // If not being set to ourself if (this != &geometry_) @@ -478,3 +478,140 @@ inline void Magick::Geometry::yOff(::ssize_t yOff_) { return(_yOff); } + +MagickPPExport int Magick::operator == (const Magick::Point& left_, + const Magick::Point& right_) +{ + return((left_.x() == right_.x()) && + (left_.y() == right_.y())); +} + +MagickPPExport int Magick::operator != (const Magick::Point& left_, + const Magick::Point& right_) +{ + return(!(left_ == right_)); +} + +Magick::Point::Point(void) + : _x(0.0), + _y(0.0) +{ +} + +Magick::Point::Point(const char *point_) + : _x(0.0), + _y(0.0) +{ + *this=point_; // Use assignment operator +} + +Magick::Point::Point(const Point &point_) + : _x(point_._x), + _y(point_._y) +{ +} + +Magick::Point::Point(const std::string &point_) + : _x(0.0), + _y(0.0) +{ + *this=point_; // Use assignment operator +} + +Magick::Point::Point(double x_,double y_) + : _x(x_), + _y(y_) +{ +} + +Magick::Point::Point(double xy_) + : _x(xy_), + _y(xy_) +{ +} + +Magick::Point::~Point(void) +{ +} + +const Magick::Point& Magick::Point::operator=(const char *point_) +{ + MagickCore::GeometryInfo + geometry_info; + + MagickCore::MagickStatusType + flags; + + flags=ParseGeometry(point_,&geometry_info); + _x=geometry_info.rho; + _y=geometry_info.sigma; + if ((flags & MagickCore::SigmaValue) == 0) + _y=_x; + return(*this); +} + +const Magick::Point& Magick::Point::operator=(const double xy_) +{ + _x=xy_; + _y=xy_; + return(*this); +} + +Magick::Point& Magick::Point::operator=(const Point &point_) +{ + // If not being set to ourself + if (this != &point_) + { + _x=point_._x; + _y=point_._y; + } + return(*this); +} + +const Magick::Point& Magick::Point::operator=(const std::string &point_) +{ + *this=point_.c_str(); + return(*this); +} + +Magick::Point::operator std::string() const +{ + char + buffer[MaxTextExtent]; + + string + point; + + if (_x < 0.0) + point+='-'; + else + point+='+'; + + FormatLocaleString(buffer,MaxTextExtent,"%.20g",_x); + point+=buffer; + + if (_y < 0.0) + point+='-'; + else + point+='+'; + + FormatLocaleString(buffer,MaxTextExtent,"%.20g",(double) _y); + point+=buffer; + + return(point); +} + +bool Magick::Point::isValid(void) const +{ + return(_x > 0.0); +} + +double Magick::Point::x(void) const +{ + return(_x); +} + +double Magick::Point::y(void) const +{ + return(_y); +} \ No newline at end of file diff --git a/Magick++/lib/Image.cpp b/Magick++/lib/Image.cpp index 026e14cdc..a9958eeb7 100644 --- a/Magick++/lib/Image.cpp +++ b/Magick++/lib/Image.cpp @@ -682,27 +682,27 @@ bool Magick::Image::debug(void) const return(constOptions()->debug()); } -void Magick::Image::density(const Geometry &density_) +void Magick::Image::density(const Point &density_) { modifyImage(); options()->density(density_); if (density_.isValid()) { - image()->resolution.x=density_.width(); - if (density_.height() != 0) - image()->resolution.y=density_.height(); + image()->resolution.x=density_.x(); + if (density_.y() != 0.0) + image()->resolution.y=density_.y(); else - image()->resolution.y=density_.width(); + image()->resolution.y=density_.x(); } else { // Reset to default - image()->resolution.x=0; - image()->resolution.y=0; + image()->resolution.x=0.0; + image()->resolution.y=0.0; } } -Magick::Geometry Magick::Image::density(void) const +Magick::Point Magick::Image::density(void) const { if (isValid()) { @@ -711,12 +711,12 @@ Magick::Geometry Magick::Image::density(void) const y_resolution=72; if (constImage()->resolution.x > 0.0) - x_resolution=static_cast(constImage()->resolution.x + 0.5); + x_resolution=constImage()->resolution.x; if (constImage()->resolution.y > 0.0) - y_resolution=static_cast(constImage()->resolution.y + 0.5); + y_resolution=constImage()->resolution.y; - return(Geometry(x_resolution,y_resolution)); + return(Point(x_resolution,y_resolution)); } return(constOptions()->density()); diff --git a/Magick++/lib/Magick++/Geometry.h b/Magick++/lib/Magick++/Geometry.h index 39bf097a1..11657037e 100644 --- a/Magick++/lib/Magick++/Geometry.h +++ b/Magick++/lib/Magick++/Geometry.h @@ -61,7 +61,7 @@ namespace Magick Geometry& operator=(const Geometry& Geometry_); // Set via geometry string - const Geometry& operator=(const std::string &geometry_ ); + const Geometry& operator=(const std::string &geometry_); // Return geometry string operator std::string() const; @@ -136,6 +136,68 @@ namespace Magick bool _fillArea; // Resize the image based on the smallest fitting dimension (^) bool _limitPixels; // Resize using a pixel area count limit (@) }; + + class MagickPPExport Point; + + // Compare two Point objects + MagickPPExport int operator == + (const Magick::Point& left_,const Magick::Point& right_); + MagickPPExport int operator != + (const Magick::Point& left_,const Magick::Point& right_); + + class MagickPPExport Point + { + public: + + // Default constructor + Point(); + + // Construct Geometry from specified string + Point(const char *point_); + + // Copy constructor + Point(const Point &point_); + + // Construct Point from specified string + Point(const std::string &point_); + + // Construct Point from specified x and y + Point(double x_,double y_); + + // Construct Point from specified x y + Point(double xy_); + + // Destructor + ~Point(void); + + // Set via point string + const Point& operator=(const char *point_); + + // Set via double value + const Point& operator=(double xy_); + + // Assignment operator + Point& operator=(const Point& point_); + + // Set via point string + const Point& operator=(const std::string &point_); + + // Return point string + operator std::string() const; + + // Does object contain valid point? + bool isValid() const; + + // X offset from origin + double x(void) const; + + // Y offset from origin + double y(void) const; + + private: + double _x; + double _y; + }; } // namespace Magick #endif // Magick_Geometry_header diff --git a/Magick++/lib/Magick++/Image.h b/Magick++/lib/Magick++/Image.h index 884101596..fef85867d 100644 --- a/Magick++/lib/Magick++/Image.h +++ b/Magick++/lib/Magick++/Image.h @@ -208,8 +208,8 @@ namespace Magick bool debug(void) const; // Vertical and horizontal resolution in pixels of the image - void density(const Geometry &geomery_); - Geometry density(void) const; + void density(const Point &density_); + Point density(void) const; // Image depth (bits allocated to red/green/blue components) void depth(const size_t depth_); diff --git a/Magick++/lib/Magick++/Options.h b/Magick++/lib/Magick++/Options.h index de04efa2a..b41f63e0b 100644 --- a/Magick++/lib/Magick++/Options.h +++ b/Magick++/lib/Magick++/Options.h @@ -80,8 +80,8 @@ namespace Magick bool debug(void) const; // Vertical and horizontal resolution in pixels of the image - void density(const Geometry &geomery_); - Geometry density(void) const; + void density(const Point &density_); + Point density(void) const; // Image depth (8 or 16) void depth(size_t depth_); diff --git a/Magick++/lib/Magick++/STL.h b/Magick++/lib/Magick++/STL.h index 6f0879641..03ee35549 100644 --- a/Magick++/lib/Magick++/STL.h +++ b/Magick++/lib/Magick++/STL.h @@ -1444,12 +1444,12 @@ namespace Magick class MagickPPExport densityImage : public std::unary_function { public: - densityImage( const Geometry &geomery_ ); + densityImage( const Point &point_ ); void operator()( Image &image_ ) const; private: - Geometry _geomery; + Point _point; }; // Image depth (bits allocated to red/green/blue components) diff --git a/Magick++/lib/Options.cpp b/Magick++/lib/Options.cpp index 9eb374dd9..6431483b8 100644 --- a/Magick++/lib/Options.cpp +++ b/Magick++/lib/Options.cpp @@ -173,20 +173,20 @@ bool Magick::Options::debug(void) const return(false); } -void Magick::Options::density(const Magick::Geometry &density_) +void Magick::Options::density(const Magick::Point &density_) { - if ( !density_.isValid() ) + if (!density_.isValid()) _imageInfo->density=(char *) RelinquishMagickMemory(_imageInfo->density); else Magick::CloneString(&_imageInfo->density,density_); } -Magick::Geometry Magick::Options::density(void) const +Magick::Point Magick::Options::density(void) const { if (_imageInfo->density) - return(Geometry(_imageInfo->density)); + return(Point(_imageInfo->density)); - return(Geometry()); + return(Point()); } void Magick::Options::depth(size_t depth_) diff --git a/Magick++/lib/STL.cpp b/Magick++/lib/STL.cpp index 297377e19..89561585e 100644 --- a/Magick++/lib/STL.cpp +++ b/Magick++/lib/STL.cpp @@ -1314,13 +1314,13 @@ void Magick::compressTypeImage::operator()( Magick::Image &image_ ) const } // Vertical and horizontal resolution in pixels of the image -Magick::densityImage::densityImage( const Geometry &geomery_ ) - : _geomery( geomery_ ) +Magick::densityImage::densityImage( const Point &point_ ) + : _point( point_ ) { } void Magick::densityImage::operator()( Magick::Image &image_ ) const { - image_.density( _geomery ); + image_.density( _point ); } // Image depth (bits allocated to red/green/blue components) diff --git a/Magick++/tests/attributes.cpp b/Magick++/tests/attributes.cpp index a57e53e2c..3ff1db46b 100644 --- a/Magick++/tests/attributes.cpp +++ b/Magick++/tests/attributes.cpp @@ -538,7 +538,7 @@ int main( int /*argc*/, char ** argv) // { // Test defaults - if ( image.density() != Geometry(72,72) ) + if ( image.density() != Point(72) ) { ++failures; cout << "Line: " << __LINE__ @@ -546,7 +546,7 @@ int main( int /*argc*/, char ** argv) } // Test set/get - Geometry density(150,75); + Point density(150,75); image.density(density); if ( image.density() != density ) { -- 2.40.0