diff --git a/ChangeLog b/ChangeLog index 7b2c741d..780c16e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -333,6 +333,7 @@ - dzsave puts vips-properties.xml in the main dir for gm and zoomify layouts - resize and reduce have @centre option for centre convention downsampling - vipsthumbnail uses centre convention to better match imagemagick +_ add vips_foreign_get_suffixes() 19/8/16 started 8.3.4 - better transparency handling in gifload, thanks diegocsandrim diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index bb13c4bb..af284bde 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -1694,6 +1694,78 @@ vips_foreign_find_save( const char *name ) return( G_OBJECT_CLASS_NAME( save_class ) ); } +static void * +vips_foreign_get_suffixes_count_cb( VipsForeignSaveClass *save_class, + void *a, void *b ) +{ + VipsForeignClass *foreign_class = VIPS_FOREIGN_CLASS( save_class ); + int *n_fields = (int *) a; + + int i; + + if( foreign_class->suffs ) + for( i = 0; foreign_class->suffs[i]; i++ ) + *n_fields += 1; + + return( NULL ); +} + +static void * +vips_foreign_get_suffixes_add_cb( VipsForeignSaveClass *save_class, + void *a, void *b ) +{ + VipsForeignClass *foreign_class = VIPS_FOREIGN_CLASS( save_class ); + gchar ***p = (gchar ***) a; + + int i; + + if( foreign_class->suffs ) + for( i = 0; foreign_class->suffs[i]; i++ ) { + **p = g_strdup( foreign_class->suffs[i] ); + *p += 1; + } + + return( NULL ); +} + +/** + * vips_foreign_get_suffixes: (method) + * + * Get a %NULL-terminated array listing all the supported suffixes. + * + * This is not the same as all the supported file types, since libvips + * detects image format for load by testing the first few bytes. + * + * Use vips_foreign_find_load() to detect type for a specific file. + * + * Free the return result with g_strfreev(). + * + * Returns: (transfer full): all supported file extensions, as a + * %NULL-terminated array. + */ +gchar ** +vips_foreign_get_suffixes( void ) +{ + int n_suffs; + gchar **suffs; + gchar **p; + + n_suffs = 0; + (void) vips_foreign_map( + "VipsForeignSave", + (VipsSListMap2Fn) vips_foreign_get_suffixes_count_cb, + &n_suffs, NULL ); + + suffs = g_new0( gchar *, n_suffs + 1 ); + p = suffs; + (void) vips_foreign_map( + "VipsForeignSave", + (VipsSListMap2Fn) vips_foreign_get_suffixes_add_cb, + &p, NULL ); + + return( suffs ); +} + /* Kept for early vips8 API compat. */ diff --git a/libvips/include/vips/foreign.h b/libvips/include/vips/foreign.h index 05a3b608..d9c4c39e 100644 --- a/libvips/include/vips/foreign.h +++ b/libvips/include/vips/foreign.h @@ -342,6 +342,7 @@ typedef struct _VipsForeignSaveClass { GType vips_foreign_save_get_type(void); const char *vips_foreign_find_save( const char *filename ); +gchar **vips_foreign_get_suffixes( void ); const char *vips_foreign_find_save_buffer( const char *suffix ); int vips_vipsload( const char *filename, VipsImage **out, ... ) diff --git a/libvips/iofuncs/object.c b/libvips/iofuncs/object.c index c6f1050b..39567f53 100644 --- a/libvips/iofuncs/object.c +++ b/libvips/iofuncs/object.c @@ -2877,8 +2877,8 @@ vips_class_add_hash( VipsObjectClass *class, GHashTable *table ) return( NULL ); } -static void -vips_class_build_hash( void ) +static void * +vips_class_build_hash_cb( void *dummy ) { GType base; @@ -2891,6 +2891,8 @@ vips_class_build_hash( void ) vips_class_map_all( base, (VipsClassMapFn) vips_class_add_hash, (void *) vips__object_nickname_table ); + + return( NULL ); } /** @@ -2919,7 +2921,7 @@ vips_type_find( const char *basename, const char *nickname ) GType base; GType type; - VIPS_ONCE( &once, (GThreadFunc) vips_class_build_hash, NULL ); + VIPS_ONCE( &once, vips_class_build_hash_cb, NULL ); hit = (NicknameGType *) g_hash_table_lookup( vips__object_nickname_table,