From 5160010edacfb0a76957b16623b09a39c523dc9e Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sun, 25 Oct 2015 17:15:45 +0000 Subject: [PATCH] add vips_array_image_empty()/_append() to help bindings without init from array --- libvips/include/vips/image.h | 3 ++ libvips/iofuncs/type.c | 57 ++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/libvips/include/vips/image.h b/libvips/include/vips/image.h index f47982cc..48fc8068 100644 --- a/libvips/include/vips/image.h +++ b/libvips/include/vips/image.h @@ -482,6 +482,9 @@ int vips_system( const char *cmd_format, ... ) */ VipsArrayImage *vips_array_image_new( VipsImage **array, int n ); VipsArrayImage *vips_array_image_newv( int n, ... ); +VipsArrayImage *vips_array_image_empty( void ); +VipsArrayImage *vips_array_image_append( VipsArrayImage *array, + VipsImage *image ); VipsImage **vips_array_image_get( VipsArrayImage *array, int *n ); VipsImage **vips_value_get_array_image( const GValue *value, int *n ); void vips_value_set_array_image( GValue *value, int n ); diff --git a/libvips/iofuncs/type.c b/libvips/iofuncs/type.c index 6106734e..ee76916f 100644 --- a/libvips/iofuncs/type.c +++ b/libvips/iofuncs/type.c @@ -1205,6 +1205,63 @@ vips_array_image_newv( int n, ... ) return( (VipsArrayImage *) area ); } +/** + * vips_array_image_empty: + * + * Make an empty image array. + * Handy with vips_array_image_add() for bindings + * which can't handle object array arguments. + * + * See also: vips_array_image_add(). + * + * Returns: (transfer full): A new #VipsArrayImage. + */ +VipsArrayImage * +vips_array_image_empty( void ) +{ + return( vips_array_image_new( NULL, 0 ) ); +} + +/** + * vips_array_image_append: + * @array: (transfer none): append to this + * @image: add this + * + * Make a new #VipsArrayImage, one larger than @array, with @image appended + * to the end. + * Handy with vips_array_image_empty() for bindings + * which can't handle object array arguments. + * + * See also: vips_array_image_empty(). + * + * Returns: (transfer full): A new #VipsArrayImage. + */ +VipsArrayImage * +vips_array_image_append( VipsArrayImage *array, VipsImage *image ) +{ + VipsArea *old_area = VIPS_AREA( array ); + int n = old_area->n; + + VipsArea *new_area; + VipsImage **old_vector; + VipsImage **new_vector; + int i; + + new_area = vips_area_new_array_object( n + 1 ); + new_area->type = VIPS_TYPE_IMAGE; + + old_vector = vips_area_get_data( old_area, NULL, NULL, NULL, NULL ); + new_vector = vips_area_get_data( new_area, NULL, NULL, NULL, NULL ); + for( i = 0; i < n; i++ ) { + new_vector[i] = (VipsImage *) old_vector[i]; + g_object_ref( new_vector[i] ); + } + new_vector[i] = image; + g_object_ref( new_vector[i] ); + + return( (VipsArrayImage *) new_area ); +} + /** * vips_array_image_get: * @array: the #VipsArrayImage to fetch from