]> granicus.if.org Git - imagemagick/commitdiff
Added new Point class for density in Image and Options.
authordirk <dirk@git.imagemagick.org>
Tue, 16 Dec 2014 11:56:14 +0000 (11:56 +0000)
committerdirk <dirk@git.imagemagick.org>
Tue, 16 Dec 2014 11:56:14 +0000 (11:56 +0000)
Magick++/demo/gravity.cpp
Magick++/demo/zoom.cpp
Magick++/lib/Geometry.cpp
Magick++/lib/Image.cpp
Magick++/lib/Magick++/Geometry.h
Magick++/lib/Magick++/Image.h
Magick++/lib/Magick++/Options.h
Magick++/lib/Magick++/STL.h
Magick++/lib/Options.cpp
Magick++/lib/STL.cpp
Magick++/tests/attributes.cpp

index c262515531e31bc1a969690ea95a729fbbc11df9..cb18ef6cec637f55793ec856c80e7126e46a325f 100644 (file)
@@ -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 );
index 8db2c8e3d502cad70c4c5d730b2cac4af89e8d5a..7f5f25bbe4703ff40e776713e36c0188353d0324 100644 (file)
@@ -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<size_t>
-                     (image.columns()*((double)resample.width()/density.width())+0.5),
+                     (image.columns()*((double)resample.x()/density.x())+0.5),
                      static_cast<size_t>
-                     (image.rows()*((double)resample.height()/density.height())+0.5));
+                     (image.rows()*((double)resample.y()/density.y())+0.5));
           image.density(resample);
         }
       switch (resize_algorithm)
index 966b62fdcdaedc3c846a0975f354b907ac4447e5..4ce2e43885c30823d7d507be7985a48936d91fec 100644 (file)
@@ -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 Geometrygeometry_)
+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
index 026e14cdcaef88b98a99b4343e9a4f946702d04c..a9958eeb704971be2a96f4c522ce155326dbc94b 100644 (file)
@@ -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<ssize_t>(constImage()->resolution.x + 0.5);
+        x_resolution=constImage()->resolution.x;
 
       if (constImage()->resolution.y > 0.0)
-        y_resolution=static_cast<ssize_t>(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());
index 39bf097a1ca60ac7557692da9c3bed18a2b29cf0..11657037ed88cd131c202e86f50f47c0bd33fee9 100644 (file)
@@ -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
index 884101596f7b1516b5a2f76669a32d5abd199415..fef85867dec026c72cf85b0a24135bb12f8c6560 100644 (file)
@@ -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_);
index de04efa2aecc203ca54039d4b5f71b6ce2f73278..b41f63e0b80998b61636594d9c06910a938f6cc6 100644 (file)
@@ -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_);
index 6f0879641cf1a9d50b23e4840ff973b1c12a4b1b..03ee35549a30f04a8998f4a8d83266b89b154bf4 100644 (file)
@@ -1444,12 +1444,12 @@ namespace Magick
   class MagickPPExport densityImage : public std::unary_function<Image&,void>
   {
   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)
index 9eb374dd9a1ebfe7ae6c028d867a2437c521a1c3..6431483b81ca4e2197d7cbb38ff8824606644ee6 100644 (file)
@@ -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_)
index 297377e195a7977c91544464c8ede577f2ed8fad..89561585e9a671c7ec2a70eae2543cc5779a5c05 100644 (file)
@@ -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)
index a57e53e2c30d3ff750ef6d89797422255bc73ba9..3ff1db46b7c2169f12d4e36bf96ae7dcd228a772 100644 (file)
@@ -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 )
        {