better file format sniffing
and vips_error_freeze/thaw() to stop errors from sniffing being logged plus better matrix sniffing
This commit is contained in:
parent
0180a61be4
commit
1ba188dc83
@ -3,6 +3,8 @@
|
||||
- rename image arrays as image matrices ... INTERPRETATION_ARRAY ->
|
||||
INTERPRETATION_MATRIX etc.
|
||||
- convert im_buildlut(), im_identity*() to classes
|
||||
- added vips_error_freeze()/vips_error_thaw()
|
||||
- used freeze()/thaw() to stop file format sniffers logging spurious errors
|
||||
|
||||
3/7/13 started 7.34.2
|
||||
- lower priority for Matlab load to reduce segvs from Mat_Open(), thanks
|
||||
|
@ -492,24 +492,29 @@ vips__isanalyze( const char *filename )
|
||||
int width, height;
|
||||
int bands;
|
||||
VipsBandFormat fmt;
|
||||
int result;
|
||||
|
||||
generate_filenames( filename, header, image );
|
||||
if( !vips_existsf( "%s", header ) )
|
||||
return( 0 );
|
||||
if( !(d = read_header( header )) )
|
||||
|
||||
vips_error_freeze();
|
||||
d = read_header( header );
|
||||
vips_error_thaw();
|
||||
if( !d )
|
||||
return( 0 );
|
||||
|
||||
#ifdef DEBUG
|
||||
print_dsr( d );
|
||||
#endif /*DEBUG*/
|
||||
|
||||
if( get_vips_properties( d, &width, &height, &bands, &fmt ) ) {
|
||||
vips_free( d );
|
||||
return( 0 );
|
||||
}
|
||||
vips_error_freeze();
|
||||
result = get_vips_properties( d, &width, &height, &bands, &fmt );
|
||||
vips_error_thaw();
|
||||
|
||||
vips_free( d );
|
||||
|
||||
return( 1 );
|
||||
return( result == 0 );
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -482,6 +482,7 @@ read_ascii_double( FILE *fp, const char whitemap[256], double *out )
|
||||
{
|
||||
int ch;
|
||||
char buf[256];
|
||||
char *p;
|
||||
|
||||
ch = skip_white( fp, whitemap );
|
||||
|
||||
@ -491,6 +492,16 @@ read_ascii_double( FILE *fp, const char whitemap[256], double *out )
|
||||
|
||||
fetch_nonwhite( fp, whitemap, buf, 256 );
|
||||
|
||||
/* The str we fetched must contain at least 1 digit. This helps stop
|
||||
* us trying to convert "MATLAB" (for example) to a number and
|
||||
* getting zero.
|
||||
*/
|
||||
for( p = buf; *p; p++ )
|
||||
if( isdigit( *p ) )
|
||||
break;
|
||||
if( !*p )
|
||||
return( *buf );
|
||||
|
||||
*out = g_ascii_strtod( buf, NULL );
|
||||
|
||||
return( 0 );
|
||||
@ -603,6 +614,23 @@ vips__matrix_read_header( const char *filename,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
vips__matrix_ismatrix( const char *filename )
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
double scale;
|
||||
double offset;
|
||||
int result;
|
||||
|
||||
vips_error_freeze();
|
||||
result = vips__matrix_read_header( filename,
|
||||
&width, &height, &scale, &offset );
|
||||
vips_error_thaw();
|
||||
|
||||
return( result == 0 );
|
||||
}
|
||||
|
||||
static int
|
||||
vips__matrix_body( char *whitemap, VipsImage *out, FILE *fp )
|
||||
{
|
||||
|
@ -47,6 +47,7 @@ int vips__csv_write( VipsImage *in, const char *filename,
|
||||
|
||||
int vips__matrix_read_header( const char *filename,
|
||||
int *width, int *height, double *scale, double *offset );
|
||||
int vips__matrix_ismatrix( const char *filename );
|
||||
VipsImage *vips__matrix_read( const char *filename );
|
||||
int vips__matrix_write( VipsImage *in, const char *filename );
|
||||
|
||||
|
@ -73,15 +73,15 @@ static gboolean
|
||||
ismagick( const char *filename )
|
||||
{
|
||||
VipsImage *t;
|
||||
int result;
|
||||
|
||||
t = vips_image_new();
|
||||
if( vips__magick_read_header( filename, t, FALSE ) ) {
|
||||
g_object_unref( t );
|
||||
return( FALSE );
|
||||
}
|
||||
vips_error_freeze();
|
||||
result = vips__magick_read_header( filename, t, FALSE );
|
||||
g_object_unref( t );
|
||||
vips_error_thaw();
|
||||
|
||||
return( TRUE );
|
||||
return( result == 0 );
|
||||
}
|
||||
|
||||
static VipsForeignFlags
|
||||
|
@ -300,11 +300,12 @@ vips__mat_ismat( const char *filename )
|
||||
{
|
||||
mat_t *mat;
|
||||
|
||||
if( !(mat = Mat_Open( filename, MAT_ACC_RDONLY )) )
|
||||
return( 0 );
|
||||
vips_error_freeze();
|
||||
mat = Mat_Open( filename, MAT_ACC_RDONLY );
|
||||
Mat_Close( mat );
|
||||
vips_error_thaw();
|
||||
|
||||
return( 1 );
|
||||
return( mat != NULL );
|
||||
}
|
||||
|
||||
const char *vips__mat_suffs[] = { ".mat", NULL };
|
||||
|
@ -136,6 +136,7 @@ vips_foreign_load_matrix_class_init( VipsForeignLoadMatrixClass *class )
|
||||
|
||||
foreign_class->suffs = vips__foreign_matrix_suffs;
|
||||
|
||||
load_class->is_a = vips__matrix_ismatrix;
|
||||
load_class->get_flags_filename =
|
||||
vips_foreign_load_matrix_get_flags_filename;
|
||||
load_class->get_flags = vips_foreign_load_matrix_get_flags;
|
||||
|
@ -107,7 +107,11 @@ vips__openslide_isslide( const char *filename )
|
||||
int ok;
|
||||
|
||||
ok = 0;
|
||||
if( (osr = openslide_open( filename )) ) {
|
||||
vips_error_freeze();
|
||||
osr = openslide_open( filename );
|
||||
vips_error_thaw();
|
||||
|
||||
if( osr ) {
|
||||
const char *vendor;
|
||||
|
||||
/* Generic tiled tiff images can be opened by openslide as
|
||||
|
@ -38,6 +38,9 @@ extern "C" {
|
||||
const char *vips_error_buffer( void );
|
||||
void vips_error_clear( void );
|
||||
|
||||
void vips_error_freeze( void );
|
||||
void vips_error_thaw( void );
|
||||
|
||||
void vips_error( const char *domain, const char *fmt, ... )
|
||||
__attribute__((format(printf, 2, 3)));
|
||||
void vips_verror( const char *domain, const char *fmt, va_list ap );
|
||||
|
@ -110,10 +110,40 @@
|
||||
#define VIPS_MAX_ERROR (10240)
|
||||
static char vips_error_text[VIPS_MAX_ERROR] = "";
|
||||
static VipsBuf vips_error_buf = VIPS_BUF_STATIC( vips_error_text );
|
||||
static int vips_error_freeze_count = 0;
|
||||
|
||||
#define IM_DIAGNOSTICS "IM_DIAGNOSTICS"
|
||||
#define IM_WARNING "IM_WARNING"
|
||||
|
||||
/**
|
||||
* vips_error_freeze:
|
||||
*
|
||||
* Stop errors being logged. Use vips_error_thaw() to unfreeze. You can
|
||||
* nest freeze/thaw pairs.
|
||||
*/
|
||||
void
|
||||
vips_error_freeze( void )
|
||||
{
|
||||
g_mutex_lock( vips__global_lock );
|
||||
g_assert( vips_error_freeze_count >= 0 );
|
||||
vips_error_freeze_count += 1;
|
||||
g_mutex_unlock( vips__global_lock );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_error_thaw:
|
||||
*
|
||||
* Reenable error logging.
|
||||
*/
|
||||
void
|
||||
vips_error_thaw( void )
|
||||
{
|
||||
g_mutex_lock( vips__global_lock );
|
||||
vips_error_freeze_count -= 1;
|
||||
g_assert( vips_error_freeze_count >= 0 );
|
||||
g_mutex_unlock( vips__global_lock );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_error_buffer:
|
||||
*
|
||||
@ -173,9 +203,12 @@ vips_verror( const char *domain, const char *fmt, va_list ap )
|
||||
#endif /*VIPS_DEBUG*/
|
||||
|
||||
g_mutex_lock( vips__global_lock );
|
||||
vips_buf_appendf( &vips_error_buf, "%s: ", domain );
|
||||
vips_buf_vappendf( &vips_error_buf, fmt, ap );
|
||||
vips_buf_appends( &vips_error_buf, "\n" );
|
||||
g_assert( vips_error_freeze_count >= 0 );
|
||||
if( !vips_error_freeze_count ) {
|
||||
vips_buf_appendf( &vips_error_buf, "%s: ", domain );
|
||||
vips_buf_vappendf( &vips_error_buf, fmt, ap );
|
||||
vips_buf_appends( &vips_error_buf, "\n" );
|
||||
}
|
||||
g_mutex_unlock( vips__global_lock );
|
||||
|
||||
if( vips__fatal )
|
||||
|
Loading…
Reference in New Issue
Block a user