From cd340d0ace849fdea851d3e070a36fc11184d551 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Thu, 10 Jan 2019 14:56:04 +0100 Subject: [PATCH 1/5] Add missing C++ functions The functions has_alpha() and copy_memory() were missing from the C++ binding. --- cplusplus/include/vips/VImage8.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cplusplus/include/vips/VImage8.h b/cplusplus/include/vips/VImage8.h index d7b745fe..4eee3113 100644 --- a/cplusplus/include/vips/VImage8.h +++ b/cplusplus/include/vips/VImage8.h @@ -327,6 +327,12 @@ public: return( vips_image_get_yoffset( get_image() ) ); } + bool + has_alpha() const + { + return( vips_image_hasalpha( get_image() ) ); + } + const char * filename() const { @@ -495,6 +501,17 @@ public: return( new_from_image( to_vectorv( 1, pixel ) ) ); } + VImage + copy_memory() const + { + VipsImage *image; + + if( !(image = vips_image_copy_memory( this->get_image() )) ) + throw( VError() ); + + return( VImage( image ) ); + } + VImage write( VImage out ) const; void write_to_file( const char *name, VOption *options = 0 ) const; From bd5711ef8ef4957aaae5b7e48b0edc0fd0d578d7 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Thu, 10 Jan 2019 17:39:45 +0100 Subject: [PATCH 2/5] Add remove function to the C++ binding To remove an item of metadata. --- cplusplus/include/vips/VImage8.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cplusplus/include/vips/VImage8.h b/cplusplus/include/vips/VImage8.h index 4eee3113..c9e3471f 100644 --- a/cplusplus/include/vips/VImage8.h +++ b/cplusplus/include/vips/VImage8.h @@ -422,6 +422,12 @@ public: return( value ); } + bool + remove( const char *name ) const + { + return( vips_image_remove( get_image(), name ) ); + } + static VOption * option() { From c397543c8e1710d57d61e788a72dfd84e8aeabf0 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Fri, 11 Jan 2019 13:25:40 +0100 Subject: [PATCH 3/5] Add a std::string overload function for new_from_buffer --- cplusplus/VError.cpp | 2 -- cplusplus/VImage.cpp | 9 ++++++++- cplusplus/include/vips/VError8.h | 6 +++--- cplusplus/include/vips/VImage8.h | 7 +++++-- cplusplus/include/vips/VInterpolate8.h | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/cplusplus/VError.cpp b/cplusplus/VError.cpp index 67e67348..a3d82188 100644 --- a/cplusplus/VError.cpp +++ b/cplusplus/VError.cpp @@ -32,8 +32,6 @@ #endif /*HAVE_CONFIG_H*/ #include -#include - #include VIPS_NAMESPACE_START diff --git a/cplusplus/VImage.cpp b/cplusplus/VImage.cpp index 3c1acd98..205b46cb 100644 --- a/cplusplus/VImage.cpp +++ b/cplusplus/VImage.cpp @@ -563,7 +563,7 @@ VImage::new_from_file( const char *name, VOption *options ) } VImage -VImage::new_from_buffer( void *buf, size_t len, const char *option_string, +VImage::new_from_buffer( const void *buf, size_t len, const char *option_string, VOption *options ) { const char *operation_name; @@ -588,6 +588,13 @@ VImage::new_from_buffer( void *buf, size_t len, const char *option_string, return( out ); } +VImage +VImage::new_from_buffer( const std::string &buf, const char *option_string, + VOption *options ) +{ + return( new_from_buffer( buf.c_str(), buf.size(), option_string, options ) ); +} + VImage VImage::new_matrix( int width, int height ) { diff --git a/cplusplus/include/vips/VError8.h b/cplusplus/include/vips/VError8.h index 627222c1..29f3e9fb 100644 --- a/cplusplus/include/vips/VError8.h +++ b/cplusplus/include/vips/VError8.h @@ -31,8 +31,8 @@ #ifndef VIPS_VERROR_H #define VIPS_VERROR_H -#include -#include +#include +#include #include #include @@ -43,7 +43,7 @@ class VIPS_CPLUSPLUS_API VError : public std::exception { std::string _what; public: - VError( std::string what ) : _what( what ) {} + VError( const std::string &what ) : _what( what ) {} VError() : _what( vips_error_buffer() ) {} virtual ~VError() throw() {} diff --git a/cplusplus/include/vips/VImage8.h b/cplusplus/include/vips/VImage8.h index c9e3471f..2416ae18 100644 --- a/cplusplus/include/vips/VImage8.h +++ b/cplusplus/include/vips/VImage8.h @@ -34,7 +34,7 @@ #include #include -#include +#include #include @@ -470,7 +470,10 @@ public: return( VImage( image ) ); } - static VImage new_from_buffer( void *buf, size_t len, + static VImage new_from_buffer( const void *buf, size_t len, + const char *option_string, VOption *options = 0 ); + + static VImage new_from_buffer( const std::string &buf, const char *option_string, VOption *options = 0 ); static VImage new_matrix( int width, int height ); diff --git a/cplusplus/include/vips/VInterpolate8.h b/cplusplus/include/vips/VInterpolate8.h index 606a696a..8ef6f99e 100644 --- a/cplusplus/include/vips/VInterpolate8.h +++ b/cplusplus/include/vips/VInterpolate8.h @@ -34,7 +34,7 @@ #include #include -#include +#include #include From f815ec6801a6809b4abe49bbc03cff86f7024c64 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Fri, 11 Jan 2019 18:09:20 +0000 Subject: [PATCH 4/5] Truncate rather than floor when casting from float to int --- libvips/conversion/cast.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libvips/conversion/cast.c b/libvips/conversion/cast.c index abdc8327..21078ae3 100644 --- a/libvips/conversion/cast.c +++ b/libvips/conversion/cast.c @@ -195,9 +195,7 @@ G_DEFINE_TYPE( VipsCast, vips_cast, VIPS_TYPE_CONVERSION ); OTYPE * restrict q = (OTYPE *) out; \ \ for( x = 0; x < sz; x++ ) { \ - TEMP v = VIPS_FLOOR( p[x] ); \ - \ - q[x] = CAST( v ); \ + q[x] = CAST( p[x] ); \ } \ } From d2f48a88757a47ada0bd29fff63281ec791715b3 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sat, 12 Jan 2019 13:51:35 +0000 Subject: [PATCH 5/5] remove a stray floor() from cast thanks lovell --- libvips/conversion/cast.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libvips/conversion/cast.c b/libvips/conversion/cast.c index 21078ae3..26fa7be4 100644 --- a/libvips/conversion/cast.c +++ b/libvips/conversion/cast.c @@ -194,9 +194,8 @@ G_DEFINE_TYPE( VipsCast, vips_cast, VIPS_TYPE_CONVERSION ); ITYPE * restrict p = (ITYPE *) in; \ OTYPE * restrict q = (OTYPE *) out; \ \ - for( x = 0; x < sz; x++ ) { \ + for( x = 0; x < sz; x++ ) \ q[x] = CAST( p[x] ); \ - } \ } /* Cast complex types to an int type. Just take the real part. @@ -206,10 +205,8 @@ G_DEFINE_TYPE( VipsCast, vips_cast, VIPS_TYPE_CONVERSION ); OTYPE * restrict q = (OTYPE *) out; \ \ for( x = 0; x < sz; x++ ) { \ - TEMP v = VIPS_FLOOR( p[0] ); \ - \ + q[x] = CAST( p[0] ); \ p += 2; \ - q[x] = CAST( v ); \ } \ }