use vips__substitute() more
should probably remove vips_snprintf() from a few more places
This commit is contained in:
parent
61bae5eeff
commit
e458365970
2
TODO
2
TODO
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
easier to get into CPAN or whatever the python thing is called
|
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
|
see
|
||||||
|
|
||||||
|
|
|
@ -218,7 +218,7 @@ void vips_draw_operation_init( void );
|
||||||
void vips_mosaicing_operation_init( void );
|
void vips_mosaicing_operation_init( void );
|
||||||
|
|
||||||
guint64 vips__parse_size( const char *size_string );
|
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_labq( const char *domain, VipsImage *im );
|
||||||
int vips_check_coding_rad( const char *domain, VipsImage *im );
|
int vips_check_coding_rad( const char *domain, VipsImage *im );
|
||||||
|
|
|
@ -159,13 +159,19 @@ vips_system_build( VipsObject *object )
|
||||||
vips_strncpy( cmd, system->cmd_format, VIPS_PATH_MAX );
|
vips_strncpy( cmd, system->cmd_format, VIPS_PATH_MAX );
|
||||||
if( system->in )
|
if( system->in )
|
||||||
for( i = 0; i < VIPS_AREA( system->in )->n; i++ )
|
for( i = 0; i < VIPS_AREA( system->in )->n; i++ )
|
||||||
if( vips__substitute( class->nickname,
|
if( vips__substitute( cmd, VIPS_PATH_MAX,
|
||||||
cmd, VIPS_PATH_MAX, system->in_name[i] ) )
|
system->in_name[i] ) ) {
|
||||||
|
vips_error( class->nickname, "%s",
|
||||||
|
_( "unable to substitute "
|
||||||
|
"input filename" ) );
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
}
|
||||||
if( system->out_name &&
|
if( system->out_name &&
|
||||||
vips__substitute( class->nickname,
|
vips__substitute( cmd, VIPS_PATH_MAX, system->out_name ) ) {
|
||||||
cmd, VIPS_PATH_MAX, system->out_name ) )
|
vips_error( class->nickname, "%s",
|
||||||
|
_( "unable to substitute output filename" ) );
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
}
|
||||||
|
|
||||||
/* Swap all "%%" in the string for a single "%". We need this for
|
/* Swap all "%%" in the string for a single "%". We need this for
|
||||||
* compatibility with older printf-based vips_system()s which
|
* compatibility with older printf-based vips_system()s which
|
||||||
|
|
|
@ -1596,15 +1596,13 @@ vips_enum_from_nick( const char *domain, GType type, const char *nick )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BIGBUF (10000)
|
|
||||||
|
|
||||||
/* Scan @buf for the first "%ns" (eg. "%12s") and substitute the
|
/* Scan @buf for the first "%ns" (eg. "%12s") and substitute the
|
||||||
* lowest-numbered one for @sub. @buf is @len bytes in size.
|
* lowest-numbered one for @sub. @buf is @len bytes in size.
|
||||||
*
|
*
|
||||||
* If there are no %ns, use the first %s.
|
* If there are no %ns, use the first %s.
|
||||||
*/
|
*/
|
||||||
int
|
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 buflen = strlen( buf );
|
||||||
size_t sublen = strlen( sub );
|
size_t sublen = strlen( sub );
|
||||||
|
@ -1646,21 +1644,15 @@ vips__substitute( const char *domain, char *buf, size_t len, char *sub )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !sub_start ) {
|
if( !sub_start )
|
||||||
vips_error( domain,
|
|
||||||
"%s", _( "string contains no substitute marker" ) );
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
|
||||||
|
|
||||||
before_len = sub_start - buf;
|
before_len = sub_start - buf;
|
||||||
marker_len = sub_end - sub_start;
|
marker_len = sub_end - sub_start;
|
||||||
after_len = buflen - (before_len + marker_len);
|
after_len = buflen - (before_len + marker_len);
|
||||||
final_len = before_len + sublen + after_len + 1;
|
final_len = before_len + sublen + after_len + 1;
|
||||||
if( final_len > len ) {
|
if( final_len > len )
|
||||||
vips_error( domain,
|
|
||||||
"%s", _( "not enough space to substitute" ) );
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
|
||||||
|
|
||||||
memmove( buf + before_len + sublen, buf + before_len + marker_len,
|
memmove( buf + before_len + sublen, buf + before_len + marker_len,
|
||||||
after_len + 1 );
|
after_len + 1 );
|
||||||
|
|
|
@ -281,19 +281,24 @@ class TestConversion(unittest.TestCase):
|
||||||
black = self.mono * 0.0
|
black = self.mono * 0.0
|
||||||
|
|
||||||
for fmt in all_formats:
|
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()
|
im = test.flatten()
|
||||||
|
|
||||||
self.assertEqual(im.bands, 3)
|
self.assertEqual(im.bands, 3)
|
||||||
pixel = im.getpoint(30, 30)
|
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])
|
im = test.flatten(background = [100, 100, 100])
|
||||||
|
|
||||||
self.assertEqual(im.bands, 3)
|
self.assertEqual(im.bands, 3)
|
||||||
pixel = im.getpoint(30, 30)
|
pixel = im.getpoint(30, 30)
|
||||||
self.assertAlmostEqualObjects(pixel, [50, 50, 51])
|
print pixel
|
||||||
|
self.assertAlmostEqualObjects(pixel, [50, 51, 51])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,7 @@
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
|
||||||
#include <vips/vips.h>
|
#include <vips/vips.h>
|
||||||
|
#include <vips/internal.h>
|
||||||
|
|
||||||
#define ORIENTATION ("exif-ifd0-Orientation")
|
#define ORIENTATION ("exif-ifd0-Orientation")
|
||||||
|
|
||||||
|
@ -699,10 +700,15 @@ thumbnail_write( VipsObject *process, VipsImage *im, const char *filename )
|
||||||
if( (p = strrchr( file, '.' )) )
|
if( (p = strrchr( file, '.' )) )
|
||||||
*p = '\0';
|
*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
|
/* output_format can be an absolute path, in which case we discard the
|
||||||
* path from the incoming file.
|
* path from the incoming file.
|
||||||
*/
|
*/
|
||||||
vips_snprintf( buf, FILENAME_MAX, output_format, file );
|
|
||||||
if( g_path_is_absolute( output_format ) )
|
if( g_path_is_absolute( output_format ) )
|
||||||
output_name = g_strdup( buf );
|
output_name = g_strdup( buf );
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue