From 7b4a6d07d4aba6ed28aa7e7b6c78df1448e095d3 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sat, 17 Dec 2011 11:03:08 +0000 Subject: [PATCH] fix analyze load, csv save, copy_swap --- TODO | 17 ---------------- libvips/conversion/copy.c | 4 ++-- libvips/foreign/analyze2vips.c | 36 ++++++++++++++++++++-------------- libvips/foreign/csvsave.c | 2 +- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/TODO b/TODO index d1f7d3bc..41761e89 100644 --- a/TODO +++ b/TODO @@ -1,20 +1,3 @@ -- suppression for the strspn() thing? - -- test analyze load - - .... appears to be broken, byteswap problem? also, leaks an image - -- test csv load/save - - $ vips im_copy pics/Gugg_coloured.jpg x.csv - Segmentation fault - - some arg mixup? - - - - - - "header fred.png" does not work, since header uses im_open() which uses VipsForeign diff --git a/libvips/conversion/copy.c b/libvips/conversion/copy.c index 91fff93c..e986b31f 100644 --- a/libvips/conversion/copy.c +++ b/libvips/conversion/copy.c @@ -192,14 +192,14 @@ vips_copy_gen( VipsRegion *or, void *seq, void *a, void *b, gboolean *stop ) VipsRegion *ir = (VipsRegion *) seq; VipsRect *r = &or->valid; VipsCopy *copy = (VipsCopy *) b; + SwapFn swap = vips_copy_swap_fn[copy->in->BandFmt]; /* Ask for input we need. */ if( vips_region_prepare( ir, r ) ) return( -1 ); - if( copy->swap ) { - SwapFn swap = vips_copy_swap_fn[copy->in->BandFmt]; + if( copy->swap && swap ) { int y; for( y = 0; y < r->height; y++ ) { diff --git a/libvips/foreign/analyze2vips.c b/libvips/foreign/analyze2vips.c index 807c95f2..f6a2ae58 100644 --- a/libvips/foreign/analyze2vips.c +++ b/libvips/foreign/analyze2vips.c @@ -302,10 +302,11 @@ read_header( const char *header ) if( !(d = (struct dsr *) vips__file_read_name( header, NULL, &len )) ) return( NULL ); + if( len != sizeof( struct dsr ) ) { - vips_free( d ); vips_error( "analyze2vips", "%s", _( "header file size incorrect" ) ); + vips_free( d ); return( NULL ); } @@ -348,6 +349,8 @@ read_header( const char *header ) } if( (int) len != d->hk.sizeof_hdr ) { + vips_error( "analyze2vips", + "%s", _( "header size incorrect" ) ); vips_free( d ); return( NULL ); } @@ -549,35 +552,38 @@ vips__analyze_read( const char *filename, VipsImage *out ) char header[FILENAME_MAX]; char image[FILENAME_MAX]; struct dsr *d; - VipsImage *t; + VipsImage *x = vips_image_new(); + VipsImage **t = (VipsImage **) + vips_object_local_array( VIPS_OBJECT( x ), 3 ); int width, height; int bands; VipsBandFormat fmt; generate_filenames( filename, header, image ); - if( !(d = read_header( header )) ) + if( !(d = read_header( header )) ) { + g_object_unref( x ); return( -1 ); + } + attach_meta( out, d ); #ifdef DEBUG print_dsr( d ); #endif /*DEBUG*/ if( get_vips_properties( d, &width, &height, &bands, &fmt ) || - !(t = vips_image_new_from_file_raw( image, width, height, - bands * vips_format_sizeof( fmt ), 0 )) ) - return( -1 ); - - if( vips_copy( t, &t, - "bands", bands, "format", fmt, "swap", vips_amiMSBfirst(), - NULL ) || - vips_image_write( t, out ) ) { - g_object_unref( t ); - vips_free( d ); + !(t[0] = vips_image_new_from_file_raw( image, width, height, + bands * vips_format_sizeof( fmt ), 0 )) ) { + g_object_unref( x ); return( -1 ); } - g_object_unref( t ); - attach_meta( out, d ); + if( vips_copy( t[0], &t[1], "bands", bands, "format", fmt, NULL ) || + vips_copy( t[1], &t[2], "swap", !vips_amiMSBfirst(), NULL ) || + vips_image_write( t[2], out ) ) { + g_object_unref( x ); + return( -1 ); + } + g_object_unref( x ); return( 0 ); } diff --git a/libvips/foreign/csvsave.c b/libvips/foreign/csvsave.c index 5636a4f9..f01b1d3f 100644 --- a/libvips/foreign/csvsave.c +++ b/libvips/foreign/csvsave.c @@ -165,7 +165,7 @@ vips_csvsave( VipsImage *in, const char *filename, ... ) int result; va_start( ap, filename ); - result = vips_call_split( "csvsave", ap, filename ); + result = vips_call_split( "csvsave", ap, in, filename ); va_end( ap ); return( result );