From ad822109d4067932bf1002059fff43474606d61d Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 11 Oct 2019 07:51:43 +0100 Subject: [PATCH] input works this works now: cat k2.jpg | vips invert - x.jpg output next --- libvips/foreign/foreign.c | 3 --- libvips/foreign/jpeg2vips.c | 15 +++++++++------ libvips/iofuncs/stream.c | 10 ++++++---- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index fdf87822..0a6c580f 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -661,12 +661,9 @@ vips_foreign_find_load_stream( VipsStreamInput *input ) input, NULL )) ) { vips_error( "VipsForeignLoad", "%s", _( "stream is not in a known format" ) ); - (void) vips_stream_input_rewind( input ); return( NULL ); } - (void) vips_stream_input_rewind( input ); - return( G_OBJECT_CLASS_NAME( load_class ) ); } diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index b6135c26..8cd0fd43 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -134,9 +134,9 @@ */ /* - */ #define DEBUG_VERBOSE #define DEBUG + */ #ifdef HAVE_CONFIG_H #include @@ -396,6 +396,9 @@ readjpeg_open_input( ReadJpeg *jpeg ) !cinfo->src ) { InputSource *src; + if( vips_stream_input_rewind( jpeg->input ) ) + return( -1 ); + cinfo->src = (struct jpeg_source_mgr *) (*cinfo->mem->alloc_small)( (j_common_ptr) cinfo, JPOOL_PERMANENT, @@ -403,7 +406,6 @@ readjpeg_open_input( ReadJpeg *jpeg ) src = (InputSource *) cinfo->src; src->input = jpeg->input; - src->pub.init_source = stream_init_source; src->pub.fill_input_buffer = stream_fill_input_buffer; src->pub.skip_input_data = skip_input_data; @@ -887,6 +889,11 @@ read_jpeg_generate( VipsRegion *or, g_thread_self(), r->top, r->height ); #endif /*DEBUG_VERBOSE*/ + /* In pixel decode mode. + */ + if( jpeg->input ) + vips_stream_input_decode( jpeg->input ); + VIPS_GATE_START( "read_jpeg_generate: work" ); /* We're inside a tilecache where tiles are the full image width, so @@ -1216,10 +1223,6 @@ vips__jpeg_read_stream( VipsStreamInput *input, VipsImage *out, if( vips__jpeg_read( jpeg, out, header_only ) ) return( -1 ); - /* We've read the header ... it's pixel decode from now on. - vips_stream_input_decode( input ); - */ - return( 0 ); } diff --git a/libvips/iofuncs/stream.c b/libvips/iofuncs/stream.c index 49803881..76dacc7a 100644 --- a/libvips/iofuncs/stream.c +++ b/libvips/iofuncs/stream.c @@ -553,11 +553,13 @@ vips_stream_input_eof( VipsStreamInput *input ) void vips_stream_input_decode( VipsStreamInput *input ) { - VIPS_DEBUG_MSG( "vips_stream_input_decode:\n" ); + if( !input->decode ) { + VIPS_DEBUG_MSG( "vips_stream_input_decode:\n" ); - input->decode = TRUE; - VIPS_FREEF( g_byte_array_unref, input->header_bytes ); - VIPS_FREEF( g_byte_array_unref, input->sniff ); + input->decode = TRUE; + VIPS_FREEF( g_byte_array_unref, input->header_bytes ); + VIPS_FREEF( g_byte_array_unref, input->sniff ); + } } /**