From 28efdf1695a9a689c74287e8bf42d1b7c5f1ca0b Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sat, 11 Jun 2016 17:36:06 +0100 Subject: [PATCH] working! --- ChangeLog | 1 + TODO | 9 +- cplusplus/VImage.cpp | 185 ++++++++++++++++++++++++++++++- cplusplus/include/vips/VImage8.h | 62 +++++------ 4 files changed, 217 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6cee415f..72237578 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21,6 +21,7 @@ combine many images in bounded memory - VImage::write() implementation was missing - VImage::write() return value changed from void to VImage to help chaining +- added C++ arithmetic assignment overloads, += etc. 18/5/16 started 8.3.2 - more robust vips image reading diff --git a/TODO b/TODO index 447e5f59..84de1b53 100644 --- a/TODO +++ b/TODO @@ -1,11 +1,4 @@ -- could add operator+= and friends to allow this - - VImage im = ...; - VImage x = ...; - - im += x; - - unlike Python, C++ will not do this automatically +- add tests for C++ += etc. - add more webp tests to py suite diff --git a/cplusplus/VImage.cpp b/cplusplus/VImage.cpp index 7f9d8187..4b8b34f2 100644 --- a/cplusplus/VImage.cpp +++ b/cplusplus/VImage.cpp @@ -4,6 +4,8 @@ * - allow set enum value from string * 10/6/16 * - missing implementation of VImage::write() + * 11/6/16 + * - added arithmetic assignment overloads, += etc. */ /* @@ -766,13 +768,32 @@ operator+( VImage a, std::vector b ) return( a.linear( 1.0, b ) ); } +VImage & +VImage::operator+=( const VImage b ) +{ + return( *this = *this + b ); +} + +VImage & +VImage::operator+=( const double b ) +{ + return( *this = *this + b ); +} + +VImage & +VImage::operator+=( std::vector b ) +{ + return( *this = *this + b ); +} + VImage operator-( VImage a, VImage b ) { return( a.subtract( b ) ); } -VImage operator-( double a, VImage b ) +VImage +operator-( double a, VImage b ) { return( b.linear( -1.0, a ) ); } @@ -795,6 +816,24 @@ operator-( VImage a, std::vector b ) return( a.linear( 1.0, vips::negate( b ) ) ); } +VImage & +VImage::operator-=( const VImage b ) +{ + return( *this = *this - b ); +} + +VImage & +VImage::operator-=( const double b ) +{ + return( *this = *this - b ); +} + +VImage & +VImage::operator-=( std::vector b ) +{ + return( *this = *this - b ); +} + VImage operator-( VImage a ) { @@ -831,6 +870,24 @@ operator*( VImage a, std::vector b ) return( a.linear( b, 0.0 ) ); } +VImage & +VImage::operator*=( const VImage b ) +{ + return( *this = *this * b ); +} + +VImage & +VImage::operator*=( const double b ) +{ + return( *this = *this * b ); +} + +VImage & +VImage::operator*=( std::vector b ) +{ + return( *this = *this * b ); +} + VImage operator/( VImage a, VImage b ) { @@ -861,6 +918,24 @@ operator/( VImage a, std::vector b ) return( a.linear( vips::invert( b ), 0.0 ) ); } +VImage & +VImage::operator/=( const VImage b ) +{ + return( *this = *this / b ); +} + +VImage & +VImage::operator/=( const double b ) +{ + return( *this = *this / b ); +} + +VImage & +VImage::operator/=( std::vector b ) +{ + return( *this = *this / b ); +} + VImage operator%( VImage a, VImage b ) { @@ -879,6 +954,24 @@ operator%( VImage a, std::vector b ) return( a.remainder_const( b ) ); } +VImage & +VImage::operator%=( const VImage b ) +{ + return( *this = *this % b ); +} + +VImage & +VImage::operator%=( const double b ) +{ + return( *this = *this % b ); +} + +VImage & +VImage::operator%=( std::vector b ) +{ + return( *this = *this % b ); +} + VImage operator<( VImage a, VImage b ) { @@ -1115,6 +1208,24 @@ operator&( VImage a, std::vector b ) return( a.boolean_const( b, VIPS_OPERATION_BOOLEAN_AND ) ); } +VImage & +VImage::operator&=( const VImage b ) +{ + return( *this = *this & b ); +} + +VImage & +VImage::operator&=( const double b ) +{ + return( *this = *this & b ); +} + +VImage & +VImage::operator&=( std::vector b ) +{ + return( *this = *this & b ); +} + VImage operator|( VImage a, VImage b ) { @@ -1147,6 +1258,24 @@ operator|( VImage a, std::vector b ) return( a.boolean_const( b, VIPS_OPERATION_BOOLEAN_OR ) ); } +VImage & +VImage::operator|=( const VImage b ) +{ + return( *this = *this | b ); +} + +VImage & +VImage::operator|=( const double b ) +{ + return( *this = *this | b ); +} + +VImage & +VImage::operator|=( std::vector b ) +{ + return( *this = *this | b ); +} + VImage operator^( VImage a, VImage b ) { @@ -1179,6 +1308,24 @@ operator^( VImage a, std::vector b ) return( a.boolean_const( b, VIPS_OPERATION_BOOLEAN_EOR ) ); } +VImage & +VImage::operator^=( const VImage b ) +{ + return( *this = *this ^ b ); +} + +VImage & +VImage::operator^=( const double b ) +{ + return( *this = *this ^ b ); +} + +VImage & +VImage::operator^=( std::vector b ) +{ + return( *this = *this ^ b ); +} + VImage operator<<( VImage a, VImage b ) { @@ -1198,6 +1345,24 @@ operator<<( VImage a, std::vector b ) return( a.boolean_const( b, VIPS_OPERATION_BOOLEAN_LSHIFT ) ); } +VImage & +VImage::operator<<=( const VImage b ) +{ + return( *this = *this << b ); +} + +VImage & +VImage::operator<<=( const double b ) +{ + return( *this = *this << b ); +} + +VImage & +VImage::operator<<=( std::vector b ) +{ + return( *this = *this << b ); +} + VImage operator>>( VImage a, VImage b ) { @@ -1217,4 +1382,22 @@ operator>>( VImage a, std::vector b ) return( a.boolean_const( b, VIPS_OPERATION_BOOLEAN_RSHIFT ) ); } +VImage & +VImage::operator>>=( const VImage b ) +{ + return( *this = *this << b ); +} + +VImage & +VImage::operator>>=( const double b ) +{ + return( *this = *this << b ); +} + +VImage & +VImage::operator>>=( std::vector b ) +{ + return( *this = *this << b ); +} + VIPS_NAMESPACE_END diff --git a/cplusplus/include/vips/VImage8.h b/cplusplus/include/vips/VImage8.h index d7bd2235..c7b29d57 100644 --- a/cplusplus/include/vips/VImage8.h +++ b/cplusplus/include/vips/VImage8.h @@ -781,11 +781,9 @@ public: friend VImage VIPS_CPLUSPLUS_API operator+( std::vector a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator+( VImage a, std::vector b ); - VImage VIPS_CPLUSPLUS_API &operator+=( const VImage &b ) - - friend VImage VIPS_CPLUSPLUS_API operator+=( VImage a ); - friend VImage VIPS_CPLUSPLUS_API operator+=( double a ); - friend VImage VIPS_CPLUSPLUS_API operator+=( std::vector a ); + VImage & VIPS_CPLUSPLUS_API operator+=( const VImage b ); + VImage & VIPS_CPLUSPLUS_API operator+=( const double b ); + VImage & VIPS_CPLUSPLUS_API operator+=( const std::vector b ); friend VImage VIPS_CPLUSPLUS_API operator-( VImage a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator-( double a, VImage b ); @@ -793,9 +791,9 @@ public: friend VImage VIPS_CPLUSPLUS_API operator-( std::vector a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator-( VImage a, std::vector b ); - friend VImage VIPS_CPLUSPLUS_API operator-=( VImage a ); - friend VImage VIPS_CPLUSPLUS_API operator-=( double a ); - friend VImage VIPS_CPLUSPLUS_API operator-=( std::vector a ); + VImage & VIPS_CPLUSPLUS_API operator-=( const VImage b ); + VImage & VIPS_CPLUSPLUS_API operator-=( const double b ); + VImage & VIPS_CPLUSPLUS_API operator-=( const std::vector b ); friend VImage VIPS_CPLUSPLUS_API operator-( VImage a ); @@ -805,9 +803,9 @@ public: friend VImage VIPS_CPLUSPLUS_API operator*( std::vector a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator*( VImage a, std::vector b ); - friend VImage VIPS_CPLUSPLUS_API operator*=( VImage a ); - friend VImage VIPS_CPLUSPLUS_API operator*=( double a ); - friend VImage VIPS_CPLUSPLUS_API operator*=( std::vector a ); + VImage & VIPS_CPLUSPLUS_API operator*=( const VImage b ); + VImage & VIPS_CPLUSPLUS_API operator*=( const double b ); + VImage & VIPS_CPLUSPLUS_API operator*=( const std::vector b ); friend VImage VIPS_CPLUSPLUS_API operator/( VImage a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator/( double a, VImage b ); @@ -815,18 +813,18 @@ public: friend VImage VIPS_CPLUSPLUS_API operator/( std::vector a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator/( VImage a, std::vector b ); - friend VImage VIPS_CPLUSPLUS_API operator/=( VImage a ); - friend VImage VIPS_CPLUSPLUS_API operator/=( double a ); - friend VImage VIPS_CPLUSPLUS_API operator/=( std::vector a ); + VImage & VIPS_CPLUSPLUS_API operator/=( const VImage b ); + VImage & VIPS_CPLUSPLUS_API operator/=( const double b ); + VImage & VIPS_CPLUSPLUS_API operator/=( const std::vector b ); friend VImage VIPS_CPLUSPLUS_API operator%( VImage a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator%( VImage a, double b ); friend VImage VIPS_CPLUSPLUS_API operator%( VImage a, std::vector b ); - friend VImage VIPS_CPLUSPLUS_API operator%=( VImage a ); - friend VImage VIPS_CPLUSPLUS_API operator%=( double a ); - friend VImage VIPS_CPLUSPLUS_API operator%=( std::vector a ); -% + VImage & VIPS_CPLUSPLUS_API operator%=( const VImage b ); + VImage & VIPS_CPLUSPLUS_API operator%=( const double b ); + VImage & VIPS_CPLUSPLUS_API operator%=( const std::vector b ); + friend VImage VIPS_CPLUSPLUS_API operator<( VImage a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator<( double a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator<( VImage a, double b ); @@ -869,9 +867,9 @@ public: friend VImage VIPS_CPLUSPLUS_API operator&( std::vector a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator&( VImage a, std::vector b ); - friend VImage VIPS_CPLUSPLUS_API operator&=( VImage a ); - friend VImage VIPS_CPLUSPLUS_API operator&=( double a ); - friend VImage VIPS_CPLUSPLUS_API operator&=( std::vector a ); + VImage & VIPS_CPLUSPLUS_API operator&=( const VImage b ); + VImage & VIPS_CPLUSPLUS_API operator&=( const double b ); + VImage & VIPS_CPLUSPLUS_API operator&=( const std::vector b ); friend VImage VIPS_CPLUSPLUS_API operator|( VImage a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator|( double a, VImage b ); @@ -879,9 +877,9 @@ public: friend VImage VIPS_CPLUSPLUS_API operator|( std::vector a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator|( VImage a, std::vector b ); - friend VImage VIPS_CPLUSPLUS_API operator|=( VImage a ); - friend VImage VIPS_CPLUSPLUS_API operator|=( double a ); - friend VImage VIPS_CPLUSPLUS_API operator|=( std::vector a ); + VImage & VIPS_CPLUSPLUS_API operator|=( const VImage b ); + VImage & VIPS_CPLUSPLUS_API operator|=( const double b ); + VImage & VIPS_CPLUSPLUS_API operator|=( const std::vector b ); friend VImage VIPS_CPLUSPLUS_API operator^( VImage a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator^( double a, VImage b ); @@ -889,23 +887,25 @@ public: friend VImage VIPS_CPLUSPLUS_API operator^( std::vector a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator^( VImage a, std::vector b ); - friend VImage VIPS_CPLUSPLUS_API operator^=( VImage a ); - friend VImage VIPS_CPLUSPLUS_API operator^=( double a ); - friend VImage VIPS_CPLUSPLUS_API operator^=( std::vector a ); + VImage & VIPS_CPLUSPLUS_API operator^=( const VImage b ); + VImage & VIPS_CPLUSPLUS_API operator^=( const double b ); + VImage & VIPS_CPLUSPLUS_API operator^=( const std::vector b ); friend VImage VIPS_CPLUSPLUS_API operator<<( VImage a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator<<( VImage a, double b ); friend VImage VIPS_CPLUSPLUS_API operator<<( VImage a, std::vector b ); - friend VImage VIPS_CPLUSPLUS_API operator<<=( double a ); - friend VImage VIPS_CPLUSPLUS_API operator<<=( std::vector a ); + VImage & VIPS_CPLUSPLUS_API operator<<=( const VImage b ); + VImage & VIPS_CPLUSPLUS_API operator<<=( const double b ); + VImage & VIPS_CPLUSPLUS_API operator<<=( const std::vector b ); friend VImage VIPS_CPLUSPLUS_API operator>>( VImage a, VImage b ); friend VImage VIPS_CPLUSPLUS_API operator>>( VImage a, double b ); friend VImage VIPS_CPLUSPLUS_API operator>>( VImage a, std::vector b ); - friend VImage VIPS_CPLUSPLUS_API operator>>=( double a ); - friend VImage VIPS_CPLUSPLUS_API operator>>=( std::vector a ); + VImage & VIPS_CPLUSPLUS_API operator>>=( const VImage b ); + VImage & VIPS_CPLUSPLUS_API operator>>=( const double b ); + VImage & VIPS_CPLUSPLUS_API operator>>=( const std::vector b ); };