From be9f62c7943cfd2c3fc13892319933a9e7ae1322 Mon Sep 17 00:00:00 2001 From: dirk Date: Sat, 23 Nov 2013 20:50:58 +0000 Subject: [PATCH] Whitespace cleanup. Renamed ColorRGB to ColorRGBA. Some refactoring in Color class. --- Magick++/lib/Blob.cpp | 32 +- Magick++/lib/BlobRef.cpp | 4 - Magick++/lib/CoderInfo.cpp | 52 +- Magick++/lib/Color.cpp | 928 +++++++++++++++--------------- Magick++/lib/Magick++/Blob.h | 28 +- Magick++/lib/Magick++/CoderInfo.h | 16 +- Magick++/lib/Magick++/Color.h | 539 +++++++---------- Magick++/lib/Magick++/STL.h | 14 +- Magick++/tests/attributes.cpp | 24 +- Magick++/tests/color.cpp | 4 +- 10 files changed, 754 insertions(+), 887 deletions(-) diff --git a/Magick++/lib/Blob.cpp b/Magick++/lib/Blob.cpp index 83e951818..e890094bf 100644 --- a/Magick++/lib/Blob.cpp +++ b/Magick++/lib/Blob.cpp @@ -14,10 +14,6 @@ #include -// -// Implementation of Magick::Blob -// - Magick::Blob::Blob(void) : _blobRef(new Magick::BlobRef(0,0)) { @@ -79,10 +75,9 @@ Magick::Blob& Magick::Blob::operator=(const Magick::Blob& blob_) } _blobRef=blob_._blobRef; } - return *this; + return(*this); } -// Update object contents from Base64-encoded string representation. void Magick::Blob::base64(const std::string base64_) { size_t @@ -98,8 +93,7 @@ void Magick::Blob::base64(const std::string base64_) Magick::Blob::MallocAllocator); } -// Return Base64-encoded string representation. -std::string Magick::Blob::base64(void) +std::string Magick::Blob::base64(void) const { size_t encoded_length; @@ -121,7 +115,17 @@ std::string Magick::Blob::base64(void) return result; } - return std::string(); + return(std::string()); +} + +const void* Magick::Blob::data(void) const +{ + return(_blobRef->data); +} + +size_t Magick::Blob::length(void) const +{ + return(_blobRef->length); } void Magick::Blob::update(const void* data_,size_t length_) @@ -167,13 +171,3 @@ void Magick::Blob::updateNoCopy(void* data_,size_t length_, _blobRef->allocator=allocator_; } -const void* Magick::Blob::data(void) const -{ - return _blobRef->data; -} - -size_t Magick::Blob::length(void) const -{ - return _blobRef->length; -} - diff --git a/Magick++/lib/BlobRef.cpp b/Magick++/lib/BlobRef.cpp index 2236dd361..58bc18413 100644 --- a/Magick++/lib/BlobRef.cpp +++ b/Magick++/lib/BlobRef.cpp @@ -14,10 +14,6 @@ #include -// -// Implementation of Magick::BlobRef -// - Magick::BlobRef::BlobRef(const void* data_,size_t length_) : data(0), length(length_), diff --git a/Magick++/lib/CoderInfo.cpp b/Magick++/lib/CoderInfo.cpp index 3c146aff6..05d65d719 100644 --- a/Magick++/lib/CoderInfo.cpp +++ b/Magick++/lib/CoderInfo.cpp @@ -71,57 +71,47 @@ Magick::CoderInfo::~CoderInfo(void) { } +Magick::CoderInfo& Magick::CoderInfo::operator=(const CoderInfo &coder_) +{ + // If not being set to ourself + if (this != &coder_) + { + _name=coder_._name; + _description=coder_._description; + _mimeType=coder_._mimeType; + _isReadable=coder_._isReadable; + _isWritable=coder_._isWritable; + _isMultiFrame=coder_._isMultiFrame; + } + return(*this); +} + std::string Magick::CoderInfo::description(void) const { - return _description; + return(_description); } bool Magick::CoderInfo::isReadable(void) const { - return _isReadable; + return(_isReadable); } bool Magick::CoderInfo::isWritable(void) const { - return _isWritable; + return(_isWritable); } bool Magick::CoderInfo::isMultiFrame(void) const { - return _isMultiFrame; + return(_isMultiFrame); } std::string Magick::CoderInfo::mimeType(void) const { - return _mimeType; + return(_mimeType); } std::string Magick::CoderInfo::name(void) const { - return _name; -} - -Magick::CoderInfo& Magick::CoderInfo::operator=(const CoderInfo &coder_) -{ - // If not being set to ourself - if (this != &coder_) - { - _name=coder_._name; - _description=coder_._description; - _mimeType=coder_._mimeType; - _isReadable=coder_._isReadable; - _isWritable=coder_._isWritable; - _isMultiFrame=coder_._isMultiFrame; - } - return *this; -} - -Magick::CoderInfo::CoderInfo(const MagickCore::MagickInfo *magickInfo_) - : _name(string(magickInfo_->name ? magickInfo_->name : "")), - _description(string(magickInfo_->description ? magickInfo_->description : "")), - _mimeType(string(magickInfo_->mime_type ? magickInfo_->mime_type : "")), - _isReadable(magickInfo_->decoder ? true : false), - _isWritable(magickInfo_->encoder ? true : false), - _isMultiFrame(magickInfo_->adjoin ? true : false) -{ + return(_name); } diff --git a/Magick++/lib/Color.cpp b/Magick++/lib/Color.cpp index 790508857..deed4cc7b 100644 --- a/Magick++/lib/Color.cpp +++ b/Magick++/lib/Color.cpp @@ -16,197 +16,164 @@ using namespace std; #include "Magick++/Color.h" #include "Magick++/Exception.h" -// -// Color operator fuctions -// -int Magick::operator == ( const Magick::Color& left_, - const Magick::Color& right_ ) +int Magick::operator == (const Magick::Color &left_, + const Magick::Color &right_) { - return ( ( left_.isValid() == right_.isValid() ) && - ( left_.redQuantum() == right_.redQuantum() ) && - ( left_.greenQuantum() == right_.greenQuantum() ) && - ( left_.blueQuantum() == right_.blueQuantum() ) - ); + return((left_.isValid() == right_.isValid()) && + (left_.quantumRed() == right_.quantumRed()) && + (left_.quantumGreen() == right_.quantumGreen()) && + (left_.quantumBlue() == right_.quantumBlue())); } -int Magick::operator != ( const Magick::Color& left_, - const Magick::Color& right_ ) + +int Magick::operator != (const Magick::Color &left_, + const Magick::Color &right_) { - return ( ! (left_ == right_) ); + return(!(left_ == right_)); } -int Magick::operator > ( const Magick::Color& left_, - const Magick::Color& right_ ) + +int Magick::operator > (const Magick::Color &left_, + const Magick::Color &right_) { - return ( !( left_ < right_ ) && ( left_ != right_ ) ); + return(!(left_ < right_ ) && (left_ != right_ )); } -int Magick::operator < ( const Magick::Color& left_, - const Magick::Color& right_ ) + +int Magick::operator < ( const Magick::Color &left_, + const Magick::Color &right_) { - if(left_.redQuantum() < right_.redQuantum()) return true; - if(left_.redQuantum() > right_.redQuantum()) return false; - if(left_.greenQuantum() < right_.greenQuantum()) return true; - if(left_.greenQuantum() > right_.greenQuantum()) return false; - if(left_.blueQuantum() < right_.blueQuantum()) return true; - return false; + if(left_.quantumRed() < right_.quantumRed()) + return(true); + if(left_.quantumRed() > right_.quantumRed()) + return(false); + if(left_.quantumGreen() < right_.quantumGreen()) + return(true); + if(left_.quantumGreen() > right_.quantumGreen()) + return(false); + if(left_.quantumBlue() < right_.quantumBlue()) + return(true); + return(false); } -int Magick::operator >= ( const Magick::Color& left_, - const Magick::Color& right_ ) + +int Magick::operator >= (const Magick::Color &left_, + const Magick::Color &right_) { - return ( ( left_ > right_ ) || ( left_ == right_ ) ); + return((left_ > right_) || (left_ == right_)); } -int Magick::operator <= ( const Magick::Color& left_, - const Magick::Color& right_ ) + +int Magick::operator <= ( const Magick::Color &left_, + const Magick::Color &right_) { - return ( ( left_ < right_ ) || ( left_ == right_ ) ); + return((left_ < right_) || (left_ == right_)); } -// -// Color Implementation -// - -// Default constructor -Magick::Color::Color ( void ) - : _pixel(new PixelInfo), - _pixelOwn(true), - _isValid(false), - _pixelType(RGBPixel) +Magick::Color::Color(void) + : _pixel(new PixelInfo),_pixelOwn(true),_isValid(false),_pixelType(RGBPixel) { initPixel(); } -// Construct from RGB -Magick::Color::Color ( Quantum red_, - Quantum green_, - Quantum blue_ ) - : _pixel(new PixelInfo), - _pixelOwn(true), - _isValid(true), - _pixelType(RGBPixel) +Magick::Color::Color(const Quantum red_,const Quantum green_, + const Quantum blue_) + : _pixel(new PixelInfo),_pixelOwn(true),_isValid(true),_pixelType(RGBPixel) { - redQuantum ( red_ ); - greenQuantum ( green_ ); - blueQuantum ( blue_ ); - alphaQuantum ( OpaqueAlpha ); + quantumRed(red_); + quantumGreen(green_); + quantumBlue(blue_); + quantumAlpha(OpaqueAlpha); } -// Construct from RGBA -Magick::Color::Color ( Quantum red_, - Quantum green_, - Quantum blue_, - Quantum alpha_ ) - : _pixel(new PixelInfo), - _pixelOwn(true), - _isValid(true), - _pixelType(RGBAPixel) +Magick::Color::Color(const Quantum red_,const Quantum green_, + const Quantum blue_, const Quantum alpha_) + : _pixel(new PixelInfo),_pixelOwn(true),_isValid(true),_pixelType(RGBAPixel) { - redQuantum ( red_ ); - greenQuantum ( green_ ); - blueQuantum ( blue_ ); - alphaQuantum ( alpha_ ); + quantumRed(red_); + quantumGreen(green_); + quantumBlue(blue_); + quantumAlpha(alpha_); } -// Copy constructor -Magick::Color::Color ( const Magick::Color & color_ ) - : _pixel( new PixelInfo ), - _pixelOwn( true ), - _isValid( color_._isValid ), - _pixelType( color_._pixelType ) +Magick::Color::Color(const Magick::Color & color_) + : _pixel(new PixelInfo),_pixelOwn(true),_isValid(color_._isValid), + _pixelType(color_._pixelType) { - *_pixel = *color_._pixel; + *_pixel=*color_._pixel; } -// Construct from color expressed as C++ string -Magick::Color::Color ( const std::string &x11color_ ) - : _pixel(new PixelInfo), - _pixelOwn(true), - _isValid(true), - _pixelType(RGBPixel) +Magick::Color::Color(const PixelInfo &color_) + : _pixel(new PixelInfo),_pixelOwn(true),_isValid(true),_pixelType(RGBPixel) { - initPixel(); + *_pixel=color_; - // Use operator = implementation - *this = x11color_; + if (color_.alpha != OpaqueAlpha) + _pixelType=RGBAPixel; } -// Construct from color expressed as C string -Magick::Color::Color ( const char * x11color_ ) - : _pixel(new PixelInfo), - _pixelOwn(true), - _isValid(true), - _pixelType(RGBPixel) +Magick::Color::Color(const std::string &color_) + : _pixel(new PixelInfo),_pixelOwn(true),_isValid(true),_pixelType(RGBPixel) { initPixel(); // Use operator = implementation - *this = x11color_; -} - -// Construct color via ImageMagick PixelInfo -Magick::Color::Color ( const PixelInfo &color_ ) - : _pixel(new PixelInfo), - _pixelOwn(true), // We allocated this pixel - _isValid(true), - _pixelType(RGBPixel) // RGB pixel by default -{ - *_pixel = color_; - - if ( color_.alpha != OpaqueAlpha ) - _pixelType = RGBAPixel; + *this=color_; } -// Protected constructor to construct with PixelInfo* -// Used to point Color at a pixel. -Magick::Color::Color ( PixelInfo* rep_, PixelType pixelType_ ) - : _pixel(rep_), - _pixelOwn(false), - _isValid(true), - _pixelType(pixelType_) +Magick::Color::~Color(void) { -} - -// Destructor -Magick::Color::~Color( void ) -{ - if ( _pixelOwn ) + if (_pixelOwn) delete _pixel; - _pixel=0; + + _pixel=(PixelInfo *)NULL; } -// Assignment operator -Magick::Color& Magick::Color::operator = ( const Magick::Color& color_ ) +Magick::Color& Magick::Color::operator=(const Magick::Color& color_) { // If not being set to ourself - if ( this != &color_ ) + if (this != &color_) { // Copy pixel value - *_pixel = *color_._pixel; + *_pixel=*color_._pixel; // Validity - _isValid = color_._isValid; + _isValid=color_._isValid; // Copy pixel type - _pixelType = color_._pixelType; + _pixelType=color_._pixelType; } - return *this; + return(*this); } -// Set color via X11 color specification string -const Magick::Color& Magick::Color::operator = ( const std::string &x11color_ ) +const Magick::Color& Magick::Color::operator=(const MagickCore::PixelInfo &color_) { + *_pixel=color_; + if (color_.alpha != OpaqueAlpha) + _pixelType=RGBAPixel; + else + _pixelType=RGBPixel; + + return(*this); +} + +const Magick::Color& Magick::Color::operator=(const std::string &color_) +{ + ExceptionInfo + exception; + + PixelInfo + target_color; + initPixel(); - PixelInfo target_color; - ExceptionInfo exception; - GetExceptionInfo( &exception ); - if ( QueryColorCompliance( x11color_.c_str(), AllCompliance, &target_color, &exception ) ) + GetExceptionInfo(&exception); + if (QueryColorCompliance(color_.c_str(),AllCompliance,&target_color, + &exception)) { - redQuantum( ClampToQuantum( target_color.red ) ); - greenQuantum( ClampToQuantum( target_color.green ) ); - blueQuantum( ClampToQuantum( target_color.blue ) ); - alphaQuantum( ClampToQuantum( target_color.alpha ) ); + quantumRed(target_color.red); + quantumGreen(target_color.green); + quantumBlue(target_color.blue); + quantumAlpha(target_color.alpha); - if ( target_color.alpha != OpaqueAlpha ) - _pixelType = RGBAPixel; + if (quantumAlpha() != OpaqueAlpha) + _pixelType=RGBAPixel; else - _pixelType = RGBPixel; + _pixelType=RGBPixel; } else { @@ -215,27 +182,25 @@ const Magick::Color& Magick::Color::operator = ( const std::string &x11color_ ) } (void) DestroyExceptionInfo( &exception ); - return *this; + return(*this); } -// Set color via X11 color specification C string -const Magick::Color& Magick::Color::operator = ( const char * x11color_ ) +inline Magick::Color::operator MagickCore::PixelInfo() const { - *this = std::string(x11color_); - return *this; + return *_pixel; } -// Return X11 color specification string Magick::Color::operator std::string() const { - if ( !isValid() ) - return std::string("none"); - - char colorbuf[MaxTextExtent]; + char + colorbuf[MaxTextExtent]; PixelInfo pixel; + if (!isValid()) + return std::string("none"); + pixel.colorspace=RGBColorspace; pixel.alpha_trait=_pixelType == RGBAPixel ? BlendPixelTrait : UndefinedPixelTrait; @@ -244,48 +209,55 @@ Magick::Color::operator std::string() const pixel.green=_pixel->green; pixel.blue=_pixel->blue; pixel.alpha=_pixel->alpha; - GetColorTuple( &pixel, MagickTrue, colorbuf ); + GetColorTuple(&pixel,MagickTrue,colorbuf); - return std::string(colorbuf); + return(std::string(colorbuf)); } -// Set color via ImageMagick PixelInfo -const Magick::Color& Magick::Color::operator= ( const MagickCore::PixelInfo &color_ ) +void Magick::Color::alpha(const double alpha_) { - *_pixel = color_; - if ( color_.alpha != OpaqueAlpha ) - _pixelType = RGBAPixel; - else - _pixelType = RGBPixel; - return *this; + quantumAlpha(scaleDoubleToQuantum(alpha_)); } -// Set pixel -// Used to point Color at a pixel in an image -void Magick::Color::pixel ( PixelInfo* rep_, PixelType pixelType_ ) +double Magick::Color::alpha(void) const { - if ( _pixelOwn ) - delete _pixel; - _pixel = rep_; - _pixelOwn = false; - _isValid = true; - _pixelType = pixelType_; + return scaleQuantumToDouble(quantumAlpha()); +} + +void Magick::Color::blue(const double blue_) +{ + quantumBlue(scaleDoubleToQuantum(blue_)); +} + +double Magick::Color::blue(void) const +{ + return scaleQuantumToDouble(quantumBlue()); +} + +void Magick::Color::green(const double green_) +{ + quantumGreen(scaleDoubleToQuantum(green_)); } -// Does object contain valid color? -bool Magick::Color::isValid ( void ) const +double Magick::Color::green(void) const { - return( _isValid ); + return scaleQuantumToDouble(quantumGreen()); } -void Magick::Color::isValid ( bool valid_ ) + +bool Magick::Color::isValid(void) const { - if ( (valid_ && isValid()) || (!valid_ && !isValid()) ) + return(_isValid); +} + +void Magick::Color::isValid(bool valid_) +{ + if ((valid_ && isValid()) || (!valid_ && !isValid())) return; - if ( !_pixelOwn ) + if (!_pixelOwn) { - _pixel = new PixelInfo; - _pixelOwn = true; + _pixel=new PixelInfo; + _pixelOwn=true; } _isValid=valid_; @@ -293,404 +265,438 @@ void Magick::Color::isValid ( bool valid_ ) initPixel(); } -// -// ColorHSL Implementation -// +void Magick::Color::quantumAlpha(const Magick::Quantum alpha_) +{ + _pixel->alpha=alpha_; + _isValid=true ; +} -Magick::ColorHSL::ColorHSL ( double hue_, - double saturation_, - double luminosity_ ) - : Color () +Magick::Quantum Magick::Color::quantumAlpha(void) const { - double red, green, blue; + return _pixel->alpha; +} - ConvertHSLToRGB ( hue_, - saturation_, - luminosity_, - &red, - &green, - &blue ); +void Magick::Color::quantumBlue(const Magick::Quantum blue_) +{ + _pixel->blue=blue_; + _isValid=true; +} - redQuantum ( ClampToQuantum( red ) ); - greenQuantum ( ClampToQuantum( green ) ); - blueQuantum ( ClampToQuantum( blue ) ); - alphaQuantum ( OpaqueAlpha ); +Magick::Quantum Magick::Color::quantumBlue(void) const +{ + return _pixel->blue; } -// Null constructor -Magick::ColorHSL::ColorHSL ( ) - : Color () +void Magick::Color::quantumGreen(const Magick::Quantum green_) { + _pixel->green=green_; + _isValid=true; } -// Copy constructor from base class -Magick::ColorHSL::ColorHSL ( const Magick::Color & color_ ) - : Color( color_ ) +Magick::Quantum Magick::Color::quantumGreen(void) const { -} - -// Destructor -Magick::ColorHSL::~ColorHSL ( ) -{ - // Nothing to do -} - -void Magick::ColorHSL::hue ( double hue_ ) -{ - double hue_val, saturation_val, luminosity_val; - ConvertRGBToHSL ( redQuantum(), - greenQuantum(), - blueQuantum(), - &hue_val, - &saturation_val, - &luminosity_val ); - - hue_val = hue_; - - double red, green, blue; - ConvertHSLToRGB ( hue_val, - saturation_val, - luminosity_val, - &red, - &green, - &blue - ); - - redQuantum ( ClampToQuantum( red ) ); - greenQuantum ( ClampToQuantum( green ) ); - blueQuantum ( ClampToQuantum( blue ) ); -} - -double Magick::ColorHSL::hue ( void ) const -{ - double hue_val, saturation_val, luminosity_val; - ConvertRGBToHSL ( redQuantum(), - greenQuantum(), - blueQuantum(), - &hue_val, - &saturation_val, - &luminosity_val ); - return hue_val; -} - -void Magick::ColorHSL::saturation ( double saturation_ ) -{ - double hue_val, saturation_val, luminosity_val; - ConvertRGBToHSL ( redQuantum(), - greenQuantum(), - blueQuantum(), - &hue_val, - &saturation_val, - &luminosity_val ); - - saturation_val = saturation_; - - double red, green, blue; - ConvertHSLToRGB ( hue_val, - saturation_val, - luminosity_val, - &red, - &green, - &blue - ); - - redQuantum ( ClampToQuantum( red ) ); - greenQuantum ( ClampToQuantum( green ) ); - blueQuantum ( ClampToQuantum( blue ) ); -} - -double Magick::ColorHSL::saturation ( void ) const -{ - double hue_val, saturation_val, luminosity_val; - ConvertRGBToHSL ( redQuantum(), - greenQuantum(), - blueQuantum(), - &hue_val, - &saturation_val, - &luminosity_val ); - return saturation_val; -} + return _pixel->green; +} -void Magick::ColorHSL::luminosity ( double luminosity_ ) -{ - double hue_val, saturation_val, luminosity_val; - ConvertRGBToHSL ( redQuantum(), - greenQuantum(), - blueQuantum(), - &hue_val, - &saturation_val, - &luminosity_val ); - - luminosity_val = luminosity_; - - double red, green, blue; - ConvertHSLToRGB ( hue_val, - saturation_val, - luminosity_val, - &red, - &green, - &blue - ); - - redQuantum ( ClampToQuantum( red ) ); - greenQuantum ( ClampToQuantum( green ) ); - blueQuantum ( ClampToQuantum( blue ) ); +void Magick::Color::quantumRed(const Magick::Quantum red_) +{ + _pixel->red=red_; + _isValid=true; } -double Magick::ColorHSL::luminosity ( void ) const +inline Magick::Quantum Magick::Color::quantumRed(void) const { - double hue_val, saturation_val, luminosity_val; - ConvertRGBToHSL ( redQuantum(), - greenQuantum(), - blueQuantum(), - &hue_val, - &saturation_val, - &luminosity_val ); - return luminosity_val; + return _pixel->red; } -// Assignment from base class -Magick::ColorHSL& Magick::ColorHSL::operator = ( const Magick::Color& color_ ) +void Magick::Color::red(const double red_) { - *static_cast(this) = color_; - return *this; + quantumRed(scaleDoubleToQuantum(red_)); } -// -// ColorGray Implementation -// -Magick::ColorGray::ColorGray ( double shade_ ) - : Color ( scaleDoubleToQuantum( shade_ ), - scaleDoubleToQuantum( shade_ ), - scaleDoubleToQuantum( shade_ ) ) +double Magick::Color::red(void) const { - alphaQuantum ( OpaqueAlpha ); + return scaleQuantumToDouble(quantumRed()); } -// Null constructor -Magick::ColorGray::ColorGray ( void ) - : Color () +Magick::Color::Color(PixelInfo* rep_,PixelType pixelType_) + : _pixel(rep_),_pixelOwn(false),_isValid(true),_pixelType(pixelType_) { } -// Copy constructor from base class -Magick::ColorGray::ColorGray ( const Magick::Color & color_ ) - : Color( color_ ) +void Magick::Color::pixel(PixelInfo *rep_,PixelType pixelType_) { + if (_pixelOwn) + delete _pixel; + + _pixel=rep_; + _pixelOwn=false; + _isValid=true; + _pixelType=pixelType_; } -// Destructor -Magick::ColorGray::~ColorGray () +Magick::Quantum Magick::Color::scaleDoubleToQuantum(const double double_) { - // Nothing to do + return (static_cast(double_*QuantumRange)); } -void Magick::ColorGray::shade ( double shade_ ) +double Magick::Color::scaleQuantumToDouble(const Magick::Quantum quantum_) { - Quantum gray = scaleDoubleToQuantum( shade_ ); - redQuantum ( gray ); - greenQuantum ( gray ); - blueQuantum ( gray ); +#if (MAGICKCORE_QUANTUM_DEPTH != 64) + return (static_cast(quantum_)/QuantumRange); +#else + return (quantum_/QuantumRange); +#endif } -double Magick::ColorGray::shade ( void ) const +void Magick::Color::initPixel() +{ + _pixel->red=0; + _pixel->green=0; + _pixel->blue=0; + _pixel->alpha=TransparentAlpha; +} + +Magick::ColorGray::ColorGray(void) + : Color() { - return scaleQuantumToDouble ( greenQuantum() ); } -// Assignment from base class -Magick::ColorGray& Magick::ColorGray::operator = ( const Magick::Color& color_ ) +Magick::ColorGray::ColorGray(const Magick::Color & color_) + : Color(color_) { - *static_cast(this) = color_; - return *this; } -// -// ColorMono Implementation -// -Magick::ColorMono::ColorMono ( bool mono_ ) - : Color ( ( mono_ ? QuantumRange : 0 ), - ( mono_ ? QuantumRange : 0 ), - ( mono_ ? QuantumRange : 0 ) ) +Magick::ColorGray::ColorGray(double shade_) + : Color(scaleDoubleToQuantum(shade_),scaleDoubleToQuantum(shade_), + scaleDoubleToQuantum(shade_)) { - alphaQuantum ( OpaqueAlpha ); + quantumAlpha(OpaqueAlpha); } -// Null constructor -Magick::ColorMono::ColorMono ( void ) - : Color () +Magick::ColorGray::~ColorGray() { } -// Copy constructor from base class -Magick::ColorMono::ColorMono ( const Magick::Color & color_ ) - : Color( color_ ) +void Magick::ColorGray::shade(double shade_) { + red(shade_); + green(shade_); + blue(shade_); } -// Destructor -Magick::ColorMono::~ColorMono () +double Magick::ColorGray::shade(void) const { - // Nothing to do + return(green()); } -void Magick::ColorMono::mono ( bool mono_ ) +Magick::ColorGray& Magick::ColorGray::operator=(const Magick::Color& color_) { - redQuantum ( mono_ ? QuantumRange : 0 ); - greenQuantum ( mono_ ? QuantumRange : 0 ); - blueQuantum ( mono_ ? QuantumRange : 0 ); + *static_cast(this)=color_; + return(*this); } -bool Magick::ColorMono::mono ( void ) const +Magick::ColorGray::ColorGray(PixelInfo *rep_,PixelType pixelType_) +: Color(rep_,pixelType_) { - if ( greenQuantum() ) - return true; - else - return false; } -// Assignment from base class -Magick::ColorMono& Magick::ColorMono::operator = ( const Magick::Color& color_ ) +Magick::ColorHSL::ColorHSL(void) + : Color() +{ +} + +Magick::ColorHSL::ColorHSL(const Magick::Color &color_) + : Color(color_) +{ +} + +Magick::ColorHSL::ColorHSL(const double hue_,const double saturation_, + const double luminosity_) + : Color() +{ + double + blue, + green, + red; + + ConvertHSLToRGB(hue_,saturation_,luminosity_,&red,&green,&blue); + + quantumRed(red); + quantumGreen(green); + quantumBlue(blue); + quantumAlpha(OpaqueAlpha); +} + +Magick::ColorHSL::~ColorHSL() +{ +} + +Magick::ColorHSL& Magick::ColorHSL::operator=(const Magick::Color& color_) { *static_cast(this) = color_; - return *this; + return(*this); } -// -// ColorRGB Implementation -// +void Magick::ColorHSL::hue(const double hue_) +{ + double + hue, + luminosity, + saturation; + + double + blue, + green, + red; + + ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation, + &luminosity); + + hue=hue_; + + ConvertHSLToRGB(hue,saturation,luminosity,&red,&green,&blue); + + quantumRed(red); + quantumGreen(green); + quantumBlue(blue); +} + +double Magick::ColorHSL::hue(void) const +{ + double + hue, + luminosity, + saturation; + + ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation, + &luminosity); + + return(hue); +} + +void Magick::ColorHSL::luminosity(const double luminosity_) +{ + double + hue, + luminosity, + saturation; + + double + blue, + green, + red; + + ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation, + &luminosity); -// Construct from red, green, and blue, components -Magick::ColorRGB::ColorRGB ( double red_, - double green_, - double blue_ ) - : Color ( scaleDoubleToQuantum(red_), - scaleDoubleToQuantum(green_), - scaleDoubleToQuantum(blue_) ) + luminosity=luminosity_; + + ConvertHSLToRGB(hue,saturation,luminosity,&red,&green,&blue); + + quantumRed(red); + quantumGreen(green); + quantumBlue(blue); +} + +double Magick::ColorHSL::luminosity ( void ) const { - alphaQuantum ( OpaqueAlpha ); + double + hue, + luminosity, + saturation; + + ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation, + &luminosity); + + return(luminosity); +} + +void Magick::ColorHSL::saturation(const double saturation_) +{ + double + hue, + luminosity, + saturation; + + double + blue, + green, + red; + + ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation, + &luminosity); + + saturation=saturation_; + + ConvertHSLToRGB(hue,saturation,luminosity,&red,&green,&blue); + + quantumRed(red); + quantumGreen(green); + quantumBlue(blue); } -// Null constructor -Magick::ColorRGB::ColorRGB ( void ) - : Color () + +double Magick::ColorHSL::saturation(void) const { + double + hue, + luminosity, + saturation; + + ConvertRGBToHSL(quantumRed(),quantumGreen(),quantumBlue(),&hue,&saturation, + &luminosity); + + return(saturation); } -// Copy constructor from base class -Magick::ColorRGB::ColorRGB ( const Magick::Color & color_ ) - : Color( color_ ) + +Magick::ColorMono::ColorMono(void) + : Color() { } -// Destructor -Magick::ColorRGB::~ColorRGB ( void ) + +Magick::ColorMono::ColorMono(const bool mono_) + : Color((Quantum)(mono_ ? QuantumRange : 0), + (Quantum)(mono_ ? QuantumRange : 0), + (Quantum)(mono_ ? QuantumRange : 0)) { - // Nothing to do + quantumAlpha(OpaqueAlpha); } -// Assignment from base class -Magick::ColorRGB& Magick::ColorRGB::operator = ( const Magick::Color& color_ ) +Magick::ColorMono::ColorMono(const Magick::Color &color_) + : Color(color_) +{ +} + +Magick::ColorMono::~ColorMono() +{ +} + +Magick::ColorMono& Magick::ColorMono::operator = ( const Magick::Color& color_ ) { *static_cast(this) = color_; return *this; } -// -// ColorYUV Implementation -// +void Magick::ColorMono::mono(bool mono_) +{ + quantumRed(mono_ ? QuantumRange : 0); + quantumGreen(mono_ ? QuantumRange : 0); + quantumBlue(mono_ ? QuantumRange : 0); +} -// R = Y +1.13980*V -// G = Y-0.39380*U-0.58050*V -// B = Y+2.02790*U -// -// U and V, normally -0.5 through 0.5, must be normalized to the range 0 -// through QuantumRange. -// -// Y = 0.29900*R+0.58700*G+0.11400*B -// U = -0.14740*R-0.28950*G+0.43690*B -// V = 0.61500*R-0.51500*G-0.10000*B -// -// U and V, normally -0.5 through 0.5, are normalized to the range 0 -// through QuantumRange. Note that U = 0.493*(B-Y), V = 0.877*(R-Y). -// +bool Magick::ColorMono::mono(void) const +{ + return(quantumGreen() == 0); +} -// Construct from color components -Magick::ColorYUV::ColorYUV ( double y_, - double u_, - double v_ ) - : Color ( scaleDoubleToQuantum(y_ + 1.13980 * v_ ), - scaleDoubleToQuantum(y_ - (0.39380 * u_) - (0.58050 * v_) ), - scaleDoubleToQuantum(y_ + 2.02790 * u_ ) ) +Magick::ColorMono::ColorMono(PixelInfo *rep_,PixelType pixelType_) + : Color(rep_,pixelType_) { - alphaQuantum ( OpaqueAlpha ); } -// Null constructor -Magick::ColorYUV::ColorYUV ( void ) - : Color () + +Magick::ColorRGBA::ColorRGBA(void) + : Color() { } -// Copy constructor from base class -Magick::ColorYUV::ColorYUV ( const Magick::Color & color_ ) - : Color( color_ ) + +Magick::ColorRGBA::ColorRGBA(const Magick::Color & color_) + : Color(color_) { } -// Destructor -Magick::ColorYUV::~ColorYUV ( void ) + +Magick::ColorRGBA::ColorRGBA(const double red_,const double green_, + const double blue_) + : Color(scaleDoubleToQuantum(red_),scaleDoubleToQuantum(green_), + scaleDoubleToQuantum(blue_)) { - // Nothing to do + quantumAlpha(OpaqueAlpha); } -void Magick::ColorYUV::u ( double u_ ) +Magick::ColorRGBA::ColorRGBA(const double red_,const double green_, + const double blue_,const double alpha_) + : Color(scaleDoubleToQuantum(red_),scaleDoubleToQuantum(green_), + scaleDoubleToQuantum(blue_),scaleDoubleToQuantum(alpha_)) { - double V = v(); - double Y = y(); +} - redQuantum ( scaleDoubleToQuantum( Y + 1.13980 * V ) ); - greenQuantum ( scaleDoubleToQuantum( Y - (0.39380 * u_) - (0.58050 * V) ) ); - blueQuantum ( scaleDoubleToQuantum( Y + 2.02790 * u_ ) ); +Magick::ColorRGBA::~ColorRGBA(void) +{ } -double Magick::ColorYUV::u ( void ) const +Magick::ColorRGBA& Magick::ColorRGBA::operator=(const Magick::Color& color_) { - return scaleQuantumToDouble( (-0.14740 * redQuantum()) - (0.28950 * - greenQuantum()) + (0.43690 * blueQuantum()) ); + *static_cast(this)=color_; + return(*this); } -void Magick::ColorYUV::v ( double v_ ) +Magick::ColorYUV::ColorYUV(void) + : Color() { - double U = u(); - double Y = y(); +} - redQuantum ( scaleDoubleToQuantum( Y + 1.13980 * v_ ) ); - greenQuantum ( scaleDoubleToQuantum( Y - (0.39380 * U) - (0.58050 * v_) ) ); - blueQuantum ( scaleDoubleToQuantum( Y + 2.02790 * U ) ); +Magick::ColorYUV::ColorYUV(const Magick::Color &color_) + : Color(color_) +{ } -double Magick::ColorYUV::v ( void ) const +Magick::ColorYUV::ColorYUV(const double y_,const double u_,const double v_) + : Color() { - return scaleQuantumToDouble((0.61500 * redQuantum()) - - (0.51500 * greenQuantum()) - - (0.10000 * blueQuantum())); + convert(y_, u_, v_); + quantumAlpha(OpaqueAlpha); } -void Magick::ColorYUV::y ( double y_ ) +Magick::ColorYUV::~ColorYUV(void) { - double U = u(); - double V = v(); +} + +Magick::ColorYUV& Magick::ColorYUV::operator=(const Magick::Color &color_) +{ + *static_cast(this)=color_; + return(*this); +} - redQuantum ( scaleDoubleToQuantum( y_ + 1.13980 * V ) ); - greenQuantum ( scaleDoubleToQuantum( y_ - (0.39380 * U) - (0.58050 * V) ) ); - blueQuantum ( scaleDoubleToQuantum( y_ + 2.02790 * U ) ); +void Magick::ColorYUV::u(const double u_) +{ + convert(y(), u_, v()); +} + +double Magick::ColorYUV::u(void) const +{ + return scaleQuantumToDouble((-0.14740 * quantumRed()) - (0.28950 * + quantumGreen()) + (0.43690 * quantumBlue())); +} + +void Magick::ColorYUV::v(const double v_) +{ + convert(y(), u(), v_); +} + +double Magick::ColorYUV::v(void) const +{ + return scaleQuantumToDouble((0.61500 * quantumRed()) - (0.51500 * + quantumGreen()) - (0.10000 * quantumBlue())); +} + +void Magick::ColorYUV::y(const double y_) +{ + convert(y_, u(), v()); } double Magick::ColorYUV::y ( void ) const { - return scaleQuantumToDouble((0.29900 * redQuantum()) + - (0.58700 * greenQuantum()) + - (0.11400 * blueQuantum())); + return scaleQuantumToDouble((0.29900 * quantumRed()) + (0.58700 * + quantumGreen()) + (0.11400 * quantumBlue())); } -// Assignment from base class -Magick::ColorYUV& Magick::ColorYUV::operator = ( const Magick::Color& color_ ) +void Magick::ColorYUV::convert(const double y_,const double u_,const double v_) { - *static_cast(this) = color_; - return *this; + quantumRed(scaleDoubleToQuantum(y_ + 1.13980 * v_)); + quantumGreen(scaleDoubleToQuantum(y_ - (0.39380 * u_) - (0.58050 * v_))); + quantumBlue(scaleDoubleToQuantum(y_ + 2.02790 * u_)); } + +Magick::ColorYUV::ColorYUV(PixelInfo *rep_,PixelType pixelType_) + : Color(rep_,pixelType_) +{ +} \ No newline at end of file diff --git a/Magick++/lib/Magick++/Blob.h b/Magick++/lib/Magick++/Blob.h index 0bea044a1..84c69877f 100644 --- a/Magick++/lib/Magick++/Blob.h +++ b/Magick++/lib/Magick++/Blob.h @@ -44,11 +44,21 @@ namespace Magick // Update object contents from Base64-encoded string representation. void base64(const std::string base64_); // Return Base64-encoded string representation. - std::string base64(void); + std::string base64(void) const; + + // Obtain pointer to data. The user should never try to modify or + // free this data since the Blob class manages its own data. The + // user must be finished with the data before allowing the Blob to + // be destroyed since the pointer is invalid once the Blob is + // destroyed. + const void* data(void) const; + + // Obtain data length + size_t length(void) const; // Update object contents, making a copy of the supplied data. // Any existing data in the object is deallocated. - void update(const void* data_,size_t length_); + void update(const void* data_,const size_t length_); // Update object contents, using supplied pointer directly (no // copy). Any existing data in the object is deallocated. The user @@ -57,18 +67,8 @@ namespace Magick // Specify allocator_ as "MallocAllocator" if memory is allocated // via the C language malloc() function, or "NewAllocator" if // memory is allocated via C++ 'new'. - void updateNoCopy(void* data_,size_t length_, - Allocator allocator_=NewAllocator); - - // Obtain pointer to data. The user should never try to modify or - // free this data since the Blob class manages its own data. The - // user must be finished with the data before allowing the Blob to - // be destroyed since the pointer is invalid once the Blob is - // destroyed. - const void* data(void) const; - - // Obtain data length - size_t length(void) const; + void updateNoCopy(void* data_,const size_t length_, + const Allocator allocator_=NewAllocator); private: BlobRef *_blobRef; diff --git a/Magick++/lib/Magick++/CoderInfo.h b/Magick++/lib/Magick++/CoderInfo.h index c3a6b1c90..62ad22f8c 100644 --- a/Magick++/lib/Magick++/CoderInfo.h +++ b/Magick++/lib/Magick++/CoderInfo.h @@ -37,6 +37,9 @@ namespace Magick // Destructor ~CoderInfo(void); + // Assignment operator + CoderInfo& operator=(const CoderInfo &coder_); + // Format description std::string description(void) const; @@ -55,14 +58,6 @@ namespace Magick // Format name std::string name(void) const; - // Assignment operator - CoderInfo& operator=(const CoderInfo &coder_); - - // - // Implemementation methods - // - CoderInfo(const MagickCore::MagickInfo *magickInfo_); - private: std::string _name; std::string _description; @@ -74,9 +69,4 @@ namespace Magick } // namespace Magick -// -// Inlines -// - - #endif // Magick_CoderInfo_header diff --git a/Magick++/lib/Magick++/Color.h b/Magick++/lib/Magick++/Color.h index 2c3c9a7d3..d37dc05f4 100644 --- a/Magick++/lib/Magick++/Color.h +++ b/Magick++/lib/Magick++/Color.h @@ -12,110 +12,109 @@ namespace Magick { - class MagickPPExport Color; // Compare two Color objects regardless of LHS/RHS - int MagickPPExport operator == ( const Magick::Color& left_, const Magick::Color& right_ ); - int MagickPPExport operator != ( const Magick::Color& left_, const Magick::Color& right_ ); - int MagickPPExport operator > ( const Magick::Color& left_, const Magick::Color& right_ ); - int MagickPPExport operator < ( const Magick::Color& left_, const Magick::Color& right_ ); - int MagickPPExport operator >= ( const Magick::Color& left_, const Magick::Color& right_ ); - int MagickPPExport operator <= ( const Magick::Color& left_, const Magick::Color& right_ ); - - // Base color class stores RGB components scaled to fit Quantum + int MagickPPExport operator == + (const Magick::Color& left_,const Magick::Color& right_); + int MagickPPExport operator != + (const Magick::Color& left_,const Magick::Color& right_); + int MagickPPExport operator > + (const Magick::Color& left_,const Magick::Color& right_); + int MagickPPExport operator < + (const Magick::Color& left_,const Magick::Color& right_); + int MagickPPExport operator >= + (const Magick::Color& left_,const Magick::Color& right_); + int MagickPPExport operator <= + (const Magick::Color& left_,const Magick::Color& right_); + + // Base color class stores RGBA components scaled to fit Quantum + // All double arguments have a valid range of 0.0 - 1.0. class MagickPPExport Color { public: - Color ( Quantum red_, - Quantum green_, - Quantum blue_ ); - Color ( Quantum red_, - Quantum green_, - Quantum blue_, - Quantum alpha_ ); - Color ( const std::string &x11color_ ); - Color ( const char * x11color_ ); - Color ( void ); - virtual ~Color ( void ); - Color ( const Color & color_ ); - // Red color (range 0 to QuantumRange) - void redQuantum ( Quantum red_ ); - Quantum redQuantum ( void ) const; + // Default constructor + Color(void); - // Green color (range 0 to QuantumRange) - void greenQuantum ( Quantum green_ ); - Quantum greenQuantum ( void ) const; + // Construct Color using the specified RGB values + Color(const Quantum red_,const Quantum green_,const Quantum blue_); - // Blue color (range 0 to QuantumRange) - void blueQuantum ( Quantum blue_ ); - Quantum blueQuantum ( void ) const; + // Construct Color using the specified RGBA values + Color(const Quantum red_,const Quantum green_,const Quantum blue_, + const Quantum alpha_); - // Alpha level (range OpaqueAlpha=0 to TransparentAlpha=QuantumRange) - void alphaQuantum ( Quantum alpha_ ); - Quantum alphaQuantum ( void ) const; - - // Scaled (to 1.0) version of alpha for use in sub-classes - // (range opaque=0 to transparent=1.0) - void alpha ( double alpha_ ); - double alpha ( void ) const; - - // Does object contain valid color? - void isValid ( bool valid_ ); - bool isValid ( void ) const; - - // Set color via X11 color specification string - const Color& operator= ( const std::string &x11color_ ); - const Color& operator= ( const char * x11color_ ); + // Copy constructor + Color(const Color &color_); + + // Construct color via ImageMagick PixelInfo + Color(const PixelInfo &color_); + + // Constructor Color using the specified color string + Color(const std::string &color_); + + // Destructor + virtual ~Color(void); // Assignment operator - Color& operator= ( const Color& color_ ); + Color& operator=(const Color &color_); + + // Set color via ImageMagick PixelInfo + const Color& operator=(const PixelInfo &color_); - // Return X11 color specification string - /* virtual */ operator std::string() const; + // Set color via color specification string + const Color& operator=(const std::string &color); // Return ImageMagick PixelInfo operator PixelInfo() const; - // Construct color via ImageMagick PixelInfo - Color ( const PixelInfo &color_ ); + // Return color specification string + operator std::string() const; - // Set color via ImageMagick PixelInfo - const Color& operator= ( const PixelInfo &color_ ); + // Alpha level (range 0.0=0 to 1.0=QuantumRange) + void alpha(const double alpha_); + double alpha(void) const; - // - // Public methods beyond this point are for Magick++ use only. - // + // Blue color (range 0.0 to 1.0) + void blue(const double blue_); + double blue(void) const; - // Obtain pixel intensity as a double - double intensity ( void ) const - { - return (0.299*(_pixel->red)+0.587*(_pixel->green)+0.114*(_pixel->blue)); - } + // Green color (range 0 to QuantumRange) + void green(const double green_); + double green(void) const; - // Scale a value expressed as a double (0-1) to Quantum range (0-QuantumRange) - static Quantum scaleDoubleToQuantum( const double double_ ) - { - return (static_cast(double_*QuantumRange)); - } + // Does object contain valid color? + void isValid(const bool valid_); + bool isValid(void) const; - // Scale a value expressed as a Quantum (0-QuantumRange) to double range (0-1) -#if (MAGICKCORE_QUANTUM_DEPTH < 64) - static double scaleQuantumToDouble( const Quantum quantum_ ) - { - return (static_cast(quantum_)/QuantumRange); - } -#endif - static double scaleQuantumToDouble( const double quantum_ ) - { - return (quantum_/QuantumRange); - } + // Alpha level (range OpaqueAlpha=0 to TransparentAlpha=QuantumRange) + void quantumAlpha(const Quantum alpha_); + Quantum quantumAlpha(void) const; + // Blue color (range 0 to QuantumRange) + void quantumBlue(const Quantum blue_); + Quantum quantumBlue(void) const; + + // Green color (range 0 to QuantumRange) + void quantumGreen(const Quantum green_); + Quantum quantumGreen(void) const; + + // Red color (range 0 to QuantumRange) + void quantumRed(const Quantum red_); + Quantum quantumRed(void) const; + + // Red color (range 0 to 1.0) + void red(const double red_); + double red(void) const; protected: // PixelType specifies the interpretation of PixelInfo members + // CYMKPixel: + // Cyan = red + // Yellow = green + // Magenta = blue + // Black(K) = alpha // RGBPixel: // Red = red; // Green = green; @@ -125,155 +124,184 @@ namespace Magick // Green = green; // Blue = blue; // Alpha = alpha; - // CYMKPixel: - // Cyan = red - // Yellow = green - // Magenta = blue - // Black(K) = alpha enum PixelType { + CYMKPixel, RGBPixel, - RGBAPixel, - CYMKPixel + RGBAPixel }; // Constructor to construct with PixelInfo* // Used to point Color at a pixel in an image - Color ( PixelInfo* rep_, PixelType pixelType_ ); + Color(PixelInfo *rep_,PixelType pixelType_); // Set pixel // Used to point Color at a pixel in an image - void pixel ( PixelInfo* rep_, PixelType pixelType_ ); + void pixel(PixelInfo *rep_,PixelType pixelType_); + + // Scale a value expressed as a double (0-1) to Quantum range (0-QuantumRange) + static Quantum scaleDoubleToQuantum(const double double_); + + // Scale a value expressed as a Quantum (0-QuantumRange) to double range (0-1) + static double scaleQuantumToDouble(const Quantum quantum_); // PixelInfo represents a color pixel: // red = red (range 0 to QuantumRange) // green = green (range 0 to QuantumRange) // blue = blue (range 0 to QuantumRange) - // alpha = alpha (range OpaqueAlpha=0 to TransparentAlpha=QuantumRange) + // alpha = alpha (range OpaqueAlpha=0 to TransparentAlpha=QuantumRange) // index = PseudoColor colormap index - PixelInfo* _pixel; + PixelInfo *_pixel; private: + bool _isValid; // Set true if pixel is "valid" + bool _pixelOwn; // Set true if we allocated pixel + PixelType _pixelType; // Color type supported by _pixel + // Common initializer for PixelInfo representation void initPixel(); - - // Set true if we allocated pixel - bool _pixelOwn; - - // Set true if pixel is "valid" - bool _isValid; - - // Color type supported by _pixel - PixelType _pixelType; - }; // - // HSL Colorspace colors + // Grayscale RGB color // - class MagickPPExport ColorHSL : public Color + // Grayscale is simply RGB with equal parts of red, green, and blue + // All double arguments have a valid range of 0.0 - 1.0. + class MagickPPExport ColorGray: public Color { public: - ColorHSL ( double hue_, double saturation_, double luminosity_ ); - ColorHSL ( void ); - ColorHSL ( const Color & color_ ); - /* virtual */ ~ColorHSL ( ); - - void hue ( double hue_ ); - double hue ( void ) const; - - void saturation ( double saturation_ ); - double saturation ( void ) const; - - void luminosity ( double luminosity_ ); - double luminosity ( void ) const; + + // Default constructor + ColorGray(void); + + // Copy constructor + ColorGray(const Color &color_); + + // Construct ColorGray using the specified shade + ColorGray(const double shade_); + + // Destructor + ~ColorGray(); + + // Shade + void shade(const double shade_); + double shade(void) const; // Assignment operator from base class - ColorHSL& operator= ( const Color& color_ ); + ColorGray& operator=(const Color& color_); protected: + // Constructor to construct with PixelInfo* - ColorHSL ( PixelInfo* rep_, PixelType pixelType_ ); + ColorGray(PixelInfo *rep_,PixelType pixelType_); }; - + // - // Grayscale RGB color + // HSL Colorspace colors // - // Grayscale is simply RGB with equal parts of red, green, and blue // All double arguments have a valid range of 0.0 - 1.0. - class MagickPPExport ColorGray : public Color + class MagickPPExport ColorHSL: public Color { public: - ColorGray ( double shade_ ); - ColorGray ( void ); - ColorGray ( const Color & color_ ); - /* virtual */ ~ColorGray (); - void shade ( double shade_ ); - double shade ( void ) const; + // Default constructor + ColorHSL(void); + + // Copy constructor + ColorHSL(const Color &color_); + + // Construct ColorHSL using the specified HSL values + ColorHSL(const double hue_,const double saturation_, + const double luminosity_); + + // Destructor + ~ColorHSL(); // Assignment operator from base class - ColorGray& operator= ( const Color& color_ ); + ColorHSL& operator=(const Color& color_); + + // Hue color + void hue(const double hue_); + double hue(void) const; + + // Luminosity color + void luminosity(const double luminosity_); + double luminosity(void) const; + + // Saturation color + void saturation(const double saturation_); + double saturation(void) const; protected: + // Constructor to construct with PixelInfo* - ColorGray ( PixelInfo* rep_, PixelType pixelType_ ); + ColorHSL(PixelInfo *rep_,PixelType pixelType_); }; - + // // Monochrome color // // Color arguments are constrained to 'false' (black pixel) and 'true' // (white pixel) - class MagickPPExport ColorMono : public Color + class MagickPPExport ColorMono: public Color { public: - ColorMono ( bool mono_ ); - ColorMono ( void ); - ColorMono ( const Color & color_ ); - /* virtual */ ~ColorMono (); - - void mono ( bool mono_ ); - bool mono ( void ) const; + + // Default constructor + ColorMono(void); + + // Construct ColorMono (false=black, true=white) + ColorMono(const bool mono_); + + // Copy constructor + ColorMono(const Color &color_); + + // Destructor + ~ColorMono(); // Assignment operator from base class - ColorMono& operator= ( const Color& color_ ); + ColorMono& operator=(const Color& color_); + + // Mono color + void mono(const bool mono_); + bool mono(void) const; protected: + // Constructor to construct with PixelInfo* - ColorMono ( PixelInfo* rep_, PixelType pixelType_ ); + ColorMono(PixelInfo* rep_,PixelType pixelType_); }; - - // - // RGB color - // - // All color arguments have a valid range of 0.0 - 1.0. - class MagickPPExport ColorRGB : public Color + + class MagickPPExport ColorRGBA: public Color { public: - ColorRGB ( double red_, double green_, double blue_ ); - ColorRGB ( void ); - ColorRGB ( const Color & color_ ); - /* virtual */ ~ColorRGB ( void ); - - void red ( double red_ ); - double red ( void ) const; - - void green ( double green_ ); - double green ( void ) const; - - void blue ( double blue_ ); - double blue ( void ) const; + + // Default constructor + ColorRGBA(void); + + // Copy constructor + ColorRGBA(const Color &color_); + + // Construct ColorRGBA using the specified RGB values + ColorRGBA(const double red_,const double green_,const double blue_); + + // Construct ColorRGBA using the specified RGBA values + ColorRGBA(const double red_,const double green_,const double blue_, + const double alpha); + + // Destructor + ~ColorRGBA(void); // Assignment operator from base class - ColorRGB& operator= ( const Color& color_ ); + ColorRGBA& operator=(const Color& color_); protected: + // Constructor to construct with PixelInfo* - ColorRGB ( PixelInfo* rep_, PixelType pixelType_ ); + ColorRGBA(PixelInfo *rep_,PixelType pixelType_); }; - + // // YUV Colorspace color // @@ -281,184 +309,47 @@ namespace Magick // Y: 0.0 through 1.0 // U: -0.5 through 0.5 // V: -0.5 through 0.5 - class MagickPPExport ColorYUV : public Color + class MagickPPExport ColorYUV: public Color { public: - ColorYUV ( double y_, double u_, double v_ ); - ColorYUV ( void ); - ColorYUV ( const Color & color_ ); - /* virtual */ ~ColorYUV ( void ); - - void u ( double u_ ); - double u ( void ) const; - - void v ( double v_ ); - double v ( void ) const; - - void y ( double y_ ); - double y ( void ) const; - - // Assignment operator from base class - ColorYUV& operator= ( const Color& color_ ); - - protected: - // Constructor to construct with PixelInfo* - ColorYUV ( PixelInfo* rep_, PixelType pixelType_ ); - }; -} // namespace Magick - -// -// Inlines -// - -// -// Color -// - -// Common initializer for PixelInfo representation -// Initialized transparent black -inline void Magick::Color::initPixel() -{ - _pixel->red = 0; - _pixel->green = 0; - _pixel->blue = 0; - _pixel->alpha = TransparentAlpha; -} - -inline void Magick::Color::redQuantum ( Magick::Quantum red_ ) -{ - _pixel->red = (double) red_; - _isValid = true; -} - -inline Magick::Quantum Magick::Color::redQuantum ( void ) const -{ - return MagickCore::ClampToQuantum(_pixel->red); -} - -inline void Magick::Color::greenQuantum ( Magick::Quantum green_ ) -{ - _pixel->green = (double) green_; - _isValid = true; -} - -inline Magick::Quantum Magick::Color::greenQuantum ( void ) const -{ - return MagickCore::ClampToQuantum(_pixel->green); -} - -inline void Magick::Color::blueQuantum ( Magick::Quantum blue_ ) -{ - _pixel->blue = (double) blue_; - _isValid = true; -} - -inline Magick::Quantum Magick::Color::blueQuantum ( void ) const -{ - return MagickCore::ClampToQuantum(_pixel->blue); -} - -inline void Magick::Color::alphaQuantum ( Magick::Quantum alpha_ ) -{ - _pixel->alpha = alpha_; - _isValid = true ; -} - -inline Magick::Quantum Magick::Color::alphaQuantum ( void ) const -{ - return MagickCore::ClampToQuantum(_pixel->alpha); -} -// Return ImageMagick PixelInfo struct based on color. -inline Magick::Color::operator MagickCore::PixelInfo () const -{ - return *_pixel; -} - -// Scaled version of alpha for use in sub-classes -inline void Magick::Color::alpha ( double alpha_ ) -{ - alphaQuantum( scaleDoubleToQuantum(alpha_) ); -} -inline double Magick::Color::alpha ( void ) const -{ - return scaleQuantumToDouble( alphaQuantum() ); -} + // Default constructor + ColorYUV(void); -// -// ColorHSL -// -inline Magick::ColorHSL::ColorHSL ( Magick::PixelInfo* rep_, - Magick::Color::PixelType pixelType_ ) -: Color( rep_, pixelType_ ) -{ -} + // Copy constructor + ColorYUV(const Color &color_); -// -// ColorGray -// -inline Magick::ColorGray::ColorGray ( Magick::PixelInfo* rep_, - Magick::Color::PixelType pixelType_ ) -: Color( rep_, pixelType_ ) -{ -} + // Construct ColorYUV using the specified YUV values + ColorYUV(const double y_,const double u_,const double v_); -// -// ColorMono -// -inline Magick::ColorMono::ColorMono ( Magick::PixelInfo* rep_, - Magick::Color::PixelType pixelType_ ) - : Color( rep_, pixelType_ ) -{ -} + // Destructor + ~ColorYUV(void); -// -// ColorRGB -// -inline Magick::ColorRGB::ColorRGB ( Magick::PixelInfo* rep_, - Magick::Color::PixelType pixelType_ ) - : Color( rep_, pixelType_ ) -{ -} + // Assignment operator from base class + ColorYUV& operator=(const Color& color_); -inline void Magick::ColorRGB::red ( double red_ ) -{ - redQuantum( scaleDoubleToQuantum(red_) ); -} + // Color U (0.0 through 1.0) + void u(const double u_); + double u(void) const; -inline double Magick::ColorRGB::red ( void ) const -{ - return scaleQuantumToDouble( redQuantum() ); -} + // Color V (-0.5 through 0.5) + void v(const double v_); + double v(void) const; -inline void Magick::ColorRGB::green ( double green_ ) -{ - greenQuantum( scaleDoubleToQuantum(green_) ); -} + // Color Y (-0.5 through 0.5) + void y(const double y_); + double y(void) const; -inline double Magick::ColorRGB::green ( void ) const -{ - return scaleQuantumToDouble( greenQuantum() ); -} + protected: -inline void Magick::ColorRGB::blue ( double blue_ ) -{ - blueQuantum( scaleDoubleToQuantum(blue_) ); -} + // Constructor to construct with PixelInfo* + ColorYUV(PixelInfo *rep_,PixelType pixelType_); -inline double Magick::ColorRGB::blue ( void ) const -{ - return scaleQuantumToDouble( blueQuantum() ); -} + private: -// -// ColorYUV -// + void convert(const double y_,const double u_,const double v_); -inline Magick::ColorYUV::ColorYUV ( Magick::PixelInfo* rep_, - Magick::Color::PixelType pixelType_ ) - : Color( rep_, pixelType_ ) -{ -} + }; +} // namespace Magick #endif // Magick_Color_header diff --git a/Magick++/lib/Magick++/STL.h b/Magick++/lib/Magick++/STL.h index 95ef0e171..7c107021d 100644 --- a/Magick++/lib/Magick++/STL.h +++ b/Magick++/lib/Magick++/STL.h @@ -2513,13 +2513,13 @@ namespace Magick names_->clear(); - MagickCore::ResetImageProfileIterator( image_->constImage() ); - name=MagickCore::GetNextImageProfile( image_->constImage() ); - while (name != (const char *) NULL) - { - names_->push_back( std::string(name) ); - name=MagickCore::GetNextImageProfile( image_->constImage() ); - } + MagickCore::ResetImageProfileIterator( image_->constImage() ); + name=MagickCore::GetNextImageProfile( image_->constImage() ); + while (name != (const char *) NULL) + { + names_->push_back( std::string(name) ); + name=MagickCore::GetNextImageProfile( image_->constImage() ); + } } // Quantize colors in images using current quantization settings diff --git a/Magick++/tests/attributes.cpp b/Magick++/tests/attributes.cpp index c065f24fe..4048be755 100644 --- a/Magick++/tests/attributes.cpp +++ b/Magick++/tests/attributes.cpp @@ -154,7 +154,7 @@ int main( int /*argc*/, char ** argv) // // Test default value. - if ( image.backgroundColor() != ColorRGB("white") ) + if ( image.backgroundColor() != ColorRGBA("white") ) { ++failures; cout << "Line: " << __LINE__ << ", backgroundColor default (" @@ -288,7 +288,7 @@ int main( int /*argc*/, char ** argv) // // borderColor // - if ( image.borderColor() != ColorRGB("#dfdfdf") ) + if ( image.borderColor() != ColorRGBA("#dfdfdf") ) { ++failures; cout << "Line: " << __LINE__ @@ -941,8 +941,8 @@ int main( int /*argc*/, char ** argv) } // Test set/get - image.matteColor(ColorRGB(0.5,0.5,1)); - if ( image.matteColor() != ColorRGB(0.5,0.5,1) ) + image.matteColor(ColorRGBA(0.5,0.5,1)); + if ( image.matteColor() != ColorRGBA(0.5,0.5,1) ) { ++failures; cout << "Line: " << __LINE__ << ", matteColor set/get failed" << endl; @@ -1028,8 +1028,8 @@ int main( int /*argc*/, char ** argv) // penColor // - image.penColor(ColorRGB(0.5,0.5,1)); - if ( image.penColor() != ColorRGB(0.5,0.5,1) ) + image.penColor(ColorRGBA(0.5,0.5,1)); + if ( image.penColor() != ColorRGBA(0.5,0.5,1) ) { ++failures; cout << "Line: " << __LINE__ << ", penColor (" @@ -1041,8 +1041,8 @@ int main( int /*argc*/, char ** argv) // strokeColor // - image.strokeColor(ColorRGB(0.5,0.5,1)); - if ( image.strokeColor() != ColorRGB(0.5,0.5,1) ) + image.strokeColor(ColorRGBA(0.5,0.5,1)); + if ( image.strokeColor() != ColorRGBA(0.5,0.5,1) ) { ++failures; cout << "Line: " << __LINE__ << ", strokeColor (" @@ -1055,8 +1055,8 @@ int main( int /*argc*/, char ** argv) // fillColor // - image.fillColor(ColorRGB(0.5,0.5,1)); - if ( image.fillColor() != ColorRGB(0.5,0.5,1) ) + image.fillColor(ColorRGBA(0.5,0.5,1)); + if ( image.fillColor() != ColorRGBA(0.5,0.5,1) ) { ++failures; cout << "Line: " << __LINE__ << ", fillColor (" @@ -1079,8 +1079,8 @@ int main( int /*argc*/, char ** argv) } // Test set/get - image.pixelColor(40,60, ColorRGB(0.5,1,1)); - if ( image.pixelColor(40,60) != ColorRGB(0.5,1,1) ) + image.pixelColor(40,60, ColorRGBA(0.5,1,1)); + if ( image.pixelColor(40,60) != ColorRGBA(0.5,1,1) ) { ++failures; cout << "Line: " << __LINE__ << ", pixelColor set/get failed" << endl; diff --git a/Magick++/tests/color.cpp b/Magick++/tests/color.cpp index 0ce2ebc00..bfbcaf49e 100644 --- a/Magick++/tests/color.cpp +++ b/Magick++/tests/color.cpp @@ -24,7 +24,7 @@ int main( int /*argc*/, char **argv) try { // - // Verify conversion from named colors as well as ColorRGB constructor + // Verify conversion from named colors as well as ColorRGBA constructor // { @@ -54,7 +54,7 @@ int main( int /*argc*/, char **argv) { { Color color( colorMap[i].color ); - ColorRGB colorMatch( colorMap[i].red, + ColorRGBA colorMatch( colorMap[i].red, colorMap[i].green, colorMap[i].blue ); if ( color != colorMatch ) -- 2.40.0