From 63d54e5df24d6b2fd80e7261fed143277650d65b Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 30 Dec 2019 14:23:51 +0000 Subject: [PATCH] final code cleanups after stream -> source rename --- libvips/deprecated/im_webp2vips.c | 6 +- libvips/foreign/foreign.c | 15 +- libvips/foreign/jpegsave.c | 4 +- libvips/foreign/pforeign.h | 10 +- libvips/foreign/radsave.c | 2 +- libvips/foreign/vips2jpeg.c | 12 +- libvips/foreign/vips2webp.c | 4 +- libvips/foreign/webp2vips.c | 8 +- libvips/foreign/webpload.c | 54 +-- libvips/foreign/webpsave.c | 48 +-- libvips/iofuncs/bufis.c | 40 +- libvips/iofuncs/connection.c | 52 +-- libvips/iofuncs/destination.c | 609 ---------------------------- libvips/iofuncs/destinationcustom.c | 194 --------- libvips/iofuncs/image.c | 17 +- libvips/iofuncs/source.c | 139 +++---- libvips/iofuncs/sourcecustom.c | 14 +- libvips/iofuncs/target.c | 65 +-- libvips/iofuncs/targetcustom.c | 12 +- libvips/resample/thumbnail.c | 68 ++-- 20 files changed, 283 insertions(+), 1090 deletions(-) delete mode 100644 libvips/iofuncs/destination.c delete mode 100644 libvips/iofuncs/destinationcustom.c diff --git a/libvips/deprecated/im_webp2vips.c b/libvips/deprecated/im_webp2vips.c index ee5c0dcc..f7a235dd 100644 --- a/libvips/deprecated/im_webp2vips.c +++ b/libvips/deprecated/im_webp2vips.c @@ -58,9 +58,9 @@ webp2vips( const char *name, IMAGE *out, gboolean header_only ) if( !(source = vips_source_new_from_file( filename )) ) return( -1 ); if( header_only ) - result = vips__webp_read_header_stream( source, out, 0, 1, 1 ); + result = vips__webp_read_header_source( source, out, 0, 1, 1 ); else - result = vips__webp_read_stream( source, out, 0, 1, 1 ); + result = vips__webp_read_source( source, out, 0, 1, 1 ); VIPS_UNREF( source ); if( result ) @@ -86,7 +86,7 @@ vips__iswebp( const char *filename ) if( !(source = vips_source_new_from_file( filename )) ) return( FALSE ); - result = vips__iswebp_stream( source ); + result = vips__iswebp_source( source ); VIPS_UNREF( source ); #else /*!HAVE_LIBWEBP*/ result = -1; diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index 4ab17ebf..5df33751 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -2072,21 +2072,19 @@ vips_foreign_operation_init( void ) extern GType vips_foreign_load_webp_file_get_type( void ); extern GType vips_foreign_load_webp_buffer_get_type( void ); - extern GType vips_foreign_load_webp_stream_get_type( void ); + extern GType vips_foreign_load_webp_source_get_type( void ); extern GType vips_foreign_save_webp_file_get_type( void ); extern GType vips_foreign_save_webp_buffer_get_type( void ); - extern GType vips_foreign_save_webp_stream_get_type( void ); + extern GType vips_foreign_save_webp_target_get_type( void ); extern GType vips_foreign_load_pdf_get_type( void ); extern GType vips_foreign_load_pdf_file_get_type( void ); extern GType vips_foreign_load_pdf_buffer_get_type( void ); - extern GType vips_foreign_load_svg_get_type( void ); extern GType vips_foreign_load_svg_file_get_type( void ); extern GType vips_foreign_load_svg_buffer_get_type( void ); extern GType vips_foreign_load_svg_source_get_type( void ); - extern GType vips_foreign_load_heif_get_type( void ); extern GType vips_foreign_load_heif_file_get_type( void ); extern GType vips_foreign_load_heif_buffer_get_type( void ); extern GType vips_foreign_save_heif_get_type( void ); @@ -2096,7 +2094,6 @@ vips_foreign_operation_init( void ) extern GType vips_foreign_load_nifti_get_type( void ); extern GType vips_foreign_save_nifti_get_type( void ); - extern GType vips_foreign_load_gif_get_type( void ); extern GType vips_foreign_load_gif_file_get_type( void ); extern GType vips_foreign_load_gif_buffer_get_type( void ); @@ -2142,14 +2139,12 @@ vips_foreign_operation_init( void ) #endif /*HAVE_PDFIUM*/ #ifdef HAVE_RSVG - vips_foreign_load_svg_get_type(); vips_foreign_load_svg_file_get_type(); vips_foreign_load_svg_buffer_get_type(); vips_foreign_load_svg_source_get_type(); #endif /*HAVE_RSVG*/ #ifdef HAVE_GIFLIB - vips_foreign_load_gif_get_type(); vips_foreign_load_gif_file_get_type(); vips_foreign_load_gif_buffer_get_type(); #endif /*HAVE_GIFLIB*/ @@ -2185,10 +2180,10 @@ vips_foreign_operation_init( void ) #ifdef HAVE_LIBWEBP vips_foreign_load_webp_file_get_type(); vips_foreign_load_webp_buffer_get_type(); - vips_foreign_load_webp_stream_get_type(); + vips_foreign_load_webp_source_get_type(); vips_foreign_save_webp_file_get_type(); vips_foreign_save_webp_buffer_get_type(); - vips_foreign_save_webp_stream_get_type(); + vips_foreign_save_webp_target_get_type(); #endif /*HAVE_LIBWEBP*/ #ifdef HAVE_TIFF @@ -2235,13 +2230,11 @@ vips_foreign_operation_init( void ) #endif /*HAVE_NIFTI*/ #ifdef HAVE_HEIF_DECODER - vips_foreign_load_heif_get_type(); vips_foreign_load_heif_file_get_type(); vips_foreign_load_heif_buffer_get_type(); #endif /*HAVE_HEIF_DECODER*/ #ifdef HAVE_HEIF_ENCODER - vips_foreign_save_heif_get_type(); vips_foreign_save_heif_file_get_type(); vips_foreign_save_heif_buffer_get_type(); #endif /*HAVE_HEIF_ENCODER*/ diff --git a/libvips/foreign/jpegsave.c b/libvips/foreign/jpegsave.c index 31e03b88..cb500145 100644 --- a/libvips/foreign/jpegsave.c +++ b/libvips/foreign/jpegsave.c @@ -265,8 +265,8 @@ vips_foreign_save_jpeg_target_class_init( object_class->build = vips_foreign_save_jpeg_target_build; VIPS_ARG_OBJECT( class, "target", 1, - _( "Streamo" ), - _( "Stream to save to" ), + _( "Target" ), + _( "Target to save to" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsForeignSaveJpegTarget, target ), VIPS_TYPE_TARGET ); diff --git a/libvips/foreign/pforeign.h b/libvips/foreign/pforeign.h index 702c6278..b19ec78e 100644 --- a/libvips/foreign/pforeign.h +++ b/libvips/foreign/pforeign.h @@ -145,7 +145,7 @@ int vips__mat_ismat( const char *filename ); extern const char *vips__ppm_suffs[]; -int vips__ppm_save_stream( VipsImage *in, VipsTarget *target, +int vips__ppm_save_target( VipsImage *in, VipsTarget *target, gboolean ascii, gboolean squash ); int vips__rad_israd( VipsSource *source ); int vips__rad_header( VipsSource *source, VipsImage *out ); @@ -192,14 +192,14 @@ extern const VipsWebPNames vips__webp_names[]; extern const int vips__n_webp_names; extern const char *vips__webp_suffs[]; -int vips__iswebp_stream( VipsSource *source ); +int vips__iswebp_source( VipsSource *source ); -int vips__webp_read_header_stream( VipsSource *source, VipsImage *out, +int vips__webp_read_header_source( VipsSource *source, VipsImage *out, int page, int n, double scale ); -int vips__webp_read_stream( VipsSource *source, VipsImage *out, +int vips__webp_read_source( VipsSource *source, VipsImage *out, int page, int n, double scale ); -int vips__webp_write_stream( VipsImage *image, VipsTarget *target, +int vips__webp_write_target( VipsImage *image, VipsTarget *target, int Q, gboolean lossless, VipsForeignWebpPreset preset, gboolean smart_subsample, gboolean near_lossless, int alpha_q, int reduction_effort, diff --git a/libvips/foreign/radsave.c b/libvips/foreign/radsave.c index bc65a6d0..e2dc9c00 100644 --- a/libvips/foreign/radsave.c +++ b/libvips/foreign/radsave.c @@ -207,7 +207,7 @@ vips_foreign_save_rad_target_class_init( VipsForeignSaveRadTargetClass *class ) VIPS_ARG_OBJECT( class, "target", 1, _( "Target" ), - _( "Stream to save to" ), + _( "Target to save to" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsForeignSaveRadTarget, target ), VIPS_TYPE_TARGET ); diff --git a/libvips/foreign/vips2jpeg.c b/libvips/foreign/vips2jpeg.c index 23551f26..b96ab3e9 100644 --- a/libvips/foreign/vips2jpeg.c +++ b/libvips/foreign/vips2jpeg.c @@ -687,7 +687,7 @@ write_vips( Write *write, int qfac, const char *profile, return( 0 ); } -#define STREAM_BUFFER_SIZE (4096) +#define TARGET_BUFFER_SIZE (4096) typedef struct { /* Public jpeg fields. @@ -703,7 +703,7 @@ typedef struct { /* Our output buffer. */ - unsigned char buf[STREAM_BUFFER_SIZE]; + unsigned char buf[TARGET_BUFFER_SIZE]; } Dest; /* Buffer full method. This is only called when the output area is exactly @@ -715,11 +715,11 @@ empty_output_buffer( j_compress_ptr cinfo ) Dest *dest = (Dest *) cinfo->dest; if( vips_target_write( dest->target, - dest->buf, STREAM_BUFFER_SIZE ) ) + dest->buf, TARGET_BUFFER_SIZE ) ) ERREXIT( cinfo, JERR_FILE_WRITE ); dest->pub.next_output_byte = dest->buf; - dest->pub.free_in_buffer = STREAM_BUFFER_SIZE; + dest->pub.free_in_buffer = TARGET_BUFFER_SIZE; return( TRUE ); } @@ -732,7 +732,7 @@ init_destination( j_compress_ptr cinfo ) Dest *dest = (Dest *) cinfo->dest; dest->pub.next_output_byte = dest->buf; - dest->pub.free_in_buffer = STREAM_BUFFER_SIZE; + dest->pub.free_in_buffer = TARGET_BUFFER_SIZE; } /* Flush any remaining bytes to the output. @@ -743,7 +743,7 @@ term_destination( j_compress_ptr cinfo ) Dest *dest = (Dest *) cinfo->dest; if( vips_target_write( dest->target, - dest->buf, STREAM_BUFFER_SIZE - dest->pub.free_in_buffer ) ) + dest->buf, TARGET_BUFFER_SIZE - dest->pub.free_in_buffer ) ) ERREXIT( cinfo, JERR_FILE_WRITE ); vips_target_finish( dest->target ); diff --git a/libvips/foreign/vips2webp.c b/libvips/foreign/vips2webp.c index d34660a6..c63f2a8d 100644 --- a/libvips/foreign/vips2webp.c +++ b/libvips/foreign/vips2webp.c @@ -17,7 +17,7 @@ * 8/7/19 * - set loop even if we strip * 14/10/19 - * - revise for stream IO + * - revise for target IO */ /* @@ -525,7 +525,7 @@ vips_webp_add_metadata( VipsWebPWrite *write ) } int -vips__webp_write_stream( VipsImage *image, VipsTarget *target, +vips__webp_write_target( VipsImage *image, VipsTarget *target, int Q, gboolean lossless, VipsForeignWebpPreset preset, gboolean smart_subsample, gboolean near_lossless, int alpha_q, int reduction_effort, diff --git a/libvips/foreign/webp2vips.c b/libvips/foreign/webp2vips.c index 02e309df..2bf6edba 100644 --- a/libvips/foreign/webp2vips.c +++ b/libvips/foreign/webp2vips.c @@ -25,7 +25,7 @@ * 6/7/19 [deftomat] * - support array of delays * 14/10/19 - * - revise for stream IO + * - revise for source IO */ /* @@ -311,7 +311,7 @@ vips_image_paint_image( VipsImage *frame, } int -vips__iswebp_stream( VipsSource *source ) +vips__iswebp_source( VipsSource *source ) { const unsigned char *p; @@ -763,7 +763,7 @@ read_image( Read *read, VipsImage *out ) } int -vips__webp_read_header_stream( VipsSource *source, VipsImage *out, +vips__webp_read_header_source( VipsSource *source, VipsImage *out, int page, int n, double scale ) { Read *read; @@ -782,7 +782,7 @@ vips__webp_read_header_stream( VipsSource *source, VipsImage *out, } int -vips__webp_read_stream( VipsSource *source, VipsImage *out, +vips__webp_read_source( VipsSource *source, VipsImage *out, int page, int n, double scale ) { Read *read; diff --git a/libvips/foreign/webpload.c b/libvips/foreign/webpload.c index 8e79c7f1..5a83fcf1 100644 --- a/libvips/foreign/webpload.c +++ b/libvips/foreign/webpload.c @@ -131,7 +131,7 @@ vips_foreign_load_webp_header( VipsForeignLoad *load ) { VipsForeignLoadWebp *webp = (VipsForeignLoadWebp *) load; - if( vips__webp_read_header_stream( webp->source, load->out, + if( vips__webp_read_header_source( webp->source, load->out, webp->page, webp->n, webp->scale ) ) return( -1 ); @@ -143,7 +143,7 @@ vips_foreign_load_webp_load( VipsForeignLoad *load ) { VipsForeignLoadWebp *webp = (VipsForeignLoadWebp *) load; - if( vips__webp_read_stream( webp->source, load->real, + if( vips__webp_read_source( webp->source, load->real, webp->page, webp->n, webp->scale ) ) return( -1 ); @@ -217,31 +217,31 @@ vips_foreign_load_webp_init( VipsForeignLoadWebp *webp ) webp->scale = 1.0; } -typedef struct _VipsForeignLoadWebpStream { +typedef struct _VipsForeignLoadWebpSource { VipsForeignLoadWebp parent_object; VipsSource *source; -} VipsForeignLoadWebpStream; +} VipsForeignLoadWebpSource; -typedef VipsForeignLoadWebpClass VipsForeignLoadWebpStreamClass; +typedef VipsForeignLoadWebpClass VipsForeignLoadWebpSourceClass; -G_DEFINE_TYPE( VipsForeignLoadWebpStream, vips_foreign_load_webp_stream, +G_DEFINE_TYPE( VipsForeignLoadWebpSource, vips_foreign_load_webp_source, vips_foreign_load_webp_get_type() ); static int -vips_foreign_load_webp_stream_build( VipsObject *object ) +vips_foreign_load_webp_source_build( VipsObject *object ) { VipsForeignLoadWebp *webp = (VipsForeignLoadWebp *) object; - VipsForeignLoadWebpStream *stream = - (VipsForeignLoadWebpStream *) object; + VipsForeignLoadWebpSource *source = + (VipsForeignLoadWebpSource *) object; - if( stream->source ) { - webp->source = stream->source; + if( source->source ) { + webp->source = source->source; g_object_ref( webp->source ); } - if( VIPS_OBJECT_CLASS( vips_foreign_load_webp_stream_parent_class )-> + if( VIPS_OBJECT_CLASS( vips_foreign_load_webp_source_parent_class )-> build( object ) ) return( -1 ); @@ -249,8 +249,8 @@ vips_foreign_load_webp_stream_build( VipsObject *object ) } static void -vips_foreign_load_webp_stream_class_init( - VipsForeignLoadWebpStreamClass *class ) +vips_foreign_load_webp_source_class_init( + VipsForeignLoadWebpSourceClass *class ) { GObjectClass *gobject_class = G_OBJECT_CLASS( class ); VipsObjectClass *object_class = (VipsObjectClass *) class; @@ -259,23 +259,23 @@ vips_foreign_load_webp_stream_class_init( gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property; - object_class->nickname = "webpload_stream"; - object_class->description = _( "load webp from stream" ); - object_class->build = vips_foreign_load_webp_stream_build; + object_class->nickname = "webpload_source"; + object_class->description = _( "load webp from source" ); + object_class->build = vips_foreign_load_webp_source_build; - load_class->is_a_source = vips__iswebp_stream; + load_class->is_a_source = vips__iswebp_source; VIPS_ARG_OBJECT( class, "source", 1, - _( "Streami" ), - _( "Stream to load from" ), + _( "Source" ), + _( "Source to load from" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsForeignLoadWebpStream, source ), + G_STRUCT_OFFSET( VipsForeignLoadWebpSource, source ), VIPS_TYPE_SOURCE ); } static void -vips_foreign_load_webp_stream_init( VipsForeignLoadWebpStream *buffer ) +vips_foreign_load_webp_source_init( VipsForeignLoadWebpSource *buffer ) { } @@ -319,7 +319,7 @@ vips_foreign_load_webp_file_is_a( const char *filename ) if( !(source = vips_source_new_from_file( filename )) ) return( FALSE ); - result = vips__iswebp_stream( source ); + result = vips__iswebp_source( source ); VIPS_UNREF( source ); return( result ); @@ -401,7 +401,7 @@ vips_foreign_load_webp_buffer_is_a_buffer( const void *buf, size_t len ) if( !(source = vips_source_new_from_memory( buf, len )) ) return( FALSE ); - result = vips__iswebp_stream( source ); + result = vips__iswebp_source( source ); VIPS_UNREF( source ); return( result ); @@ -527,7 +527,7 @@ vips_webpload_buffer( void *buf, size_t len, VipsImage **out, ... ) /** * vips_webpload_source: - * @source: stream to load from + * @source: source to load from * @out: (out): image to write * @...: %NULL-terminated list of optional named arguments * @@ -537,7 +537,7 @@ vips_webpload_buffer( void *buf, size_t len, VipsImage **out, ... ) * * @n: %gint, load this many pages * * @scale: %gdouble, scale by this much on load * - * Exactly as vips_webpload(), but read from a stream. + * Exactly as vips_webpload(), but read from a source. * * See also: vips_webpload() * @@ -550,7 +550,7 @@ vips_webpload_source( VipsSource *source, VipsImage **out, ... ) int result; va_start( ap, out ); - result = vips_call_split( "webpload_stream", ap, source, out ); + result = vips_call_split( "webpload_source", ap, source, out ); va_end( ap ); return( result ); diff --git a/libvips/foreign/webpsave.c b/libvips/foreign/webpsave.c index f8c4fdbc..ef08e8a2 100644 --- a/libvips/foreign/webpsave.c +++ b/libvips/foreign/webpsave.c @@ -219,31 +219,31 @@ vips_foreign_save_webp_init( VipsForeignSaveWebp *webp ) webp->kmax = INT_MAX; } -typedef struct _VipsForeignSaveWebpStream { +typedef struct _VipsForeignSaveWebpTarget { VipsForeignSaveWebp parent_object; VipsTarget *target; -} VipsForeignSaveWebpStream; +} VipsForeignSaveWebpTarget; -typedef VipsForeignSaveWebpClass VipsForeignSaveWebpStreamClass; +typedef VipsForeignSaveWebpClass VipsForeignSaveWebpTargetClass; -G_DEFINE_TYPE( VipsForeignSaveWebpStream, vips_foreign_save_webp_stream, +G_DEFINE_TYPE( VipsForeignSaveWebpTarget, vips_foreign_save_webp_target, vips_foreign_save_webp_get_type() ); static int -vips_foreign_save_webp_stream_build( VipsObject *object ) +vips_foreign_save_webp_target_build( VipsObject *object ) { VipsForeignSave *save = (VipsForeignSave *) object; VipsForeignSaveWebp *webp = (VipsForeignSaveWebp *) object; - VipsForeignSaveWebpStream *stream = - (VipsForeignSaveWebpStream *) object; + VipsForeignSaveWebpTarget *target = + (VipsForeignSaveWebpTarget *) object; - if( VIPS_OBJECT_CLASS( vips_foreign_save_webp_stream_parent_class )-> + if( VIPS_OBJECT_CLASS( vips_foreign_save_webp_target_parent_class )-> build( object ) ) return( -1 ); - if( vips__webp_write_stream( save->ready, stream->target, + if( vips__webp_write_target( save->ready, target->target, webp->Q, webp->lossless, webp->preset, webp->smart_subsample, webp->near_lossless, webp->alpha_q, webp->reduction_effort, @@ -255,8 +255,8 @@ vips_foreign_save_webp_stream_build( VipsObject *object ) } static void -vips_foreign_save_webp_stream_class_init( - VipsForeignSaveWebpStreamClass *class ) +vips_foreign_save_webp_target_class_init( + VipsForeignSaveWebpTargetClass *class ) { GObjectClass *gobject_class = G_OBJECT_CLASS( class ); VipsObjectClass *object_class = (VipsObjectClass *) class; @@ -264,20 +264,20 @@ vips_foreign_save_webp_stream_class_init( gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property; - object_class->nickname = "webpsave_stream"; - object_class->description = _( "save image to webp stream" ); - object_class->build = vips_foreign_save_webp_stream_build; + object_class->nickname = "webpsave_target"; + object_class->description = _( "save image to webp target" ); + object_class->build = vips_foreign_save_webp_target_build; VIPS_ARG_OBJECT( class, "target", 1, - _( "target" ), - _( "Stream to save to" ), + _( "Target" ), + _( "Target to save to" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsForeignSaveWebpStream, target ), + G_STRUCT_OFFSET( VipsForeignSaveWebpTarget, target ), VIPS_TYPE_TARGET ); } static void -vips_foreign_save_webp_stream_init( VipsForeignSaveWebpStream *stream ) +vips_foreign_save_webp_target_init( VipsForeignSaveWebpTarget *target ) { } @@ -311,7 +311,7 @@ vips_foreign_save_webp_file_build( VipsObject *object ) if( !(target = vips_target_new_to_file( file->filename )) ) return( -1 ); - if( vips__webp_write_stream( save->ready, target, + if( vips__webp_write_target( save->ready, target, webp->Q, webp->lossless, webp->preset, webp->smart_subsample, webp->near_lossless, webp->alpha_q, webp->reduction_effort, @@ -383,7 +383,7 @@ vips_foreign_save_webp_buffer_build( VipsObject *object ) if( !(target = vips_target_new_to_memory()) ) return( -1 ); - if( vips__webp_write_stream( save->ready, target, + if( vips__webp_write_target( save->ready, target, webp->Q, webp->lossless, webp->preset, webp->smart_subsample, webp->near_lossless, webp->alpha_q, webp->reduction_effort, @@ -457,7 +457,7 @@ vips_foreign_save_webp_mime_build( VipsObject *object ) if( !(target = vips_target_new_to_memory()) ) return( -1 ); - if( vips__webp_write_stream( save->ready, target, + if( vips__webp_write_target( save->ready, target, webp->Q, webp->lossless, webp->preset, webp->smart_subsample, webp->near_lossless, webp->alpha_q, webp->reduction_effort, @@ -673,7 +673,7 @@ vips_webpsave_mime( VipsImage *in, ... ) /** * vips_webpsave_target: (method) * @in: image to save - * @target: save image to this stream + * @target: save image to this target * @...: %NULL-terminated list of optional named arguments * * Optional arguments: @@ -690,7 +690,7 @@ vips_webpsave_mime( VipsImage *in, ... ) * * @kmax: %gint, maximum number of frames between keyframes * * @strip: %gboolean, remove all metadata from image * - * As vips_webpsave(), but save to a stream. + * As vips_webpsave(), but save to a target. * * See also: vips_webpsave(). * @@ -703,7 +703,7 @@ vips_webpsave_target( VipsImage *in, VipsTarget *target, ... ) int result; va_start( ap, target ); - result = vips_call_split( "webpsave_stream", ap, in, target ); + result = vips_call_split( "webpsave_target", ap, in, target ); va_end( ap ); return( result ); diff --git a/libvips/iofuncs/bufis.c b/libvips/iofuncs/bufis.c index 56e29809..047dfaf7 100644 --- a/libvips/iofuncs/bufis.c +++ b/libvips/iofuncs/bufis.c @@ -1,4 +1,4 @@ -/* Buffered input from a stream. +/* Buffered input from a source. * * J.Cupitt, 18/11/19 */ @@ -68,11 +68,11 @@ vips_bufis_class_init( VipsBufisClass *class ) gobject_class->get_property = vips_object_get_property; object_class->nickname = "bufis"; - object_class->description = _( "buffered input stream" ); + object_class->description = _( "buffered source" ); VIPS_ARG_OBJECT( class, "input", 1, _( "Input" ), - _( "Stream to load from" ), + _( "Source to load from" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsBufis, source ), VIPS_TYPE_SOURCE ); @@ -89,7 +89,7 @@ vips_bufis_init( VipsBufis *bufis ) /** * vips_bufis_new_from_source: - * @source: stream to operate on + * @source: source to operate on * * Create a bufis wrapping a source. * @@ -114,7 +114,7 @@ vips_bufis_new_from_source( VipsSource *source ) /** * vips_bufis_unbuffer: - * @bufis: stream to operate on + * @bufis: source to operate on * * Discard the input buffer and reset the read point. You must call this * before using read or seek on the underlying #VipsSource class. @@ -161,9 +161,9 @@ vips_bufis_refill( VipsBufis *bufis ) /** * vips_bufis_getc: - * @bufis: stream to operate on + * @bufis: source to operate on * - * Fetch the next character from the stream. + * Fetch the next character from the source. * * If you can, use the macro VIPS_BUFIS_GETC() instead for speed. * @@ -183,16 +183,16 @@ vips_bufis_getc( VipsBufis *bufis ) /** * VIPS_BUFIS_GETC: - * @bufis: stream to operate on + * @bufis: source to operate on * - * Fetch the next character from the stream. + * Fetch the next character from the source. * * Returns: the next char from @bufis, -1 on read error or EOF. */ /** * vips_bufis_ungetc: - * @bufis: stream to operate on + * @bufis: source to operate on * * The opposite of vips_bufis_getc(): undo the previous getc. * @@ -210,7 +210,7 @@ vips_bufis_ungetc( VipsBufis *bufis ) /** * VIPS_BUFIS_UNGETC: - * @bufis: stream to operate on + * @bufis: source to operate on * * The opposite of vips_bufis_getc(): undo the previous getc. * @@ -220,7 +220,7 @@ vips_bufis_ungetc( VipsBufis *bufis ) /** * vips_bufis_require: - * @bufis: stream to operate on + * @bufis: source to operate on * @require: make sure we have at least this many chars available * * Make sure there are at least @require bytes of readahead available. @@ -276,7 +276,7 @@ vips_bufis_require( VipsBufis *bufis, int require ) /** * VIPS_BUFIS_REQUIRE: - * @bufis: stream to operate on + * @bufis: source to operate on * @require: need this many characters * * Make sure at least @require characters are available for @@ -287,7 +287,7 @@ vips_bufis_require( VipsBufis *bufis, int require ) /** * VIPS_BUFIS_PEEK: - * @bufis: stream to operate on + * @bufis: source to operate on * * After a successful VIPS_BUFIS_REQUIRE(), you can index this to get * require characters of input. @@ -297,7 +297,7 @@ vips_bufis_require( VipsBufis *bufis, int require ) /** * VIPS_BUFIS_FETCH: - * @bufis: stream to operate on + * @bufis: source to operate on * * After a successful VIPS_BUFIS_REQUIRE(), you can use this require times * to fetch characters of input. @@ -307,7 +307,7 @@ vips_bufis_require( VipsBufis *bufis, int require ) /** * vips_bufis_get_line: - * @bufis: stream to operate on + * @bufis: source to operate on * * Fetch the next line of text from @bufis and return it. The end of * line character (or characters, for DOS files) are removed, and the string @@ -378,7 +378,7 @@ vips_bufis_get_line( VipsBufis *bufis ) /** * vips_bufis_get_line_copy: - * @bufis: stream to operate on + * @bufis: source to operate on * * Fetch the next line of text from @bufis and return it. The end of * line character (or characters, for DOS files) are removed, and the string @@ -438,9 +438,9 @@ vips_bufis_get_line_copy( VipsBufis *bufis ) /** * vips_bufis_get_non_whitespace: - * @bufis: stream to operate on + * @bufis: source to operate on * - * Fetch the next chunk of non-whitespace text from the stream, and + * Fetch the next chunk of non-whitespace text from the source, and * null-terminate it. * * After this, the next getc will be the first char of the next block of @@ -488,7 +488,7 @@ vips_bufis_get_non_whitespace( VipsBufis *bufis ) /** * vips_bufis_skip_whitespace: - * @bufis: stream to operate on + * @bufis: source to operate on * * After this, the next getc will be the first char of the next block of * non-whitespace (or EOF). diff --git a/libvips/iofuncs/connection.c b/libvips/iofuncs/connection.c index d23df29f..a148ff07 100644 --- a/libvips/iofuncs/connection.c +++ b/libvips/iofuncs/connection.c @@ -57,15 +57,15 @@ #include /** - * SECTION: stream + * SECTION: connection * @short_description: a source/sink of bytes, perhaps a network socket * @stability: Stable * @see_also: foreign * @include: vips/vips.h * - * A #VipsConnection is a source or sink of bytes for something like jpeg loading. - * It can be connected to a network socket, for example, or perhaps a node.js - * stream, or to an area of memory. + * A #VipsConnection is a source or sink of bytes for something like jpeg + * loading. It can be connected to a network socket, for example, or perhaps + * a node.js stream, or to an area of memory. * * Subclass to add other input sources. */ @@ -73,8 +73,8 @@ /** * VipsConnection: * - * A #VipsConnection is a source or sink of bytes for something like jpeg loading. - * It can be connected to a network socket, for example. + * A #VipsConnection is a source or sink of bytes for something like jpeg + * loading. It can be connected to a network socket, for example. */ G_DEFINE_ABSTRACT_TYPE( VipsConnection, vips_connection, VIPS_TYPE_OBJECT ); @@ -82,7 +82,7 @@ G_DEFINE_ABSTRACT_TYPE( VipsConnection, vips_connection, VIPS_TYPE_OBJECT ); static void vips_connection_finalize( GObject *gobject ) { - VipsConnection *stream = (VipsConnection *) gobject; + VipsConnection *connection = (VipsConnection *) gobject; #ifdef VIPS_DEBUG VIPS_DEBUG_MSG( "vips_connection_finalize: " ); @@ -90,21 +90,21 @@ vips_connection_finalize( GObject *gobject ) VIPS_DEBUG_MSG( "\n" ); #endif /*VIPS_DEBUG*/ - if( stream->tracked_descriptor >= 0 ) { + if( connection->tracked_descriptor >= 0 ) { VIPS_DEBUG_MSG( " tracked_close()\n" ); - vips_tracked_close( stream->tracked_descriptor ); - stream->tracked_descriptor = -1; - stream->descriptor = -1; + vips_tracked_close( connection->tracked_descriptor ); + connection->tracked_descriptor = -1; + connection->descriptor = -1; } - if( stream->close_descriptor >= 0 ) { + if( connection->close_descriptor >= 0 ) { VIPS_DEBUG_MSG( " close()\n" ); - close( stream->close_descriptor ); - stream->close_descriptor = -1; - stream->descriptor = -1; + close( connection->close_descriptor ); + connection->close_descriptor = -1; + connection->descriptor = -1; } - VIPS_FREE( stream->filename ); + VIPS_FREE( connection->filename ); G_OBJECT_CLASS( vips_connection_parent_class )->finalize( gobject ); } @@ -135,23 +135,23 @@ vips_connection_class_init( VipsConnectionClass *class ) } static void -vips_connection_init( VipsConnection *stream ) +vips_connection_init( VipsConnection *connection ) { - stream->descriptor = -1; - stream->tracked_descriptor = -1; - stream->close_descriptor = -1; + connection->descriptor = -1; + connection->tracked_descriptor = -1; + connection->close_descriptor = -1; } const char * -vips_connection_filename( VipsConnection *stream ) +vips_connection_filename( VipsConnection *connection ) { - return( stream->filename ); + return( connection->filename ); } const char * -vips_connection_nick( VipsConnection *stream ) +vips_connection_nick( VipsConnection *connection ) { - return( stream->filename ? - stream->filename : - VIPS_OBJECT( stream )->nickname ); + return( connection->filename ? + connection->filename : + VIPS_OBJECT( connection )->nickname ); } diff --git a/libvips/iofuncs/destination.c b/libvips/iofuncs/destination.c deleted file mode 100644 index b08ac431..00000000 --- a/libvips/iofuncs/destination.c +++ /dev/null @@ -1,609 +0,0 @@ -/* A byte source/sink .. it can be a pipe, file descriptor, memory area, - * socket, node.js stream, etc. - * - * J.Cupitt, 19/6/14 - */ - -/* - - This file is part of VIPS. - - VIPS is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA - - */ - -/* - - These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk - - */ - -/* -#define VIPS_DEBUG - */ - -#ifdef HAVE_CONFIG_H -#include -#endif /*HAVE_CONFIG_H*/ -#include - -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif /*HAVE_UNISTD_H*/ -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -/* Try to make an O_BINARY ... sometimes need the leading '_'. - */ -#ifdef BINARY_OPEN -#ifndef O_BINARY -#ifdef _O_BINARY -#define O_BINARY _O_BINARY -#endif /*_O_BINARY*/ -#endif /*!O_BINARY*/ -#endif /*BINARY_OPEN*/ - -/* If we have O_BINARY, add it to a mode flags set. - */ -#ifdef O_BINARY -#define BINARYIZE(M) ((M) | O_BINARY) -#else /*!O_BINARY*/ -#define BINARYIZE(M) (M) -#endif /*O_BINARY*/ - -#define MODE_READ BINARYIZE (O_RDONLY) -#define MODE_READWRITE BINARYIZE (O_RDWR) -#define MODE_WRITE BINARYIZE (O_WRONLY | O_CREAT | O_TRUNC) - -G_DEFINE_TYPE( VipsDestination, vips_destination, VIPS_TYPE_CONNECTION ); - -static void -vips_destination_finalize( GObject *gobject ) -{ - VipsDestination *destination = VIPS_DESTINATION( gobject ); - - VIPS_DEBUG_MSG( "vips_destination_finalize:\n" ); - - VIPS_FREEF( g_byte_array_unref, destination->memory_buffer ); - if( destination->blob ) { - vips_area_unref( VIPS_AREA( destination->blob ) ); - destination->blob = NULL; - } - - G_OBJECT_CLASS( vips_destination_parent_class )->finalize( gobject ); -} - -static int -vips_destination_build( VipsObject *object ) -{ - VipsConnection *stream = VIPS_CONNECTION( object ); - VipsDestination *destination = VIPS_DESTINATION( object ); - - VIPS_DEBUG_MSG( "vips_destination_build: %p\n", stream ); - - if( VIPS_OBJECT_CLASS( vips_destination_parent_class )->build( object ) ) - return( -1 ); - - if( vips_object_argument_isset( object, "filename" ) && - vips_object_argument_isset( object, "descriptor" ) ) { - vips_error( vips_connection_nick( stream ), - "%s", _( "don't set 'filename' and 'descriptor'" ) ); - return( -1 ); - } - - if( stream->filename ) { - const char *filename = stream->filename; - - int fd; - - /* 0644 is rw user, r group and other. - */ - if( (fd = vips_tracked_open( filename, - MODE_WRITE, 0644 )) == -1 ) { - vips_error_system( errno, vips_connection_nick( stream ), - "%s", _( "unable to open for write" ) ); - return( -1 ); - } - - stream->tracked_descriptor = fd; - stream->descriptor = fd; - } - else if( vips_object_argument_isset( object, "descriptor" ) ) { - stream->descriptor = dup( stream->descriptor ); - stream->close_descriptor = stream->descriptor; - } - else if( destination->memory ) { - destination->memory_buffer = g_byte_array_new(); - } - - return( 0 ); -} - -static gint64 -vips_destination_write_real( VipsDestination *destination, const void *data, size_t length ) -{ - VipsConnection *stream = VIPS_CONNECTION( destination ); - - VIPS_DEBUG_MSG( "vips_destination_write_real: %zd bytes\n", length ); - - return( write( stream->descriptor, data, length ) ); -} - -static void -vips_destination_finish_real( VipsDestination *destination ) -{ - VIPS_DEBUG_MSG( "vips_destination_finish_real:\n" ); -} - -static void -vips_destination_class_init( VipsDestinationClass *class ) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS( class ); - VipsObjectClass *object_class = VIPS_OBJECT_CLASS( class ); - - gobject_class->finalize = vips_destination_finalize; - gobject_class->set_property = vips_object_set_property; - gobject_class->get_property = vips_object_get_property; - - object_class->nickname = "destination"; - object_class->description = _( "stream stream" ); - - object_class->build = vips_destination_build; - - class->write = vips_destination_write_real; - class->finish = vips_destination_finish_real; - - VIPS_ARG_BOOL( class, "memory", 3, - _( "Memory" ), - _( "File descriptor should output to memory" ), - VIPS_ARGUMENT_OPTIONAL_INPUT, - G_STRUCT_OFFSET( VipsDestination, memory ), - FALSE ); - - /* SET_ALWAYS means that blob is set by C and the obj system is not - * involved in creation or destruction. It can be read at any time. - */ - VIPS_ARG_BOXED( class, "blob", 4, - _( "Blob" ), - _( "Blob to save to" ), - VIPS_ARGUMENT_SET_ALWAYS, - G_STRUCT_OFFSET( VipsDestination, blob ), - VIPS_TYPE_BLOB ); - -} - -static void -vips_destination_init( VipsDestination *destination ) -{ - destination->blob = vips_blob_new( NULL, NULL, 0 ); - destination->write_point = 0; -} - -/** - * vips_destination_new_to_descriptor: - * @descriptor: write to this file descriptor - * - * Create a stream attached to a file descriptor. - * @descriptor is kept open until the #VipsDestination is finalized. - * - * See also: vips_destination_new_to_file(). - * - * Returns: a new #VipsDestination - */ -VipsDestination * -vips_destination_new_to_descriptor( int descriptor ) -{ - VipsDestination *destination; - - VIPS_DEBUG_MSG( "vips_destination_new_to_descriptor: %d\n", - descriptor ); - - destination = VIPS_DESTINATION( g_object_new( VIPS_TYPE_DESTINATION, - "descriptor", descriptor, - NULL ) ); - - if( vips_object_build( VIPS_OBJECT( destination ) ) ) { - VIPS_UNREF( destination ); - return( NULL ); - } - - return( destination ); -} - -/** - * vips_destination_new_to_file: - * @filename: write to this file - * - * Create a stream attached to a file. - * - * Returns: a new #VipsDestination - */ -VipsDestination * -vips_destination_new_to_file( const char *filename ) -{ - VipsDestination *destination; - - VIPS_DEBUG_MSG( "vips_destination_new_to_file: %s\n", - filename ); - - destination = VIPS_DESTINATION( g_object_new( VIPS_TYPE_DESTINATION, - "filename", filename, - NULL ) ); - - if( vips_object_build( VIPS_OBJECT( destination ) ) ) { - VIPS_UNREF( destination ); - return( NULL ); - } - - return( destination ); -} - -/** - * vips_destination_new_to_memory: - * - * Create a stream which will stream to a memory area. Read from @blob to get - * memory. - * - * See also: vips_destination_new_to_file(). - * - * Returns: a new #VipsConnection - */ -VipsDestination * -vips_destination_new_to_memory( void ) -{ - VipsDestination *destination; - - VIPS_DEBUG_MSG( "vips_destination_new_to_memory:\n" ); - - destination = VIPS_DESTINATION( g_object_new( VIPS_TYPE_DESTINATION, - "memory", TRUE, - NULL ) ); - - if( vips_object_build( VIPS_OBJECT( destination ) ) ) { - VIPS_UNREF( destination ); - return( NULL ); - } - - return( destination ); -} - -static int -vips_destination_write_unbuffered( VipsDestination *destination, - const void *data, size_t length ) -{ - VipsDestinationClass *class = VIPS_DESTINATION_GET_CLASS( destination ); - - VIPS_DEBUG_MSG( "vips_destination_write_unbuffered:\n" ); - - if( destination->finished ) - return( 0 ); - - if( destination->memory_buffer ) - g_byte_array_append( destination->memory_buffer, data, length ); - else - while( length > 0 ) { - gint64 bytes_written; - - bytes_written = class->write( destination, data, length ); - - /* n == 0 isn't strictly an error, but we treat it as - * one to make sure we don't get stuck in this loop. - */ - if( bytes_written <= 0 ) { - vips_error_system( errno, - vips_connection_nick( - VIPS_CONNECTION( destination ) ), - "%s", _( "write error" ) ); - return( -1 ); - } - - length -= bytes_written; - data += bytes_written; - } - - return( 0 ); -} - -static int -vips_destination_flush( VipsDestination *destination ) -{ - g_assert( destination->write_point >= 0 ); - g_assert( destination->write_point <= VIPS_DESTINATION_BUFFER_SIZE ); - - VIPS_DEBUG_MSG( "vips_destination_flush:\n" ); - - if( destination->write_point > 0 ) { - if( vips_destination_write_unbuffered( destination, - destination->output_buffer, destination->write_point ) ) - return( -1 ); - destination->write_point = 0; - } - - return( 0 ); -} - -/** - * vips_destination_write: - * @destination: output stream to operate on - * @buffer: bytes to write - * @length: length of @buffer in bytes - * - * Write @length bytes from @buffer to the output. - * - * Returns: 0 on success, -1 on error. - */ -int -vips_destination_write( VipsDestination *destination, const void *buffer, size_t length ) -{ - VIPS_DEBUG_MSG( "vips_destination_write: %zd bytes\n", length ); - - if( length > VIPS_DESTINATION_BUFFER_SIZE - destination->write_point && - vips_destination_flush( destination ) ) - return( -1 ); - - if( length > VIPS_DESTINATION_BUFFER_SIZE - destination->write_point ) { - /* Still too large? Do an unbuffered write. - */ - if( vips_destination_write_unbuffered( destination, buffer, length ) ) - return( -1 ); - } - else { - memcpy( destination->output_buffer + destination->write_point, - buffer, length ); - destination->write_point += length; - } - - return( 0 ); -} - -/** - * vips_destination_finish: - * @destination: output stream to operate on - * @buffer: bytes to write - * @length: length of @buffer in bytes - * - * Call this at the end of write to make the stream do any cleaning up. You - * can call it many times. - * - * After a destination has been finished, further writes will do nothing. - */ -void -vips_destination_finish( VipsDestination *destination ) -{ - VipsDestinationClass *class = VIPS_DESTINATION_GET_CLASS( destination ); - - VIPS_DEBUG_MSG( "vips_destination_finish:\n" ); - - if( destination->finished ) - return; - - (void) vips_destination_flush( destination ); - - /* Move the stream buffer into the blob so it can be read out. - */ - if( destination->memory_buffer ) { - unsigned char *data; - size_t length; - - length = destination->memory_buffer->len; - data = g_byte_array_free( destination->memory_buffer, FALSE ); - destination->memory_buffer = NULL; - vips_blob_set( destination->blob, - (VipsCallbackFn) g_free, data, length ); - } - else - class->finish( destination ); - - destination->finished = TRUE; -} - -/** - * vips_destination_steal: - * @destination: output stream to operate on - * @length: return number of bytes of data - * - * Memory streams only (see vips_destination_new_to_memory()). Steal all data - * written to the stream so far, and finish it. - * - * You must free the returned pointer with g_free(). - * - * The data is NOT automatically null-terminated. vips_destination_putc() a '\0' - * before calling this to get a null-terminated string. - * - * Returns: (array length=length) (element-type guint8) (transfer full): the - * data - */ -unsigned char * -vips_destination_steal( VipsDestination *destination, size_t *length ) -{ - unsigned char *data; - - (void) vips_destination_flush( destination ); - - if( !destination->memory_buffer || - destination->finished ) { - if( length ) - *length = destination->memory_buffer->len; - - return( NULL ); - } - - if( length ) - *length = destination->memory_buffer->len; - data = g_byte_array_free( destination->memory_buffer, FALSE ); - destination->memory_buffer = NULL; - - /* We must have a valid byte array or finish will fail. - */ - destination->memory_buffer = g_byte_array_new(); - - vips_destination_finish( destination ); - - return( data ); -} - -/** - * vips_destination_steal_text: - * @destination: output stream to operate on - * - * As vips_destination_steal_text(), but return a null-terminated string. - * - * Returns: (transfer full): stream contents as a null-terminated string. - */ -char * -vips_destination_steal_text( VipsDestination *destination ) -{ - vips_destination_putc( destination, '\0' ); - - return( (char *) vips_destination_steal( destination, NULL ) ); -} - -/** - * vips_destination_putc: - * @destination: output stream to operate on - * @ch: character to write - * - * Write a single character @ch to @destination. See the macro VIPS_DESTINATION_PUTC() - * for a faster way to do this. - * - * Returns: 0 on success, -1 on error. - */ -int -vips_destination_putc( VipsDestination *destination, int ch ) -{ - VIPS_DEBUG_MSG( "vips_destination_putc: %d\n", ch ); - - if( destination->write_point >= VIPS_DESTINATION_BUFFER_SIZE && - vips_destination_flush( destination ) ) - return( -1 ); - - destination->output_buffer[destination->write_point++] = ch; - - return( 0 ); -} - -/** - * vips_destination_writes: - * @destination: output stream to operate on - * @str: string to write - * - * Write a null-terminated string to @destination. - * - * Returns: 0 on success, and -1 on error. - */ -int -vips_destination_writes( VipsDestination *destination, const char *str ) -{ - return( vips_destination_write( destination, - (unsigned char *) str, strlen( str ) ) ); -} - -/** - * vips_destination_writef: - * @destination: output stream to operate on - * @fmt: printf()-style format string - * @...: arguments to format string - * - * Format the string and write to @destination. - * - * Returns: 0 on success, and -1 on error. - */ -int -vips_destination_writef( VipsDestination *destination, const char *fmt, ... ) -{ - va_list ap; - char *line; - int result; - - va_start( ap, fmt ); - line = g_strdup_vprintf( fmt, ap ); - va_end( ap ); - - result = vips_destination_writes( destination, line ); - - g_free( line ); - - return( result ); -} - -/** - * vips_destination_write_amp: - * @destination: output stream to operate on - * @str: string to write - * - * Write @str to @destination, but escape stuff that xml hates in text. Our - * argument string is utf-8. - * - * XML rules: - * - * - We must escape &<> - * - Don't escape \n, \t, \r - * - Do escape the other ASCII codes. - * - * Returns: 0 on success, -1 on error. - */ -int -vips_destination_write_amp( VipsDestination *destination, const char *str ) -{ - const char *p; - - for( p = str; *p; p++ ) - if( *p < 32 && - *p != '\n' && - *p != '\t' && - *p != '\r' ) { - /* You'd think we could output "%x;", but xml - * 1.0 parsers barf on that. xml 1.1 allows this, but - * there are almost no parsers. - * - * U+2400 onwards are unicode glyphs for the ASCII - * control characters, so we can use them -- thanks - * electroly. - */ - if( vips_destination_writef( destination, - "&#x%04x;", 0x2400 + *p ) ) - return( -1 ); - } - else if( *p == '<' ) { - if( vips_destination_writes( destination, "<" ) ) - return( -1 ); - } - else if( *p == '>' ) { - if( vips_destination_writes( destination, ">" ) ) - return( -1 ); - } - else if( *p == '&' ) { - if( vips_destination_writes( destination, "&" ) ) - return( -1 ); - } - else { - if( VIPS_DESTINATION_PUTC( destination, *p ) ) - return( -1 ); - } - - return( 0 ); -} - diff --git a/libvips/iofuncs/destinationcustom.c b/libvips/iofuncs/destinationcustom.c deleted file mode 100644 index e80d1caf..00000000 --- a/libvips/iofuncs/destinationcustom.c +++ /dev/null @@ -1,194 +0,0 @@ -/* A Streamo subclass with signals you can easily hook up to other output - * sources. - * - * J.Cupitt, 21/11/19 - */ - -/* - - This file is part of VIPS. - - VIPS is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA - - */ - -/* - - These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk - - */ - -/* -#define VIPS_DEBUG - */ - -#ifdef HAVE_CONFIG_H -#include -#endif /*HAVE_CONFIG_H*/ -#include - -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif /*HAVE_UNISTD_H*/ -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "vipsmarshal.h" - -G_DEFINE_TYPE( VipsDestinationCustom, vips_destination_custom, VIPS_TYPE_DESTINATION ); - -/* Our signals. - */ -enum { - SIG_WRITE, - SIG_FINISH, - SIG_LAST -}; - -static guint vips_destination_custom_signals[SIG_LAST] = { 0 }; - -static gint64 -vips_destination_custom_write_real( VipsDestination *destination, - const void *data, size_t length ) -{ - gint64 bytes_written; - - VIPS_DEBUG_MSG( "vips_destination_custom_write_real:\n" ); - - /* Return value if no attached handler. - */ - bytes_written = 0; - - g_signal_emit( destination, vips_destination_custom_signals[SIG_WRITE], 0, - data, (gint64) length, &bytes_written ); - - VIPS_DEBUG_MSG( " %zd\n", bytes_written ); - - return( bytes_written ); -} - -static void -vips_destination_custom_finish_real( VipsDestination *destination ) -{ - VIPS_DEBUG_MSG( "vips_destination_custom_seek_real:\n" ); - - g_signal_emit( destination, vips_destination_custom_signals[SIG_FINISH], 0 ); -} - -static gint64 -vips_destination_custom_write_signal_real( VipsDestinationCustom *destination_custom, - const void *data, gint64 length ) -{ - VIPS_DEBUG_MSG( "vips_destination_custom_write_signal_real:\n" ); - - return( 0 ); -} - -static void -vips_destination_custom_finish_signal_real( VipsDestinationCustom *destination_custom ) -{ - VIPS_DEBUG_MSG( "vips_destination_custom_finish_signal_real:\n" ); -} - -static void -vips_destination_custom_class_init( VipsDestinationCustomClass *class ) -{ - VipsObjectClass *object_class = VIPS_OBJECT_CLASS( class ); - VipsDestinationClass *destination_class = VIPS_DESTINATION_CLASS( class ); - - object_class->nickname = "destination_custom"; - object_class->description = _( "input stream" ); - - destination_class->write = vips_destination_custom_write_real; - destination_class->finish = vips_destination_custom_finish_real; - - class->write = vips_destination_custom_write_signal_real; - class->finish = vips_destination_custom_finish_signal_real; - - /** - * VipsDestinationCustom::write: - * @destination_custom: the stream being operated on - * @data: %pointer, bytes to write - * @length: %gint64, number of bytes - * - * This signal is emitted to write bytes to the stream. - * - * Returns: the number of bytes written. - */ - vips_destination_custom_signals[SIG_WRITE] = g_signal_new( "write", - G_TYPE_FROM_CLASS( class ), - G_SIGNAL_ACTION, - G_STRUCT_OFFSET( VipsDestinationCustomClass, write ), - NULL, NULL, - vips_INT64__POINTER_INT64, - G_TYPE_INT64, 2, - G_TYPE_POINTER, G_TYPE_INT64 ); - - /** - * VipsDestinationCustom::finish: - * @destination_custom: the stream being operated on - * - * This signal is emitted at the end of write. The stream should do - * any finishing necessary. - */ - vips_destination_custom_signals[SIG_FINISH] = g_signal_new( "finish", - G_TYPE_FROM_CLASS( class ), - G_SIGNAL_ACTION, - G_STRUCT_OFFSET( VipsDestinationCustomClass, finish ), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0 ); - -} - -static void -vips_destination_custom_init( VipsDestinationCustom *destination_custom ) -{ -} - -/** - * vips_destination_custom_new: - * - * Create a #VipsDestinationCustom. Attach signals to implement write and finish. - * - * Returns: a new #VipsDestinationCustom - */ -VipsDestinationCustom * -vips_destination_custom_new( void ) -{ - VipsDestinationCustom *destination_custom; - - VIPS_DEBUG_MSG( "vips_destination_custom_new:\n" ); - - destination_custom = VIPS_DESTINATION_CUSTOM( g_object_new( VIPS_TYPE_DESTINATION_CUSTOM, NULL ) ); - - if( vips_object_build( VIPS_OBJECT( destination_custom ) ) ) { - VIPS_UNREF( destination_custom ); - return( NULL ); - } - - return( destination_custom ); -} diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index 1b59ca44..8d260c72 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -1917,7 +1917,7 @@ vips_image_new_from_file( const char *name, ... ) vips__filename_split8( name, filename, option_string ); - /* Search with the new stream API first, then fall back to the older + /* Search with the new source API first, then fall back to the older * mechanism in case the loader we need has not been converted yet. * * We need to hide any errors from this first phase. @@ -2167,7 +2167,7 @@ vips_image_new_from_buffer( const void *buf, size_t len, vips_check_init(); - /* Search with the new stream API first, then fall back to the older + /* Search with the new source API first, then fall back to the older * mechanism in case the loader we need has not been converted yet. */ if( !(source = vips_source_new_from_memory( buf, len )) ) @@ -2208,11 +2208,11 @@ vips_image_new_from_buffer( const void *buf, size_t len, /** * vips_image_new_from_source: (constructor) - * @source: (transfer none): stream to fetch image from + * @source: (transfer none): source to fetch image from * @option_string: set of extra options as a string * @...: %NULL-terminated list of optional named arguments * - * Loads an image from the formatted stream @input, + * Loads an image from the formatted source @input, * loader recommended by vips_foreign_find_load_source(). * * Load options may be given in @option_string as "[name=value,...]" or given as @@ -2227,7 +2227,8 @@ VipsImage * vips_image_new_from_source( VipsSource *source, const char *option_string, ... ) { - const char *filename = vips_connection_filename( VIPS_CONNECTION( source ) ); + const char *filename = + vips_connection_filename( VIPS_CONNECTION( source ) ); const char *operation_name; va_list ap; @@ -2283,7 +2284,7 @@ vips_image_new_from_source( VipsSource *source, } else { vips_error( "VipsImage", - "%s", _( "unable to load stream" ) ); + "%s", _( "unable to load source" ) ); result = -1; } @@ -2712,7 +2713,7 @@ vips_image_write_to_file( VipsImage *image, const char *name, ... ) va_list ap; int result; - /* Save with the new stream API if we can. Fall back to the older + /* Save with the new target API if we can. Fall back to the older * mechanism in case the loader we need has not been converted yet. * * We need to hide any errors from this first phase. @@ -2840,7 +2841,7 @@ vips_image_write_to_buffer( VipsImage *in, * vips_image_write_to_target: (method) * @in: image to write * @suffix: format to write - * @target: stream to write to + * @target: target to write to * @...: %NULL-terminated list of optional named arguments * * Writes @in to @output in format @suffix. diff --git a/libvips/iofuncs/source.c b/libvips/iofuncs/source.c index 0b439f07..c9b248a6 100644 --- a/libvips/iofuncs/source.c +++ b/libvips/iofuncs/source.c @@ -117,7 +117,7 @@ vips_source_test_features( VipsSource *source ) class->seek( source, 0, SEEK_CUR ) != -1 ) { gint64 length; - VIPS_DEBUG_MSG( " seekable stream\n" ); + VIPS_DEBUG_MSG( " seekable source\n" ); /* We should be able to get the length of seekable * objects. @@ -239,7 +239,7 @@ vips_source_finalize( GObject *gobject ) static int vips_source_build( VipsObject *object ) { - VipsConnection *stream = VIPS_CONNECTION( object ); + VipsConnection *connection = VIPS_CONNECTION( object ); VipsSource *source = VIPS_SOURCE( object ); VIPS_DEBUG_MSG( "vips_source_build: %p\n", source ); @@ -250,7 +250,7 @@ vips_source_build( VipsObject *object ) if( vips_object_argument_isset( object, "filename" ) && vips_object_argument_isset( object, "descriptor" ) ) { - vips_error( vips_connection_nick( stream ), + vips_error( vips_connection_nick( connection ), "%s", _( "don't set 'filename' and 'descriptor'" ) ); return( -1 ); } @@ -262,8 +262,8 @@ vips_source_build( VipsObject *object ) return( -1 ); if( vips_object_argument_isset( object, "descriptor" ) ) { - stream->descriptor = dup( stream->descriptor ); - stream->close_descriptor = stream->descriptor; + connection->descriptor = dup( connection->descriptor ); + connection->close_descriptor = connection->descriptor; } if( vips_object_argument_isset( object, "blob" ) ) { @@ -279,14 +279,14 @@ vips_source_build( VipsObject *object ) static gint64 vips_source_read_real( VipsSource *source, void *data, size_t length ) { - VipsConnection *stream = VIPS_CONNECTION( source ); + VipsConnection *connection = VIPS_CONNECTION( source ); gint64 bytes_read; VIPS_DEBUG_MSG( "vips_source_read_real:\n" ); do { - bytes_read = read( stream->descriptor, data, length ); + bytes_read = read( connection->descriptor, data, length ); } while( bytes_read < 0 && errno == EINTR ); return( bytes_read ); @@ -295,7 +295,7 @@ vips_source_read_real( VipsSource *source, void *data, size_t length ) static gint64 vips_source_seek_real( VipsSource *source, gint64 offset, int whence ) { - VipsConnection *stream = VIPS_CONNECTION( source ); + VipsConnection *connection = VIPS_CONNECTION( source ); gint64 new_pos; @@ -304,7 +304,7 @@ vips_source_seek_real( VipsSource *source, gint64 offset, int whence ) /* Like _read_real(), we must not set a vips_error. We need to use the * vips__seek() wrapper so we can seek long files on Windows. */ - new_pos = vips__seek_no_error( stream->descriptor, offset, whence ); + new_pos = vips__seek_no_error( connection->descriptor, offset, whence ); return( new_pos ); } @@ -320,7 +320,7 @@ vips_source_class_init( VipsSourceClass *class ) gobject_class->get_property = vips_object_get_property; object_class->nickname = "source"; - object_class->description = _( "input stream" ); + object_class->description = _( "input source" ); object_class->build = vips_source_build; @@ -348,10 +348,10 @@ vips_source_init( VipsSource *source ) * vips_source_new_from_descriptor: * @descriptor: read from this file descriptor * - * Create an source stream attached to a file descriptor. @descriptor is - * closed with close() when the #VipsConnection is finalized. + * Create an source attached to a file descriptor. @descriptor is + * closed with close() when source is finalized. * - * Returns: a new #VipsConnection + * Returns: a new source. */ VipsSource * vips_source_new_from_descriptor( int descriptor ) @@ -379,9 +379,9 @@ vips_source_new_from_descriptor( int descriptor ) * vips_source_new_from_file: * @descriptor: read from this filename * - * Create an source stream attached to a file. + * Create an source attached to a file. * - * Returns: a new #VipsConnection + * Returns: a new source. */ VipsSource * vips_source_new_from_file( const char *filename ) @@ -409,9 +409,9 @@ vips_source_new_from_file( const char *filename ) * vips_source_new_from_blob: * @blob: memory area to load * - * Create a stream attached to an area of memory. + * Create a source attached to an area of memory. * - * Returns: a new #VipsConnection + * Returns: a new source. */ VipsSource * vips_source_new_from_blob( VipsBlob *blob ) @@ -439,11 +439,11 @@ vips_source_new_from_blob( VipsBlob *blob ) * @data: memory area to load * @length: size of memory area * - * Create a stream attached to an area of memory. + * Create a source attached to an area of memory. * - * You must not free @data while the stream is active. + * You must not free @data while the source is active. * - * Returns: a new #VipsConnection + * Returns: a new source. */ VipsSource * vips_source_new_from_memory( const void *data, size_t length ) @@ -471,9 +471,9 @@ vips_source_new_from_memory( const void *data, size_t length ) * vips_source_new_from_options: * @options: option string * - * Create a stream from an option string. + * Create a source from an option string. * - * Returns: a new #VipsSource + * Returns: a new source. */ VipsSource * vips_source_new_from_options( const char *options ) @@ -497,10 +497,10 @@ vips_source_new_from_options( const char *options ) /** * vips_source_minimise: - * @source: input stream to operate on + * @source: source to operate on * - * Minimise the stream. As many stream resources as can be safely removed are - * removed. Use vips_source_unminimise() to restore the stream if you wish to + * Minimise the source. As many resources as can be safely removed are + * removed. Use vips_source_unminimise() to restore the source if you wish to * use it again. * * Loaders should call this in response to the minimise signal on their output @@ -511,7 +511,7 @@ vips_source_new_from_options( const char *options ) void vips_source_minimise( VipsSource *source ) { - VipsConnection *stream = VIPS_CONNECTION( source ); + VipsConnection *connection = VIPS_CONNECTION( source ); VIPS_DEBUG_MSG( "vips_source_minimise:\n" ); @@ -519,14 +519,14 @@ vips_source_minimise( VipsSource *source ) (void) vips_source_test_features( source ); - if( stream->filename && - stream->descriptor != -1 && - stream->tracked_descriptor == stream->descriptor && + if( connection->filename && + connection->descriptor != -1 && + connection->tracked_descriptor == connection->descriptor && !source->is_pipe ) { VIPS_DEBUG_MSG( " tracked_close()\n" ); - vips_tracked_close( stream->tracked_descriptor ); - stream->tracked_descriptor = -1; - stream->descriptor = -1; + vips_tracked_close( connection->tracked_descriptor ); + connection->tracked_descriptor = -1; + connection->descriptor = -1; } SANITY( source ); @@ -534,10 +534,10 @@ vips_source_minimise( VipsSource *source ) /** * vips_source_unminimise: - * @source: input stream to operate on + * @source: source to operate on * - * Restore the stream after minimisation. This is called at the start - * of every stream method, so loaders should not usually need this. + * Restore the source after minimisation. This is called at the start + * of every source method, so loaders should not usually need this. * * See also: vips_source_minimise(). * @@ -546,29 +546,30 @@ vips_source_minimise( VipsSource *source ) int vips_source_unminimise( VipsSource *source ) { - VipsConnection *stream = VIPS_CONNECTION( source ); + VipsConnection *connection = VIPS_CONNECTION( source ); VIPS_DEBUG_MSG( "vips_source_unminimise:\n" ); - if( stream->descriptor == -1 && - stream->tracked_descriptor == -1 && - stream->filename ) { + if( connection->descriptor == -1 && + connection->tracked_descriptor == -1 && + connection->filename ) { int fd; - if( (fd = vips_tracked_open( stream->filename, + if( (fd = vips_tracked_open( connection->filename, MODE_READ )) == -1 ) { - vips_error_system( errno, vips_connection_nick( stream ), + vips_error_system( errno, + vips_connection_nick( connection ), "%s", _( "unable to open for read" ) ); return( -1 ); } - stream->tracked_descriptor = fd; - stream->descriptor = fd; + connection->tracked_descriptor = fd; + connection->descriptor = fd; VIPS_DEBUG_MSG( "vips_source_unminimise: " "restoring read position %" G_GINT64_FORMAT "\n", source->read_position ); - if( vips__seek( stream->descriptor, + if( vips__seek( connection->descriptor, source->read_position, SEEK_SET ) == -1 ) return( -1 ); } @@ -578,10 +579,10 @@ vips_source_unminimise( VipsSource *source ) /** * vips_source_decode: - * @source: input stream to operate on + * @source: source to operate on * * Signal the end of header read and the start of the pixel decode phase. - * After this, you can no longer seek on this stream. + * After this, you can no longer seek on this source. * * Loaders should call this at the end of header read. * @@ -614,7 +615,7 @@ vips_source_decode( VipsSource *source ) /** * vips_source_read: - * @source: input stream to operate on + * @source: source to operate on * @buffer: store bytes here * @length: length of @buffer in bytes * @@ -719,13 +720,13 @@ vips_source_read( VipsSource *source, void *buffer, size_t length ) } /* -1 on a pipe isn't actually unbounded. Have a limit to prevent - * huge streams accidentally filling memory. + * huge sources accidentally filling memory. * * 1gb. Why not. */ static const int vips_pipe_read_limit = 1024 * 1024 * 1024; -/* Read to a position. -1 means read to end of stream. Does not change +/* Read to a position. -1 means read to end of source. Does not change * read_position. */ static int @@ -835,7 +836,7 @@ vips_source_read_to_memory( VipsSource *source ) return( 0 ); } -/* Read the entire pipe into memory and turn this into a memory source stream. +/* Read the entire pipe into memory and turn this into a memory source. */ static int vips_source_pipe_to_memory( VipsSource *source ) @@ -866,14 +867,14 @@ vips_source_pipe_to_memory( VipsSource *source ) static int vips_source_descriptor_to_memory( VipsSource *source ) { - VipsConnection *stream = VIPS_CONNECTION( source ); + VipsConnection *connection = VIPS_CONNECTION( source ); VIPS_DEBUG_MSG( "vips_source_descriptor_to_memory:\n" ); g_assert( !source->blob ); g_assert( !source->mmap_baseaddr ); - if( !(source->mmap_baseaddr = vips__mmap( stream->descriptor, + if( !(source->mmap_baseaddr = vips__mmap( connection->descriptor, FALSE, source->length, 0 )) ) return( -1 ); @@ -887,13 +888,13 @@ vips_source_descriptor_to_memory( VipsSource *source ) /** * vips_source_is_mappable: - * @source: input stream to operate on + * @source: source to operate on * - * Some streams can be efficiently mapped into memory. + * Some sources can be efficiently mapped into memory. * You can still use vips_source_map() if this function returns %FALSE, * but it will be slow. * - * Returns: %TRUE if the stream can be efficiently mapped into memory. + * Returns: %TRUE if the source can be efficiently mapped into memory. */ gboolean vips_source_is_mappable( VipsSource *source ) @@ -913,11 +914,11 @@ vips_source_is_mappable( VipsSource *source ) /** * vips_source_map: - * @source: input stream to operate on + * @source: source to operate on * @length_out: return the file length here, or NULL * - * Map the stream object entirely into memory and return a pointer to the - * start. If @length_out is non-NULL, the stream size is written to it. + * Map the source entirely into memory and return a pointer to the + * start. If @length_out is non-NULL, the source size is written to it. * * This operation can take a long time. Use vips_source_is_mappable() to * check if a source can be mapped efficiently. @@ -976,7 +977,7 @@ vips_source_map_cb( void *a, void *b ) /** * vips_source_map_blob: - * @source: input stream to operate on + * @source: source to operate on * * Just like vips_source_map(), but return a #VipsBlob containing the * pointer. @source will stay alive as long as the result is alive. @@ -1004,7 +1005,7 @@ vips_source_map_blob( VipsSource *source ) /** * vips_source_seek: - * @source: input stream to operate on + * @source: source to operate on * @offset: seek by this offset * @whence: seek relative to this point * @@ -1058,7 +1059,7 @@ vips_source_seek( VipsSource *source, gint64 offset, int whence ) break; case SEEK_END: - /* We have to read the whole stream into memory to get + /* We have to read the whole source into memory to get * the length. */ if( source->length == -1 && @@ -1104,9 +1105,9 @@ vips_source_seek( VipsSource *source, gint64 offset, int whence ) /** * vips_source_rewind: - * @source: input stream to operate on + * @source: source to operate on * - * Rewind the stream to the start. You can't do this after pixel decode phase + * Rewind the source to the start. You can't do this after pixel decode phase * starts. * * Returns: 0 on success, or -1 on error. @@ -1129,13 +1130,13 @@ vips_source_rewind( VipsSource *source ) /** * vips_source_length: - * @source: input stream to operate on + * @source: source to operate on * - * Return the length in bytes of the stream object. Unseekable streams, for + * Return the length in bytes of the source. Unseekable sources, for * example pipes, will have to be read entirely into memory before the length * can be found, so this operation can take a long time. * - * Returns: number of bytes in stream, or -1 on error. + * Returns: number of bytes in source, or -1 on error. */ gint64 vips_source_length( VipsSource *source ) @@ -1157,11 +1158,11 @@ vips_source_length( VipsSource *source ) /** * vips_source_peek: - * @source: peek this stream + * @source: peek this source * @data: return a pointer to the bytes read here * @length: max number of bytes to read * - * Attempt to sniff at most @length bytes from the start of the stream. A + * Attempt to sniff at most @length bytes from the start of the source. A * pointer to the bytes is returned in @data. The number of bytes actually * read is returned -- it may be less than @length if the file is shorter than * @length. A negative number indicates a read error. @@ -1210,7 +1211,7 @@ vips_source_sniff_at_most( VipsSource *source, /** * vips_source_sniff: - * @source: sniff this stream + * @source: sniff this source * @length: number of bytes to sniff * * Return a pointer to the first few bytes of the file. If the file is too diff --git a/libvips/iofuncs/sourcecustom.c b/libvips/iofuncs/sourcecustom.c index 1bfed8e6..78e0e2fe 100644 --- a/libvips/iofuncs/sourcecustom.c +++ b/libvips/iofuncs/sourcecustom.c @@ -1,4 +1,4 @@ -/* A Streami subclass with signals you can easily hook up to other input +/* A Source subclass with signals you can easily hook up to other input * sources. * * J.Cupitt, 21/11/19 @@ -159,7 +159,7 @@ vips_source_custom_class_init( VipsSourceCustomClass *class ) VipsSourceClass *source_class = VIPS_SOURCE_CLASS( class ); object_class->nickname = "source_custom"; - object_class->description = _( "input stream" ); + object_class->description = _( "Custom source" ); source_class->read = vips_source_custom_read_real; source_class->seek = vips_source_custom_seek_real; @@ -169,7 +169,7 @@ vips_source_custom_class_init( VipsSourceCustomClass *class ) /** * VipsSourceCustom::read: - * @source_custom: the stream being operated on + * @source_custom: the source being operated on * @buffer: %gpointer, buffer to fill * @size: %gint64, size of buffer * @@ -188,14 +188,14 @@ vips_source_custom_class_init( VipsSourceCustomClass *class ) /** * VipsSourceCustom::seek: - * @source_custom: the stream being operated on + * @source_custom: the source being operated on * @offset: %gint64, seek offset * @whence: %gint, seek origin * - * This signal is emitted to seek the stream. The handler should - * change the stream position appropriately. + * This signal is emitted to seek the source. The handler should + * change the source position appropriately. * - * The handler on an unseekable stream should always return -1. + * The handler for an unseekable source should always return -1. * * Returns: the new seek position. */ diff --git a/libvips/iofuncs/target.c b/libvips/iofuncs/target.c index 71bd0660..11ca2fc6 100644 --- a/libvips/iofuncs/target.c +++ b/libvips/iofuncs/target.c @@ -99,23 +99,23 @@ vips_target_finalize( GObject *gobject ) static int vips_target_build( VipsObject *object ) { - VipsConnection *stream = VIPS_CONNECTION( object ); + VipsConnection *connection = VIPS_CONNECTION( object ); VipsTarget *target = VIPS_TARGET( object ); - VIPS_DEBUG_MSG( "vips_target_build: %p\n", stream ); + VIPS_DEBUG_MSG( "vips_target_build: %p\n", connection ); if( VIPS_OBJECT_CLASS( vips_target_parent_class )->build( object ) ) return( -1 ); if( vips_object_argument_isset( object, "filename" ) && vips_object_argument_isset( object, "descriptor" ) ) { - vips_error( vips_connection_nick( stream ), + vips_error( vips_connection_nick( connection ), "%s", _( "don't set 'filename' and 'descriptor'" ) ); return( -1 ); } - if( stream->filename ) { - const char *filename = stream->filename; + if( connection->filename ) { + const char *filename = connection->filename; int fd; @@ -123,17 +123,18 @@ vips_target_build( VipsObject *object ) */ if( (fd = vips_tracked_open( filename, MODE_WRITE, 0644 )) == -1 ) { - vips_error_system( errno, vips_connection_nick( stream ), + vips_error_system( errno, + vips_connection_nick( connection ), "%s", _( "unable to open for write" ) ); return( -1 ); } - stream->tracked_descriptor = fd; - stream->descriptor = fd; + connection->tracked_descriptor = fd; + connection->descriptor = fd; } else if( vips_object_argument_isset( object, "descriptor" ) ) { - stream->descriptor = dup( stream->descriptor ); - stream->close_descriptor = stream->descriptor; + connection->descriptor = dup( connection->descriptor ); + connection->close_descriptor = connection->descriptor; } else if( target->memory ) { target->memory_buffer = g_byte_array_new(); @@ -145,11 +146,11 @@ vips_target_build( VipsObject *object ) static gint64 vips_target_write_real( VipsTarget *target, const void *data, size_t length ) { - VipsConnection *stream = VIPS_CONNECTION( target ); + VipsConnection *connection = VIPS_CONNECTION( target ); VIPS_DEBUG_MSG( "vips_target_write_real: %zd bytes\n", length ); - return( write( stream->descriptor, data, length ) ); + return( write( connection->descriptor, data, length ) ); } static void @@ -169,7 +170,7 @@ vips_target_class_init( VipsTargetClass *class ) gobject_class->get_property = vips_object_get_property; object_class->nickname = "target"; - object_class->description = _( "stream stream" ); + object_class->description = _( "Target" ); object_class->build = vips_target_build; @@ -206,12 +207,12 @@ vips_target_init( VipsTarget *target ) * vips_target_new_to_descriptor: * @descriptor: write to this file descriptor * - * Create a stream attached to a file descriptor. - * @descriptor is kept open until the #VipsTarget is finalized. + * Create a target attached to a file descriptor. + * @descriptor is kept open until the target is finalized. * * See also: vips_target_new_to_file(). * - * Returns: a new #VipsTarget + * Returns: a new target. */ VipsTarget * vips_target_new_to_descriptor( int descriptor ) @@ -237,9 +238,9 @@ vips_target_new_to_descriptor( int descriptor ) * vips_target_new_to_file: * @filename: write to this file * - * Create a stream attached to a file. + * Create a target attached to a file. * - * Returns: a new #VipsTarget + * Returns: a new target. */ VipsTarget * vips_target_new_to_file( const char *filename ) @@ -264,7 +265,7 @@ vips_target_new_to_file( const char *filename ) /** * vips_target_new_to_memory: * - * Create a stream which will stream to a memory area. Read from @blob to get + * Create a target which will write to a memory area. Read from @blob to get * memory. * * See also: vips_target_new_to_file(). @@ -347,7 +348,7 @@ vips_target_flush( VipsTarget *target ) /** * vips_target_write: - * @target: output stream to operate on + * @target: target to operate on * @buffer: bytes to write * @length: length of @buffer in bytes * @@ -381,11 +382,11 @@ vips_target_write( VipsTarget *target, const void *buffer, size_t length ) /** * vips_target_finish: - * @target: output stream to operate on + * @target: target to operate on * @buffer: bytes to write * @length: length of @buffer in bytes * - * Call this at the end of write to make the stream do any cleaning up. You + * Call this at the end of write to make the target do any cleaning up. You * can call it many times. * * After a target has been finished, further writes will do nothing. @@ -402,7 +403,7 @@ vips_target_finish( VipsTarget *target ) (void) vips_target_flush( target ); - /* Move the stream buffer into the blob so it can be read out. + /* Move the target buffer into the blob so it can be read out. */ if( target->memory_buffer ) { unsigned char *data; @@ -422,11 +423,11 @@ vips_target_finish( VipsTarget *target ) /** * vips_target_steal: - * @target: output stream to operate on + * @target: target to operate on * @length: return number of bytes of data * - * Memory streams only (see vips_target_new_to_memory()). Steal all data - * written to the stream so far, and finish it. + * Memory targets only (see vips_target_new_to_memory()). Steal all data + * written to the target so far, and finish it. * * You must free the returned pointer with g_free(). * @@ -467,11 +468,11 @@ vips_target_steal( VipsTarget *target, size_t *length ) /** * vips_target_steal_text: - * @target: output stream to operate on + * @target: target to operate on * * As vips_target_steal_text(), but return a null-terminated string. * - * Returns: (transfer full): stream contents as a null-terminated string. + * Returns: (transfer full): target contents as a null-terminated string. */ char * vips_target_steal_text( VipsTarget *target ) @@ -483,7 +484,7 @@ vips_target_steal_text( VipsTarget *target ) /** * vips_target_putc: - * @target: output stream to operate on + * @target: target to operate on * @ch: character to write * * Write a single character @ch to @target. See the macro VIPS_TARGET_PUTC() @@ -507,7 +508,7 @@ vips_target_putc( VipsTarget *target, int ch ) /** * vips_target_writes: - * @target: output stream to operate on + * @target: target to operate on * @str: string to write * * Write a null-terminated string to @target. @@ -523,7 +524,7 @@ vips_target_writes( VipsTarget *target, const char *str ) /** * vips_target_writef: - * @target: output stream to operate on + * @target: target to operate on * @fmt: printf()-style format string * @...: arguments to format string * @@ -551,7 +552,7 @@ vips_target_writef( VipsTarget *target, const char *fmt, ... ) /** * vips_target_write_amp: - * @target: output stream to operate on + * @target: target to operate on * @str: string to write * * Write @str to @target, but escape stuff that xml hates in text. Our diff --git a/libvips/iofuncs/targetcustom.c b/libvips/iofuncs/targetcustom.c index 26b6bea4..c16200a5 100644 --- a/libvips/iofuncs/targetcustom.c +++ b/libvips/iofuncs/targetcustom.c @@ -1,4 +1,4 @@ -/* A Streamo subclass with signals you can easily hook up to other output +/* A Target subclass with signals you can easily hook up to other output * sources. * * J.Cupitt, 21/11/19 @@ -120,7 +120,7 @@ vips_target_custom_class_init( VipsTargetCustomClass *class ) VipsTargetClass *target_class = VIPS_TARGET_CLASS( class ); object_class->nickname = "target_custom"; - object_class->description = _( "input stream" ); + object_class->description = _( "Custom target" ); target_class->write = vips_target_custom_write_real; target_class->finish = vips_target_custom_finish_real; @@ -130,11 +130,11 @@ vips_target_custom_class_init( VipsTargetCustomClass *class ) /** * VipsTargetCustom::write: - * @target_custom: the stream being operated on + * @target_custom: the target being operated on * @data: %pointer, bytes to write * @length: %gint64, number of bytes * - * This signal is emitted to write bytes to the stream. + * This signal is emitted to write bytes to the target. * * Returns: the number of bytes written. */ @@ -149,9 +149,9 @@ vips_target_custom_class_init( VipsTargetCustomClass *class ) /** * VipsTargetCustom::finish: - * @target_custom: the stream being operated on + * @target_custom: the target being operated on * - * This signal is emitted at the end of write. The stream should do + * This signal is emitted at the end of write. The target should do * any finishing necessary. */ vips_target_custom_signals[SIG_FINISH] = g_signal_new( "finish", diff --git a/libvips/resample/thumbnail.c b/libvips/resample/thumbnail.c index be187fb8..3a9e72c6 100644 --- a/libvips/resample/thumbnail.c +++ b/libvips/resample/thumbnail.c @@ -27,7 +27,7 @@ * 30/9/19 * - smarter heif thumbnail selection * 12/10/19 - * - add thumbnail_stream + * - add thumbnail_source */ /* @@ -1254,33 +1254,33 @@ vips_thumbnail_buffer( void *buf, size_t len, VipsImage **out, int width, ... ) return( result ); } -typedef struct _VipsThumbnailStream { +typedef struct _VipsThumbnailSource { VipsThumbnail parent_object; VipsSource *source; char *option_string; -} VipsThumbnailStream; +} VipsThumbnailSource; -typedef VipsThumbnailClass VipsThumbnailStreamClass; +typedef VipsThumbnailClass VipsThumbnailSourceClass; -G_DEFINE_TYPE( VipsThumbnailStream, vips_thumbnail_source, +G_DEFINE_TYPE( VipsThumbnailSource, vips_thumbnail_source, vips_thumbnail_get_type() ); -/* Get the info from a stream. +/* Get the info from a source. */ static int vips_thumbnail_source_get_info( VipsThumbnail *thumbnail ) { - VipsThumbnailStream *stream = (VipsThumbnailStream *) thumbnail; + VipsThumbnailSource *source = (VipsThumbnailSource *) thumbnail; VipsImage *image; - g_info( "thumbnailing stream" ); + g_info( "thumbnailing source" ); if( !(thumbnail->loader = vips_foreign_find_load_source( - stream->source )) || - !(image = vips_image_new_from_source( stream->source, - stream->option_string, NULL )) ) + source->source )) || + !(image = vips_image_new_from_source( source->source, + source->option_string, NULL )) ) return( -1 ); vips_thumbnail_read_header( thumbnail, image ); @@ -1295,12 +1295,12 @@ vips_thumbnail_source_get_info( VipsThumbnail *thumbnail ) static VipsImage * vips_thumbnail_source_open( VipsThumbnail *thumbnail, double factor ) { - VipsThumbnailStream *stream = (VipsThumbnailStream *) thumbnail; + VipsThumbnailSource *source = (VipsThumbnailSource *) thumbnail; if( vips_isprefix( "VipsForeignLoadJpeg", thumbnail->loader ) ) { return( vips_image_new_from_source( - stream->source, - stream->option_string, + source->source, + source->option_string, "access", VIPS_ACCESS_SEQUENTIAL, "shrink", (int) factor, NULL ) ); @@ -1308,8 +1308,8 @@ vips_thumbnail_source_open( VipsThumbnail *thumbnail, double factor ) else if( vips_isprefix( "VipsForeignLoadOpenslide", thumbnail->loader ) ) { return( vips_image_new_from_source( - stream->source, - stream->option_string, + source->source, + source->option_string, "access", VIPS_ACCESS_SEQUENTIAL, "level", (int) factor, NULL ) ); @@ -1318,32 +1318,32 @@ vips_thumbnail_source_open( VipsThumbnail *thumbnail, double factor ) vips_isprefix( "VipsForeignLoadSvg", thumbnail->loader ) || vips_isprefix( "VipsForeignLoadWebp", thumbnail->loader ) ) { return( vips_image_new_from_source( - stream->source, - stream->option_string, + source->source, + source->option_string, "access", VIPS_ACCESS_SEQUENTIAL, "scale", 1.0 / factor, NULL ) ); } else if( vips_isprefix( "VipsForeignLoadTiff", thumbnail->loader ) ) { return( vips_image_new_from_source( - stream->source, - stream->option_string, + source->source, + source->option_string, "access", VIPS_ACCESS_SEQUENTIAL, "page", (int) factor, NULL ) ); } else if( vips_isprefix( "VipsForeignLoadHeif", thumbnail->loader ) ) { return( vips_image_new_from_source( - stream->source, - stream->option_string, + source->source, + source->option_string, "access", VIPS_ACCESS_SEQUENTIAL, "thumbnail", (int) factor, NULL ) ); } else { return( vips_image_new_from_source( - stream->source, - stream->option_string, + source->source, + source->option_string, "access", VIPS_ACCESS_SEQUENTIAL, NULL ) ); } @@ -1359,36 +1359,36 @@ vips_thumbnail_source_class_init( VipsThumbnailClass *class ) gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property; - vobject_class->nickname = "thumbnail_stream"; - vobject_class->description = _( "generate thumbnail from stream" ); + vobject_class->nickname = "thumbnail_source"; + vobject_class->description = _( "generate thumbnail from source" ); thumbnail_class->get_info = vips_thumbnail_source_get_info; thumbnail_class->open = vips_thumbnail_source_open; VIPS_ARG_OBJECT( class, "source", 1, - _( "Streami" ), - _( "Stream to load from" ), + _( "Source" ), + _( "Source to load from" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsThumbnailStream, source ), + G_STRUCT_OFFSET( VipsThumbnailSource, source ), VIPS_TYPE_SOURCE ); VIPS_ARG_STRING( class, "option_string", 20, _( "Extra options" ), _( "Options that are passed on to the underlying loader" ), VIPS_ARGUMENT_OPTIONAL_INPUT, - G_STRUCT_OFFSET( VipsThumbnailStream, option_string ), + G_STRUCT_OFFSET( VipsThumbnailSource, option_string ), "" ); } static void -vips_thumbnail_source_init( VipsThumbnailStream *stream ) +vips_thumbnail_source_init( VipsThumbnailSource *source ) { } /** * vips_thumbnail_source: - * @source: stream to thumbnail + * @source: source to thumbnail * @out: (out): output image * @width: target width in pixels * @...: %NULL-terminated list of optional named arguments @@ -1404,7 +1404,7 @@ vips_thumbnail_source_init( VipsThumbnailStream *stream ) * * @export_profile: %gchararray, export ICC profile * * @intent: #VipsIntent, rendering intent * - * Exacty as vips_thumbnail(), but read from a stream. + * Exactly as vips_thumbnail(), but read from a source. * * See also: vips_thumbnail(). * @@ -1417,7 +1417,7 @@ vips_thumbnail_source( VipsSource *source, VipsImage **out, int width, ... ) int result; va_start( ap, width ); - result = vips_call_split( "thumbnail_stream", ap, source, out, width ); + result = vips_call_split( "thumbnail_source", ap, source, out, width ); va_end( ap ); return( result );