add vips_image_get/set_array_int()

This commit is contained in:
John Cupitt 2019-06-20 11:32:47 +01:00
parent 8a98bea063
commit 2aef873fcd
3 changed files with 67 additions and 0 deletions

View File

@ -1,3 +1,6 @@
20/6/19 started 8.9.0
- add vips_image_get/set_array_int()
24/5/19 started 8.8.1
- improve realpath() use on older libc
- better magickload error messages

View File

@ -216,6 +216,10 @@ void vips_image_print_field( const VipsImage *image, const char *field );
int vips_image_get_image( const VipsImage *image,
const char *name, VipsImage **out );
void vips_image_set_image( VipsImage *image, const char *name, VipsImage *im );
void vips_image_set_array_int( VipsImage *image, const char *name,
const int *array, int n );
int vips_image_get_array_int( VipsImage *image, const char *name,
int **out, int *n );
int vips_image_history_printf( VipsImage *image, const char *format, ... )
__attribute__((format(printf, 2, 3)));

View File

@ -34,6 +34,8 @@
* - add vips_image_get_page_height()
* 19/6/19
* - add vips_image_get_n_pages()
* 20/6/19
* - add vips_image_get/set_array_int()
*/
/*
@ -1797,6 +1799,64 @@ vips_image_set_image( VipsImage *image, const char *name, VipsImage *im )
g_value_unset( &value );
}
/**
* vips_image_get_array_int: (method)
* @image: image to get the metadata from
* @name: metadata name
* @out: (transfer none): return pointer to array
* @n: (allow-none): return the number of elements here, optionally
*
* Gets @out from @im under the name @name.
* The field must be of type
* #VIPS_TYPE_ARRAY_INT.
*
* Do not free @out. @out is valid as long as @image is valid.
*
* Use vips_image_get_typeof() to test for the
* existence of a piece of metadata.
*
* See also: vips_image_get(), vips_image_set_image()
*
* Returns: 0 on success, -1 otherwise.
*/
int
vips_image_get_array_int( VipsImage *image, const char *name,
int **out, int *n )
{
GValue value = { 0 };
if( meta_get_value( image, name, VIPS_TYPE_ARRAY_INT, &value ) )
return( -1 );
*out = vips_value_get_array_int( &value, n );
g_value_unset( &value );
return( 0 );
}
/**
* vips_image_set_array_int: (method)
* @image: image to attach the metadata to
* @name: metadata name
* @array: (array length=n) (allow-none): array of ints
* @n: the number of elements
*
* Attaches @array as a metadata item on @image as @name.
* A convenience function over vips_image_set().
*
* See also: vips_image_get_image(), vips_image_set().
*/
void
vips_image_set_array_int( VipsImage *image, const char *name,
const int *array, int n )
{
GValue value = { 0 };
g_value_init( &value, VIPS_TYPE_ARRAY_INT );
vips_value_set_array_int( &value, array, n );
vips_image_set( image, name, &value );
g_value_unset( &value );
}
/**
* vips_image_history_printf: (method)
* @image: add history line to this image