Merge pull request #1758 from Zeranoe/master

Add C++ bindings for new_from_memory_steal()
This commit is contained in:
John Cupitt 2020-09-24 10:31:53 +01:00 committed by GitHub
commit 62e1cb4862
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 0 deletions

View File

@ -917,6 +917,22 @@ 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

View File

@ -524,6 +524,8 @@ int vips_reorder_prepare_many( VipsImage *image,
VipsRegion **regions, VipsRect *r );
void vips_reorder_margin_hint( VipsImage *image, int margin );
void vips_image_free_buffer( VipsImage *image, void *buffer );
#ifdef __cplusplus
}
#endif /*__cplusplus*/

View File

@ -3872,6 +3872,20 @@ vips_band_format_iscomplex( VipsBandFormat format )
}
}
/**
* vips_image_free_buffer:
* @image: the image that contains the buffer
* @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.
*/
void
vips_image_free_buffer( VipsImage *image, void *buffer )
{
free( buffer );
}
/* Handy for debugging: view an image in nip2.
*/
int