From e61f9e4bea62d3910a563413b673fb70ea292639 Mon Sep 17 00:00:00 2001 From: asl Date: Wed, 17 Jul 2013 06:21:33 +0000 Subject: [PATCH] now the operators have constructors without arguments and allows getting/setting arguments in binary form --- src/ImageComposer/ImageComposer.h | 2 +- .../ImageComposer_ColorMaskOperator.cxx | 53 +++++++++++++----- .../ImageComposer_ColorMaskOperator.h | 15 ++++-- .../ImageComposer_CropOperator.cxx | 44 +++++++++++---- .../ImageComposer_CropOperator.h | 11 +++- .../ImageComposer_CutOperator.cxx | 5 +- src/ImageComposer/ImageComposer_CutOperator.h | 2 +- .../ImageComposer_FuseOperator.cxx | 5 +- .../ImageComposer_FuseOperator.h | 2 +- src/ImageComposer/ImageComposer_Image.cxx | 16 ++++-- src/ImageComposer/ImageComposer_Operator.cxx | 54 +++++++++++++++++-- src/ImageComposer/ImageComposer_Operator.h | 11 +++- 12 files changed, 174 insertions(+), 46 deletions(-) diff --git a/src/ImageComposer/ImageComposer.h b/src/ImageComposer/ImageComposer.h index c759c8f84..13d2d232e 100644 --- a/src/ImageComposer/ImageComposer.h +++ b/src/ImageComposer/ImageComposer.h @@ -1,7 +1,7 @@ #ifdef WIN32 - #ifdef IMAGECOMPOSER_EXPORTS + #ifdef IMAGE_COMPOSER_EXPORTS #define IMAGE_COMPOSER_API __declspec( dllexport ) #else #define IMAGE_COMPOSER_API __declspec( dllimport ) diff --git a/src/ImageComposer/ImageComposer_ColorMaskOperator.cxx b/src/ImageComposer/ImageComposer_ColorMaskOperator.cxx index b0ceddc9c..9a1110679 100644 --- a/src/ImageComposer/ImageComposer_ColorMaskOperator.cxx +++ b/src/ImageComposer/ImageComposer_ColorMaskOperator.cxx @@ -8,19 +8,11 @@ /** Constructor - @param theRefColor the color to the searched (the color for mask) - @param isMakeTransparent the boolean flag controlling if the pixels with matching color - should be made transparent or one with non-matching color - @param theRGBThreshold the threshold for RGB components - @param theAlphaThreshold the threshold for Alpha component */ -ImageComposer_ColorMaskOperator::ImageComposer_ColorMaskOperator( const QColor& theRefColor, - bool isMakeTransparent, - int theRGBThreshold, - int theAlphaThreshold ) -: ImageComposer_Operator( TRANSPARENT ), - myRefColor( theRefColor ), myIsMakeTransparent( isMakeTransparent ), - myRGBThreshold( theRGBThreshold ), myAlphaThreshold( theAlphaThreshold ) +ImageComposer_ColorMaskOperator::ImageComposer_ColorMaskOperator() +: ImageComposer_Operator(), + myRefColor( Qt::black ), myIsMakeTransparent( false ), + myRGBThreshold( 0 ), myAlphaThreshold( 0 ) { } @@ -30,6 +22,25 @@ ImageComposer_ColorMaskOperator::~ImageComposer_ColorMaskOperator() { } +/** + Set operator arguments + @param theRefColor the color to the searched (the color for mask) + @param isMakeTransparent the boolean flag controlling if the pixels with matching color + should be made transparent or one with non-matching color + @param theRGBThreshold the threshold for RGB components + @param theAlphaThreshold the threshold for Alpha component +*/ +void ImageComposer_ColorMaskOperator::setArgs( const QColor& theRefColor, + bool isMakeTransparent, + int theRGBThreshold, + int theAlphaThreshold ) +{ + myRefColor = theRefColor; + myIsMakeTransparent = isMakeTransparent; + myRGBThreshold = theRGBThreshold; + myAlphaThreshold = theAlphaThreshold; +} + /** */ QString ImageComposer_ColorMaskOperator::name() const @@ -84,3 +95,21 @@ void ImageComposer_ColorMaskOperator::drawResult( QPainter& thePainter, aResult.setTransform( theImage1.transform() ); aResult.draw( thePainter ); } + +void ImageComposer_ColorMaskOperator::storeArgs( QDataStream& theStream ) const +{ + ImageComposer_Operator::storeArgs( theStream ); + theStream << myRefColor; + theStream << myIsMakeTransparent; + theStream << myRGBThreshold; + theStream << myAlphaThreshold; +} + +void ImageComposer_ColorMaskOperator::restoreArgs( QDataStream& theStream ) +{ + ImageComposer_Operator::restoreArgs( theStream ); + theStream >> myRefColor; + theStream >> myIsMakeTransparent; + theStream >> myRGBThreshold; + theStream >> myAlphaThreshold; +} diff --git a/src/ImageComposer/ImageComposer_ColorMaskOperator.h b/src/ImageComposer/ImageComposer_ColorMaskOperator.h index 15b15aa6d..d3b6ec67c 100644 --- a/src/ImageComposer/ImageComposer_ColorMaskOperator.h +++ b/src/ImageComposer/ImageComposer_ColorMaskOperator.h @@ -12,12 +12,14 @@ class IMAGE_COMPOSER_API ImageComposer_ColorMaskOperator : public ImageComposer_Operator { public: - ImageComposer_ColorMaskOperator( const QColor& theRefColor, - bool isMakeTransparent, - int theRGBThreshold, - int theAlphaThreshold ); + ImageComposer_ColorMaskOperator(); virtual ~ImageComposer_ColorMaskOperator(); + void setArgs( const QColor& theRefColor, + bool isMakeTransparent, + int theRGBThreshold, + int theAlphaThreshold ); + virtual QString name() const; protected: @@ -26,7 +28,12 @@ protected: virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1, const ImageComposer_Image& theImage2 ) const; + virtual void storeArgs( QDataStream& theStream ) const; + virtual void restoreArgs( QDataStream& theStream ); + private: + friend class ImageComposerTests_TestOperators; + QColor myRefColor; ///< the color to the searched (the color for mask) bool myIsMakeTransparent; ///< the boolean flag controlling if the pixels with matching color ///< should be made transparent or one with non-matching color diff --git a/src/ImageComposer/ImageComposer_CropOperator.cxx b/src/ImageComposer/ImageComposer_CropOperator.cxx index a1de87547..bacee5a7f 100644 --- a/src/ImageComposer/ImageComposer_CropOperator.cxx +++ b/src/ImageComposer/ImageComposer_CropOperator.cxx @@ -6,30 +6,39 @@ /** Constructor - @param theBackground the background color for result image - @param theRect the cropping rectangle (in the global CS) */ -ImageComposer_CropOperator::ImageComposer_CropOperator( const QColor& theBackground, const QRect& theRect ) -: ImageComposer_Operator( theBackground ) +ImageComposer_CropOperator::ImageComposer_CropOperator() +: ImageComposer_Operator() { - myClipPath.addRect( theRect ); } /** - Constructor +*/ +ImageComposer_CropOperator::~ImageComposer_CropOperator() +{ +} + +/** + Set operator arguments @param theBackground the background color for result image - @param thePath the cropping path (in the global CS) + @param theRect the cropping rectangle (in the global CS) */ -ImageComposer_CropOperator::ImageComposer_CropOperator( const QColor& theBackground, const QPainterPath& thePath ) -: ImageComposer_Operator( theBackground ) +void ImageComposer_CropOperator::setArgs( const QColor& theBackground, const QRect& theRect ) { - myClipPath = thePath; + ImageComposer_Operator::setArgs( theBackground ); + myClipPath = QPainterPath(); + myClipPath.addRect( theRect ); } /** + Set operator arguments + @param theBackground the background color for result image + @param thePath the cropping path (in the global CS) */ -ImageComposer_CropOperator::~ImageComposer_CropOperator() +void ImageComposer_CropOperator::setArgs( const QColor& theBackground, const QPainterPath& thePath ) { + ImageComposer_Operator::setArgs( theBackground ); + myClipPath = thePath; } /** @@ -84,3 +93,16 @@ ImageComposer_Image ImageComposer_CropOperator::process( const ImageComposer_Ima return ImageComposer_Operator::process( theImage1, theImage2 ); } + + +void ImageComposer_CropOperator::storeArgs( QDataStream& theStream ) const +{ + ImageComposer_Operator::storeArgs( theStream ); + theStream << myClipPath; +} + +void ImageComposer_CropOperator::restoreArgs( QDataStream& theStream ) +{ + ImageComposer_Operator::restoreArgs( theStream ); + theStream >> myClipPath; +} diff --git a/src/ImageComposer/ImageComposer_CropOperator.h b/src/ImageComposer/ImageComposer_CropOperator.h index a359249fd..d4a545990 100644 --- a/src/ImageComposer/ImageComposer_CropOperator.h +++ b/src/ImageComposer/ImageComposer_CropOperator.h @@ -13,10 +13,12 @@ class IMAGE_COMPOSER_API ImageComposer_CropOperator : public ImageComposer_Operator { public: - ImageComposer_CropOperator( const QColor& theBackground, const QRect& ); - ImageComposer_CropOperator( const QColor& theBackground, const QPainterPath& ); + ImageComposer_CropOperator(); virtual ~ImageComposer_CropOperator(); + void setArgs( const QColor& theBackground, const QRect& ); + void setArgs( const QColor& theBackground, const QPainterPath& ); + QPainterPath clipPath() const; virtual QString name() const; @@ -29,7 +31,12 @@ protected: virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1, const ImageComposer_Image& theImage2 ) const; + virtual void storeArgs( QDataStream& theStream ) const; + virtual void restoreArgs( QDataStream& theStream ); + private: + friend class ImageComposerTests_TestOperators; + QPainterPath myClipPath; ///< the clipping path specified initially QPainterPath myImgClipPath; ///< the clipping path mapped to first image's local CS }; diff --git a/src/ImageComposer/ImageComposer_CutOperator.cxx b/src/ImageComposer/ImageComposer_CutOperator.cxx index f516235b4..07af47e45 100644 --- a/src/ImageComposer/ImageComposer_CutOperator.cxx +++ b/src/ImageComposer/ImageComposer_CutOperator.cxx @@ -7,10 +7,9 @@ /** Constructor - @param theBackground the background color for result image */ -ImageComposer_CutOperator::ImageComposer_CutOperator( const QColor& theBackground ) - : ImageComposer_Operator( theBackground ) +ImageComposer_CutOperator::ImageComposer_CutOperator() + : ImageComposer_Operator() { } diff --git a/src/ImageComposer/ImageComposer_CutOperator.h b/src/ImageComposer/ImageComposer_CutOperator.h index 4df8224a8..fd12d3a2b 100644 --- a/src/ImageComposer/ImageComposer_CutOperator.h +++ b/src/ImageComposer/ImageComposer_CutOperator.h @@ -12,7 +12,7 @@ class IMAGE_COMPOSER_API ImageComposer_CutOperator : public ImageComposer_Operator { public: - ImageComposer_CutOperator( const QColor& theBackground ); + ImageComposer_CutOperator(); virtual ~ImageComposer_CutOperator(); virtual QString name() const; diff --git a/src/ImageComposer/ImageComposer_FuseOperator.cxx b/src/ImageComposer/ImageComposer_FuseOperator.cxx index 2c314e2e8..9012f8af9 100644 --- a/src/ImageComposer/ImageComposer_FuseOperator.cxx +++ b/src/ImageComposer/ImageComposer_FuseOperator.cxx @@ -7,10 +7,9 @@ /** Constructor - @param theBackground the background color for result image */ -ImageComposer_FuseOperator::ImageComposer_FuseOperator( const QColor& theBackground ) - : ImageComposer_Operator( theBackground ) +ImageComposer_FuseOperator::ImageComposer_FuseOperator() + : ImageComposer_Operator() { } diff --git a/src/ImageComposer/ImageComposer_FuseOperator.h b/src/ImageComposer/ImageComposer_FuseOperator.h index cffc368bf..a6ad4c001 100644 --- a/src/ImageComposer/ImageComposer_FuseOperator.h +++ b/src/ImageComposer/ImageComposer_FuseOperator.h @@ -12,7 +12,7 @@ class IMAGE_COMPOSER_API ImageComposer_FuseOperator : public ImageComposer_Operator { public: - ImageComposer_FuseOperator( const QColor& theBackground ); + ImageComposer_FuseOperator(); virtual ~ImageComposer_FuseOperator(); virtual QString name() const; diff --git a/src/ImageComposer/ImageComposer_Image.cxx b/src/ImageComposer/ImageComposer_Image.cxx index d08eb7b64..1d9ede6dc 100644 --- a/src/ImageComposer/ImageComposer_Image.cxx +++ b/src/ImageComposer/ImageComposer_Image.cxx @@ -137,7 +137,9 @@ void ImageComposer_Image::setDefaultBackground( const QColor& theDefaultBackgrou */ ImageComposer_Image ImageComposer_Image::operator & ( const QRect& theRect ) const { - return apply( ImageComposer_CropOperator( myDefaultBackground, theRect ) ); + ImageComposer_CropOperator anOp; + anOp.setArgs( myDefaultBackground, theRect ); + return apply( anOp ); } /** @@ -147,7 +149,9 @@ ImageComposer_Image ImageComposer_Image::operator & ( const QRect& theRect ) con */ ImageComposer_Image ImageComposer_Image::operator & ( const QPainterPath& thePath ) const { - return apply( ImageComposer_CropOperator( myDefaultBackground, thePath ) ); + ImageComposer_CropOperator anOp; + anOp.setArgs( myDefaultBackground, thePath ); + return apply( anOp ); } /** @@ -157,7 +161,9 @@ ImageComposer_Image ImageComposer_Image::operator & ( const QPainterPath& thePat */ ImageComposer_Image ImageComposer_Image::operator & ( const ImageComposer_Image& theImage ) const { - return apply( ImageComposer_CutOperator( myDefaultBackground ), theImage ); + ImageComposer_CutOperator anOp; + anOp.setArgs( myDefaultBackground ); + return apply( anOp, theImage ); } /** @@ -167,5 +173,7 @@ ImageComposer_Image ImageComposer_Image::operator & ( const ImageComposer_Image& */ ImageComposer_Image ImageComposer_Image::operator | ( const ImageComposer_Image& theImage ) const { - return apply( ImageComposer_FuseOperator( myDefaultBackground ), theImage ); + ImageComposer_FuseOperator anOp; + anOp.setArgs( myDefaultBackground ); + return apply( anOp, theImage ); } diff --git a/src/ImageComposer/ImageComposer_Operator.cxx b/src/ImageComposer/ImageComposer_Operator.cxx index 451629cfa..882015e3f 100644 --- a/src/ImageComposer/ImageComposer_Operator.cxx +++ b/src/ImageComposer/ImageComposer_Operator.cxx @@ -6,10 +6,9 @@ /** Constructor - @param theBackground the background color for result image */ -ImageComposer_Operator::ImageComposer_Operator( const QColor& theBackground ) -: myBackground( theBackground ) +ImageComposer_Operator::ImageComposer_Operator() +: myBackground( TRANSPARENT ) { } @@ -20,6 +19,15 @@ ImageComposer_Operator::~ImageComposer_Operator() { } +/** + Set operator arguments + @param theBackground the background color for result image +*/ +void ImageComposer_Operator::setArgs( const QColor& theBackground ) +{ + myBackground = theBackground; +} + /** Return name of the operator @return name of the operator @@ -73,3 +81,43 @@ ImageComposer_Image ImageComposer_Operator::process( const ImageComposer_Image& aResult.setTransform( aResultTransform ); return aResult; } + +/** + Get the operator's arguments in the form of a binary array + @return the binary array with arguments +*/ +QByteArray ImageComposer_Operator::getBinArgs() const +{ + QByteArray aData; + QDataStream aStream( &aData, QIODevice::WriteOnly ); + storeArgs( aStream ); + return aData; +} + +/** + Set the operator's arguments in the form of a binary array + @param theData the binary array with arguments +*/ +void ImageComposer_Operator::setBinArgs( const QByteArray& theData ) +{ + QDataStream aStream( theData ); + restoreArgs( aStream ); +} + +/** + Store the operator's arguments to the stream + @param theStream the stream for storing +*/ +void ImageComposer_Operator::storeArgs( QDataStream& theStream ) const +{ + theStream << myBackground; +} + +/** + Restore the operator's arguments from the stream + @param theStream the stream for restoring +*/ +void ImageComposer_Operator::restoreArgs( QDataStream& theStream ) +{ + theStream >> myBackground; +} diff --git a/src/ImageComposer/ImageComposer_Operator.h b/src/ImageComposer/ImageComposer_Operator.h index 3a21be3fa..b54552ddb 100644 --- a/src/ImageComposer/ImageComposer_Operator.h +++ b/src/ImageComposer/ImageComposer_Operator.h @@ -20,9 +20,13 @@ const QColor TRANSPARENT( 255, 255, 255, 0 ); class IMAGE_COMPOSER_API ImageComposer_Operator { public: - ImageComposer_Operator( const QColor& theBackground ); + ImageComposer_Operator(); virtual ~ImageComposer_Operator(); + void setArgs( const QColor& theBackground ); + QByteArray getBinArgs() const; + void setBinArgs( const QByteArray& ); + virtual QString name() const; virtual ImageComposer_Image process( const ImageComposer_Image& theImage1, const ImageComposer_Image& theImage2 ) const; @@ -46,7 +50,12 @@ protected: virtual void drawResult( QPainter& thePainter, const ImageComposer_Image& theImage1, const ImageComposer_Image& theImage2 ) const = 0; + virtual void storeArgs( QDataStream& theStream ) const; + virtual void restoreArgs( QDataStream& theStream ); + private: + friend class ImageComposerTests_TestOperators; + QColor myBackground; ///< the background color for result image }; -- 2.39.2