diff --git a/TODO b/TODO index cc09f423..184b4b58 100644 --- a/TODO +++ b/TODO @@ -12,7 +12,7 @@ easier to get into CPAN or whatever the python thing is called -- [put exif autorotate into jpeg load +- put exif autorotate into jpeg load see diff --git a/libvips/include/vips/internal.h b/libvips/include/vips/internal.h index 317dc1d1..f6d3da7f 100644 --- a/libvips/include/vips/internal.h +++ b/libvips/include/vips/internal.h @@ -218,7 +218,7 @@ void vips_draw_operation_init( void ); void vips_mosaicing_operation_init( void ); guint64 vips__parse_size( const char *size_string ); -int vips__substitute( const char *domain, char *buf, size_t len, char *sub ); +int vips__substitute( char *buf, size_t len, char *sub ); int vips_check_coding_labq( const char *domain, VipsImage *im ); int vips_check_coding_rad( const char *domain, VipsImage *im ); diff --git a/libvips/iofuncs/system.c b/libvips/iofuncs/system.c index a5d3d3d4..7ae1459a 100644 --- a/libvips/iofuncs/system.c +++ b/libvips/iofuncs/system.c @@ -159,13 +159,19 @@ vips_system_build( VipsObject *object ) vips_strncpy( cmd, system->cmd_format, VIPS_PATH_MAX ); if( system->in ) for( i = 0; i < VIPS_AREA( system->in )->n; i++ ) - if( vips__substitute( class->nickname, - cmd, VIPS_PATH_MAX, system->in_name[i] ) ) + if( vips__substitute( cmd, VIPS_PATH_MAX, + system->in_name[i] ) ) { + vips_error( class->nickname, "%s", + _( "unable to substitute " + "input filename" ) ); return( -1 ); + } if( system->out_name && - vips__substitute( class->nickname, - cmd, VIPS_PATH_MAX, system->out_name ) ) + vips__substitute( cmd, VIPS_PATH_MAX, system->out_name ) ) { + vips_error( class->nickname, "%s", + _( "unable to substitute output filename" ) ); return( -1 ); + } /* Swap all "%%" in the string for a single "%". We need this for * compatibility with older printf-based vips_system()s which diff --git a/libvips/iofuncs/util.c b/libvips/iofuncs/util.c index aab2e106..af287175 100644 --- a/libvips/iofuncs/util.c +++ b/libvips/iofuncs/util.c @@ -1596,15 +1596,13 @@ vips_enum_from_nick( const char *domain, GType type, const char *nick ) return( -1 ); } -#define BIGBUF (10000) - /* Scan @buf for the first "%ns" (eg. "%12s") and substitute the * lowest-numbered one for @sub. @buf is @len bytes in size. * * If there are no %ns, use the first %s. */ int -vips__substitute( const char *domain, char *buf, size_t len, char *sub ) +vips__substitute( char *buf, size_t len, char *sub ) { size_t buflen = strlen( buf ); size_t sublen = strlen( sub ); @@ -1646,21 +1644,15 @@ vips__substitute( const char *domain, char *buf, size_t len, char *sub ) break; } - if( !sub_start ) { - vips_error( domain, - "%s", _( "string contains no substitute marker" ) ); + if( !sub_start ) return( -1 ); - } before_len = sub_start - buf; marker_len = sub_end - sub_start; after_len = buflen - (before_len + marker_len); final_len = before_len + sublen + after_len + 1; - if( final_len > len ) { - vips_error( domain, - "%s", _( "not enough space to substitute" ) ); + if( final_len > len ) return( -1 ); - } memmove( buf + before_len + sublen, buf + before_len + marker_len, after_len + 1 ); diff --git a/python/test_conversion.py b/python/test_conversion.py index 2b883b4d..9b19263b 100755 --- a/python/test_conversion.py +++ b/python/test_conversion.py @@ -281,19 +281,24 @@ class TestConversion(unittest.TestCase): black = self.mono * 0.0 for fmt in all_formats: - test = self.colour.bandjoin2(black + max_value[fmt] / 2]).cast(fmt) + print fmt + test = self.colour.bandjoin2(black + max_value[fmt] / 2.0).cast(fmt) + pixel = test.getpoint(30, 30) + print 'before', pixel im = test.flatten() self.assertEqual(im.bands, 3) pixel = im.getpoint(30, 30) - self.assertAlmostEqualObjects(pixel, [2, 2, 3]) + print 'after', pixel + self.assertAlmostEqualObjects(pixel, [0, 1, 1]) im = test.flatten(background = [100, 100, 100]) self.assertEqual(im.bands, 3) pixel = im.getpoint(30, 30) - self.assertAlmostEqualObjects(pixel, [50, 50, 51]) + print pixel + self.assertAlmostEqualObjects(pixel, [50, 51, 51]) diff --git a/tools/vipsthumbnail.c b/tools/vipsthumbnail.c index 6ebb8e99..4ed8507e 100644 --- a/tools/vipsthumbnail.c +++ b/tools/vipsthumbnail.c @@ -75,6 +75,7 @@ #include #include +#include #define ORIENTATION ("exif-ifd0-Orientation") @@ -699,10 +700,15 @@ thumbnail_write( VipsObject *process, VipsImage *im, const char *filename ) if( (p = strrchr( file, '.' )) ) *p = '\0'; + /* Don't use vips_snprintf(), we only want to optionally substitute a + * single %s. + */ + vips_strncpy( buf, output_format, FILENAME_MAX ); + vips__substitute( buf, FILENAME_MAX, file ); + /* output_format can be an absolute path, in which case we discard the * path from the incoming file. */ - vips_snprintf( buf, FILENAME_MAX, output_format, file ); if( g_path_is_absolute( output_format ) ) output_name = g_strdup( buf ); else {