From acabd2dc08551efabafabba7042a1b57662e0578 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 30 Jan 2020 22:15:48 +0000 Subject: [PATCH] add gifload_source --- ChangeLog | 1 + libvips/foreign/foreign.c | 2 + libvips/foreign/gifload.c | 94 ++++++++++++++++++++++++++++++++++ libvips/include/vips/foreign.h | 2 + 4 files changed, 99 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1341d6f2..01432673 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ - allow \ as an escape character in vips_break_token() [akemrir] - tiffsave has a "depth" param to set max pyr depth - libtiff LOGLUV images load and save as libvips XYZ +- add gifload_source 20/6/19 started 8.9.1 - don't use the new source loaders for new_from_file or new_from_buffer, it diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index d59016ce..86632973 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -2107,6 +2107,7 @@ vips_foreign_operation_init( void ) extern GType vips_foreign_load_gif_file_get_type( void ); extern GType vips_foreign_load_gif_buffer_get_type( void ); + extern GType vips_foreign_load_gif_source_get_type( void ); vips_foreign_load_csv_get_type(); vips_foreign_save_csv_get_type(); @@ -2158,6 +2159,7 @@ vips_foreign_operation_init( void ) #ifdef HAVE_GIFLIB vips_foreign_load_gif_file_get_type(); vips_foreign_load_gif_buffer_get_type(); + vips_foreign_load_gif_source_get_type(); #endif /*HAVE_GIFLIB*/ #ifdef HAVE_GSF diff --git a/libvips/foreign/gifload.c b/libvips/foreign/gifload.c index 4ef82b85..a4a6b3ac 100644 --- a/libvips/foreign/gifload.c +++ b/libvips/foreign/gifload.c @@ -36,6 +36,7 @@ * - improve early close again * 30/1/19 * - rework on top of VipsSource + * - add gifload_source */ /* @@ -1431,6 +1432,70 @@ vips_foreign_load_gif_buffer_init( VipsForeignLoadGifBuffer *buffer ) { } +typedef struct _VipsForeignLoadGifSource { + VipsForeignLoadGif parent_object; + + /* Load from a source. + */ + VipsSource *source; + +} VipsForeignLoadGifSource; + +typedef VipsForeignLoadGifClass VipsForeignLoadGifSourceClass; + +G_DEFINE_TYPE( VipsForeignLoadGifSource, vips_foreign_load_gif_source, + vips_foreign_load_gif_get_type() ); + +static int +vips_foreign_load_gif_source_build( VipsObject *object ) +{ + VipsForeignLoadGif *gif = (VipsForeignLoadGif *) object; + VipsForeignLoadGifSource *source = + (VipsForeignLoadGifSource *) object; + + if( source->source ) { + gif->source = source->source; + g_object_ref( gif->source ); + } + + if( VIPS_OBJECT_CLASS( vips_foreign_load_gif_source_parent_class )-> + build( object ) ) + return( -1 ); + + return( 0 ); +} + +static void +vips_foreign_load_gif_source_class_init( + VipsForeignLoadGifSourceClass *class ) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS( class ); + VipsObjectClass *object_class = (VipsObjectClass *) class; + VipsForeignLoadClass *load_class = (VipsForeignLoadClass *) class; + + gobject_class->set_property = vips_object_set_property; + gobject_class->get_property = vips_object_get_property; + + object_class->nickname = "gifload_source"; + object_class->description = _( "load GIF with giflib" ); + object_class->build = vips_foreign_load_gif_source_build; + + load_class->is_a_source = vips_foreign_load_gif_is_a_source; + + VIPS_ARG_OBJECT( class, "source", 1, + _( "Source" ), + _( "Source to load from" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsForeignLoadGifSource, source ), + VIPS_TYPE_SOURCE ); + +} + +static void +vips_foreign_load_gif_source_init( VipsForeignLoadGifSource *source ) +{ +} + #endif /*HAVE_GIFLIB*/ /** @@ -1515,3 +1580,32 @@ vips_gifload_buffer( void *buf, size_t len, VipsImage **out, ... ) return( result ); } +/** + * vips_gifload_source: + * @source: source to load + * @out: (out): image to write + * @...: %NULL-terminated list of optional named arguments + * + * Optional arguments: + * + * * @page: %gint, page (frame) to read + * * @n: %gint, load this many pages + * + * Exactly as vips_gifload(), but read from a source. + * + * See also: vips_gifload(). + * + * Returns: 0 on success, -1 on error. + */ +int +vips_gifload_source( VipsSource *source, VipsImage **out, ... ) +{ + va_list ap; + int result; + + va_start( ap, out ); + result = vips_call_split( "gifload_source", ap, source, out ); + va_end( ap ); + + return( result ); +} diff --git a/libvips/include/vips/foreign.h b/libvips/include/vips/foreign.h index 2447b3d1..1f84f4f9 100644 --- a/libvips/include/vips/foreign.h +++ b/libvips/include/vips/foreign.h @@ -597,6 +597,8 @@ int vips_gifload( const char *filename, VipsImage **out, ... ) __attribute__((sentinel)); int vips_gifload_buffer( void *buf, size_t len, VipsImage **out, ... ) __attribute__((sentinel)); +int vips_gifload_source( VipsSource *source, VipsImage **out, ... ) + __attribute__((sentinel)); int vips_heifload( const char *filename, VipsImage **out, ... ) __attribute__((sentinel));