diff --git a/ChangeLog b/ChangeLog index 89763f00..8e6be44d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,7 @@ - better >4gb detect for zip dzsave output [Felix Bünemann] - all loaders have a @fail option, meaning fail on first warning, though it only does anything for jpg, csv, openslide +- add vips_image_get_fields() to help bindings 11/11/16 started 8.4.4 - fix crash in vips.exe arg parsing on Windows, thanks Yury diff --git a/libvips/include/vips/header.h b/libvips/include/vips/header.h index 8272aa7c..691a407f 100644 --- a/libvips/include/vips/header.h +++ b/libvips/include/vips/header.h @@ -170,6 +170,7 @@ gboolean vips_image_remove( VipsImage *image, const char *name ); typedef void *(*VipsImageMapFn)( VipsImage *image, const char *name, GValue *value, void *a ); void *vips_image_map( VipsImage *image, VipsImageMapFn fn, void *a ); +gchar **vips_image_get_fields( VipsImage *image ); void vips_image_set_area( VipsImage *image, const char *name, VipsCallbackFn free_fn, void *data ); diff --git a/libvips/iofuncs/header.c b/libvips/iofuncs/header.c index 78757617..4a4f6965 100644 --- a/libvips/iofuncs/header.c +++ b/libvips/iofuncs/header.c @@ -1176,6 +1176,55 @@ vips_image_map( VipsImage *image, VipsImageMapFn fn, void *a ) return( NULL ); } +static void * +count_fields( VipsImage *image, const char *field, GValue *value, void *a ) +{ + int *n_fields = (int *) a; + + n_fields += 1; + + return( NULL ); +} + +static void * +add_fields( VipsImage *image, const char *field, GValue *value, void *a ) +{ + gchar ***p = (gchar ***) a; + + **p = g_strdup( field ); + *p += 1; + + return( NULL ); +} + +/** + * vips_image_get_fields: + * @image: image to get fields from + * + * Get a %NULL-terminated array listing all the metadata field names on @image. + * Free the return result with g_strfreev(). + * + * This is handy for language bindings. From C, it's usually more convenient to + * use vips_image_map(). + * + * Returns: (transfer full): metadata fields in image, as a %NULL-terminated + * array. + */ +gchar ** +vips_image_get_fields( VipsImage *image ) +{ + int n_fields; + gchar **fields; + gchar **p; + + (void) vips_image_map( image, count_fields, &n_fields ); + fields = g_new0( gchar *, n_fields + 1 ); + p = fields; + (void) vips_image_map( image, add_fields, &p ); + + return( fields ); +} + /** * vips_image_set_area: * @image: image to attach the metadata to