Added new Point class for density in Image and Options.

This commit is contained in:
dirk
2014-12-16 11:56:14 +00:00
parent 84f7dd5924
commit be1bbacaa9
11 changed files with 234 additions and 35 deletions
+1 -1
View 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 );
+4 -4
View 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)
+139 -2
View 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 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);
}
+11 -11
View 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());
+63 -1
View 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
+2 -2
View 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_);
+2 -2
View 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_);
+2 -2
View 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)
+5 -5
View 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_)
+3 -3
View 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)
+2 -2
View 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 )
{