add vips_foreign_get_suffixes()

Add vips_foreign_get_suffixes(), get an array of all the filename suffixes that
libvips recognises.

See https://github.com/libvips/ruby-vips/issues/186
This commit is contained in:
John Cupitt 2019-02-23 13:50:10 +00:00
parent 52242cd70d
commit 27195cc92c
4 changed files with 79 additions and 3 deletions

View File

@ -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

View File

@ -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.
*/

View File

@ -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, ... )

View File

@ -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,