diff --git a/cplusplus/VImage.cpp b/cplusplus/VImage.cpp index 12b18d39..69994442 100644 --- a/cplusplus/VImage.cpp +++ b/cplusplus/VImage.cpp @@ -597,20 +597,20 @@ VImage::new_from_buffer( const std::string &buf, const char *option_string, } VImage -VImage::new_from_stream( VStreamI streami, const char *option_string, +VImage::new_from_source( VStreamI source, const char *option_string, VOption *options ) { const char *operation_name; VImage out; - if( !(operation_name = vips_foreign_find_load_stream( - streami.get_stream() )) ) { + if( !(operation_name = vips_foreign_find_load_source( + source.get_stream() )) ) { delete options; throw( VError() ); } options = (options ? options : VImage::option())-> - set( "streami", streami )-> + set( "source", source )-> set( "out", &out ); call_option_string( operation_name, option_string, options ); @@ -703,7 +703,7 @@ VImage::write_to_buffer( const char *suffix, void **buf, size_t *size, } void -VImage::write_to_stream( const char *suffix, VStreamO streamo, +VImage::write_to_target( const char *suffix, VStreamO target, VOption *options ) const { char filename[VIPS_PATH_MAX]; @@ -711,7 +711,7 @@ VImage::write_to_stream( const char *suffix, VStreamO streamo, const char *operation_name; vips__filename_split8( suffix, filename, option_string ); - if( !(operation_name = vips_foreign_find_save_stream( filename )) ) { + if( !(operation_name = vips_foreign_find_save_target( filename )) ) { delete options; throw VError(); } @@ -719,7 +719,7 @@ VImage::write_to_stream( const char *suffix, VStreamO streamo, call_option_string( operation_name, option_string, (options ? options : VImage::option())-> set( "in", *this )-> - set( "streamo", streamo ) ); + set( "target", target ) ); } #include "vips-operators.cpp" diff --git a/cplusplus/VStream.cpp b/cplusplus/VStream.cpp index 82b1d3ea..d85748a1 100644 --- a/cplusplus/VStream.cpp +++ b/cplusplus/VStream.cpp @@ -47,9 +47,9 @@ VIPS_NAMESPACE_START VStreamI VStreamI::new_from_descriptor( int descriptor ) { - VipsStreami *input; + VipsSource *input; - if( !(input = vips_streami_new_from_descriptor( descriptor )) ) + if( !(input = vips_source_new_from_descriptor( descriptor )) ) throw VError(); VStreamI out( input ); @@ -60,9 +60,9 @@ VStreamI::new_from_descriptor( int descriptor ) VStreamI VStreamI::new_from_file( const char *filename ) { - VipsStreami *input; + VipsSource *input; - if( !(input = vips_streami_new_from_file( filename )) ) + if( !(input = vips_source_new_from_file( filename )) ) throw VError(); VStreamI out( input ); @@ -73,9 +73,9 @@ VStreamI::new_from_file( const char *filename ) VStreamI VStreamI::new_from_blob( VipsBlob *blob ) { - VipsStreami *input; + VipsSource *input; - if( !(input = vips_streami_new_from_blob( blob )) ) + if( !(input = vips_source_new_from_blob( blob )) ) throw VError(); VStreamI out( input ); @@ -87,9 +87,9 @@ VStreamI VStreamI::new_from_memory( const void *data, size_t size ) { - VipsStreami *input; + VipsSource *input; - if( !(input = vips_streami_new_from_memory( data, size )) ) + if( !(input = vips_source_new_from_memory( data, size )) ) throw VError(); VStreamI out( input ); @@ -100,9 +100,9 @@ VStreamI::new_from_memory( const void *data, VStreamI VStreamI::new_from_options( const char *options ) { - VipsStreami *input; + VipsSource *input; - if( !(input = vips_streami_new_from_options( options )) ) + if( !(input = vips_source_new_from_options( options )) ) throw VError(); VStreamI out( input ); @@ -116,7 +116,7 @@ VOption::set( const char *name, const VStreamI value ) Pair *pair = new Pair( name ); pair->input = true; - g_value_init( &pair->value, VIPS_TYPE_STREAMI ); + g_value_init( &pair->value, VIPS_TYPE_SOURCE ); g_value_set_object( &pair->value, value.get_stream() ); options.push_back( pair ); @@ -126,9 +126,9 @@ VOption::set( const char *name, const VStreamI value ) VStreamO VStreamO::new_to_descriptor( int descriptor ) { - VipsStreamo *output; + VipsTarget *output; - if( !(output = vips_streamo_new_to_descriptor( descriptor )) ) + if( !(output = vips_target_new_to_descriptor( descriptor )) ) throw VError(); VStreamO out( output ); @@ -139,9 +139,9 @@ VStreamO::new_to_descriptor( int descriptor ) VStreamO VStreamO::new_to_file( const char *filename ) { - VipsStreamo *output; + VipsTarget *output; - if( !(output = vips_streamo_new_to_file( filename )) ) + if( !(output = vips_target_new_to_file( filename )) ) throw VError(); VStreamO out( output ); @@ -152,9 +152,9 @@ VStreamO::new_to_file( const char *filename ) VStreamO VStreamO::new_to_memory() { - VipsStreamo *output; + VipsTarget *output; - if( !(output = vips_streamo_new_to_memory()) ) + if( !(output = vips_target_new_to_memory()) ) throw VError(); VStreamO out( output ); @@ -168,7 +168,7 @@ VOption::set( const char *name, const VStreamO value ) Pair *pair = new Pair( name ); pair->input = true; - g_value_init( &pair->value, VIPS_TYPE_STREAMO ); + g_value_init( &pair->value, VIPS_TYPE_TARGET ); g_value_set_object( &pair->value, value.get_stream() ); options.push_back( pair ); diff --git a/cplusplus/include/vips/VImage8.h b/cplusplus/include/vips/VImage8.h index 0819d8cd..d404e863 100644 --- a/cplusplus/include/vips/VImage8.h +++ b/cplusplus/include/vips/VImage8.h @@ -514,7 +514,7 @@ public: static VImage new_from_buffer( const std::string &buf, const char *option_string, VOption *options = 0 ); - static VImage new_from_stream( VStreamI streami, + static VImage new_from_source( VStreamI source, const char *option_string, VOption *options = 0 ); static VImage new_matrix( int width, int height ); @@ -569,7 +569,7 @@ public: void write_to_buffer( const char *suffix, void **buf, size_t *size, VOption *options = 0 ) const; - void write_to_stream( const char *suffix, VStreamO streamo, + void write_to_target( const char *suffix, VStreamO target, VOption *options = 0 ) const; void * diff --git a/cplusplus/include/vips/VStream8.h b/cplusplus/include/vips/VStream8.h index f8667b19..ce660a05 100644 --- a/cplusplus/include/vips/VStream8.h +++ b/cplusplus/include/vips/VStream8.h @@ -37,7 +37,7 @@ VIPS_NAMESPACE_START class VStreamI : VObject { public: - VStreamI( VipsStreami *input, VSteal steal = STEAL ) : + VStreamI( VipsSource *input, VSteal steal = STEAL ) : VObject( (VipsObject *) input, steal ) { } @@ -58,10 +58,10 @@ public: static VStreamI new_from_options( const char *options ); - VipsStreami * + VipsSource * get_stream() const { - return( (VipsStreami *) VObject::get_object() ); + return( (VipsSource *) VObject::get_object() ); } }; @@ -69,7 +69,7 @@ public: class VStreamO : VObject { public: - VStreamO( VipsStreamo *output, VSteal steal = STEAL ) : + VStreamO( VipsTarget *output, VSteal steal = STEAL ) : VObject( (VipsObject *) output, steal ) { } @@ -83,10 +83,10 @@ public: static VStreamO new_to_memory(); - VipsStreamo * + VipsTarget * get_stream() const { - return( (VipsStreamo *) VObject::get_object() ); + return( (VipsTarget *) VObject::get_object() ); } }; diff --git a/cplusplus/include/vips/vips-operators.h b/cplusplus/include/vips/vips-operators.h index dbc2804b..71f90e6e 100644 --- a/cplusplus/include/vips/vips-operators.h +++ b/cplusplus/include/vips/vips-operators.h @@ -1039,11 +1039,11 @@ static VImage jpegload_buffer( VipsBlob *buffer, VOption *options = 0 ); /** * Load image from jpeg stream. - * @param streami Stream to load from. + * @param source Stream to load from. * @param options Optional options. * @return Output image. */ -static VImage jpegload_stream( VStreamI streami, VOption *options = 0 ); +static VImage jpegload_stream( VStreamI source, VOption *options = 0 ); /** * Save image to jpeg file. @@ -1067,10 +1067,10 @@ void jpegsave_mime( VOption *options = 0 ) const; /** * Save image to jpeg stream. - * @param streamo Stream to save to. + * @param target Stream to save to. * @param options Optional options. */ -void jpegsave_stream( VStreamO streamo, VOption *options = 0 ) const; +void jpegsave_stream( VStreamO target, VOption *options = 0 ) const; /** * Label regions in an image. @@ -1517,11 +1517,11 @@ static VImage pngload_buffer( VipsBlob *buffer, VOption *options = 0 ); /** * Load png from stream. - * @param streami Stream to load from. + * @param source Stream to load from. * @param options Optional options. * @return Output image. */ -static VImage pngload_stream( VStreamI streami, VOption *options = 0 ); +static VImage pngload_stream( VStreamI source, VOption *options = 0 ); /** * Save image to png file. @@ -1539,10 +1539,10 @@ VipsBlob *pngsave_buffer( VOption *options = 0 ) const; /** * Save image to png stream. - * @param streamo Stream to save to. + * @param target Stream to save to. * @param options Optional options. */ -void pngsave_stream( VStreamO streamo, VOption *options = 0 ) const; +void pngsave_stream( VStreamO target, VOption *options = 0 ) const; /** * Load ppm from file. @@ -1623,11 +1623,11 @@ static VImage radload_buffer( VipsBlob *buffer, VOption *options = 0 ); /** * Load rad from stream. - * @param streami Stream to load from. + * @param source Stream to load from. * @param options Optional options. * @return Output image. */ -static VImage radload_stream( VStreamI streami, VOption *options = 0 ); +static VImage radload_stream( VStreamI source, VOption *options = 0 ); /** * Save image to radiance file. @@ -1645,10 +1645,10 @@ VipsBlob *radsave_buffer( VOption *options = 0 ) const; /** * Save image to radiance stream. - * @param streamo Stream to save to. + * @param target Stream to save to. * @param options Optional options. */ -void radsave_stream( VStreamO streamo, VOption *options = 0 ) const; +void radsave_stream( VStreamO target, VOption *options = 0 ) const; /** * Rank filter. @@ -1994,11 +1994,11 @@ static VImage svgload_buffer( VipsBlob *buffer, VOption *options = 0 ); /** * Load svg from stream. - * @param streami Stream to load from. + * @param source Stream to load from. * @param options Optional options. * @return Output image. */ -static VImage svgload_stream( VStreamI streami, VOption *options = 0 ); +static VImage svgload_stream( VStreamI source, VOption *options = 0 ); /** * Find the index of the first non-zero pixel in tests. @@ -2051,12 +2051,12 @@ VImage thumbnail_image( int width, VOption *options = 0 ) const; /** * Generate thumbnail from stream. - * @param streami Stream to load from. + * @param source Stream to load from. * @param width Size to this width. * @param options Optional options. * @return Output image. */ -static VImage thumbnail_stream( VStreamI streami, int width, VOption *options = 0 ); +static VImage thumbnail_stream( VStreamI source, int width, VOption *options = 0 ); /** * Load tiff from file. @@ -2076,11 +2076,11 @@ static VImage tiffload_buffer( VipsBlob *buffer, VOption *options = 0 ); /** * Load tiff from stream. - * @param streami Stream to load from. + * @param source Stream to load from. * @param options Optional options. * @return Output image. */ -static VImage tiffload_stream( VStreamI streami, VOption *options = 0 ); +static VImage tiffload_stream( VStreamI source, VOption *options = 0 ); /** * Save image to tiff file. @@ -2157,11 +2157,11 @@ static VImage webpload_buffer( VipsBlob *buffer, VOption *options = 0 ); /** * Load webp from stream. - * @param streami Stream to load from. + * @param source Stream to load from. * @param options Optional options. * @return Output image. */ -static VImage webpload_stream( VStreamI streami, VOption *options = 0 ); +static VImage webpload_stream( VStreamI source, VOption *options = 0 ); /** * Save image to webp file. @@ -2179,10 +2179,10 @@ VipsBlob *webpsave_buffer( VOption *options = 0 ) const; /** * Save image to webp stream. - * @param streamo Stream to save to. + * @param target Stream to save to. * @param options Optional options. */ -void webpsave_stream( VStreamO streamo, VOption *options = 0 ) const; +void webpsave_stream( VStreamO target, VOption *options = 0 ) const; /** * Make a worley noise image. diff --git a/cplusplus/vips-operators.cpp b/cplusplus/vips-operators.cpp index d6726514..9c98c563 100644 --- a/cplusplus/vips-operators.cpp +++ b/cplusplus/vips-operators.cpp @@ -1628,14 +1628,14 @@ VImage VImage::jpegload_buffer( VipsBlob *buffer, VOption *options ) return( out ); } -VImage VImage::jpegload_stream( VStreamI streami, VOption *options ) +VImage VImage::jpegload_stream( VStreamI source, VOption *options ) { VImage out; call( "jpegload_stream", (options ? options : VImage::option())-> set( "out", &out )-> - set( "streami", streami ) ); + set( "source", source ) ); return( out ); } @@ -1667,12 +1667,12 @@ void VImage::jpegsave_mime( VOption *options ) const set( "in", *this ) ); } -void VImage::jpegsave_stream( VStreamO streamo, VOption *options ) const +void VImage::jpegsave_stream( VStreamO target, VOption *options ) const { call( "jpegsave_stream", (options ? options : VImage::option())-> set( "in", *this )-> - set( "streamo", streamo ) ); + set( "target", target ) ); } VImage VImage::labelregions( VOption *options ) const @@ -2319,14 +2319,14 @@ VImage VImage::pngload_buffer( VipsBlob *buffer, VOption *options ) return( out ); } -VImage VImage::pngload_stream( VStreamI streami, VOption *options ) +VImage VImage::pngload_stream( VStreamI source, VOption *options ) { VImage out; call( "pngload_stream", (options ? options : VImage::option())-> set( "out", &out )-> - set( "streami", streami ) ); + set( "source", source ) ); return( out ); } @@ -2351,12 +2351,12 @@ VipsBlob *VImage::pngsave_buffer( VOption *options ) const return( buffer ); } -void VImage::pngsave_stream( VStreamO streamo, VOption *options ) const +void VImage::pngsave_stream( VStreamO target, VOption *options ) const { call( "pngsave_stream", (options ? options : VImage::option())-> set( "in", *this )-> - set( "streamo", streamo ) ); + set( "target", target ) ); } VImage VImage::ppmload( const char *filename, VOption *options ) @@ -2478,14 +2478,14 @@ VImage VImage::radload_buffer( VipsBlob *buffer, VOption *options ) return( out ); } -VImage VImage::radload_stream( VStreamI streami, VOption *options ) +VImage VImage::radload_stream( VStreamI source, VOption *options ) { VImage out; call( "radload_stream", (options ? options : VImage::option())-> set( "out", &out )-> - set( "streami", streami ) ); + set( "source", source ) ); return( out ); } @@ -2510,12 +2510,12 @@ VipsBlob *VImage::radsave_buffer( VOption *options ) const return( buffer ); } -void VImage::radsave_stream( VStreamO streamo, VOption *options ) const +void VImage::radsave_stream( VStreamO target, VOption *options ) const { call( "radsave_stream", (options ? options : VImage::option())-> set( "in", *this )-> - set( "streamo", streamo ) ); + set( "target", target ) ); } VImage VImage::rank( int width, int height, int index, VOption *options ) const @@ -3062,14 +3062,14 @@ VImage VImage::svgload_buffer( VipsBlob *buffer, VOption *options ) return( out ); } -VImage VImage::svgload_stream( VStreamI streami, VOption *options ) +VImage VImage::svgload_stream( VStreamI source, VOption *options ) { VImage out; call( "svgload_stream", (options ? options : VImage::option())-> set( "out", &out )-> - set( "streami", streami ) ); + set( "source", source ) ); return( out ); } @@ -3144,14 +3144,14 @@ VImage VImage::thumbnail_image( int width, VOption *options ) const return( out ); } -VImage VImage::thumbnail_stream( VStreamI streami, int width, VOption *options ) +VImage VImage::thumbnail_stream( VStreamI source, int width, VOption *options ) { VImage out; call( "thumbnail_stream", (options ? options : VImage::option())-> set( "out", &out )-> - set( "streami", streami )-> + set( "source", source )-> set( "width", width ) ); return( out ); @@ -3181,14 +3181,14 @@ VImage VImage::tiffload_buffer( VipsBlob *buffer, VOption *options ) return( out ); } -VImage VImage::tiffload_stream( VStreamI streami, VOption *options ) +VImage VImage::tiffload_stream( VStreamI source, VOption *options ) { VImage out; call( "tiffload_stream", (options ? options : VImage::option())-> set( "out", &out )-> - set( "streami", streami ) ); + set( "source", source ) ); return( out ); } @@ -3304,14 +3304,14 @@ VImage VImage::webpload_buffer( VipsBlob *buffer, VOption *options ) return( out ); } -VImage VImage::webpload_stream( VStreamI streami, VOption *options ) +VImage VImage::webpload_stream( VStreamI source, VOption *options ) { VImage out; call( "webpload_stream", (options ? options : VImage::option())-> set( "out", &out )-> - set( "streami", streami ) ); + set( "source", source ) ); return( out ); } @@ -3336,12 +3336,12 @@ VipsBlob *VImage::webpsave_buffer( VOption *options ) const return( buffer ); } -void VImage::webpsave_stream( VStreamO streamo, VOption *options ) const +void VImage::webpsave_stream( VStreamO target, VOption *options ) const { call( "webpsave_stream", (options ? options : VImage::option())-> set( "in", *this )-> - set( "streamo", streamo ) ); + set( "target", target ) ); } VImage VImage::worley( int width, int height, VOption *options ) diff --git a/libvips/deprecated/im_jpeg2vips.c b/libvips/deprecated/im_jpeg2vips.c index a58d5d17..1992c05f 100644 --- a/libvips/deprecated/im_jpeg2vips.c +++ b/libvips/deprecated/im_jpeg2vips.c @@ -112,16 +112,16 @@ jpeg2vips( const char *name, IMAGE *out, gboolean header_only ) #ifdef HAVE_JPEG { - VipsStreami *streami; + VipsSource *source; - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( -1 ); - if( vips__jpeg_read_stream( streami, out, + if( vips__jpeg_read_stream( source, out, header_only, shrink, fail_on_warn, FALSE ) ) { - VIPS_UNREF( streami ); + VIPS_UNREF( source ); return( -1 ); } - VIPS_UNREF( streami ); + VIPS_UNREF( source ); } #else vips_error( "im_jpeg2vips", diff --git a/libvips/deprecated/im_png2vips.c b/libvips/deprecated/im_png2vips.c index f155b9a0..a417acf5 100644 --- a/libvips/deprecated/im_png2vips.c +++ b/libvips/deprecated/im_png2vips.c @@ -84,16 +84,16 @@ png2vips( const char *name, IMAGE *out, gboolean header_only ) #ifdef HAVE_PNG { - VipsStreami *streami; + VipsSource *source; int result; - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( -1 ); if( header_only ) - result = vips__png_header_stream( streami, out ); + result = vips__png_header_stream( source, out ); else - result = vips__png_read_stream( streami, out, TRUE ); - VIPS_UNREF( streami ); + result = vips__png_read_stream( source, out, TRUE ); + VIPS_UNREF( source ); if( result ) return( result ); diff --git a/libvips/deprecated/im_tiff2vips.c b/libvips/deprecated/im_tiff2vips.c index 9eb3fef9..dd7496cb 100644 --- a/libvips/deprecated/im_tiff2vips.c +++ b/libvips/deprecated/im_tiff2vips.c @@ -56,13 +56,13 @@ static gboolean im_istifftiled( const char *filename ) { - VipsStreami *streami; + VipsSource *source; gboolean result; - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( FALSE ); - result = vips__istiff_stream( streami ); - VIPS_UNREF( streami ); + result = vips__istiff_stream( source ); + VIPS_UNREF( source ); return( result ); } @@ -71,16 +71,16 @@ static int im_tiff_read_header( const char *filename, VipsImage *out, int page, int n, gboolean autorotate ) { - VipsStreami *streami; + VipsSource *source; - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( -1 ); - if( vips__tiff_read_header_stream( streami, + if( vips__tiff_read_header_stream( source, out, page, n, autorotate ) ) { - VIPS_UNREF( streami ); + VIPS_UNREF( source ); return( -1 ); } - VIPS_UNREF( streami ); + VIPS_UNREF( source ); return( 0 ); } @@ -89,15 +89,15 @@ static int im_tiff_read( const char *filename, VipsImage *out, int page, int n, gboolean autorotate ) { - VipsStreami *streami; + VipsSource *source; - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( -1 ); - if( vips__tiff_read_stream( streami, out, page, n, autorotate ) ) { - VIPS_UNREF( streami ); + if( vips__tiff_read_stream( source, out, page, n, autorotate ) ) { + VIPS_UNREF( source ); return( -1 ); } - VIPS_UNREF( streami ); + VIPS_UNREF( source ); return( 0 ); } diff --git a/libvips/deprecated/im_webp2vips.c b/libvips/deprecated/im_webp2vips.c index 43a31633..e84e54b7 100644 --- a/libvips/deprecated/im_webp2vips.c +++ b/libvips/deprecated/im_webp2vips.c @@ -52,16 +52,16 @@ webp2vips( const char *name, IMAGE *out, gboolean header_only ) #ifdef HAVE_LIBWEBP { - VipsStreami *streami; + VipsSource *source; int result; - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( -1 ); if( header_only ) - result = vips__webp_read_header_stream( streami, out, 0, 1, 1 ); + result = vips__webp_read_header_stream( source, out, 0, 1, 1 ); else - result = vips__webp_read_stream( streami, out, 0, 1, 1 ); - VIPS_UNREF( streami ); + result = vips__webp_read_stream( source, out, 0, 1, 1 ); + VIPS_UNREF( source ); if( result ) return( result ); @@ -82,12 +82,12 @@ vips__iswebp( const char *filename ) gboolean result; #ifdef HAVE_LIBWEBP - VipsStreami *streami; + VipsSource *source; - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( FALSE ); - result = vips__png_ispng_stream( streami ); - VIPS_UNREF( streami ); + result = vips__png_ispng_stream( source ); + VIPS_UNREF( source ); #else /*!HAVE_LIBWEBP*/ result = -1; #endif /*HAVE_LIBWEBP*/ diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index 3fc20bb6..ddc89742 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -457,8 +457,8 @@ vips_foreign_load_summary_class( VipsObjectClass *object_class, VipsBuf *buf ) vips_buf_appends( buf, ", is_a" ); if( class->is_a_buffer ) vips_buf_appends( buf, ", is_a_buffer" ); - if( class->is_a_stream ) - vips_buf_appends( buf, ", is_a_stream" ); + if( class->is_a_source ) + vips_buf_appends( buf, ", is_a_source" ); if( class->get_flags ) vips_buf_appends( buf, ", get_flags" ); if( class->get_flags_filename ) @@ -632,20 +632,20 @@ vips_foreign_find_load_buffer( const void *data, size_t size ) /* Can this VipsForeign open this stream? */ static void * -vips_foreign_find_load_stream_sub( void *item, void *a, void *b ) +vips_foreign_find_load_source_sub( void *item, void *a, void *b ) { VipsObjectClass *object_class = VIPS_OBJECT_CLASS( item ); VipsForeignLoadClass *load_class = VIPS_FOREIGN_LOAD_CLASS( item ); - VipsStreami *streami = VIPS_STREAMI( a ); + VipsSource *source = VIPS_SOURCE( a ); - if( load_class->is_a_stream && + if( load_class->is_a_source && vips_ispostfix( object_class->nickname, "_stream" ) ) { /* We may have done a read() rather than a sniff() in one of * the is_a testers. Always rewind. */ - (void) vips_streami_rewind( streami ); + (void) vips_source_rewind( source ); - if( load_class->is_a_stream( streami ) ) + if( load_class->is_a_source( source ) ) return( load_class ); } @@ -653,28 +653,28 @@ vips_foreign_find_load_stream_sub( void *item, void *a, void *b ) } /** - * vips_foreign_find_load_stream: - * @streami: stream to load from + * vips_foreign_find_load_source: + * @source: stream to load from * * Searches for an operation you could use to load a stream. To see the * range of buffer loaders supported by your vips, try something like: * * vips -l | grep load_stream * - * See also: vips_image_new_from_stream(). + * See also: vips_image_new_from_source(). * * Returns: (transfer none): the name of an operation on success, %NULL on * error. */ const char * -vips_foreign_find_load_stream( VipsStreami *streami ) +vips_foreign_find_load_source( VipsSource *source ) { VipsForeignLoadClass *load_class; if( !(load_class = (VipsForeignLoadClass *) vips_foreign_map( "VipsForeignLoad", - vips_foreign_find_load_stream_sub, - streami, NULL )) ) { + vips_foreign_find_load_source_sub, + source, NULL )) ) { vips_error( "VipsForeignLoad", "%s", _( "stream is not in a known format" ) ); return( NULL ); @@ -737,17 +737,17 @@ vips_foreign_is_a_buffer( const char *loader, const void *data, size_t size ) } /** - * vips_foreign_is_a_stream: + * vips_foreign_is_a_source: * @loader: name of loader to use for test - * @streami: stream to test + * @source: stream to test * - * Return %TRUE if @streami can be loaded by @loader. @loader is something + * Return %TRUE if @source can be loaded by @loader. @loader is something * like "tiffload_stream" or "VipsForeignLoadTiffStream". * * Returns: %TRUE if @data can be loaded by @stream. */ gboolean -vips_foreign_is_a_stream( const char *loader, VipsStreami *streami ) +vips_foreign_is_a_source( const char *loader, VipsSource *source ) { const VipsObjectClass *class; VipsForeignLoadClass *load_class; @@ -755,8 +755,8 @@ vips_foreign_is_a_stream( const char *loader, VipsStreami *streami ) if( !(class = vips_class_find( "VipsForeignLoad", loader )) ) return( FALSE ); load_class = VIPS_FOREIGN_LOAD_CLASS( class ); - if( load_class->is_a_stream && - load_class->is_a_stream( streami ) ) + if( load_class->is_a_source && + load_class->is_a_source( source ) ) return( TRUE ); return( FALSE ); @@ -1901,7 +1901,7 @@ vips_foreign_save( VipsImage *in, const char *name, ... ) /* Can this class write this filetype to a stream? */ static void * -vips_foreign_find_save_stream_sub( VipsForeignSaveClass *save_class, +vips_foreign_find_save_target_sub( VipsForeignSaveClass *save_class, const char *suffix ) { VipsObjectClass *object_class = VIPS_OBJECT_CLASS( save_class ); @@ -1916,7 +1916,7 @@ vips_foreign_find_save_stream_sub( VipsForeignSaveClass *save_class, } /** - * vips_foreign_find_save_stream: + * vips_foreign_find_save_target: * @suffix: format to find a saver for * * Searches for an operation you could use to write to a stream in @suffix @@ -1927,7 +1927,7 @@ vips_foreign_find_save_stream_sub( VipsForeignSaveClass *save_class, * Returns: the name of an operation on success, %NULL on error */ const char * -vips_foreign_find_save_stream( const char *name ) +vips_foreign_find_save_target( const char *name ) { char suffix[VIPS_PATH_MAX]; char option_string[VIPS_PATH_MAX]; @@ -1937,7 +1937,7 @@ vips_foreign_find_save_stream( const char *name ) if( !(save_class = (VipsForeignSaveClass *) vips_foreign_map( "VipsForeignSave", - (VipsSListMap2Fn) vips_foreign_find_save_stream_sub, + (VipsSListMap2Fn) vips_foreign_find_save_target_sub, (void *) suffix, NULL )) ) { vips_error( "VipsForeignSave", _( "\"%s\" is not a known stream format" ), name ); diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index 9ead2dac..ab8b8362 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -193,7 +193,7 @@ typedef struct _ReadJpeg { /* The stream we read from. */ - VipsStreami *streami; + VipsSource *source; } ReadJpeg; @@ -208,7 +208,7 @@ typedef struct { /* Private stuff during read. */ - VipsStreami *streami; + VipsSource *source; unsigned char buf[STREAM_BUFFER_SIZE]; } Source; @@ -238,7 +238,7 @@ stream_fill_input_buffer( j_decompress_ptr cinfo ) size_t read; - if( (read = vips_streami_read( src->streami, + if( (read = vips_source_read( src->source, src->buf, STREAM_BUFFER_SIZE )) > 0 ) { src->pub.next_input_byte = src->buf; src->pub.bytes_in_buffer = read; @@ -277,11 +277,11 @@ readjpeg_open_input( ReadJpeg *jpeg ) { j_decompress_ptr cinfo = &jpeg->cinfo; - if( jpeg->streami && + if( jpeg->source && !cinfo->src ) { Source *src; - if( vips_streami_rewind( jpeg->streami ) ) + if( vips_source_rewind( jpeg->source ) ) return( -1 ); cinfo->src = (struct jpeg_source_mgr *) @@ -290,7 +290,7 @@ readjpeg_open_input( ReadJpeg *jpeg ) sizeof( Source ) ); src = (Source *) cinfo->src; - src->streami = jpeg->streami; + src->source = jpeg->source; src->pub.init_source = stream_init_source; src->pub.fill_input_buffer = stream_fill_input_buffer; src->pub.resync_to_restart = jpeg_resync_to_restart; @@ -326,7 +326,7 @@ readjpeg_free( ReadJpeg *jpeg ) */ jpeg_destroy_decompress( &jpeg->cinfo ); - VIPS_UNREF( jpeg->streami ); + VIPS_UNREF( jpeg->source ); return( 0 ); } @@ -340,11 +340,11 @@ readjpeg_close_cb( VipsObject *object, ReadJpeg *jpeg ) static void readjpeg_minimise_cb( VipsImage *image, ReadJpeg *jpeg ) { - vips_streami_minimise( jpeg->streami ); + vips_source_minimise( jpeg->source ); } static ReadJpeg * -readjpeg_new( VipsStreami *streami, VipsImage *out, +readjpeg_new( VipsSource *source, VipsImage *out, int shrink, gboolean fail, gboolean autorotate ) { ReadJpeg *jpeg; @@ -352,8 +352,8 @@ readjpeg_new( VipsStreami *streami, VipsImage *out, if( !(jpeg = VIPS_NEW( out, ReadJpeg )) ) return( NULL ); - jpeg->streami = streami; - g_object_ref( streami ); + jpeg->source = source; + g_object_ref( source ); jpeg->shrink = shrink; jpeg->fail = fail; jpeg->cinfo.err = jpeg_std_error( &jpeg->eman.pub ); @@ -559,7 +559,7 @@ read_jpeg_header( ReadJpeg *jpeg, VipsImage *out ) xres, yres ); VIPS_SETSTR( out->filename, - vips_stream_filename( VIPS_STREAM( jpeg->streami ) ) ); + vips_connection_filename( VIPS_CONNECTION( jpeg->source ) ) ); vips_image_pipelinev( out, VIPS_DEMAND_STYLE_FATSTRIP, NULL ); @@ -959,12 +959,12 @@ vips__jpeg_read( ReadJpeg *jpeg, VipsImage *out, gboolean header_only ) } int -vips__jpeg_read_stream( VipsStreami *streami, VipsImage *out, +vips__jpeg_read_stream( VipsSource *source, VipsImage *out, gboolean header_only, int shrink, int fail, gboolean autorotate ) { ReadJpeg *jpeg; - if( !(jpeg = readjpeg_new( streami, out, shrink, fail, autorotate )) ) + if( !(jpeg = readjpeg_new( source, out, shrink, fail, autorotate )) ) return( -1 ); if( setjmp( jpeg->eman.jmp ) ) @@ -975,9 +975,9 @@ vips__jpeg_read_stream( VipsStreami *streami, VipsImage *out, return( -1 ); if( header_only ) - vips_streami_minimise( streami ); + vips_source_minimise( source ); else { - if( vips_streami_decode( streami ) ) + if( vips_source_decode( source ) ) return( -1 ); } @@ -985,11 +985,11 @@ vips__jpeg_read_stream( VipsStreami *streami, VipsImage *out, } int -vips__isjpeg_stream( VipsStreami *streami ) +vips__isjpeg_stream( VipsSource *source ) { const unsigned char *p; - if( (p = vips_streami_sniff( streami, 2 )) && + if( (p = vips_source_sniff( source, 2 )) && p[0] == 0xff && p[1] == 0xd8 ) return( 1 ); diff --git a/libvips/foreign/jpegload.c b/libvips/foreign/jpegload.c index 87bd5f84..395d1ecb 100644 --- a/libvips/foreign/jpegload.c +++ b/libvips/foreign/jpegload.c @@ -70,7 +70,7 @@ typedef struct _VipsForeignLoadJpeg { /* Set by subclasses. */ - VipsStreami *streami; + VipsSource *source; /* Shrink by this much during load. */ @@ -92,7 +92,7 @@ vips_foreign_load_jpeg_dispose( GObject *gobject ) { VipsForeignLoadJpeg *jpeg = (VipsForeignLoadJpeg *) gobject; - VIPS_UNREF( jpeg->streami ); + VIPS_UNREF( jpeg->source ); G_OBJECT_CLASS( vips_foreign_load_jpeg_parent_class )-> dispose( gobject ); @@ -136,7 +136,7 @@ vips_foreign_load_jpeg_header( VipsForeignLoad *load ) { VipsForeignLoadJpeg *jpeg = (VipsForeignLoadJpeg *) load; - if( vips__jpeg_read_stream( jpeg->streami, + if( vips__jpeg_read_stream( jpeg->source, load->out, TRUE, jpeg->shrink, load->fail, jpeg->autorotate ) ) return( -1 ); @@ -148,7 +148,7 @@ vips_foreign_load_jpeg_load( VipsForeignLoad *load ) { VipsForeignLoadJpeg *jpeg = (VipsForeignLoadJpeg *) load; - if( vips__jpeg_read_stream( jpeg->streami, + if( vips__jpeg_read_stream( jpeg->source, load->real, FALSE, jpeg->shrink, load->fail, jpeg->autorotate ) ) return( -1 ); @@ -207,7 +207,7 @@ vips_foreign_load_jpeg_init( VipsForeignLoadJpeg *jpeg ) typedef struct _VipsForeignLoadJpegStream { VipsForeignLoadJpeg parent_object; - VipsStreami *streami; + VipsSource *source; } VipsForeignLoadJpegStream; @@ -223,9 +223,9 @@ vips_foreign_load_jpeg_stream_build( VipsObject *object ) VipsForeignLoadJpegStream *stream = (VipsForeignLoadJpegStream *) object; - if( stream->streami ) { - jpeg->streami = stream->streami; - g_object_ref( jpeg->streami ); + if( stream->source ) { + jpeg->source = stream->source; + g_object_ref( jpeg->source ); } if( VIPS_OBJECT_CLASS( vips_foreign_load_jpeg_stream_parent_class )-> @@ -236,9 +236,9 @@ vips_foreign_load_jpeg_stream_build( VipsObject *object ) } static gboolean -vips_foreign_load_jpeg_stream_is_a_stream( VipsStreami *streami ) +vips_foreign_load_jpeg_stream_is_a_source( VipsSource *source ) { - return( vips__isjpeg_stream( streami ) ); + return( vips__isjpeg_stream( source ) ); } static void @@ -256,14 +256,14 @@ vips_foreign_load_jpeg_stream_class_init( object_class->description = _( "load image from jpeg stream" ); object_class->build = vips_foreign_load_jpeg_stream_build; - load_class->is_a_stream = vips_foreign_load_jpeg_stream_is_a_stream; + load_class->is_a_source = vips_foreign_load_jpeg_stream_is_a_source; - VIPS_ARG_OBJECT( class, "streami", 1, + VIPS_ARG_OBJECT( class, "source", 1, _( "Streami" ), _( "Stream to load from" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsForeignLoadJpegStream, streami ), - VIPS_TYPE_STREAMI ); + G_STRUCT_OFFSET( VipsForeignLoadJpegStream, source ), + VIPS_TYPE_SOURCE ); } @@ -291,8 +291,8 @@ vips_foreign_load_jpeg_file_build( VipsObject *object ) VipsForeignLoadJpegFile *file = (VipsForeignLoadJpegFile *) object; if( file->filename && - !(jpeg->streami = - vips_streami_new_from_file( file->filename )) ) + !(jpeg->source = + vips_source_new_from_file( file->filename )) ) return( -1 ); if( VIPS_OBJECT_CLASS( vips_foreign_load_jpeg_file_parent_class )-> @@ -305,13 +305,13 @@ vips_foreign_load_jpeg_file_build( VipsObject *object ) static gboolean vips_foreign_load_jpeg_file_is_a( const char *filename ) { - VipsStreami *streami; + VipsSource *source; gboolean result; - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( FALSE ); - result = vips_foreign_load_jpeg_stream_is_a_stream( streami ); - VIPS_UNREF( streami ); + result = vips_foreign_load_jpeg_stream_is_a_source( source ); + VIPS_UNREF( source ); return( result ); } @@ -368,7 +368,7 @@ vips_foreign_load_jpeg_buffer_build( VipsObject *object ) (VipsForeignLoadJpegBuffer *) object; if( buffer->blob && - !(jpeg->streami = vips_streami_new_from_memory( + !(jpeg->source = vips_source_new_from_memory( VIPS_AREA( buffer->blob )->data, VIPS_AREA( buffer->blob )->length )) ) return( -1 ); @@ -383,13 +383,13 @@ vips_foreign_load_jpeg_buffer_build( VipsObject *object ) static gboolean vips_foreign_load_jpeg_buffer_is_a_buffer( const void *buf, size_t len ) { - VipsStreami *streami; + VipsSource *source; gboolean result; - if( !(streami = vips_streami_new_from_memory( buf, len )) ) + if( !(source = vips_source_new_from_memory( buf, len )) ) return( FALSE ); - result = vips_foreign_load_jpeg_stream_is_a_stream( streami ); - VIPS_UNREF( streami ); + result = vips_foreign_load_jpeg_stream_is_a_source( source ); + VIPS_UNREF( source ); return( result ); } diff --git a/libvips/foreign/jpegsave.c b/libvips/foreign/jpegsave.c index 0ea3357f..c23adea3 100644 --- a/libvips/foreign/jpegsave.c +++ b/libvips/foreign/jpegsave.c @@ -219,7 +219,7 @@ vips_foreign_save_jpeg_init( VipsForeignSaveJpeg *jpeg ) typedef struct _VipsForeignSaveJpegStream { VipsForeignSaveJpeg parent_object; - VipsStreamo *streamo; + VipsTarget *target; } VipsForeignSaveJpegStream; @@ -240,7 +240,7 @@ vips_foreign_save_jpeg_stream_build( VipsObject *object ) build( object ) ) return( -1 ); - if( vips__jpeg_write_stream( save->ready, stream->streamo, + if( vips__jpeg_write_stream( save->ready, stream->target, jpeg->Q, jpeg->profile, jpeg->optimize_coding, jpeg->interlace, save->strip, jpeg->no_subsample, jpeg->trellis_quant, jpeg->overshoot_deringing, @@ -264,12 +264,12 @@ vips_foreign_save_jpeg_stream_class_init( object_class->description = _( "save image to jpeg stream" ); object_class->build = vips_foreign_save_jpeg_stream_build; - VIPS_ARG_OBJECT( class, "streamo", 1, + VIPS_ARG_OBJECT( class, "target", 1, _( "Streamo" ), _( "Stream to save to" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsForeignSaveJpegStream, streamo ), - VIPS_TYPE_STREAMO ); + G_STRUCT_OFFSET( VipsForeignSaveJpegStream, target ), + VIPS_TYPE_TARGET ); } @@ -299,23 +299,23 @@ vips_foreign_save_jpeg_file_build( VipsObject *object ) VipsForeignSaveJpeg *jpeg = (VipsForeignSaveJpeg *) object; VipsForeignSaveJpegFile *file = (VipsForeignSaveJpegFile *) object; - VipsStreamo *streamo; + VipsTarget *target; if( VIPS_OBJECT_CLASS( vips_foreign_save_jpeg_file_parent_class )-> build( object ) ) return( -1 ); - if( !(streamo = vips_streamo_new_to_file( file->filename )) ) + if( !(target = vips_target_new_to_file( file->filename )) ) return( -1 ); - if( vips__jpeg_write_stream( save->ready, streamo, + if( vips__jpeg_write_stream( save->ready, target, jpeg->Q, jpeg->profile, jpeg->optimize_coding, jpeg->interlace, save->strip, jpeg->no_subsample, jpeg->trellis_quant, jpeg->overshoot_deringing, jpeg->optimize_scans, jpeg->quant_table ) ) { - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( -1 ); } - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( 0 ); } @@ -367,30 +367,30 @@ vips_foreign_save_jpeg_buffer_build( VipsObject *object ) VipsForeignSaveJpeg *jpeg = (VipsForeignSaveJpeg *) object; VipsForeignSaveJpegBuffer *file = (VipsForeignSaveJpegBuffer *) object; - VipsStreamo *streamo; + VipsTarget *target; VipsBlob *blob; if( VIPS_OBJECT_CLASS( vips_foreign_save_jpeg_buffer_parent_class )-> build( object ) ) return( -1 ); - if( !(streamo = vips_streamo_new_to_memory()) ) + if( !(target = vips_target_new_to_memory()) ) return( -1 ); - if( vips__jpeg_write_stream( save->ready, streamo, + if( vips__jpeg_write_stream( save->ready, target, jpeg->Q, jpeg->profile, jpeg->optimize_coding, jpeg->interlace, save->strip, jpeg->no_subsample, jpeg->trellis_quant, jpeg->overshoot_deringing, jpeg->optimize_scans, jpeg->quant_table ) ) { - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( -1 ); } - g_object_get( streamo, "blob", &blob, NULL ); + g_object_get( target, "blob", &blob, NULL ); g_object_set( file, "buffer", blob, NULL ); vips_area_unref( VIPS_AREA( blob ) ); - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( 0 ); } @@ -438,7 +438,7 @@ vips_foreign_save_jpeg_mime_build( VipsObject *object ) VipsForeignSave *save = (VipsForeignSave *) object; VipsForeignSaveJpeg *jpeg = (VipsForeignSaveJpeg *) object; - VipsStreamo *streamo; + VipsTarget *target; VipsBlob *blob; const unsigned char *obuf; size_t olen; @@ -447,19 +447,19 @@ vips_foreign_save_jpeg_mime_build( VipsObject *object ) build( object ) ) return( -1 ); - if( !(streamo = vips_streamo_new_to_memory()) ) + if( !(target = vips_target_new_to_memory()) ) return( -1 ); - if( vips__jpeg_write_stream( save->ready, streamo, + if( vips__jpeg_write_stream( save->ready, target, jpeg->Q, jpeg->profile, jpeg->optimize_coding, jpeg->interlace, save->strip, jpeg->no_subsample, jpeg->trellis_quant, jpeg->overshoot_deringing, jpeg->optimize_scans, jpeg->quant_table ) ) { - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( -1 ); } - g_object_get( streamo, "blob", &blob, NULL ); + g_object_get( target, "blob", &blob, NULL ); obuf = vips_blob_get( blob, &olen ); printf( "Content-length: %zu\r\n", olen ); @@ -470,7 +470,7 @@ vips_foreign_save_jpeg_mime_build( VipsObject *object ) vips_area_unref( VIPS_AREA( blob ) ); - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( 0 ); } @@ -610,9 +610,9 @@ vips_jpegsave( VipsImage *in, const char *filename, ... ) } /** - * vips_jpegsave_stream: (method) + * vips_jpegsave_target: (method) * @in: image to save - * @streamo: save image to this stream + * @target: save image to this stream * @...: %NULL-terminated list of optional named arguments * * Optional arguments: @@ -630,18 +630,18 @@ vips_jpegsave( VipsImage *in, const char *filename, ... ) * * As vips_jpegsave(), but save to a stream. * - * See also: vips_jpegsave(), vips_image_write_to_stream(). + * See also: vips_jpegsave(), vips_image_write_to_target(). * * Returns: 0 on success, -1 on error. */ int -vips_jpegsave_stream( VipsImage *in, VipsStreamo *streamo, ... ) +vips_jpegsave_target( VipsImage *in, VipsTarget *target, ... ) { va_list ap; int result; - va_start( ap, streamo ); - result = vips_call_split( "jpegsave_stream", ap, in, streamo ); + va_start( ap, target ); + result = vips_call_split( "jpegsave_stream", ap, in, target ); va_end( ap ); return( result ); diff --git a/libvips/foreign/pforeign.h b/libvips/foreign/pforeign.h index 71116f01..286ce3e0 100644 --- a/libvips/foreign/pforeign.h +++ b/libvips/foreign/pforeign.h @@ -79,11 +79,11 @@ int vips__tiff_write_buf( VipsImage *in, VipsRegionShrink region_shrink, int level, gboolean lossless ); -gboolean vips__istiff_stream( VipsStreami *streami ); -gboolean vips__istifftiled_stream( VipsStreami *streami ); -int vips__tiff_read_header_stream( VipsStreami *streami, VipsImage *out, +gboolean vips__istiff_stream( VipsSource *source ); +gboolean vips__istifftiled_stream( VipsSource *source ); +int vips__tiff_read_header_stream( VipsSource *source, VipsImage *out, int page, int n, gboolean autorotate ); -int vips__tiff_read_stream( VipsStreami *streami, VipsImage *out, +int vips__tiff_read_stream( VipsSource *source, VipsImage *out, int page, int n, gboolean autorotate ); extern const char *vips__foreign_tiff_suffs[]; @@ -145,37 +145,37 @@ int vips__mat_ismat( const char *filename ); extern const char *vips__ppm_suffs[]; -int vips__ppm_save_stream( VipsImage *in, VipsStreamo *streamo, +int vips__ppm_save_stream( VipsImage *in, VipsTarget *target, gboolean ascii, gboolean squash ); -int vips__rad_israd( VipsStreami *streami ); -int vips__rad_header( VipsStreami *streami, VipsImage *out ); -int vips__rad_load( VipsStreami *streami, VipsImage *out ); +int vips__rad_israd( VipsSource *source ); +int vips__rad_header( VipsSource *source, VipsImage *out ); +int vips__rad_load( VipsSource *source, VipsImage *out ); -int vips__rad_save( VipsImage *in, VipsStreamo *streamo ); +int vips__rad_save( VipsImage *in, VipsTarget *target ); extern const char *vips__rad_suffs[]; extern const char *vips__jpeg_suffs[]; -int vips__jpeg_write_stream( VipsImage *in, VipsStreamo *streamo, +int vips__jpeg_write_stream( VipsImage *in, VipsTarget *target, int Q, const char *profile, gboolean optimize_coding, gboolean progressive, gboolean strip, gboolean no_subsample, gboolean trellis_quant, gboolean overshoot_deringing, gboolean optimize_scans, int quant_table ); -int vips__jpeg_read_stream( VipsStreami *streami, VipsImage *out, +int vips__jpeg_read_stream( VipsSource *source, VipsImage *out, gboolean header_only, int shrink, int fail, gboolean autorotate ); -int vips__isjpeg_stream( VipsStreami *streami ); +int vips__isjpeg_stream( VipsSource *source ); -int vips__png_ispng_stream( VipsStreami *streami ); -int vips__png_header_stream( VipsStreami *streami, VipsImage *out ); -int vips__png_read_stream( VipsStreami *streami, VipsImage *out, +int vips__png_ispng_stream( VipsSource *source ); +int vips__png_header_stream( VipsSource *source, VipsImage *out ); +int vips__png_read_stream( VipsSource *source, VipsImage *out, gboolean fail ); -gboolean vips__png_isinterlaced_stream( VipsStreami *streami ); +gboolean vips__png_isinterlaced_stream( VipsSource *source ); extern const char *vips__png_suffs[]; -int vips__png_write_stream( VipsImage *in, VipsStreamo *streamo, +int vips__png_write_stream( VipsImage *in, VipsTarget *target, int compress, int interlace, const char *profile, VipsForeignPngFilter filter, gboolean strip, gboolean palette, int colours, int Q, double dither ); @@ -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( VipsStreami *streami ); +int vips__iswebp_stream( VipsSource *source ); -int vips__webp_read_header_stream( VipsStreami *streami, VipsImage *out, +int vips__webp_read_header_stream( VipsSource *source, VipsImage *out, int page, int n, double scale ); -int vips__webp_read_stream( VipsStreami *streami, VipsImage *out, +int vips__webp_read_stream( VipsSource *source, VipsImage *out, int page, int n, double scale ); -int vips__webp_write_stream( VipsImage *image, VipsStreamo *streamo, +int vips__webp_write_stream( 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/pngload.c b/libvips/foreign/pngload.c index a37fbb13..d222dbe7 100644 --- a/libvips/foreign/pngload.c +++ b/libvips/foreign/pngload.c @@ -57,7 +57,7 @@ typedef struct _VipsForeignLoadPng { /* Set by subclasses. */ - VipsStreami *streami; + VipsSource *source; } VipsForeignLoadPng; @@ -71,19 +71,19 @@ vips_foreign_load_png_dispose( GObject *gobject ) { VipsForeignLoadPng *png = (VipsForeignLoadPng *) gobject; - VIPS_UNREF( png->streami ); + VIPS_UNREF( png->source ); G_OBJECT_CLASS( vips_foreign_load_png_parent_class )-> dispose( gobject ); } static VipsForeignFlags -vips_foreign_load_png_get_flags_stream( VipsStreami *streami ) +vips_foreign_load_png_get_flags_stream( VipsSource *source ) { VipsForeignFlags flags; flags = 0; - if( vips__png_isinterlaced_stream( streami ) ) + if( vips__png_isinterlaced_stream( source ) ) flags |= VIPS_FOREIGN_PARTIAL; else flags |= VIPS_FOREIGN_SEQUENTIAL; @@ -96,19 +96,19 @@ vips_foreign_load_png_get_flags( VipsForeignLoad *load ) { VipsForeignLoadPng *png = (VipsForeignLoadPng *) load; - return( vips_foreign_load_png_get_flags_stream( png->streami ) ); + return( vips_foreign_load_png_get_flags_stream( png->source ) ); } static VipsForeignFlags vips_foreign_load_png_get_flags_filename( const char *filename ) { - VipsStreami *streami; + VipsSource *source; VipsForeignFlags flags; - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( 0 ); - flags = vips_foreign_load_png_get_flags_stream( streami ); - VIPS_UNREF( streami ); + flags = vips_foreign_load_png_get_flags_stream( source ); + VIPS_UNREF( source ); return( flags ); } @@ -118,7 +118,7 @@ vips_foreign_load_png_header( VipsForeignLoad *load ) { VipsForeignLoadPng *png = (VipsForeignLoadPng *) load; - if( vips__png_header_stream( png->streami, load->out ) ) + if( vips__png_header_stream( png->source, load->out ) ) return( -1 ); return( 0 ); @@ -129,7 +129,7 @@ vips_foreign_load_png_load( VipsForeignLoad *load ) { VipsForeignLoadPng *png = (VipsForeignLoadPng *) load; - if( vips__png_read_stream( png->streami, load->real, load->fail ) ) + if( vips__png_read_stream( png->source, load->real, load->fail ) ) return( -1 ); return( 0 ); @@ -170,7 +170,7 @@ typedef struct _VipsForeignLoadPngStream { /* Load from a stream. */ - VipsStreami *streami; + VipsSource *source; } VipsForeignLoadPngStream; @@ -185,9 +185,9 @@ vips_foreign_load_png_stream_build( VipsObject *object ) VipsForeignLoadPng *png = (VipsForeignLoadPng *) object; VipsForeignLoadPngStream *stream = (VipsForeignLoadPngStream *) object; - if( stream->streami ) { - png->streami = stream->streami; - g_object_ref( png->streami ); + if( stream->source ) { + png->source = stream->source; + g_object_ref( png->source ); } if( VIPS_OBJECT_CLASS( vips_foreign_load_png_stream_parent_class )-> @@ -198,9 +198,9 @@ vips_foreign_load_png_stream_build( VipsObject *object ) } static gboolean -vips_foreign_load_png_stream_is_a_stream( VipsStreami *streami ) +vips_foreign_load_png_stream_is_a_source( VipsSource *source ) { - return( vips__png_ispng_stream( streami ) ); + return( vips__png_ispng_stream( source ) ); } static void @@ -217,14 +217,14 @@ vips_foreign_load_png_stream_class_init( VipsForeignLoadPngStreamClass *class ) object_class->description = _( "load png from stream" ); object_class->build = vips_foreign_load_png_stream_build; - load_class->is_a_stream = vips_foreign_load_png_stream_is_a_stream; + load_class->is_a_source = vips_foreign_load_png_stream_is_a_source; - VIPS_ARG_OBJECT( class, "streami", 1, + VIPS_ARG_OBJECT( class, "source", 1, _( "Streami" ), _( "Stream to load from" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsForeignLoadPngStream, streami ), - VIPS_TYPE_STREAMI ); + G_STRUCT_OFFSET( VipsForeignLoadPngStream, source ), + VIPS_TYPE_SOURCE ); } @@ -254,7 +254,7 @@ vips_foreign_load_png_file_build( VipsObject *object ) VipsForeignLoadPngFile *file = (VipsForeignLoadPngFile *) object; if( file->filename && - !(png->streami = vips_streami_new_from_file( file->filename )) ) + !(png->source = vips_source_new_from_file( file->filename )) ) return( -1 ); if( VIPS_OBJECT_CLASS( vips_foreign_load_png_file_parent_class )-> @@ -267,13 +267,13 @@ vips_foreign_load_png_file_build( VipsObject *object ) static gboolean vips_foreign_load_png_file_is_a( const char *filename ) { - VipsStreami *streami; + VipsSource *source; gboolean result; - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( FALSE ); - result = vips_foreign_load_png_stream_is_a_stream( streami ); - VIPS_UNREF( streami ); + result = vips_foreign_load_png_stream_is_a_source( source ); + VIPS_UNREF( source ); return( result ); } @@ -331,7 +331,7 @@ vips_foreign_load_png_buffer_build( VipsObject *object ) VipsForeignLoadPngBuffer *buffer = (VipsForeignLoadPngBuffer *) object; if( buffer->blob && - !(png->streami = vips_streami_new_from_memory( + !(png->source = vips_source_new_from_memory( VIPS_AREA( buffer->blob )->data, VIPS_AREA( buffer->blob )->length )) ) return( -1 ); @@ -346,13 +346,13 @@ vips_foreign_load_png_buffer_build( VipsObject *object ) static gboolean vips_foreign_load_png_buffer_is_a_buffer( const void *buf, size_t len ) { - VipsStreami *streami; + VipsSource *source; gboolean result; - if( !(streami = vips_streami_new_from_memory( buf, len )) ) + if( !(source = vips_source_new_from_memory( buf, len )) ) return( FALSE ); - result = vips_foreign_load_png_stream_is_a_stream( streami ); - VIPS_UNREF( streami ); + result = vips_foreign_load_png_stream_is_a_source( source ); + VIPS_UNREF( source ); return( result ); } @@ -455,8 +455,8 @@ vips_pngload_buffer( void *buf, size_t len, VipsImage **out, ... ) } /** - * vips_pngload_stream: - * @streami: stream to load from + * vips_pngload_source: + * @source: stream to load from * @out: (out): image to write * @...: %NULL-terminated list of optional named arguments * @@ -467,13 +467,13 @@ vips_pngload_buffer( void *buf, size_t len, VipsImage **out, ... ) * Returns: 0 on success, -1 on error. */ int -vips_pngload_stream( VipsStreami *streami, VipsImage **out, ... ) +vips_pngload_source( VipsSource *source, VipsImage **out, ... ) { va_list ap; int result; va_start( ap, out ); - result = vips_call_split( "pngload_stream", ap, streami, out ); + result = vips_call_split( "pngload_stream", ap, source, out ); va_end( ap ); return( result ); diff --git a/libvips/foreign/pngsave.c b/libvips/foreign/pngsave.c index c508fe5d..dd32cae3 100644 --- a/libvips/foreign/pngsave.c +++ b/libvips/foreign/pngsave.c @@ -182,7 +182,7 @@ vips_foreign_save_png_init( VipsForeignSavePng *png ) typedef struct _VipsForeignSavePngStream { VipsForeignSavePng parent_object; - VipsStreamo *streamo; + VipsTarget *target; } VipsForeignSavePngStream; typedef VipsForeignSavePngClass VipsForeignSavePngStreamClass; @@ -201,7 +201,7 @@ vips_foreign_save_png_stream_build( VipsObject *object ) build( object ) ) return( -1 ); - if( vips__png_write_stream( save->ready, stream->streamo, + if( vips__png_write_stream( save->ready, stream->target, png->compression, png->interlace, png->profile, png->filter, save->strip, png->palette, png->colours, png->Q, png->dither ) ) return( -1 ); @@ -222,12 +222,12 @@ vips_foreign_save_png_stream_class_init( VipsForeignSavePngStreamClass *class ) object_class->description = _( "save image to png stream" ); object_class->build = vips_foreign_save_png_stream_build; - VIPS_ARG_OBJECT( class, "streamo", 1, + VIPS_ARG_OBJECT( class, "target", 1, _( "Streamo" ), _( "Stream to save to" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsForeignSavePngStream, streamo ), - VIPS_TYPE_STREAMO ); + G_STRUCT_OFFSET( VipsForeignSavePngStream, target ), + VIPS_TYPE_TARGET ); } @@ -254,22 +254,22 @@ vips_foreign_save_png_file_build( VipsObject *object ) VipsForeignSavePng *png = (VipsForeignSavePng *) object; VipsForeignSavePngFile *png_file = (VipsForeignSavePngFile *) object; - VipsStreamo *streamo; + VipsTarget *target; if( VIPS_OBJECT_CLASS( vips_foreign_save_png_file_parent_class )-> build( object ) ) return( -1 ); - if( !(streamo = vips_streamo_new_to_file( png_file->filename )) ) + if( !(target = vips_target_new_to_file( png_file->filename )) ) return( -1 ); - if( vips__png_write_stream( save->ready, streamo, + if( vips__png_write_stream( save->ready, target, png->compression, png->interlace, png->profile, png->filter, save->strip, png->palette, png->colours, png->Q, png->dither ) ) { - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( -1 ); } - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( 0 ); } @@ -318,29 +318,29 @@ vips_foreign_save_png_buffer_build( VipsObject *object ) VipsForeignSavePng *png = (VipsForeignSavePng *) object; VipsForeignSavePngBuffer *buffer = (VipsForeignSavePngBuffer *) object; - VipsStreamo *streamo; + VipsTarget *target; VipsBlob *blob; if( VIPS_OBJECT_CLASS( vips_foreign_save_png_buffer_parent_class )-> build( object ) ) return( -1 ); - if( !(streamo = vips_streamo_new_to_memory()) ) + if( !(target = vips_target_new_to_memory()) ) return( -1 ); - if( vips__png_write_stream( save->ready, streamo, + if( vips__png_write_stream( save->ready, target, png->compression, png->interlace, png->profile, png->filter, save->strip, png->palette, png->colours, png->Q, png->dither ) ) { - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( -1 ); } - g_object_get( streamo, "blob", &blob, NULL ); + g_object_get( target, "blob", &blob, NULL ); g_object_set( buffer, "buffer", blob, NULL ); vips_area_unref( VIPS_AREA( blob ) ); - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( 0 ); } @@ -498,9 +498,9 @@ vips_pngsave_buffer( VipsImage *in, void **buf, size_t *len, ... ) } /** - * vips_pngsave_stream: (method) + * vips_pngsave_target: (method) * @in: image to save - * @streamo: save image to this stream + * @target: save image to this stream * @...: %NULL-terminated list of optional named arguments * * Optional arguments: @@ -516,18 +516,18 @@ vips_pngsave_buffer( VipsImage *in, void **buf, size_t *len, ... ) * * As vips_pngsave(), but save to a stream. * - * See also: vips_pngsave(), vips_image_write_to_stream(). + * See also: vips_pngsave(), vips_image_write_to_target(). * * Returns: 0 on success, -1 on error. */ int -vips_pngsave_stream( VipsImage *in, VipsStreamo *streamo, ... ) +vips_pngsave_target( VipsImage *in, VipsTarget *target, ... ) { va_list ap; int result; - va_start( ap, streamo ); - result = vips_call_split( "pngsave_stream", ap, in, streamo ); + va_start( ap, target ); + result = vips_call_split( "pngsave_stream", ap, in, target ); va_end( ap ); return( result ); diff --git a/libvips/foreign/ppmload.c b/libvips/foreign/ppmload.c index adcfbaca..c18a5002 100644 --- a/libvips/foreign/ppmload.c +++ b/libvips/foreign/ppmload.c @@ -90,7 +90,7 @@ typedef struct _VipsForeignLoadPpm { /* The stream we load from, and the buffered wrapper for it. */ - VipsStreami *streami; + VipsSource *source; VipsBufis *bufis; /* Properties of this ppm, from the header. @@ -134,11 +134,11 @@ static char *magic_names[] = { const char *vips__ppm_suffs[] = { ".ppm", ".pgm", ".pbm", ".pfm", NULL }; static gboolean -vips_foreign_load_ppm_is_a_stream( VipsStreami *streami ) +vips_foreign_load_ppm_is_a_source( VipsSource *source ) { const unsigned char *data; - if( (data = vips_streami_sniff( streami, 2 )) ) { + if( (data = vips_source_sniff( source, 2 )) ) { int i; for( i = 0; i < VIPS_NUMBER( magic_names ); i++ ) @@ -185,7 +185,7 @@ vips_foreign_load_ppm_dispose( GObject *gobject ) VipsForeignLoadPpm *ppm = (VipsForeignLoadPpm *) gobject; VIPS_UNREF( ppm->bufis ); - VIPS_UNREF( ppm->streami ); + VIPS_UNREF( ppm->source ); G_OBJECT_CLASS( vips_foreign_load_ppm_parent_class )-> dispose( gobject ); @@ -213,7 +213,7 @@ vips_foreign_load_ppm_parse_header( VipsForeignLoadPpm *ppm ) 1, 1, 1, 0, 0, 0, 0, 0 }; - if( vips_streami_rewind( ppm->streami ) ) + if( vips_source_rewind( ppm->source ) ) return( -1 ); /* Read in the magic number. @@ -331,14 +331,14 @@ vips_foreign_load_ppm_get_flags( VipsForeignLoad *load ) flags = 0; - /* If this streami supports fast mmap and this PPM is >=8 bit binary, + /* If this source supports fast mmap and this PPM is >=8 bit binary, * then we can mmap the file and support partial load. Otherwise, * it's sequential. */ if( !ppm->have_read_header && vips_foreign_load_ppm_parse_header( ppm ) ) return( 0 ); - if( vips_streami_is_mappable( ppm->streami ) && + if( vips_source_is_mappable( ppm->source ) && !ppm->ascii && ppm->bits >= 8 ) flags |= VIPS_FOREIGN_PARTIAL; @@ -366,7 +366,7 @@ vips_foreign_load_ppm_set_image( VipsForeignLoadPpm *ppm, VipsImage *image ) "ppm-max-value", VIPS_ABS( ppm->max_value ) ); VIPS_SETSTR( image->filename, - vips_stream_filename( VIPS_STREAM( ppm->bufis->streami ) ) ); + vips_connection_filename( VIPS_CONNECTION( ppm->bufis->source ) ) ); } static int @@ -380,7 +380,7 @@ vips_foreign_load_ppm_header( VipsForeignLoad *load ) vips_foreign_load_ppm_set_image( ppm, load->out ); - vips_streami_minimise( ppm->streami ); + vips_source_minimise( ppm->source ); return( 0 ); } @@ -398,8 +398,8 @@ vips_foreign_load_ppm_map( VipsForeignLoadPpm *ppm, VipsImage *image ) const void *data; vips_bufis_unbuffer( ppm->bufis ); - header_offset = vips_streami_seek( ppm->streami, 0, SEEK_CUR ); - data = vips_streami_map( ppm->streami, &length ); + header_offset = vips_source_seek( ppm->source, 0, SEEK_CUR ); + data = vips_source_map( ppm->source, &length ); if( header_offset < 0 || !data ) return( -1 ); @@ -435,7 +435,7 @@ vips_foreign_load_ppm_generate_binary( VipsRegion *or, size_t bytes_read; - bytes_read = vips_streami_read( ppm->streami, q, sizeof_line ); + bytes_read = vips_source_read( ppm->source, q, sizeof_line ); if( bytes_read != sizeof_line ) { vips_error( class->nickname, "%s", _( "file truncated" ) ); @@ -564,7 +564,7 @@ vips_foreign_load_ppm_load( VipsForeignLoad *load ) /* If the stream is mappable and this is a binary file, we can map it. */ - if( vips_streami_is_mappable( ppm->streami ) && + if( vips_source_is_mappable( ppm->source ) && !ppm->ascii && ppm->bits >= 8 ) { if( vips_foreign_load_ppm_map( ppm, load->real ) ) @@ -599,7 +599,7 @@ vips_foreign_load_ppm_load( VipsForeignLoad *load ) return( -1 ); } - if( vips_streami_decode( ppm->streami ) ) + if( vips_source_decode( ppm->source ) ) return( -1 ); return( 0 ); @@ -653,13 +653,13 @@ G_DEFINE_TYPE( VipsForeignLoadPpmFile, vips_foreign_load_ppm_file, static gboolean vips_foreign_load_ppm_file_is_a( const char *filename ) { - VipsStreami *streami; + VipsSource *source; gboolean result; - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( FALSE ); - result = vips_foreign_load_ppm_is_a_stream( streami ); - VIPS_UNREF( streami ); + result = vips_foreign_load_ppm_is_a_source( source ); + VIPS_UNREF( source ); return( result ); } @@ -671,10 +671,10 @@ vips_foreign_load_ppm_file_build( VipsObject *object ) VipsForeignLoadPpm *ppm = (VipsForeignLoadPpm *) object; if( file->filename ) { - if( !(ppm->streami = - vips_streami_new_from_file( file->filename )) ) + if( !(ppm->source = + vips_source_new_from_file( file->filename )) ) return( -1 ); - ppm->bufis = vips_bufis_new_from_streami( ppm->streami ); + ppm->bufis = vips_bufis_new_from_source( ppm->source ); } if( VIPS_OBJECT_CLASS( vips_foreign_load_ppm_file_parent_class )-> diff --git a/libvips/foreign/ppmsave.c b/libvips/foreign/ppmsave.c index c563d1cd..a3e32144 100644 --- a/libvips/foreign/ppmsave.c +++ b/libvips/foreign/ppmsave.c @@ -61,7 +61,7 @@ typedef int (*VipsSavePpmFn)( VipsForeignSavePpm *, VipsImage *, VipsPel * ); typedef struct _VipsForeignSavePpm { VipsForeignSave parent_object; - VipsStreamo *streamo; + VipsTarget *target; gboolean ascii; gboolean squash; @@ -78,9 +78,9 @@ vips_foreign_save_ppm_dispose( GObject *gobject ) { VipsForeignSavePpm *ppm = (VipsForeignSavePpm *) gobject; - if( ppm->streamo ) - vips_streamo_finish( ppm->streamo ); - VIPS_UNREF( ppm->streamo ); + if( ppm->target ) + vips_target_finish( ppm->target ); + VIPS_UNREF( ppm->target ); G_OBJECT_CLASS( vips_foreign_save_ppm_parent_class )-> dispose( gobject ); @@ -97,17 +97,17 @@ vips_foreign_save_ppm_line_ascii( VipsForeignSavePpm *ppm, for( i = 0; i < n_elements; i++ ) { switch( image->BandFmt ) { case VIPS_FORMAT_UCHAR: - vips_streamo_writef( ppm->streamo, + vips_target_writef( ppm->target, "%d ", p[i] ); break; case VIPS_FORMAT_USHORT: - vips_streamo_writef( ppm->streamo, + vips_target_writef( ppm->target, "%d ", ((unsigned short *) p)[i] ); break; case VIPS_FORMAT_UINT: - vips_streamo_writef( ppm->streamo, + vips_target_writef( ppm->target, "%d ", ((unsigned int *) p)[i] ); break; @@ -116,7 +116,7 @@ vips_foreign_save_ppm_line_ascii( VipsForeignSavePpm *ppm, } } - if( vips_streamo_writes( ppm->streamo, "\n" ) ) + if( vips_target_writes( ppm->target, "\n" ) ) return( -1 ); return( 0 ); @@ -129,9 +129,9 @@ vips_foreign_save_ppm_line_ascii_squash( VipsForeignSavePpm *ppm, int x; for( x = 0; x < image->Xsize; x++ ) - vips_streamo_writef( ppm->streamo, "%d ", p[x] ? 0 : 1 ); + vips_target_writef( ppm->target, "%d ", p[x] ? 0 : 1 ); - if( vips_streamo_writes( ppm->streamo, "\n" ) ) + if( vips_target_writes( ppm->target, "\n" ) ) return( -1 ); return( 0 ); @@ -141,7 +141,7 @@ static int vips_foreign_save_ppm_line_binary( VipsForeignSavePpm *ppm, VipsImage *image, VipsPel *p ) { - if( vips_streamo_write( ppm->streamo, + if( vips_target_write( ppm->target, p, VIPS_IMAGE_SIZEOF_LINE( image ) ) ) return( -1 ); @@ -164,7 +164,7 @@ vips_foreign_save_ppm_line_binary_squash( VipsForeignSavePpm *ppm, bits |= p[x] ? 0 : 1; if( n_bits == 8 ) { - if( VIPS_STREAMO_PUTC( ppm->streamo, bits ) ) + if( VIPS_TARGET_PUTC( ppm->target, bits ) ) return( -1 ); bits = 0; @@ -175,7 +175,7 @@ vips_foreign_save_ppm_line_binary_squash( VipsForeignSavePpm *ppm, /* Flush any remaining bits in this line. */ if( n_bits && - VIPS_STREAMO_PUTC( ppm->streamo, bits ) ) + VIPS_TARGET_PUTC( ppm->target, bits ) ) return( -1 ); return( 0 ); @@ -234,28 +234,28 @@ vips_foreign_save_ppm( VipsForeignSavePpm *ppm, VipsImage *image ) else g_assert_not_reached(); - vips_streamo_writef( ppm->streamo, "%s\n", magic ); + vips_target_writef( ppm->target, "%s\n", magic ); date = vips__get_iso8601(); - vips_streamo_writef( ppm->streamo, + vips_target_writef( ppm->target, "#vips2ppm - %s\n", date ); g_free( date ); - vips_streamo_writef( ppm->streamo, + vips_target_writef( ppm->target, "%d %d\n", image->Xsize, image->Ysize ); if( !ppm->squash ) switch( image->BandFmt ) { case VIPS_FORMAT_UCHAR: - vips_streamo_writef( ppm->streamo, + vips_target_writef( ppm->target, "%d\n", UCHAR_MAX ); break; case VIPS_FORMAT_USHORT: - vips_streamo_writef( ppm->streamo, + vips_target_writef( ppm->target, "%d\n", USHRT_MAX ); break; case VIPS_FORMAT_UINT: - vips_streamo_writef( ppm->streamo, + vips_target_writef( ppm->target, "%d\n", UINT_MAX ); break; @@ -272,7 +272,7 @@ vips_foreign_save_ppm( VipsForeignSavePpm *ppm, VipsImage *image ) /* Need to be locale independent. */ g_ascii_dtostr( buf, G_ASCII_DTOSTR_BUF_SIZE, scale ); - vips_streamo_writes( ppm->streamo, buf ); + vips_target_writes( ppm->target, buf ); } break; @@ -416,7 +416,7 @@ vips_foreign_save_ppm_file_build( VipsObject *object ) VipsForeignSavePpmFile *file = (VipsForeignSavePpmFile *) object; if( file->filename && - !(ppm->streamo = vips_streamo_new_to_file( file->filename )) ) + !(ppm->target = vips_target_new_to_file( file->filename )) ) return( -1 ); return( VIPS_OBJECT_CLASS( vips_foreign_save_ppm_file_parent_class )-> diff --git a/libvips/foreign/radiance.c b/libvips/foreign/radiance.c index bb419847..9170fd0d 100644 --- a/libvips/foreign/radiance.c +++ b/libvips/foreign/radiance.c @@ -28,7 +28,7 @@ * - fix a buffer overflow for incorrectly coded old-style RLE * [HongxuChen] * 6/11/19 - * - revise for VipsStream + * - revise for VipsConnection */ /* @@ -722,7 +722,7 @@ typedef struct { } Read; int -vips__rad_israd( VipsStreami *streami ) +vips__rad_israd( VipsSource *source ) { VipsBufis *bufis; const char *line; @@ -730,7 +730,7 @@ vips__rad_israd( VipsStreami *streami ) /* Just test that the first line is the magic string. */ - bufis = vips_bufis_new_from_streami( streami ); + bufis = vips_bufis_new_from_source( source ); result = (line = vips_bufis_get_line( bufis )) && strcmp( line, "#?RADIANCE" ) == 0; VIPS_UNREF( bufis ); @@ -748,22 +748,22 @@ static void read_minimise_cb( VipsObject *object, Read *read ) { if( read->bufis ) - vips_streami_minimise( read->bufis->streami ); + vips_source_minimise( read->bufis->source ); } static Read * -read_new( VipsStreami *streami, VipsImage *out ) +read_new( VipsSource *source, VipsImage *out ) { Read *read; int i; - if( vips_streami_rewind( streami ) ) + if( vips_source_rewind( source ) ) return( NULL ); if( !(read = VIPS_NEW( out, Read )) ) return( NULL ); - read->bufis = vips_bufis_new_from_streami( streami ); + read->bufis = vips_bufis_new_from_source( source ); read->out = out; strcpy( read->format, COLRFMT ); read->expos = 1.0; @@ -869,8 +869,8 @@ rad2vips_get_header( Read *read, VipsImage *out ) 1, read->aspect ); VIPS_SETSTR( out->filename, - vips_stream_filename( - VIPS_STREAM( read->bufis->streami ) ) ); + vips_connection_filename( + VIPS_CONNECTION( read->bufis->source ) ) ); vips_image_pipelinev( out, VIPS_DEMAND_STYLE_THINSTRIP, NULL ); @@ -893,15 +893,15 @@ rad2vips_get_header( Read *read, VipsImage *out ) } int -vips__rad_header( VipsStreami *streami, VipsImage *out ) +vips__rad_header( VipsSource *source, VipsImage *out ) { Read *read; - if( !(read = read_new( streami, out )) ) + if( !(read = read_new( source, out )) ) return( -1 ); if( rad2vips_get_header( read, read->out ) ) return( -1 ); - vips_streami_minimise( streami ); + vips_source_minimise( source ); return( 0 ); } @@ -940,7 +940,7 @@ rad2vips_generate( VipsRegion *or, } int -vips__rad_load( VipsStreami *streami, VipsImage *out ) +vips__rad_load( VipsSource *source, VipsImage *out ) { VipsImage **t = (VipsImage **) vips_object_local_array( VIPS_OBJECT( out ), 3 ); @@ -949,10 +949,10 @@ vips__rad_load( VipsStreami *streami, VipsImage *out ) #ifdef DEBUG printf( "rad2vips: reading \"%s\"\n", - vips_stream_nick( VIPS_STREAM( streami ) ) ); + vips_connection_nick( VIPS_CONNECTION( source ) ) ); #endif /*DEBUG*/ - if( !(read = read_new( streami, out )) ) + if( !(read = read_new( source, out )) ) return( -1 ); t[0] = vips_image_new(); @@ -967,7 +967,7 @@ vips__rad_load( VipsStreami *streami, VipsImage *out ) vips_image_write( t[1], out ) ) return( -1 ); - if( vips_streami_decode( streami ) ) + if( vips_source_decode( source ) ) return( -1 ); return( 0 ); @@ -977,7 +977,7 @@ vips__rad_load( VipsStreami *streami, VipsImage *out ) */ typedef struct { VipsImage *in; - VipsStreamo *streamo; + VipsTarget *target; char format[256]; double expos; @@ -992,13 +992,13 @@ static void write_destroy( Write *write ) { VIPS_FREE( write->line ); - VIPS_UNREF( write->streamo ); + VIPS_UNREF( write->target ); vips_free( write ); } static Write * -write_new( VipsImage *in, VipsStreamo *streamo ) +write_new( VipsImage *in, VipsTarget *target ) { Write *write; int i; @@ -1007,8 +1007,8 @@ write_new( VipsImage *in, VipsStreamo *streamo ) return( NULL ); write->in = in; - write->streamo = streamo; - g_object_ref( streamo ); + write->target = target; + g_object_ref( target ); strcpy( write->format, COLRFMT ); write->expos = 1.0; @@ -1082,25 +1082,25 @@ vips2rad_put_header( Write *write ) { vips2rad_make_header( write ); - vips_streamo_writes( write->streamo, "#?RADIANCE\n" ); - vips_streamo_writef( write->streamo, "%s%s\n", FMTSTR, write->format ); - vips_streamo_writef( write->streamo, "%s%e\n", EXPOSSTR, write->expos ); - vips_streamo_writef( write->streamo, + vips_target_writes( write->target, "#?RADIANCE\n" ); + vips_target_writef( write->target, "%s%s\n", FMTSTR, write->format ); + vips_target_writef( write->target, "%s%e\n", EXPOSSTR, write->expos ); + vips_target_writef( write->target, "%s %f %f %f\n", COLCORSTR, write->colcor[RED], write->colcor[GRN], write->colcor[BLU] ); - vips_streamo_writef( write->streamo, + vips_target_writef( write->target, "SOFTWARE=vips %s\n", vips_version_string() ); - vips_streamo_writef( write->streamo, + vips_target_writef( write->target, "%s%f\n", ASPECTSTR, write->aspect ); - vips_streamo_writef( write->streamo, + vips_target_writef( write->target, "%s %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\n", PRIMARYSTR, write->prims[RED][CIEX], write->prims[RED][CIEY], write->prims[GRN][CIEX], write->prims[GRN][CIEY], write->prims[BLU][CIEX], write->prims[BLU][CIEY], write->prims[WHT][CIEX], write->prims[WHT][CIEY] ); - vips_streamo_writes( write->streamo, "\n" ); - vips_streamo_writes( write->streamo, + vips_target_writes( write->target, "\n" ); + vips_target_writes( write->target, resolu2str( resolu_buf, &write->rs ) ); return( 0 ); @@ -1115,7 +1115,7 @@ scanline_write( Write *write, COLR *scanline, int width ) width > MAXELEN ) { /* Too large or small for RLE ... do a simple write. */ - if( vips_streamo_write( write->streamo, + if( vips_target_write( write->target, scanline, sizeof( COLR ) * width ) ) return( -1 ); } @@ -1126,7 +1126,7 @@ scanline_write( Write *write, COLR *scanline, int width ) */ rle_scanline_write( scanline, width, write->line, &length ); - if( vips_streamo_write( write->streamo, write->line, length ) ) + if( vips_target_write( write->target, write->line, length ) ) return( -1 ); } @@ -1159,7 +1159,7 @@ vips2rad_put_data( Write *write ) } int -vips__rad_save( VipsImage *in, VipsStreamo *streamo ) +vips__rad_save( VipsImage *in, VipsTarget *target ) { Write *write; @@ -1170,7 +1170,7 @@ vips__rad_save( VipsImage *in, VipsStreamo *streamo ) if( vips_image_pio_input( in ) || vips_check_coding_rad( "vips2rad", in ) ) return( -1 ); - if( !(write = write_new( in, streamo )) ) + if( !(write = write_new( in, target )) ) return( -1 ); if( vips2rad_put_header( write ) || @@ -1179,7 +1179,7 @@ vips__rad_save( VipsImage *in, VipsStreamo *streamo ) return( -1 ); } - vips_streamo_finish( streamo ); + vips_target_finish( target ); write_destroy( write ); diff --git a/libvips/foreign/radload.c b/libvips/foreign/radload.c index 18977aef..f56e62e1 100644 --- a/libvips/foreign/radload.c +++ b/libvips/foreign/radload.c @@ -57,7 +57,7 @@ typedef struct _VipsForeignLoadRad { /* Set by subclasses. */ - VipsStreami *streami; + VipsSource *source; } VipsForeignLoadRad; @@ -71,7 +71,7 @@ vips_foreign_load_rad_dispose( GObject *gobject ) { VipsForeignLoadRad *rad = (VipsForeignLoadRad *) gobject; - VIPS_UNREF( rad->streami ); + VIPS_UNREF( rad->source ); G_OBJECT_CLASS( vips_foreign_load_rad_parent_class )-> dispose( gobject ); @@ -94,7 +94,7 @@ vips_foreign_load_rad_header( VipsForeignLoad *load ) { VipsForeignLoadRad *rad = (VipsForeignLoadRad *) load; - if( vips__rad_header( rad->streami, load->out ) ) + if( vips__rad_header( rad->source, load->out ) ) return( -1 ); return( 0 ); @@ -105,7 +105,7 @@ vips_foreign_load_rad_load( VipsForeignLoad *load ) { VipsForeignLoadRad *rad = (VipsForeignLoadRad *) load; - if( vips__rad_load( rad->streami, load->real ) ) + if( vips__rad_load( rad->source, load->real ) ) return( -1 ); return( 0 ); @@ -146,7 +146,7 @@ typedef struct _VipsForeignLoadRadStream { /* Load from a stream. */ - VipsStreami *streami; + VipsSource *source; } VipsForeignLoadRadStream; @@ -161,9 +161,9 @@ vips_foreign_load_rad_stream_build( VipsObject *object ) VipsForeignLoadRad *rad = (VipsForeignLoadRad *) object; VipsForeignLoadRadStream *stream = (VipsForeignLoadRadStream *) object; - if( stream->streami ) { - rad->streami = stream->streami; - g_object_ref( rad->streami ); + if( stream->source ) { + rad->source = stream->source; + g_object_ref( rad->source ); } if( VIPS_OBJECT_CLASS( vips_foreign_load_rad_stream_parent_class )-> @@ -174,9 +174,9 @@ vips_foreign_load_rad_stream_build( VipsObject *object ) } static gboolean -vips_foreign_load_rad_stream_is_a_stream( VipsStreami *streami ) +vips_foreign_load_rad_stream_is_a_source( VipsSource *source ) { - return( vips__rad_israd( streami ) ); + return( vips__rad_israd( source ) ); } static void @@ -193,14 +193,14 @@ vips_foreign_load_rad_stream_class_init( VipsForeignLoadRadStreamClass *class ) object_class->description = _( "load rad from stream" ); object_class->build = vips_foreign_load_rad_stream_build; - load_class->is_a_stream = vips_foreign_load_rad_stream_is_a_stream; + load_class->is_a_source = vips_foreign_load_rad_stream_is_a_source; - VIPS_ARG_OBJECT( class, "streami", 1, + VIPS_ARG_OBJECT( class, "source", 1, _( "Streami" ), _( "Stream to load from" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsForeignLoadRadStream, streami ), - VIPS_TYPE_STREAMI ); + G_STRUCT_OFFSET( VipsForeignLoadRadStream, source ), + VIPS_TYPE_SOURCE ); } @@ -230,7 +230,7 @@ vips_foreign_load_rad_file_build( VipsObject *object ) VipsForeignLoadRadFile *file = (VipsForeignLoadRadFile *) object; if( file->filename && - !(rad->streami = vips_streami_new_from_file( file->filename )) ) + !(rad->source = vips_source_new_from_file( file->filename )) ) return( -1 ); if( VIPS_OBJECT_CLASS( vips_foreign_load_rad_file_parent_class )-> @@ -243,13 +243,13 @@ vips_foreign_load_rad_file_build( VipsObject *object ) static int vips_foreign_load_rad_file_is_a( const char *filename ) { - VipsStreami *streami; + VipsSource *source; int result; - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( -1 ); - result = vips_foreign_load_rad_stream_is_a_stream( streami ); - VIPS_UNREF( streami ); + result = vips_foreign_load_rad_stream_is_a_source( source ); + VIPS_UNREF( source ); return( result ); } @@ -307,7 +307,7 @@ vips_foreign_load_rad_buffer_build( VipsObject *object ) VipsForeignLoadRadBuffer *buffer = (VipsForeignLoadRadBuffer *) object; if( buffer->blob && - !(rad->streami = vips_streami_new_from_memory( + !(rad->source = vips_source_new_from_memory( VIPS_AREA( buffer->blob )->data, VIPS_AREA( buffer->blob )->length )) ) return( -1 ); @@ -322,13 +322,13 @@ vips_foreign_load_rad_buffer_build( VipsObject *object ) static gboolean vips_foreign_load_rad_buffer_is_a_buffer( const void *buf, size_t len ) { - VipsStreami *streami; + VipsSource *source; gboolean result; - if( !(streami = vips_streami_new_from_memory( buf, len )) ) + if( !(source = vips_source_new_from_memory( buf, len )) ) return( FALSE ); - result = vips_foreign_load_rad_stream_is_a_stream( streami ); - VIPS_UNREF( streami ); + result = vips_foreign_load_rad_stream_is_a_source( source ); + VIPS_UNREF( source ); return( result ); } @@ -439,8 +439,8 @@ vips_radload_buffer( void *buf, size_t len, VipsImage **out, ... ) } /** - * vips_radload_stream: - * @streami: stream to load from + * vips_radload_source: + * @source: stream to load from * @out: (out): output image * @...: %NULL-terminated list of optional named arguments * @@ -451,13 +451,13 @@ vips_radload_buffer( void *buf, size_t len, VipsImage **out, ... ) * Returns: 0 on success, -1 on error. */ int -vips_radload_stream( VipsStreami *streami, VipsImage **out, ... ) +vips_radload_source( VipsSource *source, VipsImage **out, ... ) { va_list ap; int result; va_start( ap, out ); - result = vips_call_split( "radload_stream", ap, streami, out ); + result = vips_call_split( "radload_stream", ap, source, out ); va_end( ap ); return( result ); diff --git a/libvips/foreign/radsave.c b/libvips/foreign/radsave.c index f90fa8dd..408fe6d2 100644 --- a/libvips/foreign/radsave.c +++ b/libvips/foreign/radsave.c @@ -122,19 +122,19 @@ vips_foreign_save_rad_file_build( VipsObject *object ) VipsForeignSave *save = (VipsForeignSave *) object; VipsForeignSaveRadFile *file = (VipsForeignSaveRadFile *) object; - VipsStreamo *streamo; + VipsTarget *target; if( VIPS_OBJECT_CLASS( vips_foreign_save_rad_file_parent_class )-> build( object ) ) return( -1 ); - if( !(streamo = vips_streamo_new_to_file( file->filename )) ) + if( !(target = vips_target_new_to_file( file->filename )) ) return( -1 ); - if( vips__rad_save( save->ready, streamo ) ) { - VIPS_UNREF( streamo ); + if( vips__rad_save( save->ready, target ) ) { + VIPS_UNREF( target ); return( -1 ); } - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( 0 ); } @@ -168,7 +168,7 @@ vips_foreign_save_rad_file_init( VipsForeignSaveRadFile *file ) typedef struct _VipsForeignSaveRadStream { VipsForeignSaveRad parent_object; - VipsStreamo *streamo; + VipsTarget *target; } VipsForeignSaveRadStream; typedef VipsForeignSaveRadClass VipsForeignSaveRadStreamClass; @@ -186,7 +186,7 @@ vips_foreign_save_rad_stream_build( VipsObject *object ) build( object ) ) return( -1 ); - if( vips__rad_save( save->ready, stream->streamo ) ) + if( vips__rad_save( save->ready, stream->target ) ) return( -1 ); return( 0 ); @@ -205,12 +205,12 @@ vips_foreign_save_rad_stream_class_init( VipsForeignSaveRadStreamClass *class ) object_class->description = _( "save image to Radiance stream" ); object_class->build = vips_foreign_save_rad_stream_build; - VIPS_ARG_OBJECT( class, "streamo", 1, + VIPS_ARG_OBJECT( class, "target", 1, _( "Streamo" ), _( "Stream to save to" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsForeignSaveRadStream, streamo ), - VIPS_TYPE_STREAMO ); + G_STRUCT_OFFSET( VipsForeignSaveRadStream, target ), + VIPS_TYPE_TARGET ); } @@ -235,26 +235,26 @@ vips_foreign_save_rad_buffer_build( VipsObject *object ) { VipsForeignSave *save = (VipsForeignSave *) object; - VipsStreamo *streamo; + VipsTarget *target; VipsBlob *blob; if( VIPS_OBJECT_CLASS( vips_foreign_save_rad_buffer_parent_class )-> build( object ) ) return( -1 ); - if( !(streamo = vips_streamo_new_to_memory()) ) + if( !(target = vips_target_new_to_memory()) ) return( -1 ); - if( vips__rad_save( save->ready, streamo ) ) { - VIPS_UNREF( streamo ); + if( vips__rad_save( save->ready, target ) ) { + VIPS_UNREF( target ); return( -1 ); } - g_object_get( streamo, "blob", &blob, NULL ); + g_object_get( target, "blob", &blob, NULL ); g_object_set( save, "buffer", blob, NULL ); vips_area_unref( VIPS_AREA( blob ) ); - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( 0 ); } @@ -360,9 +360,9 @@ vips_radsave_buffer( VipsImage *in, void **buf, size_t *len, ... ) } /** - * vips_radsave_stream: (method) + * vips_radsave_target: (method) * @in: image to save - * @streamo: save image to this stream + * @target: save image to this stream * @...: %NULL-terminated list of optional named arguments * * As vips_radsave(), but save to a stream. @@ -372,13 +372,13 @@ vips_radsave_buffer( VipsImage *in, void **buf, size_t *len, ... ) * Returns: 0 on success, -1 on error. */ int -vips_radsave_stream( VipsImage *in, VipsStreamo *streamo, ... ) +vips_radsave_target( VipsImage *in, VipsTarget *target, ... ) { va_list ap; int result; - va_start( ap, streamo ); - result = vips_call_split( "radsave_stream", ap, in, streamo ); + va_start( ap, target ); + result = vips_call_split( "radsave_stream", ap, in, target ); va_end( ap ); return( result ); diff --git a/libvips/foreign/svgload.c b/libvips/foreign/svgload.c index f36e40eb..291f727b 100644 --- a/libvips/foreign/svgload.c +++ b/libvips/foreign/svgload.c @@ -74,7 +74,7 @@ #include -/* A GInputStream that's actually a VipsStreami under the hood. This lets us +/* A GInputStream that's actually a VipsSource under the hood. This lets us * hook librsvg up to libvips using the GInputStream interface. */ @@ -93,16 +93,16 @@ (G_TYPE_INSTANCE_GET_CLASS( (obj), \ VIPS_TYPE_G_INPUT_STREAM, VipsGInputStreamClass )) -/* GInputStream <--> VipsStreami +/* GInputStream <--> VipsSource */ typedef struct _VipsGInputStream { GInputStream parent_instance; /*< private >*/ - /* The VipsStreami we wrap. + /* The VipsSource we wrap. */ - VipsStreami *streami; + VipsSource *source; } VipsGInputStream; @@ -130,7 +130,7 @@ vips_g_input_stream_get_property( GObject *object, guint prop_id, switch( prop_id ) { case PROP_STREAM: - g_value_set_object( value, gstream->streami ); + g_value_set_object( value, gstream->source ); break; default: @@ -146,7 +146,7 @@ vips_g_input_stream_set_property( GObject *object, guint prop_id, switch( prop_id ) { case PROP_STREAM: - gstream->streami = g_value_dup_object( value ); + gstream->source = g_value_dup_object( value ); break; default: @@ -159,7 +159,7 @@ vips_g_input_stream_finalize( GObject *object ) { VipsGInputStream *gstream = VIPS_G_INPUT_STREAM( object ); - VIPS_FREEF( g_object_unref, gstream->streami ); + VIPS_FREEF( g_object_unref, gstream->source ); G_OBJECT_CLASS( vips_g_input_stream_parent_class )->finalize( object ); } @@ -167,13 +167,13 @@ vips_g_input_stream_finalize( GObject *object ) static goffset vips_g_input_stream_tell( GSeekable *seekable ) { - VipsStreami *streami = VIPS_G_INPUT_STREAM( seekable )->streami; + VipsSource *source = VIPS_G_INPUT_STREAM( seekable )->source; goffset pos; VIPS_DEBUG_MSG( "vips_g_input_stream_tell:\n" ); - pos = vips_streami_seek( streami, 0, SEEK_CUR ); + pos = vips_source_seek( source, 0, SEEK_CUR ); if( pos == -1 ) return( 0 ); @@ -183,12 +183,12 @@ vips_g_input_stream_tell( GSeekable *seekable ) static gboolean vips_g_input_stream_can_seek( GSeekable *seekable ) { - VipsStreami *streami = VIPS_G_INPUT_STREAM( seekable )->streami; + VipsSource *source = VIPS_G_INPUT_STREAM( seekable )->source; VIPS_DEBUG_MSG( "vips_g_input_stream_can_seek: %d\n", - !streami->is_pipe ); + !source->is_pipe ); - return( !streami->is_pipe ); + return( !source->is_pipe ); } static int @@ -209,12 +209,12 @@ static gboolean vips_g_input_stream_seek( GSeekable *seekable, goffset offset, GSeekType type, GCancellable *cancellable, GError **error ) { - VipsStreami *streami = VIPS_G_INPUT_STREAM( seekable )->streami; + VipsSource *source = VIPS_G_INPUT_STREAM( seekable )->source; VIPS_DEBUG_MSG( "vips_g_input_stream_seek: offset = %" G_GINT64_FORMAT ", type = %d\n", offset, type ); - if( vips_streami_seek( streami, offset, + if( vips_source_seek( source, offset, seek_type_to_lseek( type ) ) == -1 ) { g_set_error( error, G_IO_ERROR, G_IO_ERROR_FAILED, @@ -249,17 +249,17 @@ static gssize vips_g_input_stream_read( GInputStream *stream, void *buffer, gsize count, GCancellable *cancellable, GError **error ) { - VipsStreami *streami; + VipsSource *source; gssize res; - streami = VIPS_G_INPUT_STREAM( stream )->streami; + source = VIPS_G_INPUT_STREAM( stream )->source; VIPS_DEBUG_MSG( "vips_g_input_stream_read: count: %zd\n", count ); if( g_cancellable_set_error_if_cancelled( cancellable, error ) ) return( -1 ); - if( (res = vips_streami_read( streami, buffer, count )) == -1 ) + if( (res = vips_source_read( source, buffer, count )) == -1 ) g_set_error( error, G_IO_ERROR, G_IO_ERROR_FAILED, _( "Error while reading: %s" ), @@ -272,17 +272,17 @@ static gssize vips_g_input_stream_skip( GInputStream *stream, gsize count, GCancellable *cancellable, GError **error ) { - VipsStreami *streami; + VipsSource *source; gssize position; - streami = VIPS_G_INPUT_STREAM( stream )->streami; + source = VIPS_G_INPUT_STREAM( stream )->source; VIPS_DEBUG_MSG( "vips_g_input_stream_skip: count: %zd\n", count ); if( g_cancellable_set_error_if_cancelled( cancellable, error ) ) return( -1 ); - position = vips_streami_seek( streami, count, SEEK_CUR ); + position = vips_source_seek( source, count, SEEK_CUR ); if( position == -1 ) { g_set_error( error, G_IO_ERROR, G_IO_ERROR_FAILED, @@ -300,7 +300,7 @@ vips_g_input_stream_close( GInputStream *stream, { VipsGInputStream *gstream = VIPS_G_INPUT_STREAM( stream ); - vips_streami_minimise( gstream->streami ); + vips_source_minimise( gstream->source ); return( TRUE ); } @@ -333,7 +333,7 @@ vips_g_input_stream_class_init( VipsGInputStreamClass *class ) g_param_spec_object( "input", _( "Input" ), _( "Stream to wrap" ), - VIPS_TYPE_STREAMI, G_PARAM_CONSTRUCT_ONLY | + VIPS_TYPE_SOURCE, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS ) ); } @@ -345,17 +345,17 @@ vips_g_input_stream_init( VipsGInputStream *gstream ) /** * g_input_stream_new_from_vips: - * @streami: stream to wrap + * @source: stream to wrap * - * Create a new #GInputStream wrapping a #VipsStreami. + * Create a new #GInputStream wrapping a #VipsSource. * * Returns: a new #GInputStream */ static GInputStream * -g_input_stream_new_from_vips( VipsStreami *streami ) +g_input_stream_new_from_vips( VipsSource *source ) { return( g_object_new( VIPS_TYPE_G_INPUT_STREAM, - "input", streami, + "input", source, NULL ) ); } @@ -757,7 +757,7 @@ typedef struct _VipsForeignLoadSvgStream { /* Load from a stream. */ - VipsStreami *streami; + VipsSource *source; } VipsForeignLoadSvgStream; @@ -767,12 +767,12 @@ G_DEFINE_TYPE( VipsForeignLoadSvgStream, vips_foreign_load_svg_stream, vips_foreign_load_svg_get_type() ); gboolean -vips_foreign_load_svg_stream_is_a_stream( VipsStreami *streami ) +vips_foreign_load_svg_stream_is_a_source( VipsSource *source ) { unsigned char *data; size_t bytes_read; - if( (bytes_read = vips_streami_sniff_at_most( streami, + if( (bytes_read = vips_source_sniff_at_most( source, &data, SVG_HEADER_SIZE )) <= 0 ) return( FALSE ); @@ -791,10 +791,10 @@ vips_foreign_load_svg_stream_header( VipsForeignLoad *load ) GInputStream *gstream; - if( vips_streami_rewind( stream->streami ) ) + if( vips_source_rewind( stream->source ) ) return( -1 ); - gstream = g_input_stream_new_from_vips( stream->streami ); + gstream = g_input_stream_new_from_vips( stream->source ); if( !(svg->page = rsvg_handle_new_from_stream_sync( gstream, NULL, flags, NULL, &error )) ) { g_object_unref( gstream ); @@ -811,9 +811,9 @@ vips_foreign_load_svg_stream_load( VipsForeignLoad *load ) { VipsForeignLoadSvgStream *stream = (VipsForeignLoadSvgStream *) load; - if( vips_streami_rewind( stream->streami ) || + if( vips_source_rewind( stream->source ) || vips_foreign_load_svg_load( load ) || - vips_streami_decode( stream->streami ) ) + vips_source_decode( stream->source ) ) return( -1 ); return( 0 ); @@ -832,16 +832,16 @@ vips_foreign_load_svg_stream_class_init( VipsForeignLoadSvgStreamClass *class ) object_class->nickname = "svgload_stream"; object_class->description = _( "load svg from stream" ); - load_class->is_a_stream = vips_foreign_load_svg_stream_is_a_stream; + load_class->is_a_source = vips_foreign_load_svg_stream_is_a_source; load_class->header = vips_foreign_load_svg_stream_header; load_class->load = vips_foreign_load_svg_stream_load; - VIPS_ARG_OBJECT( class, "streami", 1, + VIPS_ARG_OBJECT( class, "source", 1, _( "Streami" ), _( "Stream to load from" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsForeignLoadSvgStream, streami ), - VIPS_TYPE_STREAMI ); + G_STRUCT_OFFSET( VipsForeignLoadSvgStream, source ), + VIPS_TYPE_SOURCE ); } @@ -1100,8 +1100,8 @@ vips_svgload_buffer( void *buf, size_t len, VipsImage **out, ... ) } /** - * vips_svgload_stream: - * @streami: stream to load from + * vips_svgload_source: + * @source: stream to load from * @out: (out): image to write * @...: %NULL-terminated list of optional named arguments * @@ -1112,13 +1112,13 @@ vips_svgload_buffer( void *buf, size_t len, VipsImage **out, ... ) * Returns: 0 on success, -1 on error. */ int -vips_svgload_stream( VipsStreami *streami, VipsImage **out, ... ) +vips_svgload_source( VipsSource *source, VipsImage **out, ... ) { va_list ap; int result; va_start( ap, out ); - result = vips_call_split( "svgload_stream", ap, streami, out ); + result = vips_call_split( "svgload_stream", ap, source, out ); va_end( ap ); return( result ); diff --git a/libvips/foreign/tiff.c b/libvips/foreign/tiff.c index 4d6a1dd2..0da48a9b 100644 --- a/libvips/foreign/tiff.c +++ b/libvips/foreign/tiff.c @@ -138,9 +138,9 @@ vips__tiff_openout( const char *path, gboolean bigtiff ) static tsize_t openin_stream_read( thandle_t st, tdata_t data, tsize_t size ) { - VipsStreami *streami = VIPS_STREAMI( st ); + VipsSource *source = VIPS_SOURCE( st ); - return( vips_streami_read( streami, data, size ) ); + return( vips_source_read( source, data, size ) ); } static tsize_t @@ -154,17 +154,17 @@ openin_stream_write( thandle_t st, tdata_t buffer, tsize_t size ) static toff_t openin_stream_seek( thandle_t st, toff_t position, int whence ) { - VipsStreami *streami = VIPS_STREAMI( st ); + VipsSource *source = VIPS_SOURCE( st ); - return( vips_streami_seek( streami, position, whence ) ); + return( vips_source_seek( source, position, whence ) ); } static int openin_stream_close( thandle_t st ) { - VipsStreami *streami = VIPS_STREAMI( st ); + VipsSource *source = VIPS_SOURCE( st ); - VIPS_UNREF( streami ); + VIPS_UNREF( source ); return( 0 ); } @@ -172,12 +172,12 @@ openin_stream_close( thandle_t st ) static toff_t openin_stream_length( thandle_t st ) { - VipsStreami *streami = VIPS_STREAMI( st ); + VipsSource *source = VIPS_SOURCE( st ); /* libtiff will use this to get file size if tags like StripByteCounts * are missing. */ - return( vips_streami_length( streami ) ); + return( vips_source_length( source ) ); } static int @@ -197,7 +197,7 @@ openin_stream_unmap( thandle_t st, tdata_t start, toff_t len ) } TIFF * -vips__tiff_openin_stream( VipsStreami *streami ) +vips__tiff_openin_stream( VipsSource *source ) { TIFF *tiff; @@ -205,11 +205,11 @@ vips__tiff_openin_stream( VipsStreami *streami ) printf( "vips__tiff_openin_stream:\n" ); #endif /*DEBUG*/ - if( vips_streami_rewind( streami ) ) + if( vips_source_rewind( source ) ) return( NULL ); if( !(tiff = TIFFClientOpen( "stream input", "rm", - (thandle_t) streami, + (thandle_t) source, openin_stream_read, openin_stream_write, openin_stream_seek, @@ -224,7 +224,7 @@ vips__tiff_openin_stream( VipsStreami *streami ) /* Unreffed on close(), see above. */ - g_object_ref( streami ); + g_object_ref( source ); return( tiff ); } diff --git a/libvips/foreign/tiff.h b/libvips/foreign/tiff.h index a309d485..bf68b4bd 100644 --- a/libvips/foreign/tiff.h +++ b/libvips/foreign/tiff.h @@ -37,7 +37,7 @@ extern "C" { #endif /*__cplusplus*/ -TIFF *vips__tiff_openin_stream( VipsStreami *streami ); +TIFF *vips__tiff_openin_stream( VipsSource *source ); TIFF *vips__tiff_openout( const char *path, gboolean bigtiff ); TIFF *vips__tiff_openout_buffer( VipsImage *image, diff --git a/libvips/foreign/tiff2vips.c b/libvips/foreign/tiff2vips.c index a98481d2..e86e34a0 100644 --- a/libvips/foreign/tiff2vips.c +++ b/libvips/foreign/tiff2vips.c @@ -307,7 +307,7 @@ typedef void (*scanline_process_fn)( struct _Rtiff *, typedef struct _Rtiff { /* Parameters. */ - VipsStreami *streami; + VipsSource *source; VipsImage *out; int page; int n; @@ -495,7 +495,7 @@ static void rtiff_free( Rtiff *rtiff ) { VIPS_FREEF( TIFFClose, rtiff->tiff ); - VIPS_UNREF( rtiff->streami ); + VIPS_UNREF( rtiff->source ); } static void @@ -507,12 +507,12 @@ rtiff_close_cb( VipsObject *object, Rtiff *rtiff ) static void rtiff_minimise_cb( VipsImage *image, Rtiff *rtiff ) { - if( rtiff->streami ) - vips_streami_minimise( rtiff->streami ); + if( rtiff->source ) + vips_source_minimise( rtiff->source ); } static Rtiff * -rtiff_new( VipsStreami *streami, VipsImage *out, +rtiff_new( VipsSource *source, VipsImage *out, int page, int n, gboolean autorotate ) { Rtiff *rtiff; @@ -520,8 +520,8 @@ rtiff_new( VipsStreami *streami, VipsImage *out, if( !(rtiff = VIPS_NEW( out, Rtiff )) ) return( NULL ); - g_object_ref( streami ); - rtiff->streami = streami; + g_object_ref( source ); + rtiff->source = source; rtiff->out = out; rtiff->page = page; rtiff->n = n; @@ -558,7 +558,7 @@ rtiff_new( VipsStreami *streami, VipsImage *out, return( NULL ); } - if( !(rtiff->tiff = vips__tiff_openin_stream( streami )) ) + if( !(rtiff->tiff = vips__tiff_openin_stream( source )) ) return( NULL ); return( rtiff ); @@ -1434,7 +1434,7 @@ rtiff_set_header( Rtiff *rtiff, VipsImage *out ) out->Ysize = rtiff->header.height * rtiff->n; VIPS_SETSTR( out->filename, - vips_stream_filename( VIPS_STREAM( rtiff->streami ) ) ); + vips_connection_filename( VIPS_CONNECTION( rtiff->source ) ) ); if( rtiff->n > 1 ) vips_image_set_int( out, @@ -2463,14 +2463,14 @@ vips__tiff_read_header_orientation( Rtiff *rtiff, VipsImage *out ) typedef gboolean (*TiffPropertyFn)( TIFF *tif ); static gboolean -vips__testtiff_stream( VipsStreami *streami, TiffPropertyFn fn ) +vips__testtiff_stream( VipsSource *source, TiffPropertyFn fn ) { TIFF *tif; gboolean property; vips__tiff_init(); - if( !(tif = vips__tiff_openin_stream( streami )) ) { + if( !(tif = vips__tiff_openin_stream( source )) ) { vips_error_clear(); return( FALSE ); } @@ -2483,26 +2483,26 @@ vips__testtiff_stream( VipsStreami *streami, TiffPropertyFn fn ) } gboolean -vips__istiff_stream( VipsStreami *streami ) +vips__istiff_stream( VipsSource *source ) { - return( vips__testtiff_stream( streami, NULL ) ); + return( vips__testtiff_stream( source, NULL ) ); } gboolean -vips__istifftiled_stream( VipsStreami *streami ) +vips__istifftiled_stream( VipsSource *source ) { - return( vips__testtiff_stream( streami, TIFFIsTiled ) ); + return( vips__testtiff_stream( source, TIFFIsTiled ) ); } int -vips__tiff_read_header_stream( VipsStreami *streami, VipsImage *out, +vips__tiff_read_header_stream( VipsSource *source, VipsImage *out, int page, int n, gboolean autorotate ) { Rtiff *rtiff; vips__tiff_init(); - if( !(rtiff = rtiff_new( streami, out, page, n, autorotate )) || + if( !(rtiff = rtiff_new( source, out, page, n, autorotate )) || rtiff_header_read_all( rtiff ) ) return( -1 ); @@ -2511,16 +2511,16 @@ vips__tiff_read_header_stream( VipsStreami *streami, VipsImage *out, vips__tiff_read_header_orientation( rtiff, out ); - /* We never call vips_streami_decode() since we need to be able to + /* We never call vips_source_decode() since we need to be able to * seek() the whole way through the file. Just minimise instead, */ - vips_streami_minimise( streami ); + vips_source_minimise( source ); return( 0 ); } int -vips__tiff_read_stream( VipsStreami *streami, VipsImage *out, +vips__tiff_read_stream( VipsSource *source, VipsImage *out, int page, int n, gboolean autorotate ) { Rtiff *rtiff; @@ -2532,7 +2532,7 @@ vips__tiff_read_stream( VipsStreami *streami, VipsImage *out, vips__tiff_init(); - if( !(rtiff = rtiff_new( streami, out, page, n, autorotate )) || + if( !(rtiff = rtiff_new( source, out, page, n, autorotate )) || rtiff_header_read_all( rtiff ) ) return( -1 ); @@ -2545,10 +2545,10 @@ vips__tiff_read_stream( VipsStreami *streami, VipsImage *out, return( -1 ); } - /* We never call vips_streami_decode() since we need to be able to + /* We never call vips_source_decode() since we need to be able to * seek() the whole way through the file. Just minimise instead, */ - vips_streami_minimise( streami ); + vips_source_minimise( source ); return( 0 ); } diff --git a/libvips/foreign/tiffload.c b/libvips/foreign/tiffload.c index 43d8faec..b6ff8b93 100644 --- a/libvips/foreign/tiffload.c +++ b/libvips/foreign/tiffload.c @@ -59,7 +59,7 @@ typedef struct _VipsForeignLoadTiff { /* Set by subclasses. */ - VipsStreami *streami; + VipsSource *source; /* Load this page. */ @@ -85,19 +85,19 @@ vips_foreign_load_tiff_dispose( GObject *gobject ) { VipsForeignLoadTiff *tiff = (VipsForeignLoadTiff *) gobject; - VIPS_UNREF( tiff->streami ); + VIPS_UNREF( tiff->source ); G_OBJECT_CLASS( vips_foreign_load_tiff_parent_class )-> dispose( gobject ); } static VipsForeignFlags -vips_foreign_load_tiff_get_flags_stream( VipsStreami *streami ) +vips_foreign_load_tiff_get_flags_stream( VipsSource *source ) { VipsForeignFlags flags; flags = 0; - if( vips__istifftiled_stream( streami ) ) + if( vips__istifftiled_stream( source ) ) flags |= VIPS_FOREIGN_PARTIAL; else flags |= VIPS_FOREIGN_SEQUENTIAL; @@ -108,13 +108,13 @@ vips_foreign_load_tiff_get_flags_stream( VipsStreami *streami ) static VipsForeignFlags vips_foreign_load_tiff_get_flags_filename( const char *filename ) { - VipsStreami *streami; + VipsSource *source; VipsForeignFlags flags; - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( 0 ); - flags = vips_foreign_load_tiff_get_flags_stream( streami ); - VIPS_UNREF( streami ); + flags = vips_foreign_load_tiff_get_flags_stream( source ); + VIPS_UNREF( source ); return( flags ); } @@ -124,7 +124,7 @@ vips_foreign_load_tiff_get_flags( VipsForeignLoad *load ) { VipsForeignLoadTiff *tiff = (VipsForeignLoadTiff *) load; - return( vips_foreign_load_tiff_get_flags_stream( tiff->streami ) ); + return( vips_foreign_load_tiff_get_flags_stream( tiff->source ) ); } static int @@ -132,7 +132,7 @@ vips_foreign_load_tiff_header( VipsForeignLoad *load ) { VipsForeignLoadTiff *tiff = (VipsForeignLoadTiff *) load; - if( vips__tiff_read_header_stream( tiff->streami, load->out, + if( vips__tiff_read_header_stream( tiff->source, load->out, tiff->page, tiff->n, tiff->autorotate ) ) return( -1 ); @@ -144,7 +144,7 @@ vips_foreign_load_tiff_load( VipsForeignLoad *load ) { VipsForeignLoadTiff *tiff = (VipsForeignLoadTiff *) load; - if( vips__tiff_read_stream( tiff->streami, load->real, + if( vips__tiff_read_stream( tiff->source, load->real, tiff->page, tiff->n, tiff->autorotate ) ) return( -1 ); @@ -217,7 +217,7 @@ typedef struct _VipsForeignLoadTiffStream { /* Load from a stream. */ - VipsStreami *streami; + VipsSource *source; } VipsForeignLoadTiffStream; @@ -233,9 +233,9 @@ vips_foreign_load_tiff_stream_build( VipsObject *object ) VipsForeignLoadTiffStream *stream = (VipsForeignLoadTiffStream *) object; - if( stream->streami ) { - tiff->streami = stream->streami; - g_object_ref( tiff->streami ); + if( stream->source ) { + tiff->source = stream->source; + g_object_ref( tiff->source ); } if( VIPS_OBJECT_CLASS( vips_foreign_load_tiff_stream_parent_class )-> @@ -246,9 +246,9 @@ vips_foreign_load_tiff_stream_build( VipsObject *object ) } static gboolean -vips_foreign_load_tiff_stream_is_a_stream( VipsStreami *streami ) +vips_foreign_load_tiff_stream_is_a_source( VipsSource *source ) { - return( vips__istiff_stream( streami ) ); + return( vips__istiff_stream( source ) ); } static void @@ -266,14 +266,14 @@ vips_foreign_load_tiff_stream_class_init( object_class->description = _( "load tiff from stream" ); object_class->build = vips_foreign_load_tiff_stream_build; - load_class->is_a_stream = vips_foreign_load_tiff_stream_is_a_stream; + load_class->is_a_source = vips_foreign_load_tiff_stream_is_a_source; - VIPS_ARG_OBJECT( class, "streami", 1, + VIPS_ARG_OBJECT( class, "source", 1, _( "Streami" ), _( "Stream to load from" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsForeignLoadTiffStream, streami ), - VIPS_TYPE_STREAMI ); + G_STRUCT_OFFSET( VipsForeignLoadTiffStream, source ), + VIPS_TYPE_SOURCE ); } @@ -303,8 +303,8 @@ vips_foreign_load_tiff_file_build( VipsObject *object ) VipsForeignLoadTiffFile *file = (VipsForeignLoadTiffFile *) object; if( file->filename && - !(tiff->streami = - vips_streami_new_from_file( file->filename )) ) + !(tiff->source = + vips_source_new_from_file( file->filename )) ) return( -1 ); if( VIPS_OBJECT_CLASS( vips_foreign_load_tiff_file_parent_class )-> @@ -317,13 +317,13 @@ vips_foreign_load_tiff_file_build( VipsObject *object ) static gboolean vips_foreign_load_tiff_file_is_a( const char *filename ) { - VipsStreami *streami; + VipsSource *source; gboolean result; - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( FALSE ); - result = vips_foreign_load_tiff_stream_is_a_stream( streami ); - VIPS_UNREF( streami ); + result = vips_foreign_load_tiff_stream_is_a_source( source ); + VIPS_UNREF( source ); return( result ); } @@ -384,7 +384,7 @@ vips_foreign_load_tiff_buffer_build( VipsObject *object ) (VipsForeignLoadTiffBuffer *) object; if( buffer->blob && - !(tiff->streami = vips_streami_new_from_memory( + !(tiff->source = vips_source_new_from_memory( VIPS_AREA( buffer->blob )->data, VIPS_AREA( buffer->blob )->length )) ) return( -1 ); @@ -399,13 +399,13 @@ vips_foreign_load_tiff_buffer_build( VipsObject *object ) static gboolean vips_foreign_load_tiff_buffer_is_a_buffer( const void *buf, size_t len ) { - VipsStreami *streami; + VipsSource *source; gboolean result; - if( !(streami = vips_streami_new_from_memory( buf, len )) ) + if( !(source = vips_source_new_from_memory( buf, len )) ) return( FALSE ); - result = vips_foreign_load_tiff_stream_is_a_stream( streami ); - VIPS_UNREF( streami ); + result = vips_foreign_load_tiff_stream_is_a_source( source ); + VIPS_UNREF( source ); return( result ); } @@ -547,8 +547,8 @@ vips_tiffload_buffer( void *buf, size_t len, VipsImage **out, ... ) } /** - * vips_tiffload_stream: - * @streami: stream to load + * vips_tiffload_source: + * @source: stream to load * @out: (out): image to write * @...: %NULL-terminated list of optional named arguments * @@ -566,13 +566,13 @@ vips_tiffload_buffer( void *buf, size_t len, VipsImage **out, ... ) * Returns: 0 on success, -1 on error. */ int -vips_tiffload_stream( VipsStreami *streami, VipsImage **out, ... ) +vips_tiffload_source( VipsSource *source, VipsImage **out, ... ) { va_list ap; int result; va_start( ap, out ); - result = vips_call_split( "tiffload_stream", ap, streami, out ); + result = vips_call_split( "tiffload_stream", ap, source, out ); va_end( ap ); return( result ); diff --git a/libvips/foreign/vips2jpeg.c b/libvips/foreign/vips2jpeg.c index bbbb27ef..6af842fc 100644 --- a/libvips/foreign/vips2jpeg.c +++ b/libvips/foreign/vips2jpeg.c @@ -699,7 +699,7 @@ typedef struct { /* Build the output area here. */ - VipsStreamo *streamo; + VipsTarget *target; /* Our output buffer. */ @@ -714,7 +714,7 @@ empty_output_buffer( j_compress_ptr cinfo ) { Dest *dest = (Dest *) cinfo->dest; - if( vips_streamo_write( dest->streamo, + if( vips_target_write( dest->target, dest->buf, STREAM_BUFFER_SIZE ) ) ERREXIT( cinfo, JERR_FILE_WRITE ); @@ -742,17 +742,17 @@ term_destination( j_compress_ptr cinfo ) { Dest *dest = (Dest *) cinfo->dest; - if( vips_streamo_write( dest->streamo, + if( vips_target_write( dest->target, dest->buf, STREAM_BUFFER_SIZE - dest->pub.free_in_buffer ) ) ERREXIT( cinfo, JERR_FILE_WRITE ); - vips_streamo_finish( dest->streamo ); + vips_target_finish( dest->target ); } /* Set dest to one of our objects. */ static void -stream_dest( j_compress_ptr cinfo, VipsStreamo *streamo ) +stream_dest( j_compress_ptr cinfo, VipsTarget *target ) { Dest *dest; @@ -767,11 +767,11 @@ stream_dest( j_compress_ptr cinfo, VipsStreamo *streamo ) dest->pub.init_destination = init_destination; dest->pub.empty_output_buffer = empty_output_buffer; dest->pub.term_destination = term_destination; - dest->streamo = streamo; + dest->target = target; } int -vips__jpeg_write_stream( VipsImage *in, VipsStreamo *streamo, +vips__jpeg_write_stream( VipsImage *in, VipsTarget *target, int Q, const char *profile, gboolean optimize_coding, gboolean progressive, gboolean strip, gboolean no_subsample, gboolean trellis_quant, @@ -795,7 +795,7 @@ vips__jpeg_write_stream( VipsImage *in, VipsStreamo *streamo, /* Attach output. */ - stream_dest( &write->cinfo, streamo ); + stream_dest( &write->cinfo, target ); /* Convert! Write errors come back here as an error return. */ diff --git a/libvips/foreign/vips2tiff.c b/libvips/foreign/vips2tiff.c index 4c345f8a..cf2eddc8 100644 --- a/libvips/foreign/vips2tiff.c +++ b/libvips/foreign/vips2tiff.c @@ -1762,7 +1762,7 @@ wtiff_gather( Wtiff *wtiff ) wtiff->layer->below ) for( layer = wtiff->layer->below; layer; layer = layer->below ) { - VipsStreami *streami; + VipsSource *source; TIFF *in; #ifdef DEBUG @@ -1770,22 +1770,22 @@ wtiff_gather( Wtiff *wtiff ) #endif /*DEBUG*/ if( layer->lname ) { - if( !(streami = - vips_streami_new_from_file( + if( !(source = + vips_source_new_from_file( layer->lname )) ) return( -1 ); } else { - if( !(streami = vips_streami_new_from_memory( + if( !(source = vips_source_new_from_memory( layer->buf, layer->len )) ) return( -1 ); } - if( !(in = vips__tiff_openin_stream( streami )) ) { - VIPS_UNREF( streami ); + if( !(in = vips__tiff_openin_stream( source )) ) { + VIPS_UNREF( source ); return( -1 ); } - VIPS_UNREF( streami ); + VIPS_UNREF( source ); if( wtiff_copy_tiff( wtiff, wtiff->layer->tif, in ) ) { TIFFClose( in ); diff --git a/libvips/foreign/vips2webp.c b/libvips/foreign/vips2webp.c index 272e0b77..d34660a6 100644 --- a/libvips/foreign/vips2webp.c +++ b/libvips/foreign/vips2webp.c @@ -525,7 +525,7 @@ vips_webp_add_metadata( VipsWebPWrite *write ) } int -vips__webp_write_stream( VipsImage *image, VipsStreamo *streamo, +vips__webp_write_stream( VipsImage *image, VipsTarget *target, int Q, gboolean lossless, VipsForeignWebpPreset preset, gboolean smart_subsample, gboolean near_lossless, int alpha_q, int reduction_effort, @@ -549,13 +549,13 @@ vips__webp_write_stream( VipsImage *image, VipsStreamo *streamo, return( -1 ); } - if( vips_streamo_write( streamo, + if( vips_target_write( target, write.memory_writer.mem, write.memory_writer.size ) ) { vips_webp_write_unset( &write ); return( -1 ); } - vips_streamo_finish( streamo ); + vips_target_finish( target ); vips_webp_write_unset( &write ); diff --git a/libvips/foreign/vipspng.c b/libvips/foreign/vipspng.c index 2b91ca96..12f27ed0 100644 --- a/libvips/foreign/vipspng.c +++ b/libvips/foreign/vipspng.c @@ -173,7 +173,7 @@ typedef struct { png_infop pInfo; png_bytep *row_pointer; - VipsStreami *streami; + VipsSource *source; /* read() to this buffer, copy to png as required. libpng does many * very small reads and we want to avoid a syscall for each one. @@ -195,7 +195,7 @@ read_destroy( Read *read ) if( read->pPng ) png_destroy_read_struct( &read->pPng, &read->pInfo, NULL ); - VIPS_UNREF( read->streami ); + VIPS_UNREF( read->source ); VIPS_FREE( read->row_pointer ); } @@ -208,8 +208,8 @@ read_close_cb( VipsImage *out, Read *read ) static void read_minimise_cb( VipsImage *image, Read *read ) { - if( read->streami ) - vips_streami_minimise( read->streami ); + if( read->source ) + vips_source_minimise( read->source ); } static void @@ -230,7 +230,7 @@ vips_png_read_stream( png_structp pPng, png_bytep data, png_size_t length ) if( read->bytes_in_buffer <= 0 ) { gint64 bytes_read; - bytes_read = vips_streami_read( read->streami, + bytes_read = vips_source_read( read->source, read->input_buffer, INPUT_BUFFER_SIZE ); if( bytes_read <= 0 ) png_error( pPng, "not enough data" ); @@ -249,7 +249,7 @@ vips_png_read_stream( png_structp pPng, png_bytep data, png_size_t length ) } static Read * -read_new( VipsStreami *streami, VipsImage *out, gboolean fail ) +read_new( VipsSource *source, VipsImage *out, gboolean fail ) { Read *read; @@ -263,8 +263,8 @@ read_new( VipsStreami *streami, VipsImage *out, gboolean fail ) read->pPng = NULL; read->pInfo = NULL; read->row_pointer = NULL; - read->streami = streami; - g_object_ref( streami ); + read->source = source; + g_object_ref( source ); g_signal_connect( out, "close", G_CALLBACK( read_close_cb ), read ); @@ -290,7 +290,7 @@ read_new( VipsStreami *streami, VipsImage *out, gboolean fail ) PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE ); #endif /*FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION*/ - if( vips_streami_rewind( streami ) ) + if( vips_source_rewind( source ) ) return( NULL ); png_set_read_fn( read->pPng, read, vips_png_read_stream ); @@ -482,7 +482,7 @@ png2vips_header( Read *read, VipsImage *out ) Xres, Yres ); VIPS_SETSTR( out->filename, - vips_stream_filename( VIPS_STREAM( read->streami ) ) ); + vips_connection_filename( VIPS_CONNECTION( read->source ) ) ); /* Uninterlaced images will be read in seq mode. Interlaced images are * read via a huge memory buffer. @@ -694,11 +694,11 @@ png2vips_image( Read *read, VipsImage *out ) } gboolean -vips__png_ispng_stream( VipsStreami *streami ) +vips__png_ispng_stream( VipsSource *source ) { const unsigned char *p; - if( (p = vips_streami_sniff( streami, 8 )) && + if( (p = vips_source_sniff( source, 8 )) && !png_sig_cmp( (png_bytep) p, 0, 8 ) ) return( TRUE ); @@ -706,27 +706,27 @@ vips__png_ispng_stream( VipsStreami *streami ) } int -vips__png_header_stream( VipsStreami *streami, VipsImage *out ) +vips__png_header_stream( VipsSource *source, VipsImage *out ) { Read *read; - if( !(read = read_new( streami, out, TRUE )) || + if( !(read = read_new( source, out, TRUE )) || png2vips_header( read, out ) ) return( -1 ); - vips_streami_minimise( streami ); + vips_source_minimise( source ); return( 0 ); } int -vips__png_read_stream( VipsStreami *streami, VipsImage *out, gboolean fail ) +vips__png_read_stream( VipsSource *source, VipsImage *out, gboolean fail ) { Read *read; - if( !(read = read_new( streami, out, fail )) || + if( !(read = read_new( source, out, fail )) || png2vips_image( read, out ) || - vips_streami_decode( streami ) ) + vips_source_decode( source ) ) return( -1 ); return( 0 ); @@ -736,7 +736,7 @@ vips__png_read_stream( VipsStreami *streami, VipsImage *out, gboolean fail ) * served partially from there. Non-interlaced PNGs may be read sequentially. */ gboolean -vips__png_isinterlaced_stream( VipsStreami *streami ) +vips__png_isinterlaced_stream( VipsSource *source ) { VipsImage *image; Read *read; @@ -744,7 +744,7 @@ vips__png_isinterlaced_stream( VipsStreami *streami ) image = vips_image_new(); - if( !(read = read_new( streami, image, TRUE )) ) { + if( !(read = read_new( source, image, TRUE )) ) { g_object_unref( image ); return( -1 ); } @@ -762,7 +762,7 @@ typedef struct { VipsImage *in; VipsImage *memory; - VipsStreamo *streamo; + VipsTarget *target; png_structp pPng; png_infop pInfo; @@ -773,9 +773,9 @@ static void write_finish( Write *write ) { VIPS_UNREF( write->memory ); - if( write->streamo ) - vips_streamo_finish( write->streamo ); - VIPS_UNREF( write->streamo ); + if( write->target ) + vips_target_finish( write->target ); + VIPS_UNREF( write->target ); if( write->pPng ) png_destroy_write_struct( &write->pPng, &write->pInfo ); } @@ -791,12 +791,12 @@ user_write_data( png_structp pPng, png_bytep data, png_size_t length ) { Write *write = (Write *) png_get_io_ptr( pPng ); - if( vips_streamo_write( write->streamo, data, length ) ) + if( vips_target_write( write->target, data, length ) ) png_error( pPng, "not enough data" ); } static Write * -write_new( VipsImage *in, VipsStreamo *streamo ) +write_new( VipsImage *in, VipsTarget *target ) { Write *write; @@ -805,8 +805,8 @@ write_new( VipsImage *in, VipsStreamo *streamo ) memset( write, 0, sizeof( Write ) ); write->in = in; write->memory = NULL; - write->streamo = streamo; - g_object_ref( streamo ); + write->target = target; + g_object_ref( target ); g_signal_connect( in, "close", G_CALLBACK( write_destroy ), write ); @@ -1169,14 +1169,14 @@ write_vips( Write *write, } int -vips__png_write_stream( VipsImage *in, VipsStreamo *streamo, +vips__png_write_stream( VipsImage *in, VipsTarget *target, int compression, int interlace, const char *profile, VipsForeignPngFilter filter, gboolean strip, gboolean palette, int colours, int Q, double dither ) { Write *write; - if( !(write = write_new( in, streamo )) ) + if( !(write = write_new( in, target )) ) return( -1 ); if( write_vips( write, diff --git a/libvips/foreign/webp2vips.c b/libvips/foreign/webp2vips.c index 3f8a7a85..02e309df 100644 --- a/libvips/foreign/webp2vips.c +++ b/libvips/foreign/webp2vips.c @@ -81,7 +81,7 @@ /* What we track during a read. */ typedef struct { - VipsStreami *streami; + VipsSource *source; /* The data we load, as a webp object. */ @@ -311,13 +311,13 @@ vips_image_paint_image( VipsImage *frame, } int -vips__iswebp_stream( VipsStreami *streami ) +vips__iswebp_stream( VipsSource *source ) { const unsigned char *p; /* WebP is "RIFF xxxx WEBP" at the start, so we need 12 bytes. */ - if( (p = vips_streami_sniff( streami, 12 )) && + if( (p = vips_source_sniff( source, 12 )) && vips_isprefix( "RIFF", (char *) p ) && vips_isprefix( "WEBP", (char *) p + 8 ) ) return( 1 ); @@ -333,7 +333,7 @@ read_free( Read *read ) VIPS_FREEF( WebPDemuxDelete, read->demux ); WebPFreeDecBuffer( &read->config.output ); - VIPS_UNREF( read->streami ); + VIPS_UNREF( read->source ); VIPS_FREE( read->delays ); VIPS_FREE( read ); @@ -341,15 +341,15 @@ read_free( Read *read ) } static Read * -read_new( VipsStreami *streami, int page, int n, double scale ) +read_new( VipsSource *source, int page, int n, double scale ) { Read *read; if( !(read = VIPS_NEW( NULL, Read )) ) return( NULL ); - read->streami = streami; - g_object_ref( streami ); + read->source = source; + g_object_ref( source ); read->page = page; read->n = n; read->scale = scale; @@ -364,7 +364,7 @@ read_new( VipsStreami *streami, int page, int n, double scale ) read->config.output.is_external_memory = 1; if( !(read->data.bytes = - vips_streami_map( streami, &read->data.size )) ) { + vips_source_map( source, &read->data.size )) ) { read_free( read ); return( NULL ); } @@ -550,7 +550,7 @@ read_header( Read *read, VipsImage *out ) 1.0, 1.0 ); vips_image_pipelinev( out, VIPS_DEMAND_STYLE_THINSTRIP, NULL ); VIPS_SETSTR( out->filename, - vips_stream_filename( VIPS_STREAM( read->streami ) ) ); + vips_connection_filename( VIPS_CONNECTION( read->source ) ) ); if( !WebPDemuxGetFrame( read->demux, 1, &read->iter ) ) { vips_error( "webp", @@ -763,12 +763,12 @@ read_image( Read *read, VipsImage *out ) } int -vips__webp_read_header_stream( VipsStreami *streami, VipsImage *out, +vips__webp_read_header_stream( VipsSource *source, VipsImage *out, int page, int n, double scale ) { Read *read; - if( !(read = read_new( streami, page, n, scale )) ) + if( !(read = read_new( source, page, n, scale )) ) return( -1 ); if( read_header( read, out ) ) { @@ -782,12 +782,12 @@ vips__webp_read_header_stream( VipsStreami *streami, VipsImage *out, } int -vips__webp_read_stream( VipsStreami *streami, VipsImage *out, +vips__webp_read_stream( VipsSource *source, VipsImage *out, int page, int n, double scale ) { Read *read; - if( !(read = read_new( streami, page, n, scale )) ) + if( !(read = read_new( source, page, n, scale )) ) return( -1 ); if( read_image( read, out ) ) { diff --git a/libvips/foreign/webpload.c b/libvips/foreign/webpload.c index 4a2798a8..8e79c7f1 100644 --- a/libvips/foreign/webpload.c +++ b/libvips/foreign/webpload.c @@ -60,7 +60,7 @@ typedef struct _VipsForeignLoadWebp { /* Set by subclasses. */ - VipsStreami *streami; + VipsSource *source; /* Load this page (frame number). */ @@ -89,7 +89,7 @@ vips_foreign_load_webp_dispose( GObject *gobject ) { VipsForeignLoadWebp *webp = (VipsForeignLoadWebp *) gobject; - VIPS_UNREF( webp->streami ); + VIPS_UNREF( webp->source ); G_OBJECT_CLASS( vips_foreign_load_webp_parent_class )-> dispose( gobject ); @@ -131,7 +131,7 @@ vips_foreign_load_webp_header( VipsForeignLoad *load ) { VipsForeignLoadWebp *webp = (VipsForeignLoadWebp *) load; - if( vips__webp_read_header_stream( webp->streami, load->out, + if( vips__webp_read_header_stream( 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->streami, load->real, + if( vips__webp_read_stream( webp->source, load->real, webp->page, webp->n, webp->scale ) ) return( -1 ); @@ -220,7 +220,7 @@ vips_foreign_load_webp_init( VipsForeignLoadWebp *webp ) typedef struct _VipsForeignLoadWebpStream { VipsForeignLoadWebp parent_object; - VipsStreami *streami; + VipsSource *source; } VipsForeignLoadWebpStream; @@ -236,9 +236,9 @@ vips_foreign_load_webp_stream_build( VipsObject *object ) VipsForeignLoadWebpStream *stream = (VipsForeignLoadWebpStream *) object; - if( stream->streami ) { - webp->streami = stream->streami; - g_object_ref( webp->streami ); + if( stream->source ) { + webp->source = stream->source; + g_object_ref( webp->source ); } if( VIPS_OBJECT_CLASS( vips_foreign_load_webp_stream_parent_class )-> @@ -263,14 +263,14 @@ vips_foreign_load_webp_stream_class_init( object_class->description = _( "load webp from stream" ); object_class->build = vips_foreign_load_webp_stream_build; - load_class->is_a_stream = vips__iswebp_stream; + load_class->is_a_source = vips__iswebp_stream; - VIPS_ARG_OBJECT( class, "streami", 1, + VIPS_ARG_OBJECT( class, "source", 1, _( "Streami" ), _( "Stream to load from" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsForeignLoadWebpStream, streami ), - VIPS_TYPE_STREAMI ); + G_STRUCT_OFFSET( VipsForeignLoadWebpStream, source ), + VIPS_TYPE_SOURCE ); } @@ -300,8 +300,8 @@ vips_foreign_load_webp_file_build( VipsObject *object ) VipsForeignLoadWebpFile *file = (VipsForeignLoadWebpFile *) object; if( file->filename && - !(webp->streami = - vips_streami_new_from_file( file->filename )) ) + !(webp->source = + vips_source_new_from_file( file->filename )) ) return( -1 ); if( VIPS_OBJECT_CLASS( vips_foreign_load_webp_file_parent_class )-> @@ -314,13 +314,13 @@ vips_foreign_load_webp_file_build( VipsObject *object ) static gboolean vips_foreign_load_webp_file_is_a( const char *filename ) { - VipsStreami *streami; + VipsSource *source; gboolean result; - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( FALSE ); - result = vips__iswebp_stream( streami ); - VIPS_UNREF( streami ); + result = vips__iswebp_stream( source ); + VIPS_UNREF( source ); return( result ); } @@ -381,7 +381,7 @@ vips_foreign_load_webp_buffer_build( VipsObject *object ) (VipsForeignLoadWebpBuffer *) object; if( buffer->blob && - !(webp->streami = vips_streami_new_from_memory( + !(webp->source = vips_source_new_from_memory( VIPS_AREA( buffer->blob )->data, VIPS_AREA( buffer->blob )->length )) ) return( -1 ); @@ -396,13 +396,13 @@ vips_foreign_load_webp_buffer_build( VipsObject *object ) static gboolean vips_foreign_load_webp_buffer_is_a_buffer( const void *buf, size_t len ) { - VipsStreami *streami; + VipsSource *source; gboolean result; - if( !(streami = vips_streami_new_from_memory( buf, len )) ) + if( !(source = vips_source_new_from_memory( buf, len )) ) return( FALSE ); - result = vips__iswebp_stream( streami ); - VIPS_UNREF( streami ); + result = vips__iswebp_stream( source ); + VIPS_UNREF( source ); return( result ); } @@ -526,8 +526,8 @@ vips_webpload_buffer( void *buf, size_t len, VipsImage **out, ... ) } /** - * vips_webpload_stream: - * @streami: stream to load from + * vips_webpload_source: + * @source: stream to load from * @out: (out): image to write * @...: %NULL-terminated list of optional named arguments * @@ -544,13 +544,13 @@ vips_webpload_buffer( void *buf, size_t len, VipsImage **out, ... ) * Returns: 0 on success, -1 on error. */ int -vips_webpload_stream( VipsStreami *streami, VipsImage **out, ... ) +vips_webpload_source( VipsSource *source, VipsImage **out, ... ) { va_list ap; int result; va_start( ap, out ); - result = vips_call_split( "webpload_stream", ap, streami, out ); + result = vips_call_split( "webpload_stream", ap, source, out ); va_end( ap ); return( result ); diff --git a/libvips/foreign/webpsave.c b/libvips/foreign/webpsave.c index 9afda455..f8c4fdbc 100644 --- a/libvips/foreign/webpsave.c +++ b/libvips/foreign/webpsave.c @@ -222,7 +222,7 @@ vips_foreign_save_webp_init( VipsForeignSaveWebp *webp ) typedef struct _VipsForeignSaveWebpStream { VipsForeignSaveWebp parent_object; - VipsStreamo *streamo; + VipsTarget *target; } VipsForeignSaveWebpStream; @@ -243,7 +243,7 @@ vips_foreign_save_webp_stream_build( VipsObject *object ) build( object ) ) return( -1 ); - if( vips__webp_write_stream( save->ready, stream->streamo, + if( vips__webp_write_stream( save->ready, stream->target, webp->Q, webp->lossless, webp->preset, webp->smart_subsample, webp->near_lossless, webp->alpha_q, webp->reduction_effort, @@ -268,12 +268,12 @@ vips_foreign_save_webp_stream_class_init( object_class->description = _( "save image to webp stream" ); object_class->build = vips_foreign_save_webp_stream_build; - VIPS_ARG_OBJECT( class, "streamo", 1, - _( "streamo" ), + VIPS_ARG_OBJECT( class, "target", 1, + _( "target" ), _( "Stream to save to" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsForeignSaveWebpStream, streamo ), - VIPS_TYPE_STREAMO ); + G_STRUCT_OFFSET( VipsForeignSaveWebpStream, target ), + VIPS_TYPE_TARGET ); } static void @@ -303,24 +303,24 @@ vips_foreign_save_webp_file_build( VipsObject *object ) VipsForeignSaveWebp *webp = (VipsForeignSaveWebp *) object; VipsForeignSaveWebpFile *file = (VipsForeignSaveWebpFile *) object; - VipsStreamo *streamo; + VipsTarget *target; if( VIPS_OBJECT_CLASS( vips_foreign_save_webp_file_parent_class )-> build( object ) ) return( -1 ); - if( !(streamo = vips_streamo_new_to_file( file->filename )) ) + if( !(target = vips_target_new_to_file( file->filename )) ) return( -1 ); - if( vips__webp_write_stream( save->ready, streamo, + if( vips__webp_write_stream( save->ready, target, webp->Q, webp->lossless, webp->preset, webp->smart_subsample, webp->near_lossless, webp->alpha_q, webp->reduction_effort, webp->min_size, webp->kmin, webp->kmax, save->strip ) ) { - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( -1 ); } - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( 0 ); } @@ -373,31 +373,31 @@ vips_foreign_save_webp_buffer_build( VipsObject *object ) VipsForeignSaveWebpBuffer *buffer = (VipsForeignSaveWebpBuffer *) object; - VipsStreamo *streamo; + VipsTarget *target; VipsBlob *blob; if( VIPS_OBJECT_CLASS( vips_foreign_save_webp_buffer_parent_class )-> build( object ) ) return( -1 ); - if( !(streamo = vips_streamo_new_to_memory()) ) + if( !(target = vips_target_new_to_memory()) ) return( -1 ); - if( vips__webp_write_stream( save->ready, streamo, + if( vips__webp_write_stream( save->ready, target, webp->Q, webp->lossless, webp->preset, webp->smart_subsample, webp->near_lossless, webp->alpha_q, webp->reduction_effort, webp->min_size, webp->kmin, webp->kmax, save->strip ) ) { - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( -1 ); } - g_object_get( streamo, "blob", &blob, NULL ); + g_object_get( target, "blob", &blob, NULL ); g_object_set( buffer, "buffer", blob, NULL ); vips_area_unref( VIPS_AREA( blob ) ); - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( 0 ); } @@ -445,7 +445,7 @@ vips_foreign_save_webp_mime_build( VipsObject *object ) VipsForeignSave *save = (VipsForeignSave *) object; VipsForeignSaveWebp *webp = (VipsForeignSaveWebp *) object; - VipsStreamo *streamo; + VipsTarget *target; VipsBlob *blob; void *data; size_t len; @@ -454,20 +454,20 @@ vips_foreign_save_webp_mime_build( VipsObject *object ) build( object ) ) return( -1 ); - if( !(streamo = vips_streamo_new_to_memory()) ) + if( !(target = vips_target_new_to_memory()) ) return( -1 ); - if( vips__webp_write_stream( save->ready, streamo, + if( vips__webp_write_stream( save->ready, target, webp->Q, webp->lossless, webp->preset, webp->smart_subsample, webp->near_lossless, webp->alpha_q, webp->reduction_effort, webp->min_size, webp->kmin, webp->kmax, save->strip ) ) { - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( -1 ); } - g_object_get( streamo, "blob", &blob, NULL ); + g_object_get( target, "blob", &blob, NULL ); data = VIPS_AREA( blob )->data; len = VIPS_AREA( blob )->length; vips_area_unref( VIPS_AREA( blob ) ); @@ -478,7 +478,7 @@ vips_foreign_save_webp_mime_build( VipsObject *object ) (void) fwrite( data, sizeof( char ), len, stdout ); fflush( stdout ); - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( 0 ); } @@ -671,9 +671,9 @@ vips_webpsave_mime( VipsImage *in, ... ) } /** - * vips_webpsave_stream: (method) + * vips_webpsave_target: (method) * @in: image to save - * @streamo: save image to this stream + * @target: save image to this stream * @...: %NULL-terminated list of optional named arguments * * Optional arguments: @@ -697,13 +697,13 @@ vips_webpsave_mime( VipsImage *in, ... ) * Returns: 0 on success, -1 on error. */ int -vips_webpsave_stream( VipsImage *in, VipsStreamo *streamo, ... ) +vips_webpsave_target( VipsImage *in, VipsTarget *target, ... ) { va_list ap; int result; - va_start( ap, streamo ); - result = vips_call_split( "webpsave_stream", ap, in, streamo ); + va_start( ap, target ); + result = vips_call_split( "webpsave_stream", ap, in, target ); va_end( ap ); return( result ); diff --git a/libvips/include/vips/Makefile.am b/libvips/include/vips/Makefile.am index 57c642dc..4cc05269 100644 --- a/libvips/include/vips/Makefile.am +++ b/libvips/include/vips/Makefile.am @@ -1,5 +1,5 @@ pkginclude_HEADERS = \ - stream.h \ + connection.h \ bufis.h \ basic.h \ type.h \ diff --git a/libvips/include/vips/bufis.h b/libvips/include/vips/bufis.h index 89121163..94160955 100644 --- a/libvips/include/vips/bufis.h +++ b/libvips/include/vips/bufis.h @@ -1,4 +1,4 @@ -/* Buffered inputput from a VipsStreami +/* Buffered inputput from a VipsSource * * J.Cupitt, 18/11/19 */ @@ -54,7 +54,7 @@ extern "C" { #define VIPS_BUFIS_BUFFER_SIZE (4096) -/* Layer over streami: read with an input buffer. +/* Layer over source: read with an input buffer. * * Libraries like libjpeg do their own input buffering and need raw IO, but * others, like radiance, need to parse the input into lines. A buffered read @@ -65,9 +65,9 @@ typedef struct _VipsBufis { /*< private >*/ - /* The VipsStreami we wrap. + /* The VipsSource we wrap. */ - VipsStreami *streami; + VipsSource *source; /* The +1 means there's always a \0 byte at the end. * @@ -93,23 +93,23 @@ typedef struct _VipsBufisClass { GType vips_bufis_get_type( void ); -VipsBufis *vips_bufis_new_from_streami( VipsStreami *streami ); +VipsBufis *vips_bufis_new_from_source( VipsSource *source ); -void vips_bufis_unbuffer( VipsBufis *streamib ); +void vips_bufis_unbuffer( VipsBufis *sourceb ); -int vips_bufis_getc( VipsBufis *streamib ); +int vips_bufis_getc( VipsBufis *sourceb ); #define VIPS_BUFIS_GETC( S ) ( \ (S)->read_point < (S)->chars_in_buffer ? \ (S)->input_buffer[(S)->read_point++] : \ vips_bufis_getc( S ) \ ) -void vips_bufis_ungetc( VipsBufis *streamib ); +void vips_bufis_ungetc( VipsBufis *sourceb ); #define VIPS_BUFIS_UNGETC( S ) { \ if( (S)->read_point > 0 ) \ (S)->read_point -= 1; \ } -int vips_bufis_require( VipsBufis *streamib, int require ); +int vips_bufis_require( VipsBufis *sourceb, int require ); #define VIPS_BUFIS_REQUIRE( S, R ) ( \ (S)->read_point + (R) <= (S)->chars_in_buffer ? \ 0 : \ @@ -118,10 +118,10 @@ int vips_bufis_require( VipsBufis *streamib, int require ); #define VIPS_BUFIS_PEEK( S ) ((S)->input_buffer + (S)->read_point) #define VIPS_BUFIS_FETCH( S ) ((S)->input_buffer[(S)->read_point++]) -const char *vips_bufis_get_line( VipsBufis *streamib ); -char *vips_bufis_get_line_copy( VipsBufis *streamib ); -const char *vips_bufis_get_non_whitespace( VipsBufis *streamib ); -int vips_bufis_skip_whitespace( VipsBufis *streamib ); +const char *vips_bufis_get_line( VipsBufis *sourceb ); +char *vips_bufis_get_line_copy( VipsBufis *sourceb ); +const char *vips_bufis_get_non_whitespace( VipsBufis *sourceb ); +int vips_bufis_skip_whitespace( VipsBufis *sourceb ); #ifdef __cplusplus } diff --git a/libvips/include/vips/connection.h b/libvips/include/vips/connection.h new file mode 100644 index 00000000..822de017 --- /dev/null +++ b/libvips/include/vips/connection.h @@ -0,0 +1,397 @@ +/* A byte source/sink .. it can be a pipe, socket, or perhaps a node.js stream. + * + * 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 + + */ + +#ifndef VIPS_CONNECTION_H +#define VIPS_CONNECTION_H + +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus*/ + +#define VIPS_TYPE_CONNECTION (vips_connection_get_type()) +#define VIPS_CONNECTION( obj ) \ + (G_TYPE_CHECK_INSTANCE_CAST( (obj), \ + VIPS_TYPE_CONNECTION, VipsConnection )) +#define VIPS_CONNECTION_CLASS( klass ) \ + (G_TYPE_CHECK_CLASS_CAST( (klass), \ + VIPS_TYPE_CONNECTION, VipsConnectionClass)) +#define VIPS_IS_CONNECTION( obj ) \ + (G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_CONNECTION )) +#define VIPS_IS_CONNECTION_CLASS( klass ) \ + (G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_CONNECTION )) +#define VIPS_CONNECTION_GET_CLASS( obj ) \ + (G_TYPE_INSTANCE_GET_CLASS( (obj), \ + VIPS_TYPE_CONNECTION, VipsConnectionClass )) + +/* Communicate with something like a socket or pipe. + */ +typedef struct _VipsConnection { + VipsObject parent_object; + + /*< private >*/ + + /* Read/write this fd if connected to a system pipe/socket. Override + * ::read() and ::write() to do something else. + */ + int descriptor; + + /* A descriptor we close with vips_tracked_close(). + */ + int tracked_descriptor; + + /* A descriptor we close with close(). + */ + int close_descriptor; + + /* If descriptor is a file, the filename we opened. Handy for error + * messages. + */ + char *filename; + +} VipsConnection; + +typedef struct _VipsConnectionClass { + VipsObjectClass parent_class; + +} VipsConnectionClass; + +GType vips_connection_get_type( void ); + +const char *vips_connection_filename( VipsConnection *stream ); +const char *vips_connection_nick( VipsConnection *stream ); + +#define VIPS_TYPE_SOURCE (vips_source_get_type()) +#define VIPS_SOURCE( obj ) \ + (G_TYPE_CHECK_INSTANCE_CAST( (obj), \ + VIPS_TYPE_SOURCE, VipsSource )) +#define VIPS_SOURCE_CLASS( klass ) \ + (G_TYPE_CHECK_CLASS_CAST( (klass), \ + VIPS_TYPE_SOURCE, VipsSourceClass)) +#define VIPS_IS_SOURCE( obj ) \ + (G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_SOURCE )) +#define VIPS_IS_SOURCE_CLASS( klass ) \ + (G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_SOURCE )) +#define VIPS_SOURCE_GET_CLASS( obj ) \ + (G_TYPE_INSTANCE_GET_CLASS( (obj), \ + VIPS_TYPE_SOURCE, VipsSourceClass )) + +/* Read from something like a socket, file or memory area and present the data + * with a unified seek / read / map interface. + * + * During the header phase, we save data from unseekable streams in a buffer + * so readers can rewind and read again. We don't buffer data during the + * decode stage. + */ +typedef struct _VipsSource { + VipsConnection parent_object; + + /* We have two phases: + * + * During the header phase, we save bytes read from the input (if this + * is an unseekable stream) so that we can rewind and try again, if + * necessary. + * + * Once we reach decode phase, we no longer support rewind and the + * buffer of saved data is discarded. + */ + gboolean decode; + + /* TRUE if this input is something like a pipe. These don't support + * stream or map -- all you can do is read() bytes sequentially. + * + * If you attempt to map or get the size of a pipe-style input, it'll + * get read entirely into memory. Seeks will cause read up to the seek + * point. + */ + gboolean have_tested_seek; + gboolean is_pipe; + + /* The current read point and length. + * + * length is -1 for is_pipe sources. + * + * off_t can be 32 bits on some platforms, so make sure we have a + * full 64. + */ + gint64 read_position; + gint64 length; + + /*< private >*/ + + /* For sources where we have the whole image in memory (from a memory + * buffer, from mmaping the file, from reading the pipe into memory), + * a pointer to the start. + */ + const void *data; + + /* For is_pipe sources, save data read during header phase here. If + * we rewind and try again, serve data from this until it runs out. + * + * If we need to force the whole pipe into memory, read everything to + * this and put a copy pf the pointer in data. + */ + GByteArray *header_bytes; + + /* Save the first few bytes here for file type sniffing. + */ + GByteArray *sniff; + + /* For a memory stream, the blob we read from. + */ + VipsBlob *blob; + + /* If we mmaped the file, whet we need to unmmap on finalize. + */ + void *mmap_baseaddr; + size_t mmap_length; + +} VipsSource; + +typedef struct _VipsSourceClass { + VipsConnectionClass parent_class; + + /* Subclasses can define these to implement other source methods. + */ + + /* Read from the stream into the supplied buffer, args exactly as + * read(2). Set errno on error. + * + * We must return gint64, since ssize_t is often defined as unsigned + * on Windows. + */ + gint64 (*read)( VipsSource *, void *, size_t ); + + /* Seek to a certain position, args exactly as lseek(2). Set errno on + * error. + * + * Unseekable streams should always return -1. VipsSource will then + * seek by _read()ing bytes into memory as required. + * + * We have to use int64 rather than off_t, since we must work on + * Windows, where off_t can be 32-bits. + */ + gint64 (*seek)( VipsSource *, gint64, int ); + +} VipsSourceClass; + +GType vips_source_get_type( void ); + +VipsSource *vips_source_new_from_descriptor( int descriptor ); +VipsSource *vips_source_new_from_file( const char *filename ); +VipsSource *vips_source_new_from_blob( VipsBlob *blob ); +VipsSource *vips_source_new_from_memory( const void *data, size_t size ); +VipsSource *vips_source_new_from_options( const char *options ); + +void vips_source_minimise( VipsSource *source ); +int vips_source_unminimise( VipsSource *source ); +int vips_source_decode( VipsSource *source ); +gint64 vips_source_read( VipsSource *source, void *data, size_t length ); +gboolean vips_source_is_mappable( VipsSource *source ); +const void *vips_source_map( VipsSource *source, size_t *length ); +VipsBlob *vips_source_map_blob( VipsSource *source ); +gint64 vips_source_seek( VipsSource *source, gint64 offset, int whence ); +int vips_source_rewind( VipsSource *source ); +size_t vips_source_sniff_at_most( VipsSource *source, + unsigned char **data, size_t length ); +unsigned char *vips_source_sniff( VipsSource *source, size_t length ); +gint64 vips_source_length( VipsSource *source ); + +#define VIPS_TYPE_SOURCE_CUSTOM (vips_source_custom_get_type()) +#define VIPS_SOURCE_CUSTOM( obj ) \ + (G_TYPE_CHECK_INSTANCE_CAST( (obj), \ + VIPS_TYPE_SOURCE_CUSTOM, VipsSourceCustom )) +#define VIPS_SOURCE_CUSTOM_CLASS( klass ) \ + (G_TYPE_CHECK_CLASS_CAST( (klass), \ + VIPS_TYPE_SOURCE_CUSTOM, VipsSourceCustomClass)) +#define VIPS_IS_SOURCE_CUSTOM( obj ) \ + (G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_SOURCE_CUSTOM )) +#define VIPS_IS_SOURCE_CUSTOM_CLASS( klass ) \ + (G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_SOURCE_CUSTOM )) +#define VIPS_SOURCE_CUSTOM_GET_CLASS( obj ) \ + (G_TYPE_INSTANCE_GET_CLASS( (obj), \ + VIPS_TYPE_SOURCE_CUSTOM, VipsSourceCustomClass )) + +/* Subclass of source_custom with signals for handlers. This is supposed to be + * useful for language bindings. + */ +typedef struct _VipsSourceCustom { + VipsSource parent_object; + +} VipsSourceCustom; + +typedef struct _VipsSourceCustomClass { + VipsSourceClass parent_class; + + /* The action signals clients can use to implement read and seek. + * We must use gint64 everywhere since there's no G_TYPE_SIZE. + */ + + gint64 (*read)( VipsSourceCustom *, void *, gint64 ); + gint64 (*seek)( VipsSourceCustom *, gint64, int ); + +} VipsSourceCustomClass; + +GType vips_source_custom_get_type( void ); +VipsSourceCustom *vips_source_custom_new( void ); + +#define VIPS_TYPE_TARGET (vips_target_get_type()) +#define VIPS_TARGET( obj ) \ + (G_TYPE_CHECK_INSTANCE_CAST( (obj), \ + VIPS_TYPE_TARGET, VipsTarget )) +#define VIPS_TARGET_CLASS( klass ) \ + (G_TYPE_CHECK_CLASS_CAST( (klass), \ + VIPS_TYPE_TARGET, VipsTargetClass)) +#define VIPS_IS_TARGET( obj ) \ + (G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_TARGET )) +#define VIPS_IS_TARGET_CLASS( klass ) \ + (G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_TARGET )) +#define VIPS_TARGET_GET_CLASS( obj ) \ + (G_TYPE_INSTANCE_GET_CLASS( (obj), \ + VIPS_TYPE_TARGET, VipsTargetClass )) + +/* PNG writes in 8kb chunks, so we need to be a little larger than that. + */ +#define VIPS_TARGET_BUFFER_SIZE (8500) + +/* Output to something like a socket, pipe or memory area. + */ +typedef struct _VipsTarget { + VipsConnection parent_object; + + /*< private >*/ + + /* This stream should write to memory. + */ + gboolean memory; + + /* The stream has been finished and can no longer be written. + */ + gboolean finished; + + /* Write memory output here. + */ + GByteArray *memory_buffer; + + /* And return memory via this blob. + */ + VipsBlob *blob; + + /* Buffer small writes here. write_point is the index of the next + * character to write. + */ + unsigned char output_buffer[VIPS_TARGET_BUFFER_SIZE]; + int write_point; + +} VipsTarget; + +typedef struct _VipsTargetClass { + VipsConnectionClass parent_class; + + /* Write to output. Args exactly as write(2). + * + * We must return gint64, since ssize_t is often defined as unsigned + * on Windows. + */ + gint64 (*write)( VipsTarget *, const void *, size_t ); + + /* Output has been generated, so do any clearing up, + * eg. copy the bytes we saved in memory to the stream blob. + */ + void (*finish)( VipsTarget * ); + +} VipsTargetClass; + +GType vips_target_get_type( void ); + +VipsTarget *vips_target_new_to_descriptor( int descriptor ); +VipsTarget *vips_target_new_to_file( const char *filename ); +VipsTarget *vips_target_new_to_memory( void ); +int vips_target_write( VipsTarget *target, const void *data, size_t length ); +void vips_target_finish( VipsTarget *target ); +unsigned char *vips_target_steal( VipsTarget *target, size_t *length ); +char *vips_target_steal_text( VipsTarget *target ); + +int vips_target_putc( VipsTarget *target, int ch ); +#define VIPS_TARGET_PUTC( S, C ) ( \ + (S)->write_point < VIPS_TARGET_BUFFER_SIZE ? \ + ((S)->output_buffer[(S)->write_point++] = (C), 0) : \ + vips_target_putc( (S), (C) ) \ +) +int vips_target_writes( VipsTarget *target, const char *str ); +int vips_target_writef( VipsTarget *target, const char *fmt, ... ) + __attribute__((format(printf, 2, 3))); +int vips_target_write_amp( VipsTarget *target, const char *str ); + +#define VIPS_TYPE_TARGET_CUSTOM (vips_target_custom_get_type()) +#define VIPS_TARGET_CUSTOM( obj ) \ + (G_TYPE_CHECK_INSTANCE_CAST( (obj), \ + VIPS_TYPE_TARGET_CUSTOM, VipsTargetCustom )) +#define VIPS_TARGET_CUSTOM_CLASS( klass ) \ + (G_TYPE_CHECK_CLASS_CAST( (klass), \ + VIPS_TYPE_TARGET_CUSTOM, VipsTargetCustomClass)) +#define VIPS_IS_TARGET_CUSTOM( obj ) \ + (G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_TARGET_CUSTOM )) +#define VIPS_IS_TARGET_CUSTOM_CLASS( klass ) \ + (G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_TARGET_CUSTOM )) +#define VIPS_TARGET_CUSTOM_GET_CLASS( obj ) \ + (G_TYPE_INSTANCE_GET_CLASS( (obj), \ + VIPS_TYPE_TARGET_CUSTOM, VipsTargetCustomClass )) + +#define VIPS_TARGET_CUSTOM_BUFFER_SIZE (4096) + +/* Output to something like a socket, pipe or memory area. + */ +typedef struct _VipsTargetCustom { + VipsTarget parent_object; + +} VipsTargetCustom; + +typedef struct _VipsTargetCustomClass { + VipsTargetClass parent_class; + + /* The action signals clients can use to implement write and finish. + * We must use gint64 everywhere since there's no G_TYPE_SIZE. + */ + + gint64 (*write)( VipsTargetCustom *, const void *, gint64 ); + void (*finish)( VipsTargetCustom * ); + +} VipsTargetCustomClass; + +GType vips_target_custom_get_type( void ); +VipsTargetCustom *vips_target_custom_new( void ); + +#ifdef __cplusplus +} +#endif /*__cplusplus*/ + +#endif /*VIPS_CONNECTION_H*/ diff --git a/libvips/include/vips/foreign.h b/libvips/include/vips/foreign.h index 4ce3d451..2447b3d1 100644 --- a/libvips/include/vips/foreign.h +++ b/libvips/include/vips/foreign.h @@ -189,7 +189,7 @@ typedef struct _VipsForeignLoadClass { * This function should return %TRUE if the stream contains an image of * this type. */ - gboolean (*is_a_stream)( VipsStreami *streami ); + gboolean (*is_a_source)( VipsSource *source ); /* Get the flags from a filename. * @@ -240,14 +240,14 @@ GType vips_foreign_load_get_type(void); const char *vips_foreign_find_load( const char *filename ); const char *vips_foreign_find_load_buffer( const void *data, size_t size ); -const char *vips_foreign_find_load_stream( VipsStreami *streami ); +const char *vips_foreign_find_load_source( VipsSource *source ); 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, const void *data, size_t size ); -gboolean vips_foreign_is_a_stream( const char *loader, - VipsStreami *streami ); +gboolean vips_foreign_is_a_source( const char *loader, + VipsSource *source ); void vips_foreign_load_invalidate( VipsImage *image ); @@ -354,7 +354,7 @@ 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 ); -const char *vips_foreign_find_save_stream( const char *suffix ); +const char *vips_foreign_find_save_target( const char *suffix ); int vips_vipsload( const char *filename, VipsImage **out, ... ) __attribute__((sentinel)); @@ -369,7 +369,7 @@ int vips_jpegload( const char *filename, VipsImage **out, ... ) int vips_jpegload_buffer( void *buf, size_t len, VipsImage **out, ... ) __attribute__((sentinel)); -int vips_jpegsave_stream( VipsImage *in, VipsStreamo *streamo, ... ) +int vips_jpegsave_target( VipsImage *in, VipsTarget *target, ... ) __attribute__((sentinel)); int vips_jpegsave( VipsImage *in, const char *filename, ... ) __attribute__((sentinel)); @@ -399,14 +399,14 @@ typedef enum { VIPS_FOREIGN_WEBP_PRESET_LAST } VipsForeignWebpPreset; -int vips_webpload_stream( VipsStreami *streami, VipsImage **out, ... ) +int vips_webpload_source( VipsSource *source, VipsImage **out, ... ) __attribute__((sentinel)); int vips_webpload( const char *filename, VipsImage **out, ... ) __attribute__((sentinel)); int vips_webpload_buffer( void *buf, size_t len, VipsImage **out, ... ) __attribute__((sentinel)); -int vips_webpsave_stream( VipsImage *in, VipsStreamo *streamo, ... ) +int vips_webpsave_target( VipsImage *in, VipsTarget *target, ... ) __attribute__((sentinel)); int vips_webpsave( VipsImage *in, const char *filename, ... ) __attribute__((sentinel)); @@ -481,7 +481,7 @@ int vips_tiffload( const char *filename, VipsImage **out, ... ) __attribute__((sentinel)); int vips_tiffload_buffer( void *buf, size_t len, VipsImage **out, ... ) __attribute__((sentinel)); -int vips_tiffload_stream( VipsStreami *streami, VipsImage **out, ... ) +int vips_tiffload_source( VipsSource *source, VipsImage **out, ... ) __attribute__((sentinel)); int vips_tiffsave( VipsImage *in, const char *filename, ... ) __attribute__((sentinel)); @@ -549,13 +549,13 @@ typedef enum /*< flags >*/ { VIPS_FOREIGN_PNG_FILTER_ALL = 0xF8 } VipsForeignPngFilter; -int vips_pngload_stream( VipsStreami *streami, VipsImage **out, ... ) +int vips_pngload_source( VipsSource *source, VipsImage **out, ... ) __attribute__((sentinel)); int vips_pngload( const char *filename, VipsImage **out, ... ) __attribute__((sentinel)); int vips_pngload_buffer( void *buf, size_t len, VipsImage **out, ... ) __attribute__((sentinel)); -int vips_pngsave_stream( VipsImage *in, VipsStreamo *streamo, ... ) +int vips_pngsave_target( VipsImage *in, VipsTarget *target, ... ) __attribute__((sentinel)); int vips_pngsave( VipsImage *in, const char *filename, ... ) __attribute__((sentinel)); @@ -570,7 +570,7 @@ int vips_ppmsave( VipsImage *in, const char *filename, ... ) int vips_matload( const char *filename, VipsImage **out, ... ) __attribute__((sentinel)); -int vips_radload_stream( VipsStreami *streami, VipsImage **out, ... ) +int vips_radload_source( VipsSource *source, VipsImage **out, ... ) __attribute__((sentinel)); int vips_radload( const char *filename, VipsImage **out, ... ) __attribute__((sentinel)); @@ -580,7 +580,7 @@ int vips_radsave( VipsImage *in, const char *filename, ... ) __attribute__((sentinel)); int vips_radsave_buffer( VipsImage *in, void **buf, size_t *len, ... ) __attribute__((sentinel)); -int vips_radsave_stream( VipsImage *in, VipsStreamo *streamo, ... ) +int vips_radsave_target( VipsImage *in, VipsTarget *target, ... ) __attribute__((sentinel)); int vips_pdfload( const char *filename, VipsImage **out, ... ) diff --git a/libvips/include/vips/image.h b/libvips/include/vips/image.h index b72e8898..d400ffc4 100644 --- a/libvips/include/vips/image.h +++ b/libvips/include/vips/image.h @@ -447,7 +447,7 @@ VipsImage *vips_image_new_from_memory_copy( const void *data, size_t size, VipsImage *vips_image_new_from_buffer( const void *buf, size_t len, const char *option_string, ... ) __attribute__((sentinel)); -VipsImage *vips_image_new_from_stream( VipsStreami *streami, +VipsImage *vips_image_new_from_source( VipsSource *source, const char *option_string, ... ) __attribute__((sentinel)); VipsImage *vips_image_new_matrix( int width, int height ); VipsImage *vips_image_new_matrixv( int width, int height, ... ); @@ -470,8 +470,8 @@ int vips_image_write_to_file( VipsImage *image, const char *name, ... ) int vips_image_write_to_buffer( VipsImage *in, const char *suffix, void **buf, size_t *size, ... ) __attribute__((sentinel)); -int vips_image_write_to_stream( VipsImage *in, - const char *suffix, VipsStreamo *streamo, ... ) +int vips_image_write_to_target( VipsImage *in, + const char *suffix, VipsTarget *target, ... ) __attribute__((sentinel)); void *vips_image_write_to_memory( VipsImage *in, size_t *size ); diff --git a/libvips/include/vips/renameE b/libvips/include/vips/renameE new file mode 100644 index 00000000..26d90937 --- /dev/null +++ b/libvips/include/vips/renameE @@ -0,0 +1,299 @@ +/* Old and broken stuff that we still enable by default, but don't document + * and certainly don't recommend. + * + * 30/6/09 + * - from vips.h + */ + +/* + + 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 + + */ + +#ifndef IM_ALMOSTDEPRECATED_H +#define IM_ALMOSTDEPRECATED_H + +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus*/ + +/* Was public, now deprecated. + */ +typedef enum { + IM_BBITS_BYTE = 8, + IM_BBITS_SHORT = 16, + IM_BBITS_INT = 32, + IM_BBITS_FLOAT = 32, + IM_BBITS_COMPLEX = 64, + IM_BBITS_DOUBLE = 64, + IM_BBITS_DPCOMPLEX = 128 +} VipsBBits; + +/* Used to define a region of interest for im_extract() etc. Too boring to be + * public API, see im_extract_area() etc. + */ +typedef struct { + int xstart; + int ystart; + int xsize; + int ysize; + int chsel; /* 1 2 3 or 0, for r g b or all respectively + *(channel select) */ +} IMAGE_BOX; + +int im_extract( IMAGE *, IMAGE *, IMAGE_BOX * ); +DOUBLEMASK *im_measure( IMAGE *im, IMAGE_BOX *box, int h, int v, + int *sel, int nsel, const char *name ); + +gboolean im_isuint( IMAGE *im ); +gboolean im_isint( IMAGE *im ); +gboolean im_isfloat( IMAGE *im ); +gboolean im_isscalar( IMAGE *im ); +gboolean im_iscomplex( IMAGE *im ); + +int im_c2ps( IMAGE *in, IMAGE *out ); + +int im_clip( IMAGE *in, IMAGE *out ); + +#define MASK_IDEAL_HIGHPASS IM_MASK_IDEAL_HIGHPASS +#define MASK_IDEAL_LOWPASS IM_MASK_IDEAL_LOWPASS +#define MASK_BUTTERWORTH_HIGHPASS IM_MASK_BUTTERWORTH_HIGHPASS +#define MASK_BUTTERWORTH_LOWPASS IM_MASK_BUTTERWORTH_LOWPASS +#define MASK_GAUSS_HIGHPASS IM_MASK_GAUSS_HIGHPASS +#define MASK_GAUSS_LOWPASS IM_MASK_GAUSS_LOWPASS + +#define MASK_IDEAL_RINGPASS IM_MASK_IDEAL_RINGPASS +#define MASK_IDEAL_RINGREJECT IM_MASK_IDEAL_RINGREJECT +#define MASK_BUTTERWORTH_RINGPASS IM_MASK_BUTTERWORTH_RINGPASS +#define MASK_BUTTERWORTH_RINGREJECT IM_MASK_BUTTERWORTH_RINGREJECT +#define MASK_GAUSS_RINGPASS IM_MASK_GAUSS_RINGPASS +#define MASK_GAUSS_RINGREJECT IM_MASK_GAUSS_RINGREJECT + +#define MASK_IDEAL_BANDPASS IM_MASK_IDEAL_BANDPASS +#define MASK_IDEAL_BANDREJECT IM_MASK_IDEAL_BANDREJECT +#define MASK_BUTTERWORTH_BANDPASS IM_MASK_BUTTERWORTH_BANDPASS +#define MASK_BUTTERWORTH_BANDREJECT IM_MASK_BUTTERWORTH_BANDREJECT +#define MASK_GAUSS_BANDPASS IM_MASK_GAUSS_BANDPASS +#define MASK_GAUSS_BANDREJECT IM_MASK_GAUSS_BANDREJECT + +#define MASK_FRACTAL_FLT IM_MASK_FRACTAL_FLT + +#define MaskType ImMaskType + +/* Copy and swap types. + */ +typedef enum { + IM_ARCH_NATIVE, + IM_ARCH_BYTE_SWAPPED, + IM_ARCH_LSB_FIRST, + IM_ARCH_MSB_FIRST +} im_arch_type; + +gboolean im_isnative( im_arch_type arch ); +int im_copy_from( IMAGE *in, IMAGE *out, im_arch_type architecture ); + +/* Backwards compatibility macros. + */ +#define im_clear_error_string() im_error_clear() +#define im_errorstring() im_error_buffer() + +/* Deprecated API. + */ +void im_errormsg( const char *fmt, ... ) + __attribute__((format(printf, 1, 2))); +void im_verrormsg( const char *fmt, va_list ap ); +void im_errormsg_system( int err, const char *fmt, ... ) + __attribute__((format(printf, 2, 3))); +void im_diagnostics( const char *fmt, ... ) + __attribute__((format(printf, 1, 2))); +void im_warning( const char *fmt, ... ) + __attribute__((format(printf, 1, 2))); + +int im_iterate( VipsImage *im, + VipsStartFn start, im_generate_fn generate, VipsStopFn stop, + void *a, void *b +); + +/* Async rendering. + */ +int im_render_priority( VipsImage *in, VipsImage *out, VipsImage *mask, + int width, int height, int max, + int priority, + void (*notify)( VipsImage *, VipsRect *, void * ), void *client ); +int im_cache( VipsImage *in, VipsImage *out, int width, int height, int max ); + +/* Deprecated operations. + */ +int im_cmulnorm( IMAGE *in1, IMAGE *in2, IMAGE *out ); +int im_fav4( IMAGE **, IMAGE * ); +int im_gadd( double, IMAGE *, double, IMAGE *, double, IMAGE *); +int im_litecor( IMAGE *, IMAGE *, IMAGE *, int, double ); +int im_render_fade( IMAGE *in, IMAGE *out, IMAGE *mask, + int width, int height, int max, + int fps, int steps, + int priority, + void (*notify)( IMAGE *, VipsRect *, void * ), void *client ); +int im_render( IMAGE *in, IMAGE *out, IMAGE *mask, + int width, int height, int max, + void (*notify)( IMAGE *, VipsRect *, void * ), void *client ); + +int im_cooc_matrix( IMAGE *im, IMAGE *m, + int xp, int yp, int xs, int ys, int dx, int dy, int flag ); +int im_cooc_asm( IMAGE *m, double *asmoment ); +int im_cooc_contrast( IMAGE *m, double *contrast ); +int im_cooc_correlation( IMAGE *m, double *correlation ); +int im_cooc_entropy( IMAGE *m, double *entropy ); + +int im_glds_matrix( IMAGE *im, IMAGE *m, + int xpos, int ypos, int xsize, int ysize, int dx, int dy ); +int im_glds_asm( IMAGE *m, double *asmoment ); +int im_glds_contrast( IMAGE *m, double *contrast ); +int im_glds_entropy( IMAGE *m, double *entropy ); +int im_glds_mean( IMAGE *m, double *mean ); + +int im_dif_std(IMAGE *im, int xpos, int ypos, int xsize, int ysize, int dx, int dy, double *pmean, double *pstd); +int im_simcontr( IMAGE *out, int xsize, int ysize ); +int im_spatres( IMAGE *in, IMAGE *out, int step ); + +int im_stretch3( IMAGE *in, IMAGE *out, double dx, double dy ); + +/* Renamed operations. + */ + +/* arithmetic + */ +int im_remainderconst_vec( IMAGE *in, IMAGE *out, int n, double *c ); + +/* boolean + */ +int im_andconst( IMAGE *, IMAGE *, double ); +int im_and_vec( IMAGE *, IMAGE *, int, double * ); +int im_orconst( IMAGE *, IMAGE *, double ); +int im_or_vec( IMAGE *, IMAGE *, int, double * ); +int im_eorconst( IMAGE *, IMAGE *, double ); +int im_eor_vec( IMAGE *, IMAGE *, int, double * ); + +/* mosaicing + */ +int im_affine( IMAGE *in, IMAGE *out, + double a, double b, double c, double d, double dx, double dy, + int ox, int oy, int ow, int oh ); +int im_similarity( IMAGE *in, IMAGE *out, + double a, double b, double dx, double dy ); +int im_similarity_area( IMAGE *in, IMAGE *out, + double a, double b, double dx, double dy, + int ox, int oy, int ow, int oh ); + +/* colour + */ +int im_icc_export( IMAGE *in, IMAGE *out, + const char *output_profile_filename, int intent ); + +/* conversion + */ +int im_clip2dcm( IMAGE *in, IMAGE *out ); +int im_clip2cm( IMAGE *in, IMAGE *out ); +int im_clip2us( IMAGE *in, IMAGE *out ); +int im_clip2ui( IMAGE *in, IMAGE *out ); +int im_clip2s( IMAGE *in, IMAGE *out ); +int im_clip2i( IMAGE *in, IMAGE *out ); +int im_clip2d( IMAGE *in, IMAGE *out ); +int im_clip2f( IMAGE *in, IMAGE *out ); +int im_clip2c( IMAGE *in, IMAGE *out ); + +int im_slice( IMAGE *in, IMAGE *out, double, double ); +int im_thresh( IMAGE *in, IMAGE *out, double ); + +int im_print( const char *message ); + +int im_convsub( IMAGE *in, IMAGE *out, INTMASK *mask, int xskip, int yskip ); + +int im_bernd( const char *tiffname, int x, int y, int w, int h ); + +int im_resize_linear( IMAGE *, IMAGE *, int, int ); + +int im_convf( IMAGE *in, IMAGE *out, DOUBLEMASK *mask ); +int im_convsepf( IMAGE *in, IMAGE *out, DOUBLEMASK *mask ); +int im_conv_raw( IMAGE *in, IMAGE *out, INTMASK *mask ); +int im_convf_raw( IMAGE *in, IMAGE *out, DOUBLEMASK *mask ); +int im_convsep_raw( IMAGE *in, IMAGE *out, INTMASK *mask ); +int im_convsepf_raw( IMAGE *in, IMAGE *out, DOUBLEMASK *mask ); +int im_fastcor_raw( IMAGE *in, IMAGE *ref, IMAGE *out ); +int im_spcor_raw( IMAGE *in, IMAGE *ref, IMAGE *out ); +int im_gradcor_raw( IMAGE *in, IMAGE *ref, IMAGE *out ); +int im_contrast_surface_raw( IMAGE *in, IMAGE *out, + int half_win_size, int spacing ); + +int im_stdif_raw( IMAGE *in, IMAGE *out, + double a, double m0, double b, double s0, int xwin, int ywin ); +int im_lhisteq_raw( IMAGE *in, IMAGE *out, int xwin, int ywin ); + +int im_erode_raw( IMAGE *in, IMAGE *out, INTMASK *m ); +int im_dilate_raw( IMAGE *in, IMAGE *out, INTMASK *m ); +int im_rank_raw( IMAGE *in, IMAGE *out, int xsize, int ysize, int order ); + +/* inplace + */ +int im_circle( IMAGE *im, int cx, int cy, int radius, int intensity ); +int im_line( IMAGE *, int, int, int, int, int ); +int im_segment( IMAGE *test, IMAGE *mask, int *segments ); +int im_paintrect( IMAGE *im, VipsRect *r, PEL *ink ); +int im_insertplace( IMAGE *main, IMAGE *sub, int x, int y ); + +int im_flood_copy( IMAGE *in, IMAGE *out, int x, int y, PEL *ink ); +int im_flood_blob_copy( IMAGE *in, IMAGE *out, int x, int y, PEL *ink ); +int im_flood_other_copy( IMAGE *test, IMAGE *mark, IMAGE *out, + int x, int y, int serial ); + +int im_flood( IMAGE *im, int x, int y, PEL *ink, VipsRect *dout ); +int im_flood_blob( IMAGE *im, int x, int y, PEL *ink, VipsRect *dout ); +int im_flood_other( IMAGE *test, IMAGE *mark, + int x, int y, int serial, VipsRect *dout ); + +int im_fastline( IMAGE *im, int x1, int y1, int x2, int y2, PEL *pel ); +int im_fastlineuser( IMAGE *im, + int x1, int y1, int x2, int y2, + VipsPlotFn fn, void *client1, void *client2, void *client3 ); + +int im_plotmask( IMAGE *im, int ix, int iy, PEL *ink, PEL *mask, VipsRect *r ); +int im_readpoint( IMAGE *im, int x, int y, PEL *pel ); +int im_plotpoint( IMAGE *im, int x, int y, PEL *pel ); + +int im_smudge( IMAGE *image, int ix, int iy, VipsRect *r ); +int im_smear( IMAGE *im, int ix, int iy, VipsRect *r ); + +void vips_warn( const char *domain, const char *fmt, ... ) + __attribute__((format(printf, 2, 3))); +void vips_vwarn( const char *domain, const char *fmt, va_list ap ); +void vips_info_set( gboolean info ); +void vips_info( const char *domain, const char *fmt, ... ) + __attribute__((format(printf, 2, 3))); +void vips_vinfo( const char *domain, const char *fmt, va_list ap ); + +#ifdef __cplusplus +} +#endif /*__cplusplus*/ + +#endif /*IM_ALMOSTDEPRECATED_H*/ diff --git a/libvips/include/vips/resample.h b/libvips/include/vips/resample.h index 8acac343..3ad2ffe3 100644 --- a/libvips/include/vips/resample.h +++ b/libvips/include/vips/resample.h @@ -79,7 +79,7 @@ int vips_thumbnail_buffer( void *buf, size_t len, VipsImage **out, __attribute__((sentinel)); int vips_thumbnail_image( VipsImage *in, VipsImage **out, int width, ... ) __attribute__((sentinel)); -int vips_thumbnail_stream( VipsStreami *streami, VipsImage **out, +int vips_thumbnail_source( VipsSource *source, VipsImage **out, int width, ... ) __attribute__((sentinel)); diff --git a/libvips/include/vips/stream.h b/libvips/include/vips/stream.h deleted file mode 100644 index 5c939759..00000000 --- a/libvips/include/vips/stream.h +++ /dev/null @@ -1,397 +0,0 @@ -/* A byte source/sink .. it can be a pipe, socket, or perhaps a node.js stream. - * - * 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 - - */ - -#ifndef VIPS_STREAM_H -#define VIPS_STREAM_H - -#ifdef __cplusplus -extern "C" { -#endif /*__cplusplus*/ - -#define VIPS_TYPE_STREAM (vips_stream_get_type()) -#define VIPS_STREAM( obj ) \ - (G_TYPE_CHECK_INSTANCE_CAST( (obj), \ - VIPS_TYPE_STREAM, VipsStream )) -#define VIPS_STREAM_CLASS( klass ) \ - (G_TYPE_CHECK_CLASS_CAST( (klass), \ - VIPS_TYPE_STREAM, VipsStreamClass)) -#define VIPS_IS_STREAM( obj ) \ - (G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_STREAM )) -#define VIPS_IS_STREAM_CLASS( klass ) \ - (G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_STREAM )) -#define VIPS_STREAM_GET_CLASS( obj ) \ - (G_TYPE_INSTANCE_GET_CLASS( (obj), \ - VIPS_TYPE_STREAM, VipsStreamClass )) - -/* Communicate with something like a socket or pipe. - */ -typedef struct _VipsStream { - VipsObject parent_object; - - /*< private >*/ - - /* Read/write this fd if connected to a system pipe/socket. Override - * ::read() and ::write() to do something else. - */ - int descriptor; - - /* A descriptor we close with vips_tracked_close(). - */ - int tracked_descriptor; - - /* A descriptor we close with close(). - */ - int close_descriptor; - - /* If descriptor is a file, the filename we opened. Handy for error - * messages. - */ - char *filename; - -} VipsStream; - -typedef struct _VipsStreamClass { - VipsObjectClass parent_class; - -} VipsStreamClass; - -GType vips_stream_get_type( void ); - -const char *vips_stream_filename( VipsStream *stream ); -const char *vips_stream_nick( VipsStream *stream ); - -#define VIPS_TYPE_STREAMI (vips_streami_get_type()) -#define VIPS_STREAMI( obj ) \ - (G_TYPE_CHECK_INSTANCE_CAST( (obj), \ - VIPS_TYPE_STREAMI, VipsStreami )) -#define VIPS_STREAMI_CLASS( klass ) \ - (G_TYPE_CHECK_CLASS_CAST( (klass), \ - VIPS_TYPE_STREAMI, VipsStreamiClass)) -#define VIPS_IS_STREAMI( obj ) \ - (G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_STREAMI )) -#define VIPS_IS_STREAMI_CLASS( klass ) \ - (G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_STREAMI )) -#define VIPS_STREAMI_GET_CLASS( obj ) \ - (G_TYPE_INSTANCE_GET_CLASS( (obj), \ - VIPS_TYPE_STREAMI, VipsStreamiClass )) - -/* Read from something like a socket, file or memory area and present the data - * with a unified seek / read / map interface. - * - * During the header phase, we save data from unseekable streams in a buffer - * so readers can rewind and read again. We don't buffer data during the - * decode stage. - */ -typedef struct _VipsStreami { - VipsStream parent_object; - - /* We have two phases: - * - * During the header phase, we save bytes read from the input (if this - * is an unseekable stream) so that we can rewind and try again, if - * necessary. - * - * Once we reach decode phase, we no longer support rewind and the - * buffer of saved data is discarded. - */ - gboolean decode; - - /* TRUE if this input is something like a pipe. These don't support - * stream or map -- all you can do is read() bytes sequentially. - * - * If you attempt to map or get the size of a pipe-style input, it'll - * get read entirely into memory. Seeks will cause read up to the seek - * point. - */ - gboolean have_tested_seek; - gboolean is_pipe; - - /* The current read point and length. - * - * length is -1 for is_pipe sources. - * - * off_t can be 32 bits on some platforms, so make sure we have a - * full 64. - */ - gint64 read_position; - gint64 length; - - /*< private >*/ - - /* For sources where we have the whole image in memory (from a memory - * buffer, from mmaping the file, from reading the pipe into memory), - * a pointer to the start. - */ - const void *data; - - /* For is_pipe sources, save data read during header phase here. If - * we rewind and try again, serve data from this until it runs out. - * - * If we need to force the whole pipe into memory, read everything to - * this and put a copy pf the pointer in data. - */ - GByteArray *header_bytes; - - /* Save the first few bytes here for file type sniffing. - */ - GByteArray *sniff; - - /* For a memory stream, the blob we read from. - */ - VipsBlob *blob; - - /* If we mmaped the file, whet we need to unmmap on finalize. - */ - void *mmap_baseaddr; - size_t mmap_length; - -} VipsStreami; - -typedef struct _VipsStreamiClass { - VipsStreamClass parent_class; - - /* Subclasses can define these to implement other streami methods. - */ - - /* Read from the stream into the supplied buffer, args exactly as - * read(2). Set errno on error. - * - * We must return gint64, since ssize_t is often defined as unsigned - * on Windows. - */ - gint64 (*read)( VipsStreami *, void *, size_t ); - - /* Seek to a certain position, args exactly as lseek(2). Set errno on - * error. - * - * Unseekable streams should always return -1. VipsStreami will then - * seek by _read()ing bytes into memory as required. - * - * We have to use int64 rather than off_t, since we must work on - * Windows, where off_t can be 32-bits. - */ - gint64 (*seek)( VipsStreami *, gint64, int ); - -} VipsStreamiClass; - -GType vips_streami_get_type( void ); - -VipsStreami *vips_streami_new_from_descriptor( int descriptor ); -VipsStreami *vips_streami_new_from_file( const char *filename ); -VipsStreami *vips_streami_new_from_blob( VipsBlob *blob ); -VipsStreami *vips_streami_new_from_memory( const void *data, size_t size ); -VipsStreami *vips_streami_new_from_options( const char *options ); - -void vips_streami_minimise( VipsStreami *streami ); -int vips_streami_unminimise( VipsStreami *streami ); -int vips_streami_decode( VipsStreami *streami ); -gint64 vips_streami_read( VipsStreami *streami, void *data, size_t length ); -gboolean vips_streami_is_mappable( VipsStreami *streami ); -const void *vips_streami_map( VipsStreami *streami, size_t *length ); -VipsBlob *vips_streami_map_blob( VipsStreami *streami ); -gint64 vips_streami_seek( VipsStreami *streami, gint64 offset, int whence ); -int vips_streami_rewind( VipsStreami *streami ); -size_t vips_streami_sniff_at_most( VipsStreami *streami, - unsigned char **data, size_t length ); -unsigned char *vips_streami_sniff( VipsStreami *streami, size_t length ); -gint64 vips_streami_length( VipsStreami *streami ); - -#define VIPS_TYPE_STREAMIU (vips_streamiu_get_type()) -#define VIPS_STREAMIU( obj ) \ - (G_TYPE_CHECK_INSTANCE_CAST( (obj), \ - VIPS_TYPE_STREAMIU, VipsStreamiu )) -#define VIPS_STREAMIU_CLASS( klass ) \ - (G_TYPE_CHECK_CLASS_CAST( (klass), \ - VIPS_TYPE_STREAMIU, VipsStreamiuClass)) -#define VIPS_IS_STREAMIU( obj ) \ - (G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_STREAMIU )) -#define VIPS_IS_STREAMIU_CLASS( klass ) \ - (G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_STREAMIU )) -#define VIPS_STREAMIU_GET_CLASS( obj ) \ - (G_TYPE_INSTANCE_GET_CLASS( (obj), \ - VIPS_TYPE_STREAMIU, VipsStreamiuClass )) - -/* Subclass of streamiu with signals for handlers. This is supposed to be - * useful for language bindings. - */ -typedef struct _VipsStreamiu { - VipsStreami parent_object; - -} VipsStreamiu; - -typedef struct _VipsStreamiuClass { - VipsStreamiClass parent_class; - - /* The action signals clients can use to implement read and seek. - * We must use gint64 everywhere since there's no G_TYPE_SIZE. - */ - - gint64 (*read)( VipsStreamiu *, void *, gint64 ); - gint64 (*seek)( VipsStreamiu *, gint64, int ); - -} VipsStreamiuClass; - -GType vips_streamiu_get_type( void ); -VipsStreamiu *vips_streamiu_new( void ); - -#define VIPS_TYPE_STREAMO (vips_streamo_get_type()) -#define VIPS_STREAMO( obj ) \ - (G_TYPE_CHECK_INSTANCE_CAST( (obj), \ - VIPS_TYPE_STREAMO, VipsStreamo )) -#define VIPS_STREAMO_CLASS( klass ) \ - (G_TYPE_CHECK_CLASS_CAST( (klass), \ - VIPS_TYPE_STREAMO, VipsStreamoClass)) -#define VIPS_IS_STREAMO( obj ) \ - (G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_STREAMO )) -#define VIPS_IS_STREAMO_CLASS( klass ) \ - (G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_STREAMO )) -#define VIPS_STREAMO_GET_CLASS( obj ) \ - (G_TYPE_INSTANCE_GET_CLASS( (obj), \ - VIPS_TYPE_STREAMO, VipsStreamoClass )) - -/* PNG writes in 8kb chunks, so we need to be a little larger than that. - */ -#define VIPS_STREAMO_BUFFER_SIZE (8500) - -/* Output to something like a socket, pipe or memory area. - */ -typedef struct _VipsStreamo { - VipsStream parent_object; - - /*< private >*/ - - /* This stream should write to memory. - */ - gboolean memory; - - /* The stream has been finished and can no longer be written. - */ - gboolean finished; - - /* Write memory output here. - */ - GByteArray *memory_buffer; - - /* And return memory via this blob. - */ - VipsBlob *blob; - - /* Buffer small writes here. write_point is the index of the next - * character to write. - */ - unsigned char output_buffer[VIPS_STREAMO_BUFFER_SIZE]; - int write_point; - -} VipsStreamo; - -typedef struct _VipsStreamoClass { - VipsStreamClass parent_class; - - /* Write to output. Args exactly as write(2). - * - * We must return gint64, since ssize_t is often defined as unsigned - * on Windows. - */ - gint64 (*write)( VipsStreamo *, const void *, size_t ); - - /* Output has been generated, so do any clearing up, - * eg. copy the bytes we saved in memory to the stream blob. - */ - void (*finish)( VipsStreamo * ); - -} VipsStreamoClass; - -GType vips_streamo_get_type( void ); - -VipsStreamo *vips_streamo_new_to_descriptor( int descriptor ); -VipsStreamo *vips_streamo_new_to_file( const char *filename ); -VipsStreamo *vips_streamo_new_to_memory( void ); -int vips_streamo_write( VipsStreamo *streamo, const void *data, size_t length ); -void vips_streamo_finish( VipsStreamo *streamo ); -unsigned char *vips_streamo_steal( VipsStreamo *streamo, size_t *length ); -char *vips_streamo_steal_text( VipsStreamo *streamo ); - -int vips_streamo_putc( VipsStreamo *streamo, int ch ); -#define VIPS_STREAMO_PUTC( S, C ) ( \ - (S)->write_point < VIPS_STREAMO_BUFFER_SIZE ? \ - ((S)->output_buffer[(S)->write_point++] = (C), 0) : \ - vips_streamo_putc( (S), (C) ) \ -) -int vips_streamo_writes( VipsStreamo *streamo, const char *str ); -int vips_streamo_writef( VipsStreamo *streamo, const char *fmt, ... ) - __attribute__((format(printf, 2, 3))); -int vips_streamo_write_amp( VipsStreamo *streamo, const char *str ); - -#define VIPS_TYPE_STREAMOU (vips_streamou_get_type()) -#define VIPS_STREAMOU( obj ) \ - (G_TYPE_CHECK_INSTANCE_CAST( (obj), \ - VIPS_TYPE_STREAMOU, VipsStreamou )) -#define VIPS_STREAMOU_CLASS( klass ) \ - (G_TYPE_CHECK_CLASS_CAST( (klass), \ - VIPS_TYPE_STREAMOU, VipsStreamouClass)) -#define VIPS_IS_STREAMOU( obj ) \ - (G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_STREAMOU )) -#define VIPS_IS_STREAMOU_CLASS( klass ) \ - (G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_STREAMOU )) -#define VIPS_STREAMOU_GET_CLASS( obj ) \ - (G_TYPE_INSTANCE_GET_CLASS( (obj), \ - VIPS_TYPE_STREAMOU, VipsStreamouClass )) - -#define VIPS_STREAMOU_BUFFER_SIZE (4096) - -/* Output to something like a socket, pipe or memory area. - */ -typedef struct _VipsStreamou { - VipsStreamo parent_object; - -} VipsStreamou; - -typedef struct _VipsStreamouClass { - VipsStreamoClass parent_class; - - /* The action signals clients can use to implement write and finish. - * We must use gint64 everywhere since there's no G_TYPE_SIZE. - */ - - gint64 (*write)( VipsStreamou *, const void *, gint64 ); - void (*finish)( VipsStreamou * ); - -} VipsStreamouClass; - -GType vips_streamou_get_type( void ); -VipsStreamou *vips_streamou_new( void ); - -#ifdef __cplusplus -} -#endif /*__cplusplus*/ - -#endif /*VIPS_STREAM_H*/ diff --git a/libvips/include/vips/vips.h b/libvips/include/vips/vips.h index de50c441..3d6751ae 100644 --- a/libvips/include/vips/vips.h +++ b/libvips/include/vips/vips.h @@ -113,7 +113,7 @@ extern "C" { #include #include #include -#include +#include #include #include diff --git a/libvips/include/vips/x.h b/libvips/include/vips/x.h new file mode 100644 index 00000000..3b46f912 --- /dev/null +++ b/libvips/include/vips/x.h @@ -0,0 +1,106 @@ +/* resample.h + * + * 20/9/09 + * - from proto.h + */ + +/* + + 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 + + */ + +#ifndef VIPS_RESAMPLE_H +#define VIPS_RESAMPLE_H + +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus*/ + +typedef enum { + VIPS_KERNEL_NEAREST, + VIPS_KERNEL_LINEAR, + VIPS_KERNEL_CUBIC, + VIPS_KERNEL_MITCHELL, + VIPS_KERNEL_LANCZOS2, + VIPS_KERNEL_LANCZOS3, + VIPS_KERNEL_LAST +} VipsKernel; + +typedef enum { + VIPS_SIZE_BOTH, + VIPS_SIZE_UP, + VIPS_SIZE_DOWN, + VIPS_SIZE_FORCE, + VIPS_SIZE_LAST +} VipsSize; + +int vips_shrink( VipsImage *in, VipsImage **out, + double hshrink, double vshrink, ... ) + __attribute__((sentinel)); +int vips_shrinkh( VipsImage *in, VipsImage **out, int hshrink, ... ) + __attribute__((sentinel)); +int vips_shrinkv( VipsImage *in, VipsImage **out, int vshrink, ... ) + __attribute__((sentinel)); + +int vips_reduce( VipsImage *in, VipsImage **out, + double hshrink, double vshrink, ... ) + __attribute__((sentinel)); +int vips_reduceh( VipsImage *in, VipsImage **out, double hshrink, ... ) + __attribute__((sentinel)); +int vips_reducev( VipsImage *in, VipsImage **out, double vshrink, ... ) + __attribute__((sentinel)); + +int vips_thumbnail( const char *filename, VipsImage **out, int width, ... ) + __attribute__((sentinel)); +int vips_thumbnail_buffer( void *buf, size_t len, VipsImage **out, + int width, ... ) + __attribute__((sentinel)); +int vips_thumbnail_image( VipsImage *in, VipsImage **out, int width, ... ) + __attribute__((sentinel)); +int vips_thumbnail_source( VipsSource *source, VipsImage **out, int width, ... ) + __attribute__((sentinel)); + +int vips_similarity( VipsImage *in, VipsImage **out, ... ) + __attribute__((sentinel)); +int vips_rotate( VipsImage *in, VipsImage **out, double angle, ... ) + __attribute__((sentinel)); +int vips_affine( VipsImage *in, VipsImage **out, + double a, double b, double c, double d, ... ) + __attribute__((sentinel)); + +int vips_resize( VipsImage *in, VipsImage **out, double scale, ... ) + __attribute__((sentinel)); + +int vips_mapim( VipsImage *in, VipsImage **out, VipsImage *index, ... ) + __attribute__((sentinel)); + +int vips_quadratic( VipsImage *in, VipsImage **out, VipsImage *coeff, ... ) + __attribute__((sentinel)); + +#ifdef __cplusplus +} +#endif /*__cplusplus*/ + +#endif /*VIPS_RESAMPLE_H*/ diff --git a/libvips/iofuncs/Makefile.am b/libvips/iofuncs/Makefile.am index 9005ead0..6f8e636e 100644 --- a/libvips/iofuncs/Makefile.am +++ b/libvips/iofuncs/Makefile.am @@ -1,11 +1,11 @@ noinst_LTLIBRARIES = libiofuncs.la libiofuncs_la_SOURCES = \ - stream.c \ - streami.c \ - streamiu.c \ - streamo.c \ - streamou.c \ + connection.c \ + source.c \ + sourceuser.c \ + target.c \ + targetuser.c \ bufis.c \ dbuf.c \ reorder.c \ diff --git a/libvips/iofuncs/bufis.c b/libvips/iofuncs/bufis.c index 91d376a6..56e29809 100644 --- a/libvips/iofuncs/bufis.c +++ b/libvips/iofuncs/bufis.c @@ -74,8 +74,8 @@ vips_bufis_class_init( VipsBufisClass *class ) _( "Input" ), _( "Stream to load from" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsBufis, streami ), - VIPS_TYPE_STREAMI ); + G_STRUCT_OFFSET( VipsBufis, source ), + VIPS_TYPE_SOURCE ); } @@ -88,20 +88,20 @@ vips_bufis_init( VipsBufis *bufis ) } /** - * vips_bufis_new_from_streami: - * @streami: stream to operate on + * vips_bufis_new_from_source: + * @source: stream to operate on * - * Create a bufis wrapping a streami. + * Create a bufis wrapping a source. * * Returns: a new #VipsBufis */ VipsBufis * -vips_bufis_new_from_streami( VipsStreami *streami ) +vips_bufis_new_from_source( VipsSource *source ) { VipsBufis *bufis; bufis = VIPS_BUFIS( g_object_new( VIPS_TYPE_BUFIS, - "input", streami, + "input", source, NULL ) ); if( vips_object_build( VIPS_OBJECT( bufis ) ) ) { @@ -117,14 +117,14 @@ vips_bufis_new_from_streami( VipsStreami *streami ) * @bufis: stream to operate on * * Discard the input buffer and reset the read point. You must call this - * before using read or seek on the underlying #VipsStreami class. + * before using read or seek on the underlying #VipsSource class. */ void vips_bufis_unbuffer( VipsBufis *bufis ) { /* We'd read ahead a little way -- seek backwards by that amount. */ - vips_streami_seek( bufis->streami, + vips_source_seek( bufis->source, bufis->read_point - bufis->chars_in_buffer, SEEK_CUR ); bufis->read_point = 0; bufis->chars_in_buffer = 0; @@ -143,7 +143,7 @@ vips_bufis_refill( VipsBufis *bufis ) */ g_assert( bufis->read_point == bufis->chars_in_buffer ); - bytes_read = vips_streami_read( bufis->streami, + bytes_read = vips_source_read( bufis->source, bufis->input_buffer, VIPS_BUFIS_BUFFER_SIZE ); if( bytes_read == -1 ) return( -1 ); @@ -255,13 +255,13 @@ vips_bufis_require( VipsBufis *bufis, int require ) bufis->chars_in_buffer; size_t bytes_read; - if( (bytes_read = vips_streami_read( bufis->streami, + if( (bytes_read = vips_source_read( bufis->source, to, space_available )) == -1 ) return( -1 ); if( bytes_read == 0 ) { vips_error( - vips_stream_nick( VIPS_STREAM( - bufis->streami ) ), + vips_connection_nick( VIPS_CONNECTION( + bufis->source ) ), "%s", _( "end of file" ) ); return( -1 ); } diff --git a/libvips/iofuncs/stream.c b/libvips/iofuncs/connection.c similarity index 79% rename from libvips/iofuncs/stream.c rename to libvips/iofuncs/connection.c index 2091f405..d23df29f 100644 --- a/libvips/iofuncs/stream.c +++ b/libvips/iofuncs/connection.c @@ -63,7 +63,7 @@ * @see_also: foreign * @include: vips/vips.h * - * A #VipsStream is a source or sink of bytes for something like jpeg loading. + * 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. * @@ -71,21 +71,21 @@ */ /** - * VipsStream: + * VipsConnection: * - * A #VipsStream is a source or sink of bytes for something like jpeg loading. + * 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( VipsStream, vips_stream, VIPS_TYPE_OBJECT ); +G_DEFINE_ABSTRACT_TYPE( VipsConnection, vips_connection, VIPS_TYPE_OBJECT ); static void -vips_stream_finalize( GObject *gobject ) +vips_connection_finalize( GObject *gobject ) { - VipsStream *stream = (VipsStream *) gobject; + VipsConnection *stream = (VipsConnection *) gobject; #ifdef VIPS_DEBUG - VIPS_DEBUG_MSG( "vips_stream_finalize: " ); + VIPS_DEBUG_MSG( "vips_connection_finalize: " ); vips_object_print_name( VIPS_OBJECT( gobject ) ); VIPS_DEBUG_MSG( "\n" ); #endif /*VIPS_DEBUG*/ @@ -106,15 +106,15 @@ vips_stream_finalize( GObject *gobject ) VIPS_FREE( stream->filename ); - G_OBJECT_CLASS( vips_stream_parent_class )->finalize( gobject ); + G_OBJECT_CLASS( vips_connection_parent_class )->finalize( gobject ); } static void -vips_stream_class_init( VipsStreamClass *class ) +vips_connection_class_init( VipsConnectionClass *class ) { GObjectClass *gobject_class = G_OBJECT_CLASS( class ); - gobject_class->finalize = vips_stream_finalize; + gobject_class->finalize = vips_connection_finalize; gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property; @@ -122,20 +122,20 @@ vips_stream_class_init( VipsStreamClass *class ) _( "Descriptor" ), _( "File descriptor for read or write" ), VIPS_ARGUMENT_OPTIONAL_INPUT, - G_STRUCT_OFFSET( VipsStream, descriptor ), + G_STRUCT_OFFSET( VipsConnection, descriptor ), -1, 1000000000, 0 ); VIPS_ARG_STRING( class, "filename", 2, _( "Filename" ), _( "Name of file to open" ), VIPS_ARGUMENT_OPTIONAL_INPUT, - G_STRUCT_OFFSET( VipsStream, filename ), + G_STRUCT_OFFSET( VipsConnection, filename ), NULL ); } static void -vips_stream_init( VipsStream *stream ) +vips_connection_init( VipsConnection *stream ) { stream->descriptor = -1; stream->tracked_descriptor = -1; @@ -143,13 +143,13 @@ vips_stream_init( VipsStream *stream ) } const char * -vips_stream_filename( VipsStream *stream ) +vips_connection_filename( VipsConnection *stream ) { return( stream->filename ); } const char * -vips_stream_nick( VipsStream *stream ) +vips_connection_nick( VipsConnection *stream ) { return( stream->filename ? stream->filename : diff --git a/libvips/iofuncs/destination.c b/libvips/iofuncs/destination.c new file mode 100644 index 00000000..b08ac431 --- /dev/null +++ b/libvips/iofuncs/destination.c @@ -0,0 +1,609 @@ +/* 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 new file mode 100644 index 00000000..e80d1caf --- /dev/null +++ b/libvips/iofuncs/destinationcustom.c @@ -0,0 +1,194 @@ +/* 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 f03798ff..1b59ca44 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -19,7 +19,7 @@ * 9/10/18 * - fix up vips_image_dump(), it was still using ints not enums * 10/12/19 - * - add vips_image_new_from_stream() / vips_image_write_to_stream() + * - add vips_image_new_from_source() / vips_image_write_to_target() */ /* @@ -1907,7 +1907,7 @@ vips_image_new_from_file( const char *name, ... ) { char filename[VIPS_PATH_MAX]; char option_string[VIPS_PATH_MAX]; - VipsStreami *streami; + VipsSource *source; const char *operation_name; va_list ap; int result; @@ -1922,17 +1922,17 @@ vips_image_new_from_file( const char *name, ... ) * * We need to hide any errors from this first phase. */ - if( !(streami = vips_streami_new_from_file( filename )) ) + if( !(source = vips_source_new_from_file( filename )) ) return( NULL ); vips_error_freeze(); - operation_name = vips_foreign_find_load_stream( streami ); + operation_name = vips_foreign_find_load_source( source ); vips_error_thaw(); if( operation_name ) { va_start( ap, name ); result = vips_call_split_option_string( operation_name, - option_string, ap, streami, &out ); + option_string, ap, source, &out ); va_end( ap ); } else { @@ -1947,7 +1947,7 @@ vips_image_new_from_file( const char *name, ... ) va_end( ap ); } - VIPS_UNREF( streami ); + VIPS_UNREF( source ); if( result ) return( NULL ); @@ -2159,7 +2159,7 @@ VipsImage * vips_image_new_from_buffer( const void *buf, size_t len, const char *option_string, ... ) { - VipsStreami *streami; + VipsSource *source; const char *operation_name; va_list ap; int result; @@ -2170,13 +2170,13 @@ vips_image_new_from_buffer( const void *buf, size_t len, /* Search with the new stream API first, then fall back to the older * mechanism in case the loader we need has not been converted yet. */ - if( !(streami = vips_streami_new_from_memory( buf, len )) ) + if( !(source = vips_source_new_from_memory( buf, len )) ) return( NULL ); - if( (operation_name = vips_foreign_find_load_stream( streami )) ) { + if( (operation_name = vips_foreign_find_load_source( source )) ) { va_start( ap, option_string ); result = vips_call_split_option_string( operation_name, - option_string, ap, streami, &out ); + option_string, ap, source, &out ); va_end( ap ); } else { @@ -2198,7 +2198,7 @@ vips_image_new_from_buffer( const void *buf, size_t len, vips_area_unref( VIPS_AREA( blob ) ); } - VIPS_UNREF( streami ); + VIPS_UNREF( source ); if( result ) return( NULL ); @@ -2207,27 +2207,27 @@ vips_image_new_from_buffer( const void *buf, size_t len, } /** - * vips_image_new_from_stream: (constructor) - * @streami: (transfer none): stream to fetch image from + * vips_image_new_from_source: (constructor) + * @source: (transfer none): stream 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, - * loader recommended by vips_foreign_find_load_stream(). + * loader recommended by vips_foreign_find_load_source(). * * Load options may be given in @option_string as "[name=value,...]" or given as * a NULL-terminated list of name-value pairs at the end of the arguments. * Options given in the function call override options given in the string. * - * See also: vips_image_write_to_stream(). + * See also: vips_image_write_to_target(). * * Returns: (transfer full): the new #VipsImage, or %NULL on error. */ VipsImage * -vips_image_new_from_stream( VipsStreami *streami, +vips_image_new_from_source( VipsSource *source, const char *option_string, ... ) { - const char *filename = vips_stream_filename( VIPS_STREAM( streami ) ); + const char *filename = vips_connection_filename( VIPS_CONNECTION( source ) ); const char *operation_name; va_list ap; @@ -2237,13 +2237,13 @@ vips_image_new_from_stream( VipsStreami *streami, vips_check_init(); vips_error_freeze(); - operation_name = vips_foreign_find_load_stream( streami ); + operation_name = vips_foreign_find_load_source( source ); vips_error_thaw(); if( operation_name ) { va_start( ap, option_string ); result = vips_call_split_option_string( operation_name, - option_string, ap, streami, &out ); + option_string, ap, source, &out ); va_end( ap ); } else if( filename ) { @@ -2257,14 +2257,14 @@ vips_image_new_from_stream( VipsStreami *streami, option_string, ap, filename, &out ); va_end( ap ); } - else if( vips_streami_is_mappable( streami ) ) { + else if( vips_source_is_mappable( source ) ) { /* Try with the old buffer-based loaders. */ VipsBlob *blob; const void *buf; size_t len; - if( !(blob = vips_streami_map_blob( streami )) ) + if( !(blob = vips_source_map_blob( source )) ) return( NULL ); buf = vips_blob_get( blob, &len ); @@ -2720,21 +2720,21 @@ vips_image_write_to_file( VipsImage *image, const char *name, ... ) vips__filename_split8( name, filename, option_string ); vips_error_freeze(); - operation_name = vips_foreign_find_save_stream( filename ); + operation_name = vips_foreign_find_save_target( filename ); vips_error_thaw(); if( operation_name ) { - VipsStreamo *streamo; + VipsTarget *target; - if( !(streamo = vips_streamo_new_to_file( filename )) ) + if( !(target = vips_target_new_to_file( filename )) ) return( -1 ); va_start( ap, name ); result = vips_call_split_option_string( operation_name, - option_string, ap, image, streamo ); + option_string, ap, image, target ); va_end( ap ); - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); } else if( (operation_name = vips_foreign_find_save( filename )) ) { va_start( ap, name ); @@ -2785,24 +2785,24 @@ vips_image_write_to_buffer( VipsImage *in, vips__filename_split8( suffix, filename, option_string ); - if( (operation_name = vips_foreign_find_save_stream( filename )) ) { - VipsStreamo *streamo; + if( (operation_name = vips_foreign_find_save_target( filename )) ) { + VipsTarget *target; - if( !(streamo = vips_streamo_new_to_memory()) ) + if( !(target = vips_target_new_to_memory()) ) return( -1 ); va_start( ap, size ); result = vips_call_split_option_string( operation_name, - option_string, ap, in, streamo ); + option_string, ap, in, target ); va_end( ap ); if( result ) { - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( -1 ); } - g_object_get( streamo, "blob", &blob, NULL ); - VIPS_UNREF( streamo ); + g_object_get( target, "blob", &blob, NULL ); + VIPS_UNREF( target ); } else if( (operation_name = vips_foreign_find_save_buffer( filename )) ) { @@ -2837,10 +2837,10 @@ vips_image_write_to_buffer( VipsImage *in, } /** - * vips_image_write_to_stream: (method) + * vips_image_write_to_target: (method) * @in: image to write * @suffix: format to write - * @streamo: stream to write to + * @target: stream to write to * @...: %NULL-terminated list of optional named arguments * * Writes @in to @output in format @suffix. @@ -2850,15 +2850,15 @@ vips_image_write_to_buffer( VipsImage *in, * Options given in the function call override options given in the filename. * * You can call the various save operations directly if you wish, see - * vips_jpegsave_stream(), for example. + * vips_jpegsave_target(), for example. * * See also: vips_image_write_to_file(). * * Returns: 0 on success, -1 on error */ int -vips_image_write_to_stream( VipsImage *in, - const char *suffix, VipsStreamo *streamo, ... ) +vips_image_write_to_target( VipsImage *in, + const char *suffix, VipsTarget *target, ... ) { char filename[VIPS_PATH_MAX]; char option_string[VIPS_PATH_MAX]; @@ -2867,12 +2867,12 @@ vips_image_write_to_stream( VipsImage *in, int result; vips__filename_split8( suffix, filename, option_string ); - if( !(operation_name = vips_foreign_find_save_stream( filename )) ) + if( !(operation_name = vips_foreign_find_save_target( filename )) ) return( -1 ); - va_start( ap, streamo ); + va_start( ap, target ); result = vips_call_split_option_string( operation_name, option_string, - ap, in, streamo ); + ap, in, target ); va_end( ap ); if( result ) diff --git a/libvips/iofuncs/init.c b/libvips/iofuncs/init.c index 9d2e98e2..f07d8653 100644 --- a/libvips/iofuncs/init.c +++ b/libvips/iofuncs/init.c @@ -330,10 +330,10 @@ vips_init( const char *argv0 ) extern GType write_thread_state_get_type( void ); extern GType sink_memory_thread_state_get_type( void ); extern GType render_thread_state_get_type( void ); - extern GType vips_streami_get_type( void ); - extern GType vips_streamiu_get_type( void ); - extern GType vips_streamo_get_type( void ); - extern GType vips_streamou_get_type( void ); + extern GType vips_source_get_type( void ); + extern GType vips_source_custom_get_type( void ); + extern GType vips_target_get_type( void ); + extern GType vips_target_custom_get_type( void ); static gboolean started = FALSE; static gboolean done = FALSE; @@ -448,10 +448,10 @@ vips_init( const char *argv0 ) (void) write_thread_state_get_type(); (void) sink_memory_thread_state_get_type(); (void) render_thread_state_get_type(); - (void) vips_streami_get_type(); - (void) vips_streamiu_get_type(); - (void) vips_streamo_get_type(); - (void) vips_streamou_get_type(); + (void) vips_source_get_type(); + (void) vips_source_custom_get_type(); + (void) vips_target_get_type(); + (void) vips_target_custom_get_type(); vips__meta_init_types(); vips__interpolate_init(); im__format_init(); diff --git a/libvips/iofuncs/object.c b/libvips/iofuncs/object.c index e5275c70..bbb6ac3c 100644 --- a/libvips/iofuncs/object.c +++ b/libvips/iofuncs/object.c @@ -1908,19 +1908,19 @@ vips_object_set_argument_from_string( VipsObject *object, vips__filename_split8( value, filename, option_string ); if( strcmp( "stdin", filename ) == 0 ) { - VipsStreami *streami; + VipsSource *source; - if( !(streami = - vips_streami_new_from_descriptor( 0 )) ) + if( !(source = + vips_source_new_from_descriptor( 0 )) ) return( -1 ); - if( !(out = vips_image_new_from_stream( streami, + if( !(out = vips_image_new_from_source( source, option_string, "access", access, NULL )) ) { - VIPS_UNREF( streami ); + VIPS_UNREF( source ); return( -1 ); } - VIPS_UNREF( streami ); + VIPS_UNREF( source ); } else { if( !(out = vips_image_new_from_file( value, @@ -1937,24 +1937,24 @@ vips_object_set_argument_from_string( VipsObject *object, */ g_object_unref( out ); } - else if( g_type_is_a( otype, VIPS_TYPE_STREAMI ) ) { - VipsStreami *streami; + else if( g_type_is_a( otype, VIPS_TYPE_SOURCE ) ) { + VipsSource *source; if( !value ) { vips_object_no_value( object, name ); return( -1 ); } - if( !(streami = vips_streami_new_from_options( value )) ) + if( !(source = vips_source_new_from_options( value )) ) return( -1 ); - g_value_init( &gvalue, VIPS_TYPE_STREAMI ); - g_value_set_object( &gvalue, streami ); + g_value_init( &gvalue, VIPS_TYPE_SOURCE ); + g_value_set_object( &gvalue, source ); /* Setting gvalue will have upped @out's count again, * go back to 1 so that gvalue has the only ref. */ - g_object_unref( streami ); + g_object_unref( source ); } else if( g_type_is_a( otype, VIPS_TYPE_ARRAY_IMAGE ) ) { /* We have to have a special case for this, we can't just rely @@ -2210,19 +2210,19 @@ vips_object_get_argument_to_string( VipsObject *object, vips__filename_split8( arg, filename, option_string ); if( vips_isprefix( ".", filename ) ) { - VipsStreamo *streamo; + VipsTarget *target; - if( !(streamo = vips_streamo_new_to_descriptor( 1 )) ) + if( !(target = vips_target_new_to_descriptor( 1 )) ) return( -1 ); g_object_get( object, name, &in, NULL ); - if( vips_image_write_to_stream( in, - arg, streamo, NULL ) ) { + if( vips_image_write_to_target( in, + arg, target, NULL ) ) { VIPS_UNREF( in ); - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( -1 ); } VIPS_UNREF( in ); - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); } else { /* Pull out the image and write it. diff --git a/libvips/iofuncs/streami.c b/libvips/iofuncs/source.c similarity index 51% rename from libvips/iofuncs/streami.c rename to libvips/iofuncs/source.c index 4a864b36..0b439f07 100644 --- a/libvips/iofuncs/streami.c +++ b/libvips/iofuncs/source.c @@ -84,26 +84,26 @@ #define MODE_READWRITE BINARYIZE (O_RDWR) #define MODE_WRITE BINARYIZE (O_WRONLY | O_CREAT | O_TRUNC) -G_DEFINE_TYPE( VipsStreami, vips_streami, VIPS_TYPE_STREAM ); +G_DEFINE_TYPE( VipsSource, vips_source, VIPS_TYPE_CONNECTION ); /* We can't test for seekability or length during _build, since the read and * seek signal handlers may not have been connected yet. Instead, we test * when we first need to know. */ static int -vips_streami_test_features( VipsStreami *streami ) +vips_source_test_features( VipsSource *source ) { - VipsStreamiClass *class = VIPS_STREAMI_GET_CLASS( streami ); + VipsSourceClass *class = VIPS_SOURCE_GET_CLASS( source ); - if( streami->have_tested_seek ) + if( source->have_tested_seek ) return( 0 ); - streami->have_tested_seek = TRUE; + source->have_tested_seek = TRUE; - VIPS_DEBUG_MSG( "vips_streami_test_features: testing seek ..\n" ); + VIPS_DEBUG_MSG( "vips_source_test_features: testing seek ..\n" ); /* We'll need a descriptor to test. */ - if( vips_streami_unminimise( streami ) ) { + if( vips_source_unminimise( source ) ) { printf( "HUGE BANANA!!!\n" ); return( -1 ); } @@ -111,10 +111,10 @@ vips_streami_test_features( VipsStreami *streami ) /* Can we seek this input? * * We need to call the method directly rather than via - * vips_streami_seek() etc. or we might trigger seek emulation. + * vips_source_seek() etc. or we might trigger seek emulation. */ - if( streami->data || - class->seek( streami, 0, SEEK_CUR ) != -1 ) { + if( source->data || + class->seek( source, 0, SEEK_CUR ) != -1 ) { gint64 length; VIPS_DEBUG_MSG( " seekable stream\n" ); @@ -122,22 +122,22 @@ vips_streami_test_features( VipsStreami *streami ) /* We should be able to get the length of seekable * objects. */ - if( (length = vips_streami_length( streami )) == -1 ) { + if( (length = vips_source_length( source )) == -1 ) { printf( "BANANA!!!\n" ); return( -1 ); } - streami->length = length; + source->length = length; /* If we can seek, we won't need to save header bytes. */ - VIPS_FREEF( g_byte_array_unref, streami->header_bytes ); + VIPS_FREEF( g_byte_array_unref, source->header_bytes ); } else { /* Not seekable. This must be some kind of pipe. */ VIPS_DEBUG_MSG( " not seekable\n" ); - streami->is_pipe = TRUE; + source->is_pipe = TRUE; } return( 0 ); @@ -145,112 +145,112 @@ vips_streami_test_features( VipsStreami *streami ) #ifdef TEST_SANITY static void -vips_streami_sanity( VipsStreami *streami ) +vips_source_sanity( VipsSource *source ) { - if( streami->data ) { + if( source->data ) { /* Not a pipe (can map and seek). */ - g_assert( !streami->is_pipe ); + g_assert( !source->is_pipe ); /* Read position must lie within the buffer. */ - g_assert( streami->read_position >= 0 ); - g_assert( streami->read_position <= streami->length ); + g_assert( source->read_position >= 0 ); + g_assert( source->read_position <= source->length ); /* After we're done with the header, the sniff buffer should * be gone. */ - g_assert( !streami->decode || - !streami->sniff ); + g_assert( !source->decode || + !source->sniff ); /* Have length. */ - g_assert( streami->length != -1 ); + g_assert( source->length != -1 ); } - else if( streami->is_pipe ) { - if( streami->decode ) { + else if( source->is_pipe ) { + if( source->decode ) { /* Reading pixel data. */ - g_assert( !streami->header_bytes ); - g_assert( !streami->sniff ); + g_assert( !source->header_bytes ); + g_assert( !source->sniff ); } else { /* Reading header data. */ - g_assert( streami->header_bytes ); - g_assert( streami->read_position >= 0 ); - g_assert( streami->read_position <= - streami->header_bytes->len ); + g_assert( source->header_bytes ); + g_assert( source->read_position >= 0 ); + g_assert( source->read_position <= + source->header_bytes->len ); } /* No length available. */ - g_assert( streami->length == -1 ); + g_assert( source->length == -1 ); } else { /* After we're done with the header, the sniff buffer should * be gone. */ - if( streami->decode ) { - g_assert( !streami->sniff ); + if( source->decode ) { + g_assert( !source->sniff ); } /* Once we've tested seek, the read position must lie within * the file. */ - if( streami->have_tested_seek ) { - g_assert( streami->length != -1 ); - g_assert( streami->read_position >= 0 ); - g_assert( streami->read_position <= streami->length ); + if( source->have_tested_seek ) { + g_assert( source->length != -1 ); + g_assert( source->read_position >= 0 ); + g_assert( source->read_position <= source->length ); } /* Supports minimise, so if descriptor is -1, we must have a * filename we can reopen. */ - g_assert( VIPS_STREAM( streami )->descriptor != -1 || - (VIPS_STREAM( streami )->filename && - VIPS_STREAM( streami )->descriptor) ); + g_assert( VIPS_CONNECTION( source )->descriptor != -1 || + (VIPS_CONNECTION( source )->filename && + VIPS_CONNECTION( source )->descriptor) ); } } #endif /*TEST_SANITY*/ #ifdef TEST_SANITY -#define SANITY( S ) vips_streami_sanity( S ) -#warning "sanity tests on in streami.c" +#define SANITY( S ) vips_source_sanity( S ) +#warning "sanity tests on in source.c" #else /*!TEST_SANITY*/ #define SANITY( S ) #endif /*TEST_SANITY*/ static void -vips_streami_finalize( GObject *gobject ) +vips_source_finalize( GObject *gobject ) { - VipsStreami *streami = VIPS_STREAMI( gobject ); + VipsSource *source = VIPS_SOURCE( gobject ); - VIPS_FREEF( g_byte_array_unref, streami->header_bytes ); - VIPS_FREEF( g_byte_array_unref, streami->sniff ); - if( streami->mmap_baseaddr ) { - vips__munmap( streami->mmap_baseaddr, streami->mmap_length ); - streami->mmap_baseaddr = NULL; + VIPS_FREEF( g_byte_array_unref, source->header_bytes ); + VIPS_FREEF( g_byte_array_unref, source->sniff ); + if( source->mmap_baseaddr ) { + vips__munmap( source->mmap_baseaddr, source->mmap_length ); + source->mmap_baseaddr = NULL; } - G_OBJECT_CLASS( vips_streami_parent_class )->finalize( gobject ); + G_OBJECT_CLASS( vips_source_parent_class )->finalize( gobject ); } static int -vips_streami_build( VipsObject *object ) +vips_source_build( VipsObject *object ) { - VipsStream *stream = VIPS_STREAM( object ); - VipsStreami *streami = VIPS_STREAMI( object ); + VipsConnection *stream = VIPS_CONNECTION( object ); + VipsSource *source = VIPS_SOURCE( object ); - VIPS_DEBUG_MSG( "vips_streami_build: %p\n", streami ); + VIPS_DEBUG_MSG( "vips_source_build: %p\n", source ); - if( VIPS_OBJECT_CLASS( vips_streami_parent_class )-> + if( VIPS_OBJECT_CLASS( vips_source_parent_class )-> build( object ) ) return( -1 ); if( vips_object_argument_isset( object, "filename" ) && vips_object_argument_isset( object, "descriptor" ) ) { - vips_error( vips_stream_nick( stream ), + vips_error( vips_connection_nick( stream ), "%s", _( "don't set 'filename' and 'descriptor'" ) ); return( -1 ); } @@ -258,7 +258,7 @@ vips_streami_build( VipsObject *object ) /* unminimise will open the filename. */ if( vips_object_argument_isset( object, "filename" ) && - vips_streami_unminimise( streami ) ) + vips_source_unminimise( source ) ) return( -1 ); if( vips_object_argument_isset( object, "descriptor" ) ) { @@ -269,21 +269,21 @@ vips_streami_build( VipsObject *object ) if( vips_object_argument_isset( object, "blob" ) ) { size_t length; - streami->data = vips_blob_get( streami->blob, &length ); - streami->length = VIPS_MIN( length, G_MAXSSIZE ); + source->data = vips_blob_get( source->blob, &length ); + source->length = VIPS_MIN( length, G_MAXSSIZE ); } return( 0 ); } static gint64 -vips_streami_read_real( VipsStreami *streami, void *data, size_t length ) +vips_source_read_real( VipsSource *source, void *data, size_t length ) { - VipsStream *stream = VIPS_STREAM( streami ); + VipsConnection *stream = VIPS_CONNECTION( source ); gint64 bytes_read; - VIPS_DEBUG_MSG( "vips_streami_read_real:\n" ); + VIPS_DEBUG_MSG( "vips_source_read_real:\n" ); do { bytes_read = read( stream->descriptor, data, length ); @@ -293,13 +293,13 @@ vips_streami_read_real( VipsStreami *streami, void *data, size_t length ) } static gint64 -vips_streami_seek_real( VipsStreami *streami, gint64 offset, int whence ) +vips_source_seek_real( VipsSource *source, gint64 offset, int whence ) { - VipsStream *stream = VIPS_STREAM( streami ); + VipsConnection *stream = VIPS_CONNECTION( source ); gint64 new_pos; - VIPS_DEBUG_MSG( "vips_streami_seek_real:\n" ); + VIPS_DEBUG_MSG( "vips_source_seek_real:\n" ); /* 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. @@ -310,132 +310,132 @@ vips_streami_seek_real( VipsStreami *streami, gint64 offset, int whence ) } static void -vips_streami_class_init( VipsStreamiClass *class ) +vips_source_class_init( VipsSourceClass *class ) { GObjectClass *gobject_class = G_OBJECT_CLASS( class ); VipsObjectClass *object_class = VIPS_OBJECT_CLASS( class ); - gobject_class->finalize = vips_streami_finalize; + gobject_class->finalize = vips_source_finalize; gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property; - object_class->nickname = "streami"; + object_class->nickname = "source"; object_class->description = _( "input stream" ); - object_class->build = vips_streami_build; + object_class->build = vips_source_build; - class->read = vips_streami_read_real; - class->seek = vips_streami_seek_real; + class->read = vips_source_read_real; + class->seek = vips_source_seek_real; VIPS_ARG_BOXED( class, "blob", 3, _( "Blob" ), _( "blob to load from" ), VIPS_ARGUMENT_OPTIONAL_INPUT, - G_STRUCT_OFFSET( VipsStreami, blob ), + G_STRUCT_OFFSET( VipsSource, blob ), VIPS_TYPE_BLOB ); } static void -vips_streami_init( VipsStreami *streami ) +vips_source_init( VipsSource *source ) { - streami->length = -1; - streami->sniff = g_byte_array_new(); - streami->header_bytes = g_byte_array_new(); + source->length = -1; + source->sniff = g_byte_array_new(); + source->header_bytes = g_byte_array_new(); } /** - * vips_streami_new_from_descriptor: + * vips_source_new_from_descriptor: * @descriptor: read from this file descriptor * - * Create an streami stream attached to a file descriptor. @descriptor is - * closed with close() when the #VipsStream is finalized. + * Create an source stream attached to a file descriptor. @descriptor is + * closed with close() when the #VipsConnection is finalized. * - * Returns: a new #VipsStream + * Returns: a new #VipsConnection */ -VipsStreami * -vips_streami_new_from_descriptor( int descriptor ) +VipsSource * +vips_source_new_from_descriptor( int descriptor ) { - VipsStreami *streami; + VipsSource *source; - VIPS_DEBUG_MSG( "vips_streami_new_from_descriptor: %d\n", + VIPS_DEBUG_MSG( "vips_source_new_from_descriptor: %d\n", descriptor ); - streami = VIPS_STREAMI( g_object_new( VIPS_TYPE_STREAMI, + source = VIPS_SOURCE( g_object_new( VIPS_TYPE_SOURCE, "descriptor", descriptor, NULL ) ); - if( vips_object_build( VIPS_OBJECT( streami ) ) ) { - VIPS_UNREF( streami ); + if( vips_object_build( VIPS_OBJECT( source ) ) ) { + VIPS_UNREF( source ); return( NULL ); } - SANITY( streami ); + SANITY( source ); - return( streami ); + return( source ); } /** - * vips_streami_new_from_file: + * vips_source_new_from_file: * @descriptor: read from this filename * - * Create an streami stream attached to a file. + * Create an source stream attached to a file. * - * Returns: a new #VipsStream + * Returns: a new #VipsConnection */ -VipsStreami * -vips_streami_new_from_file( const char *filename ) +VipsSource * +vips_source_new_from_file( const char *filename ) { - VipsStreami *streami; + VipsSource *source; - VIPS_DEBUG_MSG( "vips_streami_new_from_file: %s\n", + VIPS_DEBUG_MSG( "vips_source_new_from_file: %s\n", filename ); - streami = VIPS_STREAMI( g_object_new( VIPS_TYPE_STREAMI, + source = VIPS_SOURCE( g_object_new( VIPS_TYPE_SOURCE, "filename", filename, NULL ) ); - if( vips_object_build( VIPS_OBJECT( streami ) ) ) { - VIPS_UNREF( streami ); + if( vips_object_build( VIPS_OBJECT( source ) ) ) { + VIPS_UNREF( source ); return( NULL ); } - SANITY( streami ); + SANITY( source ); - return( streami ); + return( source ); } /** - * vips_streami_new_from_blob: + * vips_source_new_from_blob: * @blob: memory area to load * * Create a stream attached to an area of memory. * - * Returns: a new #VipsStream + * Returns: a new #VipsConnection */ -VipsStreami * -vips_streami_new_from_blob( VipsBlob *blob ) +VipsSource * +vips_source_new_from_blob( VipsBlob *blob ) { - VipsStreami *streami; + VipsSource *source; - VIPS_DEBUG_MSG( "vips_streami_new_from_blob: %p\n", blob ); + VIPS_DEBUG_MSG( "vips_source_new_from_blob: %p\n", blob ); - streami = VIPS_STREAMI( g_object_new( VIPS_TYPE_STREAMI, + source = VIPS_SOURCE( g_object_new( VIPS_TYPE_SOURCE, "blob", blob, NULL ) ); - if( vips_object_build( VIPS_OBJECT( streami ) ) ) { - VIPS_UNREF( streami ); + if( vips_object_build( VIPS_OBJECT( source ) ) ) { + VIPS_UNREF( source ); return( NULL ); } - SANITY( streami ); + SANITY( source ); - return( streami ); + return( source ); } /** - * vips_streami_new_from_memory: + * vips_source_new_from_memory: * @data: memory area to load * @length: size of memory area * @@ -443,64 +443,64 @@ vips_streami_new_from_blob( VipsBlob *blob ) * * You must not free @data while the stream is active. * - * Returns: a new #VipsStream + * Returns: a new #VipsConnection */ -VipsStreami * -vips_streami_new_from_memory( const void *data, size_t length ) +VipsSource * +vips_source_new_from_memory( const void *data, size_t length ) { - VipsStreami *streami; + VipsSource *source; VipsBlob *blob; - VIPS_DEBUG_MSG( "vips_streami_new_from_buffer: " + VIPS_DEBUG_MSG( "vips_source_new_from_buffer: " "%p, length = %zd\n", data, length ); /* We don't take a copy of the data or free it. */ blob = vips_blob_new( NULL, data, length ); - streami = vips_streami_new_from_blob( blob ); + source = vips_source_new_from_blob( blob ); vips_area_unref( VIPS_AREA( blob ) ); - SANITY( streami ); + SANITY( source ); - return( streami ); + return( source ); } /** - * vips_streami_new_from_options: + * vips_source_new_from_options: * @options: option string * * Create a stream from an option string. * - * Returns: a new #VipsStreami + * Returns: a new #VipsSource */ -VipsStreami * -vips_streami_new_from_options( const char *options ) +VipsSource * +vips_source_new_from_options( const char *options ) { - VipsStreami *streami; + VipsSource *source; - VIPS_DEBUG_MSG( "vips_streami_new_from_options: %s\n", options ); + VIPS_DEBUG_MSG( "vips_source_new_from_options: %s\n", options ); - streami = VIPS_STREAMI( g_object_new( VIPS_TYPE_STREAMI, NULL ) ); + source = VIPS_SOURCE( g_object_new( VIPS_TYPE_SOURCE, NULL ) ); - if( vips_object_set_from_string( VIPS_OBJECT( streami ), options ) || - vips_object_build( VIPS_OBJECT( streami ) ) ) { - VIPS_UNREF( streami ); + if( vips_object_set_from_string( VIPS_OBJECT( source ), options ) || + vips_object_build( VIPS_OBJECT( source ) ) ) { + VIPS_UNREF( source ); return( NULL ); } - SANITY( streami ); + SANITY( source ); - return( streami ); + return( source ); } /** - * vips_streami_minimise: - * @streami: input stream to operate on + * vips_source_minimise: + * @source: input stream to operate on * * Minimise the stream. As many stream resources as can be safely removed are - * removed. Use vips_streami_unminimise() to restore the stream if you wish to + * removed. Use vips_source_unminimise() to restore the stream if you wish to * use it again. * * Loaders should call this in response to the minimise signal on their output @@ -509,46 +509,46 @@ vips_streami_new_from_options( const char *options ) * Returns: 0 on success, or -1 on error. */ void -vips_streami_minimise( VipsStreami *streami ) +vips_source_minimise( VipsSource *source ) { - VipsStream *stream = VIPS_STREAM( streami ); + VipsConnection *stream = VIPS_CONNECTION( source ); - VIPS_DEBUG_MSG( "vips_streami_minimise:\n" ); + VIPS_DEBUG_MSG( "vips_source_minimise:\n" ); - SANITY( streami ); + SANITY( source ); - (void) vips_streami_test_features( streami ); + (void) vips_source_test_features( source ); if( stream->filename && stream->descriptor != -1 && stream->tracked_descriptor == stream->descriptor && - !streami->is_pipe ) { + !source->is_pipe ) { VIPS_DEBUG_MSG( " tracked_close()\n" ); vips_tracked_close( stream->tracked_descriptor ); stream->tracked_descriptor = -1; stream->descriptor = -1; } - SANITY( streami ); + SANITY( source ); } /** - * vips_streami_unminimise: - * @streami: input stream to operate on + * vips_source_unminimise: + * @source: input stream 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. * - * See also: vips_streami_minimise(). + * See also: vips_source_minimise(). * * Returns: 0 on success, or -1 on error. */ int -vips_streami_unminimise( VipsStreami *streami ) +vips_source_unminimise( VipsSource *source ) { - VipsStream *stream = VIPS_STREAM( streami ); + VipsConnection *stream = VIPS_CONNECTION( source ); - VIPS_DEBUG_MSG( "vips_streami_unminimise:\n" ); + VIPS_DEBUG_MSG( "vips_source_unminimise:\n" ); if( stream->descriptor == -1 && stream->tracked_descriptor == -1 && @@ -557,7 +557,7 @@ vips_streami_unminimise( VipsStreami *streami ) if( (fd = vips_tracked_open( stream->filename, MODE_READ )) == -1 ) { - vips_error_system( errno, vips_stream_nick( stream ), + vips_error_system( errno, vips_connection_nick( stream ), "%s", _( "unable to open for read" ) ); return( -1 ); } @@ -565,11 +565,11 @@ vips_streami_unminimise( VipsStreami *streami ) stream->tracked_descriptor = fd; stream->descriptor = fd; - VIPS_DEBUG_MSG( "vips_streami_unminimise: " + VIPS_DEBUG_MSG( "vips_source_unminimise: " "restoring read position %" G_GINT64_FORMAT "\n", - streami->read_position ); + source->read_position ); if( vips__seek( stream->descriptor, - streami->read_position, SEEK_SET ) == -1 ) + source->read_position, SEEK_SET ) == -1 ) return( -1 ); } @@ -577,48 +577,48 @@ vips_streami_unminimise( VipsStreami *streami ) } /** - * vips_streami_decode: - * @streami: input stream to operate on + * vips_source_decode: + * @source: input stream 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. * * Loaders should call this at the end of header read. * - * See also: vips_streami_unminimise(). + * See also: vips_source_unminimise(). * * Returns: 0 on success, -1 on error. */ int -vips_streami_decode( VipsStreami *streami ) +vips_source_decode( VipsSource *source ) { - VIPS_DEBUG_MSG( "vips_streami_decode:\n" ); + VIPS_DEBUG_MSG( "vips_source_decode:\n" ); - SANITY( streami ); + SANITY( source ); /* We have finished reading the header. We can discard the header bytes * we saved. */ - if( !streami->decode ) { - streami->decode = TRUE; - VIPS_FREEF( g_byte_array_unref, streami->header_bytes ); - VIPS_FREEF( g_byte_array_unref, streami->sniff ); + if( !source->decode ) { + source->decode = TRUE; + VIPS_FREEF( g_byte_array_unref, source->header_bytes ); + VIPS_FREEF( g_byte_array_unref, source->sniff ); } - vips_streami_minimise( streami ); + vips_source_minimise( source ); - SANITY( streami ); + SANITY( source ); return( 0 ); } /** - * vips_streami_read: - * @streami: input stream to operate on + * vips_source_read: + * @source: input stream to operate on * @buffer: store bytes here * @length: length of @buffer in bytes * - * Read up to @length bytes from @streami and store the bytes in @buffer. + * Read up to @length bytes from @source and store the bytes in @buffer. * Return the number of bytes actually read. If all bytes have been read from * the file, return 0. * @@ -627,32 +627,32 @@ vips_streami_decode( VipsStreami *streami ) * Returns: the number of bytes read, 0 on end of file, -1 on error. */ gint64 -vips_streami_read( VipsStreami *streami, void *buffer, size_t length ) +vips_source_read( VipsSource *source, void *buffer, size_t length ) { - VipsStreamiClass *class = VIPS_STREAMI_GET_CLASS( streami ); + VipsSourceClass *class = VIPS_SOURCE_GET_CLASS( source ); gint64 total_read; - VIPS_DEBUG_MSG( "vips_streami_read:\n" ); + VIPS_DEBUG_MSG( "vips_source_read:\n" ); - SANITY( streami ); + SANITY( source ); - if( vips_streami_unminimise( streami ) || - vips_streami_test_features( streami ) ) + if( vips_source_unminimise( source ) || + vips_source_test_features( source ) ) return( -1 ); total_read = 0; - if( streami->data ) { + if( source->data ) { /* The whole thing is in memory somehow. */ gint64 available = VIPS_MIN( length, - streami->length - streami->read_position ); + source->length - source->read_position ); VIPS_DEBUG_MSG( " %zd bytes from memory\n", available ); memcpy( buffer, - streami->data + streami->read_position, available ); - streami->read_position += available; + source->data + source->read_position, available ); + source->read_position += available; total_read += available; } else { @@ -661,19 +661,19 @@ vips_streami_read( VipsStreami *streami, void *buffer, size_t length ) * Get what we can from header_bytes. We may need to read * some more after this. */ - if( streami->header_bytes && - streami->read_position < streami->header_bytes->len ) { + if( source->header_bytes && + source->read_position < source->header_bytes->len ) { gint64 available = VIPS_MIN( length, - streami->header_bytes->len - - streami->read_position ); + source->header_bytes->len - + source->read_position ); VIPS_DEBUG_MSG( " %zd bytes from cache\n", available ); memcpy( buffer, - streami->header_bytes->data + - streami->read_position, + source->header_bytes->data + + source->read_position, available ); - streami->read_position += available; + source->read_position += available; buffer += available; length -= available; total_read += available; @@ -685,13 +685,13 @@ vips_streami_read( VipsStreami *streami, void *buffer, size_t length ) gint64 bytes_read; VIPS_DEBUG_MSG( " calling class->read()\n" ); - bytes_read = class->read( streami, buffer, length ); + bytes_read = class->read( source, buffer, length ); VIPS_DEBUG_MSG( " %zd bytes from read()\n", bytes_read ); if( bytes_read == -1 ) { vips_error_system( errno, - vips_stream_nick( - VIPS_STREAM( streami ) ), + vips_connection_nick( + VIPS_CONNECTION( source ) ), "%s", _( "read error" ) ); return( -1 ); } @@ -699,21 +699,21 @@ vips_streami_read( VipsStreami *streami, void *buffer, size_t length ) /* We need to save bytes if we're in header mode and * we can't seek or map. */ - if( streami->header_bytes && - streami->is_pipe && - !streami->decode && + if( source->header_bytes && + source->is_pipe && + !source->decode && bytes_read > 0 ) - g_byte_array_append( streami->header_bytes, + g_byte_array_append( source->header_bytes, buffer, bytes_read ); - streami->read_position += bytes_read; + source->read_position += bytes_read; total_read += bytes_read; } } VIPS_DEBUG_MSG( " %zd bytes total\n", total_read ); - SANITY( streami ); + SANITY( source ); return( total_read ); } @@ -729,48 +729,48 @@ static const int vips_pipe_read_limit = 1024 * 1024 * 1024; * read_position. */ static int -vips_streami_pipe_read_to_position( VipsStreami *streami, gint64 target ) +vips_source_pipe_read_to_position( VipsSource *source, gint64 target ) { gint64 old_read_position; unsigned char buffer[4096]; - VIPS_DEBUG_MSG( "vips_streami_pipe_read_position: %" G_GINT64_FORMAT + VIPS_DEBUG_MSG( "vips_source_pipe_read_position: %" G_GINT64_FORMAT "\n", target ); - g_assert( !streami->decode ); - g_assert( streami->header_bytes ); - g_assert( streami->is_pipe ); + g_assert( !source->decode ); + g_assert( source->header_bytes ); + g_assert( source->is_pipe ); if( target != -1 && (target < 0 || - (streami->length != -1 && - target > streami->length)) ) { - vips_error( vips_stream_nick( VIPS_STREAM( streami ) ), + (source->length != -1 && + target > source->length)) ) { + vips_error( vips_connection_nick( VIPS_CONNECTION( source ) ), _( "bad read to %" G_GINT64_FORMAT ), target ); return( -1 ); } - old_read_position = streami->read_position; + old_read_position = source->read_position; while( target == -1 || - streami->read_position < target ) { + source->read_position < target ) { gint64 bytes_read; - bytes_read = vips_streami_read( streami, buffer, 4096 ); + bytes_read = vips_source_read( source, buffer, 4096 ); if( bytes_read == -1 ) return( -1 ); if( bytes_read == 0 ) break; if( target == -1 && - streami->read_position > vips_pipe_read_limit ) { - vips_error( vips_stream_nick( VIPS_STREAM( streami ) ), + source->read_position > vips_pipe_read_limit ) { + vips_error( vips_connection_nick( VIPS_CONNECTION( source ) ), "%s", _( "pipe too long" ) ); return( -1 ); } } - streami->read_position = old_read_position; + source->read_position = old_read_position; return( 0 ); } @@ -779,37 +779,37 @@ vips_streami_pipe_read_to_position( VipsStreami *streami, gint64 target ) * seek method) into a memory source. */ static int -vips_streami_read_to_memory( VipsStreami *streami ) +vips_source_read_to_memory( VipsSource *source ) { GByteArray *byte_array; gint64 read_position; unsigned char *q; - VIPS_DEBUG_MSG( "vips_streami_read_to_memory:\n" ); + VIPS_DEBUG_MSG( "vips_source_read_to_memory:\n" ); - g_assert( !streami->is_pipe ); - g_assert( !streami->blob ); - g_assert( !streami->header_bytes ); - g_assert( streami->length >= 0 ); + g_assert( !source->is_pipe ); + g_assert( !source->blob ); + g_assert( !source->header_bytes ); + g_assert( source->length >= 0 ); - if( vips_streami_rewind( streami ) ) + if( vips_source_rewind( source ) ) return( -1 ); /* We know the length, so we can size the buffer correctly and read * directly to it. */ byte_array = g_byte_array_new(); - g_byte_array_set_size( byte_array, streami->length ); + g_byte_array_set_size( byte_array, source->length ); /* Read in a series of chunks to reduce stress upstream. */ read_position = 0; q = byte_array->data; - while( read_position < streami->length ) { + while( read_position < source->length ) { gint64 bytes_read; - bytes_read = vips_streami_read( streami, q, - VIPS_MAX( 4096, streami->length - read_position ) ); + bytes_read = vips_source_read( source, q, + VIPS_MAX( 4096, source->length - read_position ) ); if( bytes_read == -1 ) { VIPS_FREEF( g_byte_array_unref, byte_array ); return( -1 ); @@ -826,11 +826,11 @@ vips_streami_read_to_memory( VipsStreami *streami ) * We save byte_array in the header_bytes field to get it freed when * we are freed. */ - streami->data = byte_array->data; - streami->is_pipe = FALSE; - streami->header_bytes = byte_array; + source->data = byte_array->data; + source->is_pipe = FALSE; + source->header_bytes = byte_array; - vips_streami_minimise( streami ); + vips_source_minimise( source ); return( 0 ); } @@ -838,133 +838,133 @@ vips_streami_read_to_memory( VipsStreami *streami ) /* Read the entire pipe into memory and turn this into a memory source stream. */ static int -vips_streami_pipe_to_memory( VipsStreami *streami ) +vips_source_pipe_to_memory( VipsSource *source ) { - VIPS_DEBUG_MSG( "vips_streami_pipe_to_memory:\n" ); + VIPS_DEBUG_MSG( "vips_source_pipe_to_memory:\n" ); - g_assert( streami->is_pipe ); - g_assert( !streami->blob ); - g_assert( !streami->decode ); - g_assert( streami->header_bytes ); + g_assert( source->is_pipe ); + g_assert( !source->blob ); + g_assert( !source->decode ); + g_assert( source->header_bytes ); - if( vips_streami_pipe_read_to_position( streami, -1 ) ) + if( vips_source_pipe_read_to_position( source, -1 ) ) return( -1 ); /* Steal the header_bytes pointer and turn into a memory source. */ - streami->length = streami->header_bytes->len; - streami->data = streami->header_bytes->data; - streami->is_pipe = FALSE; + source->length = source->header_bytes->len; + source->data = source->header_bytes->data; + source->is_pipe = FALSE; /* TODO ... we could close more fds here. */ - vips_streami_minimise( streami ); + vips_source_minimise( source ); return( 0 ); } static int -vips_streami_descriptor_to_memory( VipsStreami *streami ) +vips_source_descriptor_to_memory( VipsSource *source ) { - VipsStream *stream = VIPS_STREAM( streami ); + VipsConnection *stream = VIPS_CONNECTION( source ); - VIPS_DEBUG_MSG( "vips_streami_descriptor_to_memory:\n" ); + VIPS_DEBUG_MSG( "vips_source_descriptor_to_memory:\n" ); - g_assert( !streami->blob ); - g_assert( !streami->mmap_baseaddr ); + g_assert( !source->blob ); + g_assert( !source->mmap_baseaddr ); - if( !(streami->mmap_baseaddr = vips__mmap( stream->descriptor, - FALSE, streami->length, 0 )) ) + if( !(source->mmap_baseaddr = vips__mmap( stream->descriptor, + FALSE, source->length, 0 )) ) return( -1 ); /* And it's now a memory source. */ - streami->data = streami->mmap_baseaddr; - streami->mmap_length = streami->length; + source->data = source->mmap_baseaddr; + source->mmap_length = source->length; return( 0 ); } /** - * vips_streami_is_mappable: - * @streami: input stream to operate on + * vips_source_is_mappable: + * @source: input stream to operate on * * Some streams can be efficiently mapped into memory. - * You can still use vips_streami_map() if this function returns %FALSE, + * 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. */ gboolean -vips_streami_is_mappable( VipsStreami *streami ) +vips_source_is_mappable( VipsSource *source ) { - if( vips_streami_unminimise( streami ) || - vips_streami_test_features( streami ) ) + if( vips_source_unminimise( source ) || + vips_source_test_features( source ) ) return( -1 ); /* Already a memory object, or there's a filename we can map, or * there's a seekable descriptor. */ - return( streami->data || - VIPS_STREAM( streami )->filename || - (!streami->is_pipe && - VIPS_STREAM( streami )->descriptor != -1) ); + return( source->data || + VIPS_CONNECTION( source )->filename || + (!source->is_pipe && + VIPS_CONNECTION( source )->descriptor != -1) ); } /** - * vips_streami_map: - * @streami: input stream to operate on + * vips_source_map: + * @source: input stream 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. * - * This operation can take a long time. Use vips_streami_is_mappable() to - * check if a streami can be mapped efficiently. + * This operation can take a long time. Use vips_source_is_mappable() to + * check if a source can be mapped efficiently. * - * The pointer is valid for as long as @streami is alive. + * The pointer is valid for as long as @source is alive. * * Returns: a pointer to the start of the file contents, or NULL on error. */ const void * -vips_streami_map( VipsStreami *streami, size_t *length_out ) +vips_source_map( VipsSource *source, size_t *length_out ) { - VIPS_DEBUG_MSG( "vips_streami_map:\n" ); + VIPS_DEBUG_MSG( "vips_source_map:\n" ); - SANITY( streami ); + SANITY( source ); - if( vips_streami_unminimise( streami ) || - vips_streami_test_features( streami ) ) + if( vips_source_unminimise( source ) || + vips_source_test_features( source ) ) return( NULL ); - if( !streami->data ) { + if( !source->data ) { /* Seekable descriptors can simply be mapped. Seekable sources * can be read. All other sources must be streamed into memory. */ - if( vips_streami_is_mappable( streami ) ) { - if( vips_streami_descriptor_to_memory( streami ) ) + if( vips_source_is_mappable( source ) ) { + if( vips_source_descriptor_to_memory( source ) ) return( NULL ); } - else if( !streami->is_pipe ) { - if( vips_streami_read_to_memory( streami ) ) + else if( !source->is_pipe ) { + if( vips_source_read_to_memory( source ) ) return( NULL ); } else { - if( vips_streami_pipe_to_memory( streami ) ) + if( vips_source_pipe_to_memory( source ) ) return( NULL ); } } if( length_out ) - *length_out = streami->length; + *length_out = source->length; - SANITY( streami ); + SANITY( source ); - return( streami->data ); + return( source->data ); } static int -vips_streami_map_cb( void *a, void *b ) +vips_source_map_cb( void *a, void *b ) { VipsArea *area = VIPS_AREA( b ); GObject *gobject = G_OBJECT( area->client ); @@ -975,36 +975,36 @@ vips_streami_map_cb( void *a, void *b ) } /** - * vips_streami_map_blob: - * @streami: input stream to operate on + * vips_source_map_blob: + * @source: input stream to operate on * - * Just like vips_streami_map(), but return a #VipsBlob containing the - * pointer. @streami will stay alive as long as the result is alive. + * Just like vips_source_map(), but return a #VipsBlob containing the + * pointer. @source will stay alive as long as the result is alive. * * Returns: a new #VipsBlob containing the data, or NULL on error. */ VipsBlob * -vips_streami_map_blob( VipsStreami *streami ) +vips_source_map_blob( VipsSource *source ) { const void *buf; size_t len; VipsBlob *blob; - if( !(buf = vips_streami_map( streami, &len )) || - !(blob = vips_blob_new( vips_streami_map_cb, buf, len )) ) + if( !(buf = vips_source_map( source, &len )) || + !(blob = vips_blob_new( vips_source_map_cb, buf, len )) ) return( NULL ); - /* The streami must stay alive until the blob is done. + /* The source must stay alive until the blob is done. */ - g_object_ref( streami ); - VIPS_AREA( blob )->client = streami; + g_object_ref( source ); + VIPS_AREA( blob )->client = source; return( blob ); } /** - * vips_streami_seek: - * @streami: input stream to operate on + * vips_source_seek: + * @source: input stream to operate on * @offset: seek by this offset * @whence: seek relative to this point * @@ -1014,88 +1014,88 @@ vips_streami_map_blob( VipsStreami *streami ) * Returns: the new file position, or -1 on error. */ gint64 -vips_streami_seek( VipsStreami *streami, gint64 offset, int whence ) +vips_source_seek( VipsSource *source, gint64 offset, int whence ) { - VipsStreamiClass *class = VIPS_STREAMI_GET_CLASS( streami ); + VipsSourceClass *class = VIPS_SOURCE_GET_CLASS( source ); gint64 new_pos; - VIPS_DEBUG_MSG( "vips_streami_seek: offset = %" G_GINT64_FORMAT + VIPS_DEBUG_MSG( "vips_source_seek: offset = %" G_GINT64_FORMAT ", whence = %d\n", offset, whence ); - if( vips_streami_unminimise( streami ) || - vips_streami_test_features( streami ) ) + if( vips_source_unminimise( source ) || + vips_source_test_features( source ) ) return( -1 ); - if( streami->data ) { + if( source->data ) { switch( whence ) { case SEEK_SET: new_pos = offset; break; case SEEK_CUR: - new_pos = streami->read_position + offset; + new_pos = source->read_position + offset; break; case SEEK_END: - new_pos = streami->length + offset; + new_pos = source->length + offset; break; default: - vips_error( vips_stream_nick( VIPS_STREAM( streami ) ), + vips_error( vips_connection_nick( VIPS_CONNECTION( source ) ), "%s", _( "bad 'whence'" ) ); return( -1 ); } } - else if( streami->is_pipe ) { + else if( source->is_pipe ) { switch( whence ) { case SEEK_SET: new_pos = offset; break; case SEEK_CUR: - new_pos = streami->read_position + offset; + new_pos = source->read_position + offset; break; case SEEK_END: /* We have to read the whole stream into memory to get * the length. */ - if( streami->length == -1 && - vips_streami_pipe_to_memory( streami ) ) + if( source->length == -1 && + vips_source_pipe_to_memory( source ) ) return( -1 ); - new_pos = streami->length + offset; + new_pos = source->length + offset; break; default: - vips_error( vips_stream_nick( VIPS_STREAM( streami ) ), + vips_error( vips_connection_nick( VIPS_CONNECTION( source ) ), "%s", _( "bad 'whence'" ) ); return( -1 ); } } else { - if( (new_pos = class->seek( streami, offset, whence )) == -1 ) + if( (new_pos = class->seek( source, offset, whence )) == -1 ) return( -1 ); } /* Don't allow out of range seeks. */ if( new_pos < 0 || - (streami->length != -1 && - new_pos > streami->length) ) { - vips_error( vips_stream_nick( VIPS_STREAM( streami ) ), + (source->length != -1 && + new_pos > source->length) ) { + vips_error( vips_connection_nick( VIPS_CONNECTION( source ) ), _( "bad seek to %" G_GINT64_FORMAT ), new_pos ); return( -1 ); } /* For pipes, we have to fake seek by reading to that point. */ - if( streami->is_pipe && - vips_streami_pipe_read_to_position( streami, new_pos ) ) + if( source->is_pipe && + vips_source_pipe_read_to_position( source, new_pos ) ) return( -1 ); - streami->read_position = new_pos; + source->read_position = new_pos; VIPS_DEBUG_MSG( " new_pos = %" G_GINT64_FORMAT "\n", new_pos ); @@ -1103,8 +1103,8 @@ vips_streami_seek( VipsStreami *streami, gint64 offset, int whence ) } /** - * vips_streami_rewind: - * @streami: input stream to operate on + * vips_source_rewind: + * @source: input stream to operate on * * Rewind the stream to the start. You can't do this after pixel decode phase * starts. @@ -1112,24 +1112,24 @@ vips_streami_seek( VipsStreami *streami, gint64 offset, int whence ) * Returns: 0 on success, or -1 on error. */ int -vips_streami_rewind( VipsStreami *streami ) +vips_source_rewind( VipsSource *source ) { - VIPS_DEBUG_MSG( "vips_streami_rewind:\n" ); + VIPS_DEBUG_MSG( "vips_source_rewind:\n" ); - SANITY( streami ); + SANITY( source ); - if( vips_streami_test_features( streami ) || - vips_streami_seek( streami, 0, SEEK_SET ) != 0 ) + if( vips_source_test_features( source ) || + vips_source_seek( source, 0, SEEK_SET ) != 0 ) return( -1 ); - SANITY( streami ); + SANITY( source ); return( 0 ); } /** - * vips_streami_length: - * @streami: input stream to operate on + * vips_source_length: + * @source: input stream to operate on * * Return the length in bytes of the stream object. Unseekable streams, for * example pipes, will have to be read entirely into memory before the length @@ -1138,26 +1138,26 @@ vips_streami_rewind( VipsStreami *streami ) * Returns: number of bytes in stream, or -1 on error. */ gint64 -vips_streami_length( VipsStreami *streami ) +vips_source_length( VipsSource *source ) { gint64 length; gint64 read_position; - VIPS_DEBUG_MSG( "vips_streami_length:\n" ); + VIPS_DEBUG_MSG( "vips_source_length:\n" ); - if( vips_streami_test_features( streami ) ) + if( vips_source_test_features( source ) ) return( -1 ); - read_position = vips_streami_seek( streami, 0, SEEK_CUR ); - length = vips_streami_seek( streami, 0, SEEK_END ); - vips_streami_seek( streami, read_position, SEEK_SET ); + read_position = vips_source_seek( source, 0, SEEK_CUR ); + length = vips_source_seek( source, 0, SEEK_END ); + vips_source_seek( source, read_position, SEEK_SET ); return( length ); } /** - * vips_streami_peek: - * @streami: peek this stream + * vips_source_peek: + * @source: peek this stream * @data: return a pointer to the bytes read here * @length: max number of bytes to read * @@ -1169,28 +1169,28 @@ vips_streami_length( VipsStreami *streami ) * Returns: number of bytes read, or -1 on error. */ size_t -vips_streami_sniff_at_most( VipsStreami *streami, +vips_source_sniff_at_most( VipsSource *source, unsigned char **data, size_t length ) { unsigned char *q; gint64 read_position; - VIPS_DEBUG_MSG( "vips_streami_sniff_at_most: %zd bytes\n", length ); + VIPS_DEBUG_MSG( "vips_source_sniff_at_most: %zd bytes\n", length ); - SANITY( streami ); + SANITY( source ); - if( vips_streami_test_features( streami ) || - vips_streami_rewind( streami ) ) + if( vips_source_test_features( source ) || + vips_source_rewind( source ) ) return( -1 ); - g_byte_array_set_size( streami->sniff, length ); + g_byte_array_set_size( source->sniff, length ); read_position = 0; - q = streami->sniff->data; + q = source->sniff->data; while( read_position < length ) { gint64 bytes_read; - bytes_read = vips_streami_read( streami, q, + bytes_read = vips_source_read( source, q, length - read_position ); if( bytes_read == -1 ) return( -1 ); @@ -1201,16 +1201,16 @@ vips_streami_sniff_at_most( VipsStreami *streami, q += bytes_read; } - SANITY( streami ); + SANITY( source ); - *data = streami->sniff->data; + *data = source->sniff->data; return( read_position ); } /** - * vips_streami_sniff: - * @streami: sniff this stream + * vips_source_sniff: + * @source: sniff this stream * @length: number of bytes to sniff * * Return a pointer to the first few bytes of the file. If the file is too @@ -1219,15 +1219,15 @@ vips_streami_sniff_at_most( VipsStreami *streami, * Returns: a pointer to the bytes at the start of the file, or NULL on error. */ unsigned char * -vips_streami_sniff( VipsStreami *streami, size_t length ) +vips_source_sniff( VipsSource *source, size_t length ) { unsigned char *data; size_t bytes_read; - if( vips_streami_test_features( streami ) ) + if( vips_source_test_features( source ) ) return( NULL ); - bytes_read = vips_streami_sniff_at_most( streami, &data, length ); + bytes_read = vips_source_sniff_at_most( source, &data, length ); if( bytes_read < length ) return( NULL ); diff --git a/libvips/iofuncs/streamiu.c b/libvips/iofuncs/sourcecustom.c similarity index 62% rename from libvips/iofuncs/streamiu.c rename to libvips/iofuncs/sourcecustom.c index e5711b05..1bfed8e6 100644 --- a/libvips/iofuncs/streamiu.c +++ b/libvips/iofuncs/sourcecustom.c @@ -58,7 +58,7 @@ #include "vipsmarshal.h" -G_DEFINE_TYPE( VipsStreamiu, vips_streamiu, VIPS_TYPE_STREAMI ); +G_DEFINE_TYPE( VipsSourceCustom, vips_source_custom, VIPS_TYPE_SOURCE ); /* Our signals. */ @@ -68,43 +68,43 @@ enum { SIG_LAST }; -static guint vips_streamiu_signals[SIG_LAST] = { 0 }; +static guint vips_source_custom_signals[SIG_LAST] = { 0 }; static gint64 -vips_streamiu_read_real( VipsStreami *streami, +vips_source_custom_read_real( VipsSource *source, void *buffer, size_t length ) { gint64 bytes_read; - VIPS_DEBUG_MSG( "vips_streamiu_read_real:\n" ); + VIPS_DEBUG_MSG( "vips_source_custom_read_real:\n" ); /* Return this value (error) if there's no attached handler. */ bytes_read = 0; - g_signal_emit( streami, vips_streamiu_signals[SIG_READ], 0, + g_signal_emit( source, vips_source_custom_signals[SIG_READ], 0, buffer, (gint64) length, &bytes_read ); - VIPS_DEBUG_MSG( " vips_streamiu_read_real, seen %zd bytes\n", + VIPS_DEBUG_MSG( " vips_source_custom_read_real, seen %zd bytes\n", bytes_read ); return( bytes_read ); } static gint64 -vips_streamiu_seek_real( VipsStreami *streami, +vips_source_custom_seek_real( VipsSource *source, gint64 offset, int whence ) { GValue args[3] = { { 0 } }; GValue result = { 0 }; gint64 new_position; - VIPS_DEBUG_MSG( "vips_streamiu_seek_real:\n" ); + VIPS_DEBUG_MSG( "vips_source_custom_seek_real:\n" ); /* Set the signal args. */ g_value_init( &args[0], G_TYPE_OBJECT ); - g_value_set_object( &args[0], streami ); + g_value_set_object( &args[0], source ); g_value_init( &args[1], G_TYPE_INT64 ); g_value_set_int64( &args[1], offset ); g_value_init( &args[2], G_TYPE_INT ); @@ -119,7 +119,7 @@ vips_streamiu_seek_real( VipsStreami *streami, * if no handlers are attached. */ g_signal_emitv( (const GValue *) &args, - vips_streamiu_signals[SIG_SEEK], 0, &result ); + vips_source_custom_signals[SIG_SEEK], 0, &result ); new_position = g_value_get_int64( &result ); @@ -128,48 +128,48 @@ vips_streamiu_seek_real( VipsStreami *streami, g_value_unset( &args[2] ); g_value_unset( &result ); - VIPS_DEBUG_MSG( " vips_streamiu_seek_real, seen new pos %zd\n", + VIPS_DEBUG_MSG( " vips_source_custom_seek_real, seen new pos %zd\n", new_position ); return( new_position ); } static gint64 -vips_streamiu_read_signal_real( VipsStreamiu *streamiu, +vips_source_custom_read_signal_real( VipsSourceCustom *source_custom, void *data, gint64 length ) { - VIPS_DEBUG_MSG( "vips_streamiu_read_signal_real:\n" ); + VIPS_DEBUG_MSG( "vips_source_custom_read_signal_real:\n" ); return( 0 ); } static gint64 -vips_streamiu_seek_signal_real( VipsStreamiu *streamiu, +vips_source_custom_seek_signal_real( VipsSourceCustom *source_custom, gint64 offset, int whence ) { - VIPS_DEBUG_MSG( "vips_streamiu_seek_signal_real:\n" ); + VIPS_DEBUG_MSG( "vips_source_custom_seek_signal_real:\n" ); return( -1 ); } static void -vips_streamiu_class_init( VipsStreamiuClass *class ) +vips_source_custom_class_init( VipsSourceCustomClass *class ) { VipsObjectClass *object_class = VIPS_OBJECT_CLASS( class ); - VipsStreamiClass *streami_class = VIPS_STREAMI_CLASS( class ); + VipsSourceClass *source_class = VIPS_SOURCE_CLASS( class ); - object_class->nickname = "streamiu"; + object_class->nickname = "source_custom"; object_class->description = _( "input stream" ); - streami_class->read = vips_streamiu_read_real; - streami_class->seek = vips_streamiu_seek_real; + source_class->read = vips_source_custom_read_real; + source_class->seek = vips_source_custom_seek_real; - class->read = vips_streamiu_read_signal_real; - class->seek = vips_streamiu_seek_signal_real; + class->read = vips_source_custom_read_signal_real; + class->seek = vips_source_custom_seek_signal_real; /** - * VipsStreamiu::read: - * @streamiu: the stream being operated on + * VipsSourceCustom::read: + * @source_custom: the stream being operated on * @buffer: %gpointer, buffer to fill * @size: %gint64, size of buffer * @@ -177,18 +177,18 @@ vips_streamiu_class_init( VipsStreamiuClass *class ) * * Returns: the number of bytes read. */ - vips_streamiu_signals[SIG_READ] = g_signal_new( "read", + vips_source_custom_signals[SIG_READ] = g_signal_new( "read", G_TYPE_FROM_CLASS( class ), G_SIGNAL_ACTION, - G_STRUCT_OFFSET( VipsStreamiuClass, read ), + G_STRUCT_OFFSET( VipsSourceCustomClass, read ), NULL, NULL, vips_INT64__POINTER_INT64, G_TYPE_INT64, 2, G_TYPE_POINTER, G_TYPE_INT64 ); /** - * VipsStreamiu::seek: - * @streamiu: the stream being operated on + * VipsSourceCustom::seek: + * @source_custom: the stream being operated on * @offset: %gint64, seek offset * @whence: %gint, seek origin * @@ -199,10 +199,10 @@ vips_streamiu_class_init( VipsStreamiuClass *class ) * * Returns: the new seek position. */ - vips_streamiu_signals[SIG_SEEK] = g_signal_new( "seek", + vips_source_custom_signals[SIG_SEEK] = g_signal_new( "seek", G_TYPE_FROM_CLASS( class ), G_SIGNAL_ACTION, - G_STRUCT_OFFSET( VipsStreamiuClass, seek ), + G_STRUCT_OFFSET( VipsSourceCustomClass, seek ), NULL, NULL, vips_INT64__INT64_INT, G_TYPE_INT64, 2, @@ -211,30 +211,30 @@ vips_streamiu_class_init( VipsStreamiuClass *class ) } static void -vips_streamiu_init( VipsStreamiu *streamiu ) +vips_source_custom_init( VipsSourceCustom *source_custom ) { } /** - * vips_streamiu_new: + * vips_source_custom_new: * - * Create a #VipsStreamiu. Attach signals to implement read and seek. + * Create a #VipsSourceCustom. Attach signals to implement read and seek. * - * Returns: a new #VipsStreamiu + * Returns: a new #VipsSourceCustom */ -VipsStreamiu * -vips_streamiu_new( void ) +VipsSourceCustom * +vips_source_custom_new( void ) { - VipsStreamiu *streamiu; + VipsSourceCustom *source_custom; - VIPS_DEBUG_MSG( "vips_streamiu_new:\n" ); + VIPS_DEBUG_MSG( "vips_source_custom_new:\n" ); - streamiu = VIPS_STREAMIU( g_object_new( VIPS_TYPE_STREAMIU, NULL ) ); + source_custom = VIPS_SOURCE_CUSTOM( g_object_new( VIPS_TYPE_SOURCE_CUSTOM, NULL ) ); - if( vips_object_build( VIPS_OBJECT( streamiu ) ) ) { - VIPS_UNREF( streamiu ); + if( vips_object_build( VIPS_OBJECT( source_custom ) ) ) { + VIPS_UNREF( source_custom ); return( NULL ); } - return( streamiu ); + return( source_custom ); } diff --git a/libvips/iofuncs/sourceuser.c b/libvips/iofuncs/sourceuser.c new file mode 100644 index 00000000..1bfed8e6 --- /dev/null +++ b/libvips/iofuncs/sourceuser.c @@ -0,0 +1,240 @@ +/* A Streami subclass with signals you can easily hook up to other input + * 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( VipsSourceCustom, vips_source_custom, VIPS_TYPE_SOURCE ); + +/* Our signals. + */ +enum { + SIG_SEEK, + SIG_READ, + SIG_LAST +}; + +static guint vips_source_custom_signals[SIG_LAST] = { 0 }; + +static gint64 +vips_source_custom_read_real( VipsSource *source, + void *buffer, size_t length ) +{ + gint64 bytes_read; + + VIPS_DEBUG_MSG( "vips_source_custom_read_real:\n" ); + + /* Return this value (error) if there's no attached handler. + */ + bytes_read = 0; + + g_signal_emit( source, vips_source_custom_signals[SIG_READ], 0, + buffer, (gint64) length, &bytes_read ); + + VIPS_DEBUG_MSG( " vips_source_custom_read_real, seen %zd bytes\n", + bytes_read ); + + return( bytes_read ); +} + +static gint64 +vips_source_custom_seek_real( VipsSource *source, + gint64 offset, int whence ) +{ + GValue args[3] = { { 0 } }; + GValue result = { 0 }; + gint64 new_position; + + VIPS_DEBUG_MSG( "vips_source_custom_seek_real:\n" ); + + /* Set the signal args. + */ + g_value_init( &args[0], G_TYPE_OBJECT ); + g_value_set_object( &args[0], source ); + g_value_init( &args[1], G_TYPE_INT64 ); + g_value_set_int64( &args[1], offset ); + g_value_init( &args[2], G_TYPE_INT ); + g_value_set_int( &args[2], whence ); + + /* Set the default value if no handlers are attached. + */ + g_value_init( &result, G_TYPE_INT64 ); + g_value_set_int64( &result, -1 ); + + /* We need to use this signal interface since we want a default value + * if no handlers are attached. + */ + g_signal_emitv( (const GValue *) &args, + vips_source_custom_signals[SIG_SEEK], 0, &result ); + + new_position = g_value_get_int64( &result ); + + g_value_unset( &args[0] ); + g_value_unset( &args[1] ); + g_value_unset( &args[2] ); + g_value_unset( &result ); + + VIPS_DEBUG_MSG( " vips_source_custom_seek_real, seen new pos %zd\n", + new_position ); + + return( new_position ); +} + +static gint64 +vips_source_custom_read_signal_real( VipsSourceCustom *source_custom, + void *data, gint64 length ) +{ + VIPS_DEBUG_MSG( "vips_source_custom_read_signal_real:\n" ); + + return( 0 ); +} + +static gint64 +vips_source_custom_seek_signal_real( VipsSourceCustom *source_custom, + gint64 offset, int whence ) +{ + VIPS_DEBUG_MSG( "vips_source_custom_seek_signal_real:\n" ); + + return( -1 ); +} + +static void +vips_source_custom_class_init( VipsSourceCustomClass *class ) +{ + VipsObjectClass *object_class = VIPS_OBJECT_CLASS( class ); + VipsSourceClass *source_class = VIPS_SOURCE_CLASS( class ); + + object_class->nickname = "source_custom"; + object_class->description = _( "input stream" ); + + source_class->read = vips_source_custom_read_real; + source_class->seek = vips_source_custom_seek_real; + + class->read = vips_source_custom_read_signal_real; + class->seek = vips_source_custom_seek_signal_real; + + /** + * VipsSourceCustom::read: + * @source_custom: the stream being operated on + * @buffer: %gpointer, buffer to fill + * @size: %gint64, size of buffer + * + * This signal is emitted to read bytes from the source into @buffer. + * + * Returns: the number of bytes read. + */ + vips_source_custom_signals[SIG_READ] = g_signal_new( "read", + G_TYPE_FROM_CLASS( class ), + G_SIGNAL_ACTION, + G_STRUCT_OFFSET( VipsSourceCustomClass, read ), + NULL, NULL, + vips_INT64__POINTER_INT64, + G_TYPE_INT64, 2, + G_TYPE_POINTER, G_TYPE_INT64 ); + + /** + * VipsSourceCustom::seek: + * @source_custom: the stream 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. + * + * The handler on an unseekable stream should always return -1. + * + * Returns: the new seek position. + */ + vips_source_custom_signals[SIG_SEEK] = g_signal_new( "seek", + G_TYPE_FROM_CLASS( class ), + G_SIGNAL_ACTION, + G_STRUCT_OFFSET( VipsSourceCustomClass, seek ), + NULL, NULL, + vips_INT64__INT64_INT, + G_TYPE_INT64, 2, + G_TYPE_INT64, G_TYPE_INT ); + +} + +static void +vips_source_custom_init( VipsSourceCustom *source_custom ) +{ +} + +/** + * vips_source_custom_new: + * + * Create a #VipsSourceCustom. Attach signals to implement read and seek. + * + * Returns: a new #VipsSourceCustom + */ +VipsSourceCustom * +vips_source_custom_new( void ) +{ + VipsSourceCustom *source_custom; + + VIPS_DEBUG_MSG( "vips_source_custom_new:\n" ); + + source_custom = VIPS_SOURCE_CUSTOM( g_object_new( VIPS_TYPE_SOURCE_CUSTOM, NULL ) ); + + if( vips_object_build( VIPS_OBJECT( source_custom ) ) ) { + VIPS_UNREF( source_custom ); + return( NULL ); + } + + return( source_custom ); +} diff --git a/libvips/iofuncs/streamo.c b/libvips/iofuncs/target.c similarity index 51% rename from libvips/iofuncs/streamo.c rename to libvips/iofuncs/target.c index 9cada27b..71bd0660 100644 --- a/libvips/iofuncs/streamo.c +++ b/libvips/iofuncs/target.c @@ -78,38 +78,38 @@ #define MODE_READWRITE BINARYIZE (O_RDWR) #define MODE_WRITE BINARYIZE (O_WRONLY | O_CREAT | O_TRUNC) -G_DEFINE_TYPE( VipsStreamo, vips_streamo, VIPS_TYPE_STREAM ); +G_DEFINE_TYPE( VipsTarget, vips_target, VIPS_TYPE_CONNECTION ); static void -vips_streamo_finalize( GObject *gobject ) +vips_target_finalize( GObject *gobject ) { - VipsStreamo *streamo = VIPS_STREAMO( gobject ); + VipsTarget *target = VIPS_TARGET( gobject ); - VIPS_DEBUG_MSG( "vips_streamo_finalize:\n" ); + VIPS_DEBUG_MSG( "vips_target_finalize:\n" ); - VIPS_FREEF( g_byte_array_unref, streamo->memory_buffer ); - if( streamo->blob ) { - vips_area_unref( VIPS_AREA( streamo->blob ) ); - streamo->blob = NULL; + VIPS_FREEF( g_byte_array_unref, target->memory_buffer ); + if( target->blob ) { + vips_area_unref( VIPS_AREA( target->blob ) ); + target->blob = NULL; } - G_OBJECT_CLASS( vips_streamo_parent_class )->finalize( gobject ); + G_OBJECT_CLASS( vips_target_parent_class )->finalize( gobject ); } static int -vips_streamo_build( VipsObject *object ) +vips_target_build( VipsObject *object ) { - VipsStream *stream = VIPS_STREAM( object ); - VipsStreamo *streamo = VIPS_STREAMO( object ); + VipsConnection *stream = VIPS_CONNECTION( object ); + VipsTarget *target = VIPS_TARGET( object ); - VIPS_DEBUG_MSG( "vips_streamo_build: %p\n", stream ); + VIPS_DEBUG_MSG( "vips_target_build: %p\n", stream ); - if( VIPS_OBJECT_CLASS( vips_streamo_parent_class )->build( object ) ) + 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_stream_nick( stream ), + vips_error( vips_connection_nick( stream ), "%s", _( "don't set 'filename' and 'descriptor'" ) ); return( -1 ); } @@ -123,7 +123,7 @@ vips_streamo_build( VipsObject *object ) */ if( (fd = vips_tracked_open( filename, MODE_WRITE, 0644 )) == -1 ) { - vips_error_system( errno, vips_stream_nick( stream ), + vips_error_system( errno, vips_connection_nick( stream ), "%s", _( "unable to open for write" ) ); return( -1 ); } @@ -135,52 +135,52 @@ vips_streamo_build( VipsObject *object ) stream->descriptor = dup( stream->descriptor ); stream->close_descriptor = stream->descriptor; } - else if( streamo->memory ) { - streamo->memory_buffer = g_byte_array_new(); + else if( target->memory ) { + target->memory_buffer = g_byte_array_new(); } return( 0 ); } static gint64 -vips_streamo_write_real( VipsStreamo *streamo, const void *data, size_t length ) +vips_target_write_real( VipsTarget *target, const void *data, size_t length ) { - VipsStream *stream = VIPS_STREAM( streamo ); + VipsConnection *stream = VIPS_CONNECTION( target ); - VIPS_DEBUG_MSG( "vips_streamo_write_real: %zd bytes\n", length ); + VIPS_DEBUG_MSG( "vips_target_write_real: %zd bytes\n", length ); return( write( stream->descriptor, data, length ) ); } static void -vips_streamo_finish_real( VipsStreamo *streamo ) +vips_target_finish_real( VipsTarget *target ) { - VIPS_DEBUG_MSG( "vips_streamo_finish_real:\n" ); + VIPS_DEBUG_MSG( "vips_target_finish_real:\n" ); } static void -vips_streamo_class_init( VipsStreamoClass *class ) +vips_target_class_init( VipsTargetClass *class ) { GObjectClass *gobject_class = G_OBJECT_CLASS( class ); VipsObjectClass *object_class = VIPS_OBJECT_CLASS( class ); - gobject_class->finalize = vips_streamo_finalize; + gobject_class->finalize = vips_target_finalize; gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property; - object_class->nickname = "streamo"; + object_class->nickname = "target"; object_class->description = _( "stream stream" ); - object_class->build = vips_streamo_build; + object_class->build = vips_target_build; - class->write = vips_streamo_write_real; - class->finish = vips_streamo_finish_real; + class->write = vips_target_write_real; + class->finish = vips_target_finish_real; VIPS_ARG_BOOL( class, "memory", 3, _( "Memory" ), _( "File descriptor should output to memory" ), VIPS_ARGUMENT_OPTIONAL_INPUT, - G_STRUCT_OFFSET( VipsStreamo, memory ), + G_STRUCT_OFFSET( VipsTarget, memory ), FALSE ); /* SET_ALWAYS means that blob is set by C and the obj system is not @@ -190,132 +190,132 @@ vips_streamo_class_init( VipsStreamoClass *class ) _( "Blob" ), _( "Blob to save to" ), VIPS_ARGUMENT_SET_ALWAYS, - G_STRUCT_OFFSET( VipsStreamo, blob ), + G_STRUCT_OFFSET( VipsTarget, blob ), VIPS_TYPE_BLOB ); } static void -vips_streamo_init( VipsStreamo *streamo ) +vips_target_init( VipsTarget *target ) { - streamo->blob = vips_blob_new( NULL, NULL, 0 ); - streamo->write_point = 0; + target->blob = vips_blob_new( NULL, NULL, 0 ); + target->write_point = 0; } /** - * vips_streamo_new_to_descriptor: + * 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 #VipsStreamo is finalized. + * @descriptor is kept open until the #VipsTarget is finalized. * - * See also: vips_streamo_new_to_file(). + * See also: vips_target_new_to_file(). * - * Returns: a new #VipsStreamo + * Returns: a new #VipsTarget */ -VipsStreamo * -vips_streamo_new_to_descriptor( int descriptor ) +VipsTarget * +vips_target_new_to_descriptor( int descriptor ) { - VipsStreamo *streamo; + VipsTarget *target; - VIPS_DEBUG_MSG( "vips_streamo_new_to_descriptor: %d\n", + VIPS_DEBUG_MSG( "vips_target_new_to_descriptor: %d\n", descriptor ); - streamo = VIPS_STREAMO( g_object_new( VIPS_TYPE_STREAMO, + target = VIPS_TARGET( g_object_new( VIPS_TYPE_TARGET, "descriptor", descriptor, NULL ) ); - if( vips_object_build( VIPS_OBJECT( streamo ) ) ) { - VIPS_UNREF( streamo ); + if( vips_object_build( VIPS_OBJECT( target ) ) ) { + VIPS_UNREF( target ); return( NULL ); } - return( streamo ); + return( target ); } /** - * vips_streamo_new_to_file: + * vips_target_new_to_file: * @filename: write to this file * * Create a stream attached to a file. * - * Returns: a new #VipsStreamo + * Returns: a new #VipsTarget */ -VipsStreamo * -vips_streamo_new_to_file( const char *filename ) +VipsTarget * +vips_target_new_to_file( const char *filename ) { - VipsStreamo *streamo; + VipsTarget *target; - VIPS_DEBUG_MSG( "vips_streamo_new_to_file: %s\n", + VIPS_DEBUG_MSG( "vips_target_new_to_file: %s\n", filename ); - streamo = VIPS_STREAMO( g_object_new( VIPS_TYPE_STREAMO, + target = VIPS_TARGET( g_object_new( VIPS_TYPE_TARGET, "filename", filename, NULL ) ); - if( vips_object_build( VIPS_OBJECT( streamo ) ) ) { - VIPS_UNREF( streamo ); + if( vips_object_build( VIPS_OBJECT( target ) ) ) { + VIPS_UNREF( target ); return( NULL ); } - return( streamo ); + return( target ); } /** - * vips_streamo_new_to_memory: + * vips_target_new_to_memory: * * Create a stream which will stream to a memory area. Read from @blob to get * memory. * - * See also: vips_streamo_new_to_file(). + * See also: vips_target_new_to_file(). * - * Returns: a new #VipsStream + * Returns: a new #VipsConnection */ -VipsStreamo * -vips_streamo_new_to_memory( void ) +VipsTarget * +vips_target_new_to_memory( void ) { - VipsStreamo *streamo; + VipsTarget *target; - VIPS_DEBUG_MSG( "vips_streamo_new_to_memory:\n" ); + VIPS_DEBUG_MSG( "vips_target_new_to_memory:\n" ); - streamo = VIPS_STREAMO( g_object_new( VIPS_TYPE_STREAMO, + target = VIPS_TARGET( g_object_new( VIPS_TYPE_TARGET, "memory", TRUE, NULL ) ); - if( vips_object_build( VIPS_OBJECT( streamo ) ) ) { - VIPS_UNREF( streamo ); + if( vips_object_build( VIPS_OBJECT( target ) ) ) { + VIPS_UNREF( target ); return( NULL ); } - return( streamo ); + return( target ); } static int -vips_streamo_write_unbuffered( VipsStreamo *streamo, +vips_target_write_unbuffered( VipsTarget *target, const void *data, size_t length ) { - VipsStreamoClass *class = VIPS_STREAMO_GET_CLASS( streamo ); + VipsTargetClass *class = VIPS_TARGET_GET_CLASS( target ); - VIPS_DEBUG_MSG( "vips_streamo_write_unbuffered:\n" ); + VIPS_DEBUG_MSG( "vips_target_write_unbuffered:\n" ); - if( streamo->finished ) + if( target->finished ) return( 0 ); - if( streamo->memory_buffer ) - g_byte_array_append( streamo->memory_buffer, data, length ); + if( target->memory_buffer ) + g_byte_array_append( target->memory_buffer, data, length ); else while( length > 0 ) { gint64 bytes_written; - bytes_written = class->write( streamo, data, length ); + bytes_written = class->write( target, 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_stream_nick( - VIPS_STREAM( streamo ) ), + vips_connection_nick( + VIPS_CONNECTION( target ) ), "%s", _( "write error" ) ); return( -1 ); } @@ -328,26 +328,26 @@ vips_streamo_write_unbuffered( VipsStreamo *streamo, } static int -vips_streamo_flush( VipsStreamo *streamo ) +vips_target_flush( VipsTarget *target ) { - g_assert( streamo->write_point >= 0 ); - g_assert( streamo->write_point <= VIPS_STREAMO_BUFFER_SIZE ); + g_assert( target->write_point >= 0 ); + g_assert( target->write_point <= VIPS_TARGET_BUFFER_SIZE ); - VIPS_DEBUG_MSG( "vips_streamo_flush:\n" ); + VIPS_DEBUG_MSG( "vips_target_flush:\n" ); - if( streamo->write_point > 0 ) { - if( vips_streamo_write_unbuffered( streamo, - streamo->output_buffer, streamo->write_point ) ) + if( target->write_point > 0 ) { + if( vips_target_write_unbuffered( target, + target->output_buffer, target->write_point ) ) return( -1 ); - streamo->write_point = 0; + target->write_point = 0; } return( 0 ); } /** - * vips_streamo_write: - * @streamo: output stream to operate on + * vips_target_write: + * @target: output stream to operate on * @buffer: bytes to write * @length: length of @buffer in bytes * @@ -356,183 +356,183 @@ vips_streamo_flush( VipsStreamo *streamo ) * Returns: 0 on success, -1 on error. */ int -vips_streamo_write( VipsStreamo *streamo, const void *buffer, size_t length ) +vips_target_write( VipsTarget *target, const void *buffer, size_t length ) { - VIPS_DEBUG_MSG( "vips_streamo_write: %zd bytes\n", length ); + VIPS_DEBUG_MSG( "vips_target_write: %zd bytes\n", length ); - if( length > VIPS_STREAMO_BUFFER_SIZE - streamo->write_point && - vips_streamo_flush( streamo ) ) + if( length > VIPS_TARGET_BUFFER_SIZE - target->write_point && + vips_target_flush( target ) ) return( -1 ); - if( length > VIPS_STREAMO_BUFFER_SIZE - streamo->write_point ) { + if( length > VIPS_TARGET_BUFFER_SIZE - target->write_point ) { /* Still too large? Do an unbuffered write. */ - if( vips_streamo_write_unbuffered( streamo, buffer, length ) ) + if( vips_target_write_unbuffered( target, buffer, length ) ) return( -1 ); } else { - memcpy( streamo->output_buffer + streamo->write_point, + memcpy( target->output_buffer + target->write_point, buffer, length ); - streamo->write_point += length; + target->write_point += length; } return( 0 ); } /** - * vips_streamo_finish: - * @streamo: output stream to operate on + * vips_target_finish: + * @target: 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 streamo has been finished, further writes will do nothing. + * After a target has been finished, further writes will do nothing. */ void -vips_streamo_finish( VipsStreamo *streamo ) +vips_target_finish( VipsTarget *target ) { - VipsStreamoClass *class = VIPS_STREAMO_GET_CLASS( streamo ); + VipsTargetClass *class = VIPS_TARGET_GET_CLASS( target ); - VIPS_DEBUG_MSG( "vips_streamo_finish:\n" ); + VIPS_DEBUG_MSG( "vips_target_finish:\n" ); - if( streamo->finished ) + if( target->finished ) return; - (void) vips_streamo_flush( streamo ); + (void) vips_target_flush( target ); /* Move the stream buffer into the blob so it can be read out. */ - if( streamo->memory_buffer ) { + if( target->memory_buffer ) { unsigned char *data; size_t length; - length = streamo->memory_buffer->len; - data = g_byte_array_free( streamo->memory_buffer, FALSE ); - streamo->memory_buffer = NULL; - vips_blob_set( streamo->blob, + length = target->memory_buffer->len; + data = g_byte_array_free( target->memory_buffer, FALSE ); + target->memory_buffer = NULL; + vips_blob_set( target->blob, (VipsCallbackFn) g_free, data, length ); } else - class->finish( streamo ); + class->finish( target ); - streamo->finished = TRUE; + target->finished = TRUE; } /** - * vips_streamo_steal: - * @streamo: output stream to operate on + * vips_target_steal: + * @target: output stream to operate on * @length: return number of bytes of data * - * Memory streams only (see vips_streamo_new_to_memory()). Steal all data + * Memory streams only (see vips_target_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_streamo_putc() a '\0' + * The data is NOT automatically null-terminated. vips_target_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_streamo_steal( VipsStreamo *streamo, size_t *length ) +vips_target_steal( VipsTarget *target, size_t *length ) { unsigned char *data; - (void) vips_streamo_flush( streamo ); + (void) vips_target_flush( target ); - if( !streamo->memory_buffer || - streamo->finished ) { + if( !target->memory_buffer || + target->finished ) { if( length ) - *length = streamo->memory_buffer->len; + *length = target->memory_buffer->len; return( NULL ); } if( length ) - *length = streamo->memory_buffer->len; - data = g_byte_array_free( streamo->memory_buffer, FALSE ); - streamo->memory_buffer = NULL; + *length = target->memory_buffer->len; + data = g_byte_array_free( target->memory_buffer, FALSE ); + target->memory_buffer = NULL; /* We must have a valid byte array or finish will fail. */ - streamo->memory_buffer = g_byte_array_new(); + target->memory_buffer = g_byte_array_new(); - vips_streamo_finish( streamo ); + vips_target_finish( target ); return( data ); } /** - * vips_streamo_steal_text: - * @streamo: output stream to operate on + * vips_target_steal_text: + * @target: output stream to operate on * - * As vips_streamo_steal_text(), but return a null-terminated string. + * As vips_target_steal_text(), but return a null-terminated string. * * Returns: (transfer full): stream contents as a null-terminated string. */ char * -vips_streamo_steal_text( VipsStreamo *streamo ) +vips_target_steal_text( VipsTarget *target ) { - vips_streamo_putc( streamo, '\0' ); + vips_target_putc( target, '\0' ); - return( (char *) vips_streamo_steal( streamo, NULL ) ); + return( (char *) vips_target_steal( target, NULL ) ); } /** - * vips_streamo_putc: - * @streamo: output stream to operate on + * vips_target_putc: + * @target: output stream to operate on * @ch: character to write * - * Write a single character @ch to @streamo. See the macro VIPS_STREAMO_PUTC() + * Write a single character @ch to @target. See the macro VIPS_TARGET_PUTC() * for a faster way to do this. * * Returns: 0 on success, -1 on error. */ int -vips_streamo_putc( VipsStreamo *streamo, int ch ) +vips_target_putc( VipsTarget *target, int ch ) { - VIPS_DEBUG_MSG( "vips_streamo_putc: %d\n", ch ); + VIPS_DEBUG_MSG( "vips_target_putc: %d\n", ch ); - if( streamo->write_point >= VIPS_STREAMO_BUFFER_SIZE && - vips_streamo_flush( streamo ) ) + if( target->write_point >= VIPS_TARGET_BUFFER_SIZE && + vips_target_flush( target ) ) return( -1 ); - streamo->output_buffer[streamo->write_point++] = ch; + target->output_buffer[target->write_point++] = ch; return( 0 ); } /** - * vips_streamo_writes: - * @streamo: output stream to operate on + * vips_target_writes: + * @target: output stream to operate on * @str: string to write * - * Write a null-terminated string to @streamo. + * Write a null-terminated string to @target. * * Returns: 0 on success, and -1 on error. */ int -vips_streamo_writes( VipsStreamo *streamo, const char *str ) +vips_target_writes( VipsTarget *target, const char *str ) { - return( vips_streamo_write( streamo, + return( vips_target_write( target, (unsigned char *) str, strlen( str ) ) ); } /** - * vips_streamo_writef: - * @streamo: output stream to operate on + * vips_target_writef: + * @target: output stream to operate on * @fmt: printf()-style format string * @...: arguments to format string * - * Format the string and write to @streamo. + * Format the string and write to @target. * * Returns: 0 on success, and -1 on error. */ int -vips_streamo_writef( VipsStreamo *streamo, const char *fmt, ... ) +vips_target_writef( VipsTarget *target, const char *fmt, ... ) { va_list ap; char *line; @@ -542,7 +542,7 @@ vips_streamo_writef( VipsStreamo *streamo, const char *fmt, ... ) line = g_strdup_vprintf( fmt, ap ); va_end( ap ); - result = vips_streamo_writes( streamo, line ); + result = vips_target_writes( target, line ); g_free( line ); @@ -550,11 +550,11 @@ vips_streamo_writef( VipsStreamo *streamo, const char *fmt, ... ) } /** - * vips_streamo_write_amp: - * @streamo: output stream to operate on + * vips_target_write_amp: + * @target: output stream to operate on * @str: string to write * - * Write @str to @streamo, but escape stuff that xml hates in text. Our + * Write @str to @target, but escape stuff that xml hates in text. Our * argument string is utf-8. * * XML rules: @@ -566,7 +566,7 @@ vips_streamo_writef( VipsStreamo *streamo, const char *fmt, ... ) * Returns: 0 on success, -1 on error. */ int -vips_streamo_write_amp( VipsStreamo *streamo, const char *str ) +vips_target_write_amp( VipsTarget *target, const char *str ) { const char *p; @@ -583,24 +583,24 @@ vips_streamo_write_amp( VipsStreamo *streamo, const char *str ) * control characters, so we can use them -- thanks * electroly. */ - if( vips_streamo_writef( streamo, + if( vips_target_writef( target, "&#x%04x;", 0x2400 + *p ) ) return( -1 ); } else if( *p == '<' ) { - if( vips_streamo_writes( streamo, "<" ) ) + if( vips_target_writes( target, "<" ) ) return( -1 ); } else if( *p == '>' ) { - if( vips_streamo_writes( streamo, ">" ) ) + if( vips_target_writes( target, ">" ) ) return( -1 ); } else if( *p == '&' ) { - if( vips_streamo_writes( streamo, "&" ) ) + if( vips_target_writes( target, "&" ) ) return( -1 ); } else { - if( VIPS_STREAMO_PUTC( streamo, *p ) ) + if( VIPS_TARGET_PUTC( target, *p ) ) return( -1 ); } diff --git a/libvips/iofuncs/streamou.c b/libvips/iofuncs/targetuser.c similarity index 56% rename from libvips/iofuncs/streamou.c rename to libvips/iofuncs/targetuser.c index 8fd28c66..26b6bea4 100644 --- a/libvips/iofuncs/streamou.c +++ b/libvips/iofuncs/targetuser.c @@ -58,7 +58,7 @@ #include "vipsmarshal.h" -G_DEFINE_TYPE( VipsStreamou, vips_streamou, VIPS_TYPE_STREAMO ); +G_DEFINE_TYPE( VipsTargetCustom, vips_target_custom, VIPS_TYPE_TARGET ); /* Our signals. */ @@ -68,21 +68,21 @@ enum { SIG_LAST }; -static guint vips_streamou_signals[SIG_LAST] = { 0 }; +static guint vips_target_custom_signals[SIG_LAST] = { 0 }; static gint64 -vips_streamou_write_real( VipsStreamo *streamo, +vips_target_custom_write_real( VipsTarget *target, const void *data, size_t length ) { gint64 bytes_written; - VIPS_DEBUG_MSG( "vips_streamou_write_real:\n" ); + VIPS_DEBUG_MSG( "vips_target_custom_write_real:\n" ); /* Return value if no attached handler. */ bytes_written = 0; - g_signal_emit( streamo, vips_streamou_signals[SIG_WRITE], 0, + g_signal_emit( target, vips_target_custom_signals[SIG_WRITE], 0, data, (gint64) length, &bytes_written ); VIPS_DEBUG_MSG( " %zd\n", bytes_written ); @@ -91,46 +91,46 @@ vips_streamou_write_real( VipsStreamo *streamo, } static void -vips_streamou_finish_real( VipsStreamo *streamo ) +vips_target_custom_finish_real( VipsTarget *target ) { - VIPS_DEBUG_MSG( "vips_streamou_seek_real:\n" ); + VIPS_DEBUG_MSG( "vips_target_custom_seek_real:\n" ); - g_signal_emit( streamo, vips_streamou_signals[SIG_FINISH], 0 ); + g_signal_emit( target, vips_target_custom_signals[SIG_FINISH], 0 ); } static gint64 -vips_streamou_write_signal_real( VipsStreamou *streamou, +vips_target_custom_write_signal_real( VipsTargetCustom *target_custom, const void *data, gint64 length ) { - VIPS_DEBUG_MSG( "vips_streamou_write_signal_real:\n" ); + VIPS_DEBUG_MSG( "vips_target_custom_write_signal_real:\n" ); return( 0 ); } static void -vips_streamou_finish_signal_real( VipsStreamou *streamou ) +vips_target_custom_finish_signal_real( VipsTargetCustom *target_custom ) { - VIPS_DEBUG_MSG( "vips_streamou_finish_signal_real:\n" ); + VIPS_DEBUG_MSG( "vips_target_custom_finish_signal_real:\n" ); } static void -vips_streamou_class_init( VipsStreamouClass *class ) +vips_target_custom_class_init( VipsTargetCustomClass *class ) { VipsObjectClass *object_class = VIPS_OBJECT_CLASS( class ); - VipsStreamoClass *streamo_class = VIPS_STREAMO_CLASS( class ); + VipsTargetClass *target_class = VIPS_TARGET_CLASS( class ); - object_class->nickname = "streamou"; + object_class->nickname = "target_custom"; object_class->description = _( "input stream" ); - streamo_class->write = vips_streamou_write_real; - streamo_class->finish = vips_streamou_finish_real; + target_class->write = vips_target_custom_write_real; + target_class->finish = vips_target_custom_finish_real; - class->write = vips_streamou_write_signal_real; - class->finish = vips_streamou_finish_signal_real; + class->write = vips_target_custom_write_signal_real; + class->finish = vips_target_custom_finish_signal_real; /** - * VipsStreamou::write: - * @streamou: the stream being operated on + * VipsTargetCustom::write: + * @target_custom: the stream being operated on * @data: %pointer, bytes to write * @length: %gint64, number of bytes * @@ -138,26 +138,26 @@ vips_streamou_class_init( VipsStreamouClass *class ) * * Returns: the number of bytes written. */ - vips_streamou_signals[SIG_WRITE] = g_signal_new( "write", + vips_target_custom_signals[SIG_WRITE] = g_signal_new( "write", G_TYPE_FROM_CLASS( class ), G_SIGNAL_ACTION, - G_STRUCT_OFFSET( VipsStreamouClass, write ), + G_STRUCT_OFFSET( VipsTargetCustomClass, write ), NULL, NULL, vips_INT64__POINTER_INT64, G_TYPE_INT64, 2, G_TYPE_POINTER, G_TYPE_INT64 ); /** - * VipsStreamou::finish: - * @streamou: the stream being operated on + * VipsTargetCustom::finish: + * @target_custom: the stream being operated on * * This signal is emitted at the end of write. The stream should do * any finishing necessary. */ - vips_streamou_signals[SIG_FINISH] = g_signal_new( "finish", + vips_target_custom_signals[SIG_FINISH] = g_signal_new( "finish", G_TYPE_FROM_CLASS( class ), G_SIGNAL_ACTION, - G_STRUCT_OFFSET( VipsStreamouClass, finish ), + G_STRUCT_OFFSET( VipsTargetCustomClass, finish ), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0 ); @@ -165,30 +165,30 @@ vips_streamou_class_init( VipsStreamouClass *class ) } static void -vips_streamou_init( VipsStreamou *streamou ) +vips_target_custom_init( VipsTargetCustom *target_custom ) { } /** - * vips_streamou_new: + * vips_target_custom_new: * - * Create a #VipsStreamou. Attach signals to implement write and finish. + * Create a #VipsTargetCustom. Attach signals to implement write and finish. * - * Returns: a new #VipsStreamou + * Returns: a new #VipsTargetCustom */ -VipsStreamou * -vips_streamou_new( void ) +VipsTargetCustom * +vips_target_custom_new( void ) { - VipsStreamou *streamou; + VipsTargetCustom *target_custom; - VIPS_DEBUG_MSG( "vips_streamou_new:\n" ); + VIPS_DEBUG_MSG( "vips_target_custom_new:\n" ); - streamou = VIPS_STREAMOU( g_object_new( VIPS_TYPE_STREAMOU, NULL ) ); + target_custom = VIPS_TARGET_CUSTOM( g_object_new( VIPS_TYPE_TARGET_CUSTOM, NULL ) ); - if( vips_object_build( VIPS_OBJECT( streamou ) ) ) { - VIPS_UNREF( streamou ); + if( vips_object_build( VIPS_OBJECT( target_custom ) ) ) { + VIPS_UNREF( target_custom ); return( NULL ); } - return( streamou ); + return( target_custom ); } diff --git a/libvips/iofuncs/vips.c b/libvips/iofuncs/vips.c index 3bca6571..b7b62ef8 100644 --- a/libvips/iofuncs/vips.c +++ b/libvips/iofuncs/vips.c @@ -813,7 +813,7 @@ vips__write_extension_block( VipsImage *im, void *buf, int size ) /* Append a string to a buffer, but escape " as \". */ static void -streamo_write_quotes( VipsStreamo *streamo, const char *str ) +target_write_quotes( VipsTarget *target, const char *str ) { const char *p; size_t len; @@ -821,14 +821,14 @@ streamo_write_quotes( VipsStreamo *streamo, const char *str ) for( p = str; *p; p += len ) { len = strcspn( p, "\"" ); - vips_streamo_write( streamo, (unsigned char *) p, len ); + vips_target_write( target, (unsigned char *) p, len ); if( p[len] == '"' ) - vips_streamo_writes( streamo, "\\" ); + vips_target_writes( target, "\\" ); } } static void * -build_xml_meta( VipsMeta *meta, VipsStreamo *streamo ) +build_xml_meta( VipsMeta *meta, VipsTarget *target ) { GType type = G_VALUE_TYPE( &meta->value ); @@ -853,13 +853,13 @@ build_xml_meta( VipsMeta *meta, VipsStreamo *streamo ) */ str = vips_value_get_save_string( &save_value ); if( g_utf8_validate( str, -1, NULL ) ) { - vips_streamo_writef( streamo, + vips_target_writef( target, " name ); - vips_streamo_writes( streamo, "\">" ); - vips_streamo_write_amp( streamo, str ); - vips_streamo_writes( streamo, "\n" ); + target_write_quotes( target, meta->name ); + vips_target_writes( target, "\">" ); + vips_target_write_amp( target, str ); + vips_target_writes( target, "\n" ); } g_value_unset( &save_value ); @@ -873,42 +873,42 @@ build_xml_meta( VipsMeta *meta, VipsStreamo *streamo ) static char * build_xml( VipsImage *image ) { - VipsStreamo *streamo; + VipsTarget *target; const char *str; char *result; - streamo = vips_streamo_new_to_memory(); + target = vips_target_new_to_memory(); - vips_streamo_writef( streamo, "\n" ); - vips_streamo_writef( streamo, "\n", + vips_target_writef( target, "\n" ); + vips_target_writef( target, "\n", NAMESPACE_URI, VIPS_MAJOR_VERSION, VIPS_MINOR_VERSION, VIPS_MICRO_VERSION ); - vips_streamo_writef( streamo, "
\n" ); + vips_target_writef( target, "
\n" ); str = vips_image_get_history( image ); if( g_utf8_validate( str, -1, NULL ) ) { - vips_streamo_writef( streamo, + vips_target_writef( target, " ", g_type_name( VIPS_TYPE_REF_STRING ) ); - vips_streamo_write_amp( streamo, str ); - vips_streamo_writef( streamo, "\n" ); + vips_target_write_amp( target, str ); + vips_target_writef( target, "\n" ); } - vips_streamo_writef( streamo, "
\n" ); - vips_streamo_writef( streamo, " \n" ); + vips_target_writef( target, "
\n" ); + vips_target_writef( target, " \n" ); if( vips_slist_map2( image->meta_traverse, - (VipsSListMap2Fn) build_xml_meta, streamo, NULL ) ) { - VIPS_UNREF( streamo ); + (VipsSListMap2Fn) build_xml_meta, target, NULL ) ) { + VIPS_UNREF( target ); return( NULL ); } - vips_streamo_writef( streamo, " \n" ); - vips_streamo_writef( streamo, "
\n" ); + vips_target_writef( target, " \n" ); + vips_target_writef( target, "
\n" ); - result = vips_streamo_steal_text( streamo ); + result = vips_target_steal_text( target ); - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( result ); } @@ -917,7 +917,7 @@ static void * vips__xml_properties_meta( VipsImage *image, const char *field, GValue *value, void *a ) { - VipsStreamo *streamo = (VipsStreamo *) a; + VipsTarget *target = (VipsTarget *) a; GType type = G_VALUE_TYPE( value ); const char *str; @@ -933,19 +933,19 @@ vips__xml_properties_meta( VipsImage *image, if( !g_value_transform( value, &save_value ) ) { vips_error( "VipsImage", "%s", _( "error transforming to save format" ) ); - return( streamo ); + return( target ); } str = vips_value_get_save_string( &save_value ); - vips_streamo_writef( streamo, " \n" ); - vips_streamo_writef( streamo, " " ); - vips_streamo_write_amp( streamo, field ); - vips_streamo_writef( streamo, "\n" ); - vips_streamo_writef( streamo, " ", + vips_target_writef( target, " \n" ); + vips_target_writef( target, " " ); + vips_target_write_amp( target, field ); + vips_target_writef( target, "\n" ); + vips_target_writef( target, " ", g_type_name( type ) ); - vips_streamo_write_amp( streamo, str ); - vips_streamo_writef( streamo, "\n" ); - vips_streamo_writef( streamo, " \n" ); + vips_target_write_amp( target, str ); + vips_target_writef( target, "\n" ); + vips_target_writef( target, " \n" ); g_value_unset( &save_value ); } @@ -959,34 +959,34 @@ vips__xml_properties_meta( VipsImage *image, char * vips__xml_properties( VipsImage *image ) { - VipsStreamo *streamo; + VipsTarget *target; char *date; char *result; date = vips__get_iso8601(); - streamo = vips_streamo_new_to_memory(); - vips_streamo_writef( streamo, "\n" ); - vips_streamo_writef( streamo, "\n" ); + vips_target_writef( target, "\n", NAMESPACE_URI, date, VIPS_MAJOR_VERSION, VIPS_MINOR_VERSION, VIPS_MICRO_VERSION ); - vips_streamo_writef( streamo, " \n" ); + vips_target_writef( target, " \n" ); g_free( date ); - if( vips_image_map( image, vips__xml_properties_meta, streamo ) ) { - VIPS_UNREF( streamo ); + if( vips_image_map( image, vips__xml_properties_meta, target ) ) { + VIPS_UNREF( target ); return( NULL ); } - vips_streamo_writef( streamo, " \n" ); - vips_streamo_writef( streamo, "\n" ); + vips_target_writef( target, " \n" ); + vips_target_writef( target, "\n" ); - result = vips_streamo_steal_text( streamo ); + result = vips_target_steal_text( target ); - VIPS_UNREF( streamo ); + VIPS_UNREF( target ); return( result ); } diff --git a/libvips/resample/resample.c b/libvips/resample/resample.c index 628ce572..fd7bd783 100644 --- a/libvips/resample/resample.c +++ b/libvips/resample/resample.c @@ -157,7 +157,7 @@ vips_resample_operation_init( void ) extern GType vips_thumbnail_file_get_type( void ); extern GType vips_thumbnail_buffer_get_type( void ); extern GType vips_thumbnail_image_get_type( void ); - extern GType vips_thumbnail_stream_get_type( void ); + extern GType vips_thumbnail_source_get_type( void ); extern GType vips_mapim_get_type( void ); extern GType vips_shrink_get_type( void ); extern GType vips_shrinkh_get_type( void ); @@ -174,7 +174,7 @@ vips_resample_operation_init( void ) vips_thumbnail_file_get_type(); vips_thumbnail_buffer_get_type(); vips_thumbnail_image_get_type(); - vips_thumbnail_stream_get_type(); + vips_thumbnail_source_get_type(); vips_mapim_get_type(); vips_shrink_get_type(); vips_shrinkh_get_type(); diff --git a/libvips/resample/thumbnail.c b/libvips/resample/thumbnail.c index 00c82627..be187fb8 100644 --- a/libvips/resample/thumbnail.c +++ b/libvips/resample/thumbnail.c @@ -1257,19 +1257,19 @@ vips_thumbnail_buffer( void *buf, size_t len, VipsImage **out, int width, ... ) typedef struct _VipsThumbnailStream { VipsThumbnail parent_object; - VipsStreami *streami; + VipsSource *source; char *option_string; } VipsThumbnailStream; typedef VipsThumbnailClass VipsThumbnailStreamClass; -G_DEFINE_TYPE( VipsThumbnailStream, vips_thumbnail_stream, +G_DEFINE_TYPE( VipsThumbnailStream, vips_thumbnail_source, vips_thumbnail_get_type() ); /* Get the info from a stream. */ static int -vips_thumbnail_stream_get_info( VipsThumbnail *thumbnail ) +vips_thumbnail_source_get_info( VipsThumbnail *thumbnail ) { VipsThumbnailStream *stream = (VipsThumbnailStream *) thumbnail; @@ -1277,9 +1277,9 @@ vips_thumbnail_stream_get_info( VipsThumbnail *thumbnail ) g_info( "thumbnailing stream" ); - if( !(thumbnail->loader = vips_foreign_find_load_stream( - stream->streami )) || - !(image = vips_image_new_from_stream( stream->streami, + if( !(thumbnail->loader = vips_foreign_find_load_source( + stream->source )) || + !(image = vips_image_new_from_source( stream->source, stream->option_string, NULL )) ) return( -1 ); @@ -1293,13 +1293,13 @@ vips_thumbnail_stream_get_info( VipsThumbnail *thumbnail ) /* Open an image, scaling as appropriate. */ static VipsImage * -vips_thumbnail_stream_open( VipsThumbnail *thumbnail, double factor ) +vips_thumbnail_source_open( VipsThumbnail *thumbnail, double factor ) { VipsThumbnailStream *stream = (VipsThumbnailStream *) thumbnail; if( vips_isprefix( "VipsForeignLoadJpeg", thumbnail->loader ) ) { - return( vips_image_new_from_stream( - stream->streami, + return( vips_image_new_from_source( + stream->source, stream->option_string, "access", VIPS_ACCESS_SEQUENTIAL, "shrink", (int) factor, @@ -1307,8 +1307,8 @@ vips_thumbnail_stream_open( VipsThumbnail *thumbnail, double factor ) } else if( vips_isprefix( "VipsForeignLoadOpenslide", thumbnail->loader ) ) { - return( vips_image_new_from_stream( - stream->streami, + return( vips_image_new_from_source( + stream->source, stream->option_string, "access", VIPS_ACCESS_SEQUENTIAL, "level", (int) factor, @@ -1317,32 +1317,32 @@ vips_thumbnail_stream_open( VipsThumbnail *thumbnail, double factor ) else if( vips_isprefix( "VipsForeignLoadPdf", thumbnail->loader ) || vips_isprefix( "VipsForeignLoadSvg", thumbnail->loader ) || vips_isprefix( "VipsForeignLoadWebp", thumbnail->loader ) ) { - return( vips_image_new_from_stream( - stream->streami, + return( vips_image_new_from_source( + stream->source, stream->option_string, "access", VIPS_ACCESS_SEQUENTIAL, "scale", 1.0 / factor, NULL ) ); } else if( vips_isprefix( "VipsForeignLoadTiff", thumbnail->loader ) ) { - return( vips_image_new_from_stream( - stream->streami, + return( vips_image_new_from_source( + stream->source, stream->option_string, "access", VIPS_ACCESS_SEQUENTIAL, "page", (int) factor, NULL ) ); } else if( vips_isprefix( "VipsForeignLoadHeif", thumbnail->loader ) ) { - return( vips_image_new_from_stream( - stream->streami, + return( vips_image_new_from_source( + stream->source, stream->option_string, "access", VIPS_ACCESS_SEQUENTIAL, "thumbnail", (int) factor, NULL ) ); } else { - return( vips_image_new_from_stream( - stream->streami, + return( vips_image_new_from_source( + stream->source, stream->option_string, "access", VIPS_ACCESS_SEQUENTIAL, NULL ) ); @@ -1350,7 +1350,7 @@ vips_thumbnail_stream_open( VipsThumbnail *thumbnail, double factor ) } static void -vips_thumbnail_stream_class_init( VipsThumbnailClass *class ) +vips_thumbnail_source_class_init( VipsThumbnailClass *class ) { GObjectClass *gobject_class = G_OBJECT_CLASS( class ); VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class ); @@ -1362,15 +1362,15 @@ vips_thumbnail_stream_class_init( VipsThumbnailClass *class ) vobject_class->nickname = "thumbnail_stream"; vobject_class->description = _( "generate thumbnail from stream" ); - thumbnail_class->get_info = vips_thumbnail_stream_get_info; - thumbnail_class->open = vips_thumbnail_stream_open; + thumbnail_class->get_info = vips_thumbnail_source_get_info; + thumbnail_class->open = vips_thumbnail_source_open; - VIPS_ARG_OBJECT( class, "streami", 1, + VIPS_ARG_OBJECT( class, "source", 1, _( "Streami" ), _( "Stream to load from" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsThumbnailStream, streami ), - VIPS_TYPE_STREAMI ); + G_STRUCT_OFFSET( VipsThumbnailStream, source ), + VIPS_TYPE_SOURCE ); VIPS_ARG_STRING( class, "option_string", 20, _( "Extra options" ), @@ -1382,13 +1382,13 @@ vips_thumbnail_stream_class_init( VipsThumbnailClass *class ) } static void -vips_thumbnail_stream_init( VipsThumbnailStream *stream ) +vips_thumbnail_source_init( VipsThumbnailStream *stream ) { } /** - * vips_thumbnail_stream: - * @streami: stream to thumbnail + * vips_thumbnail_source: + * @source: stream to thumbnail * @out: (out): output image * @width: target width in pixels * @...: %NULL-terminated list of optional named arguments @@ -1411,13 +1411,13 @@ vips_thumbnail_stream_init( VipsThumbnailStream *stream ) * Returns: 0 on success, -1 on error. */ int -vips_thumbnail_stream( VipsStreami *streami, VipsImage **out, int width, ... ) +vips_thumbnail_source( VipsSource *source, VipsImage **out, int width, ... ) { va_list ap; int result; va_start( ap, width ); - result = vips_call_split( "thumbnail_stream", ap, streami, out, width ); + result = vips_call_split( "thumbnail_stream", ap, source, out, width ); va_end( ap ); return( result ); diff --git a/test/Makefile.am b/test/Makefile.am index 78660f56..17d8cb51 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,6 +1,6 @@ # don't run test_thumbnail.sh by default, it takes ages TESTS = \ - test_streams.sh \ + test_connections.sh \ test_descriptors.sh \ test_cli.sh \ test_formats.sh \ @@ -13,13 +13,13 @@ SUBDIRS = \ noinst_PROGRAMS = \ test_descriptors \ - test_streams + test_connections test_descriptors_SOURCES = \ test_descriptors.c -test_streams_SOURCES = \ - test_streams.c +test_connections_SOURCES = \ + test_connections.c AM_CPPFLAGS = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@ AM_LDFLAGS = @LDFLAGS@ @@ -29,7 +29,7 @@ EXTRA_DIST = \ variables.sh.in \ test_cli.sh \ test_descriptors.sh \ - test_streams.sh \ + test_connections.sh \ test_formats.sh \ test_seq.sh \ test_thumbnail.sh \ diff --git a/test/test_connections b/test/test_connections new file mode 100755 index 00000000..73642228 --- /dev/null +++ b/test/test_connections @@ -0,0 +1,210 @@ +#! /bin/bash + +# test_connections - temporary wrapper script for .libs/test_connections +# Generated by libtool (GNU libtool) 2.4.6 Debian-2.4.6-11 +# +# The test_connections program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='s|\([`"$\\]\)|\\\1|g' + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command="" + +# This environment variable determines our operation mode. +if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then + # install mode needs the following variables: + generated_by_libtool_version='2.4.6' + notinst_deplibs=' ../libvips/libvips.la' +else + # When we are sourced in execute mode, $file and $ECHO are already set. + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + file="$0" + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +$1 +_LTECHO_EOF' +} + ECHO="printf %s\\n" + fi + +# Very basic option parsing. These options are (a) specific to +# the libtool wrapper, (b) are identical between the wrapper +# /script/ and the wrapper /executable/ that is used only on +# windows platforms, and (c) all begin with the string --lt- +# (application programs are unlikely to have options that match +# this pattern). +# +# There are only two supported options: --lt-debug and +# --lt-dump-script. There is, deliberately, no --lt-help. +# +# The first argument to this parsing function should be the +# script's ../libtool value, followed by no. +lt_option_debug= +func_parse_lt_options () +{ + lt_script_arg0=$0 + shift + for lt_opt + do + case "$lt_opt" in + --lt-debug) lt_option_debug=1 ;; + --lt-dump-script) + lt_dump_D=`$ECHO "X$lt_script_arg0" | /bin/sed -e 's/^X//' -e 's%/[^/]*$%%'` + test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=. + lt_dump_F=`$ECHO "X$lt_script_arg0" | /bin/sed -e 's/^X//' -e 's%^.*/%%'` + cat "$lt_dump_D/$lt_dump_F" + exit 0 + ;; + --lt-*) + $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2 + exit 1 + ;; + esac + done + + # Print the debug banner immediately: + if test -n "$lt_option_debug"; then + echo "test_connections:test_connections:$LINENO: libtool wrapper (GNU libtool) 2.4.6 Debian-2.4.6-11" 1>&2 + fi +} + +# Used when --lt-debug. Prints its arguments to stdout +# (redirection is the responsibility of the caller) +func_lt_dump_args () +{ + lt_dump_args_N=1; + for lt_arg + do + $ECHO "test_connections:test_connections:$LINENO: newargv[$lt_dump_args_N]: $lt_arg" + lt_dump_args_N=`expr $lt_dump_args_N + 1` + done +} + +# Core function for launching the target application +func_exec_program_core () +{ + + if test -n "$lt_option_debug"; then + $ECHO "test_connections:test_connections:$LINENO: newargv[0]: $progdir/$program" 1>&2 + func_lt_dump_args ${1+"$@"} 1>&2 + fi + exec "$progdir/$program" ${1+"$@"} + + $ECHO "$0: cannot exec $program $*" 1>&2 + exit 1 +} + +# A function to encapsulate launching the target application +# Strips options in the --lt-* namespace from $@ and +# launches target application with the remaining arguments. +func_exec_program () +{ + case " $* " in + *\ --lt-*) + for lt_wr_arg + do + case $lt_wr_arg in + --lt-*) ;; + *) set x "$@" "$lt_wr_arg"; shift;; + esac + shift + done ;; + esac + func_exec_program_core ${1+"$@"} +} + + # Parse options + func_parse_lt_options "$0" ${1+"$@"} + + # Find the directory that this script lives in. + thisdir=`$ECHO "$file" | /bin/sed 's%/[^/]*$%%'` + test "x$thisdir" = "x$file" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=`ls -ld "$file" | /bin/sed -n 's/.*-> //p'` + while test -n "$file"; do + destdir=`$ECHO "$file" | /bin/sed 's%/[^/]*$%%'` + + # If there was a directory component, then change thisdir. + if test "x$destdir" != "x$file"; then + case "$destdir" in + [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; + *) thisdir="$thisdir/$destdir" ;; + esac + fi + + file=`$ECHO "$file" | /bin/sed 's%^.*/%%'` + file=`ls -ld "$thisdir/$file" | /bin/sed -n 's/.*-> //p'` + done + + # Usually 'no', except on cygwin/mingw when embedded into + # the cwrapper. + WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no + if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then + # special case for '.' + if test "$thisdir" = "."; then + thisdir=`pwd` + fi + # remove .libs from thisdir + case "$thisdir" in + *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /bin/sed 's%[\\/][^\\/]*$%%'` ;; + .libs ) thisdir=. ;; + esac + fi + + # Try to get the absolute directory name. + absdir=`cd "$thisdir" && pwd` + test -n "$absdir" && thisdir="$absdir" + + program='test_connections' + progdir="$thisdir/.libs" + + + if test -f "$progdir/$program"; then + # Add our own library path to LD_LIBRARY_PATH + LD_LIBRARY_PATH="/home/john/GIT/libvips/libvips/.libs:/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH" + + # Some systems cannot cope with colon-terminated LD_LIBRARY_PATH + # The second colon is a workaround for a bug in BeOS R4 sed + LD_LIBRARY_PATH=`$ECHO "$LD_LIBRARY_PATH" | /bin/sed 's/::*$//'` + + export LD_LIBRARY_PATH + + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + # Run the actual program with our arguments. + func_exec_program ${1+"$@"} + fi + else + # The program doesn't exist. + $ECHO "$0: error: '$progdir/$program' does not exist" 1>&2 + $ECHO "This script is just a wrapper for $program." 1>&2 + $ECHO "See the libtool documentation for more information." 1>&2 + exit 1 + fi +fi diff --git a/test/test_streams.c b/test/test_connections.c similarity index 75% rename from test/test_streams.c rename to test/test_connections.c index 369a1e87..3dd4d082 100644 --- a/test/test_streams.c +++ b/test/test_connections.c @@ -20,7 +20,7 @@ typedef struct _MyOutput { } MyOutput; static gint64 -read_cb( VipsStreamiu *streamiu, +read_cb( VipsSourceCustom *source_custom, void *buffer, gint64 length, MyInput *my_input ) { gint64 bytes_read = VIPS_MIN( length, @@ -38,7 +38,7 @@ read_cb( VipsStreamiu *streamiu, } static gint64 -seek_cb( VipsStreamiu *streamiu, +seek_cb( VipsSourceCustom *source_custom, gint64 offset, int whence, MyInput *my_input ) { gint64 new_pos; @@ -71,7 +71,7 @@ seek_cb( VipsStreamiu *streamiu, } static gint64 -write_cb( VipsStreamou *streamou, +write_cb( VipsTargetCustom *target_custom, const void *data, gint64 length, MyOutput *my_output ) { gint64 bytes_written; @@ -86,7 +86,7 @@ write_cb( VipsStreamou *streamou, } static void -finish_cb( VipsStreamou *streamou, MyOutput *my_output ) +finish_cb( VipsTargetCustom *target_custom, MyOutput *my_output ) { /* printf( "finish_cb:\n" ); @@ -101,8 +101,8 @@ main( int argc, char **argv ) { MyInput my_input; MyOutput my_output; - VipsStreamiu *streamiu; - VipsStreamou *streamou; + VipsSourceCustom *source_custom; + VipsTargetCustom *target_custom; VipsImage *image; if( VIPS_INIT( NULL ) ) @@ -120,11 +120,14 @@ main( int argc, char **argv ) (char **) &my_input.contents, &my_input.length, NULL ) ) vips_error_exit( "unable to load from %s", my_input.filename ); - streamiu = vips_streamiu_new(); - g_signal_connect( streamiu, "seek", G_CALLBACK( seek_cb ), &my_input ); - g_signal_connect( streamiu, "read", G_CALLBACK( read_cb ), &my_input ); + source_custom = vips_source_custom_new(); + g_signal_connect( source_custom, "seek", + G_CALLBACK( seek_cb ), &my_input ); + g_signal_connect( source_custom, "read", + G_CALLBACK( read_cb ), &my_input ); - if( !(image = vips_image_new_from_stream( VIPS_STREAMI( streamiu ), "", + if( !(image = vips_image_new_from_source( + VIPS_SOURCE( source_custom ), "", "access", VIPS_ACCESS_SEQUENTIAL, NULL )) ) vips_error_exit( NULL ); @@ -136,19 +139,19 @@ main( int argc, char **argv ) O_WRONLY | O_CREAT | O_TRUNC, 0644 )) == -1 ) vips_error_exit( "unable to save to %s", my_output.filename ); - streamou = vips_streamou_new(); - g_signal_connect( streamou, "write", + target_custom = vips_target_custom_new(); + g_signal_connect( target_custom, "write", G_CALLBACK( write_cb ), &my_output ); - g_signal_connect( streamou, "finish", + g_signal_connect( target_custom, "finish", G_CALLBACK( finish_cb ), &my_output ); - if( vips_image_write_to_stream( image, ".png", - VIPS_STREAMO( streamou ), NULL ) ) + if( vips_image_write_to_target( image, ".png", + VIPS_TARGET( target_custom ), NULL ) ) vips_error_exit( NULL ); VIPS_UNREF( image ); - VIPS_UNREF( streamiu ); - VIPS_UNREF( streamou ); + VIPS_UNREF( source_custom ); + VIPS_UNREF( target_custom ); return( 0 ); } diff --git a/test/test_streams.sh b/test/test_connections.sh similarity index 83% rename from test/test_streams.sh rename to test/test_connections.sh index c0a578e5..a12c1225 100755 --- a/test/test_streams.sh +++ b/test/test_connections.sh @@ -8,7 +8,7 @@ set -e . ./variables.sh if test_supported jpegload_stream; then - ./test_streams $image $tmp/x.png + ./test_connections $image $tmp/x.png # test max difference < 10 test_difference $image $tmp/x.png 10 diff --git a/test/test_descriptors.c b/test/test_descriptors.c index 9ef919b5..64c3cda4 100644 --- a/test/test_descriptors.c +++ b/test/test_descriptors.c @@ -31,7 +31,7 @@ count_files( const char *dirname ) int main( int argc, char **argv ) { - VipsStreami *streami; + VipsSource *source; VipsImage *image, *x; char fd_dir[256]; int n_files; @@ -57,9 +57,9 @@ main( int argc, char **argv ) /* Opening an image should read the header, then close the fd. */ printf( "** seq open ..\n" ); - if( !(streami = vips_streami_new_from_file( argv[1] )) ) + if( !(source = vips_source_new_from_file( argv[1] )) ) vips_error_exit( NULL ); - if( !(image = vips_image_new_from_stream( streami, "", + if( !(image = vips_image_new_from_source( source, "", "access", VIPS_ACCESS_SEQUENTIAL, NULL )) ) vips_error_exit( NULL ); @@ -95,7 +95,7 @@ main( int argc, char **argv ) */ printf( "** unref ..\n" ); g_object_unref( image ); - g_object_unref( streami ); + g_object_unref( source ); printf( "** shutdown ..\n" ); vips_shutdown();