diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index 61ccce47..855ef7e9 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -615,6 +615,33 @@ vips_foreign_is_a( const char *loader, const char *filename ) return( FALSE ); } +/** + * vips_foreign_is_a_buffer: + * @loader: name of loader to use for test + * @data: pointer to the buffer to test + * @size: size of the buffer to test + * + * Return %TRUE if @data can be loaded by @loader. @loader is something + * like "tiffload_buffer" or "VipsForeignLoadTiffBuffer". + * + * Returns: %TRUE if @data can be loaded by @loader. + */ +gboolean +vips_foreign_is_a_buffer( const char *loader, void *data, size_t size ) +{ + VipsObjectClass *class; + VipsForeignLoadClass *load_class; + + if( !(class = vips_class_find( "VipsForeignLoad", loader )) ) + return( FALSE ); + load_class = VIPS_FOREIGN_LOAD_CLASS( class ); + if( load_class->is_a_buffer && + load_class->is_a_buffer( data, size ) ) + return( TRUE ); + + return( FALSE ); +} + /** * vips_foreign_flags: * @loader: name of loader to use for test diff --git a/libvips/include/vips/foreign.h b/libvips/include/vips/foreign.h index a695d4e0..6dfa144a 100644 --- a/libvips/include/vips/foreign.h +++ b/libvips/include/vips/foreign.h @@ -218,6 +218,7 @@ const char *vips_foreign_find_load_buffer( void *data, size_t size ); VipsForeignFlags vips_foreign_flags( const char *loader, const char *filename ); gboolean vips_foreign_is_a( const char *loader, const char *filename ); +gboolean vips_foreign_is_a_buffer( const char *loader, void *data, size_t size ); #define VIPS_TYPE_FOREIGN_SAVE (vips_foreign_save_get_type()) #define VIPS_FOREIGN_SAVE( obj ) \