From fd0a0905ff896c89fa8a94917cc954eabcfa4b43 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 24 Sep 2020 10:44:49 +0100 Subject: [PATCH] note VImage::new_from_memory_steal() in ChangeLog plus doxy commnets etc., see https://github.com/libvips/libvips/pull/1758/ --- ChangeLog | 1 + cplusplus/VImage.cpp | 16 ++++++++++++++++ cplusplus/include/vips/VImage8.h | 30 +++++++++++++----------------- libvips/iofuncs/image.c | 2 +- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index de5bd2be..22af5679 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ - integrate doxygen in build system to generate C++ API docs - improve C++ API doc comments - add VipsInterpolate and guint64 support to C++ API +- add VImage::new_from_memory_steal [Zeranoe] 6/9/20 started 8.10.2 - update magicksave/load profile handling [kelilevi] diff --git a/cplusplus/VImage.cpp b/cplusplus/VImage.cpp index 3242c016..49b006a4 100644 --- a/cplusplus/VImage.cpp +++ b/cplusplus/VImage.cpp @@ -641,6 +641,22 @@ VImage::new_from_source( VSource source, const char *option_string, return( out ); } +VImage +VImage::new_from_memory_steal( void *data, size_t size, + int width, int height, int bands, VipsBandFormat format ) +{ + VipsImage *image; + + if( !(image = vips_image_new_from_memory( data, size, + width, height, bands, format )) ) + throw( VError() ); + + g_signal_connect( image, "postclose", + G_CALLBACK( vips_image_free_buffer ), data); + + return( VImage( image ) ); +} + VImage VImage::new_matrix( int width, int height ) { diff --git a/cplusplus/include/vips/VImage8.h b/cplusplus/include/vips/VImage8.h index ee96ac60..a62ebd8d 100644 --- a/cplusplus/include/vips/VImage8.h +++ b/cplusplus/include/vips/VImage8.h @@ -862,11 +862,23 @@ public: return( VImage( image ) ); } + /** + * Create a new VImage object from an area of memory containing a + * C-style array. + * + * The VImage steals ownership of @data and will free() it when it + * goes out of scope. + */ + static VImage + new_from_memory_steal( void *data, size_t size, + int width, int height, int bands, VipsBandFormat format ); + /** * Create a matrix image of a specified size. All elements will be * zero. */ - static VImage new_matrix( int width, int height ); + static VImage + new_matrix( int width, int height ); /** * Create a matrix image of a specified size, initialized from the @@ -917,22 +929,6 @@ public: return( new_from_image( to_vectorv( 1, pixel ) ) ); } - static VImage - new_from_memory_steal( void *data, size_t size, - int width, int height, int bands, VipsBandFormat format ) - { - VipsImage *image; - - if( !(image = vips_image_new_from_memory( data, size, - width, height, bands, format )) ) - throw( VError() ); - - g_signal_connect( image, "postclose", - G_CALLBACK(vips_image_free_buffer), data); - - return( VImage( image ) ); - } - /** * Make a new image by rendering self to a large memory area, * wrapping a VImage around it, and copying all metadata over from diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index 893768a7..4dec38bb 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -3878,7 +3878,7 @@ vips_band_format_iscomplex( VipsBandFormat format ) * @buffer: the orignal buffer that was stolen * * Free the externally allocated buffer found in the input image. This function - * is intened to be used with g_signal_connect. + * is intended to be used with g_signal_connect. */ void vips_image_free_buffer( VipsImage *image, void *buffer )