better matrix header read

This commit is contained in:
John Cupitt 2016-09-13 22:56:16 +01:00
parent 1872529b76
commit e241d13339
3 changed files with 8 additions and 21 deletions

12
TODO
View File

@ -1,15 +1,3 @@
- try:
john@kiwi:~/pics$ more sharp3x3.mat
3 3
-1 -1 -1
-1 8 -1
-1 -1 -1
john@kiwi:~/pics$ vips convi k2.jpg x.jpg sharp3x3.con
VipsForeignLoad: file "sharp3x3.con" not found
works if you add 1 0 to the header line
- not sure about utf8 error messages on win
- strange:

View File

@ -31,7 +31,7 @@
* - try to support DOS files under linux ... we have to look for \r\n
* linebreaks
* 12/8/16
* - allow missing offset in matrix header
* - allow missing offset and scale in matrix header
*/
/*
@ -488,7 +488,7 @@ fetch_nonwhite( FILE *fp, const char whitemap[256], char *buf, int max )
/* Read a single double in ascii (not locale) encoding.
*
* Return the char that caused failure on fail (EOF or \n).
* Return the char that caused failure on fail (EOF or \n).
*/
static int
read_ascii_double( FILE *fp, const char whitemap[256], double *out )
@ -536,20 +536,19 @@ vips__matrix_header( char *whitemap, FILE *fp,
int i;
int ch;
/* Offset defaults to zero.
*/
header[2] = 1.0;
header[3] = 0.0;
for( i = 0; i < 4 &&
(ch = read_ascii_double( fp, whitemap, &header[i] )) == 0;
i++ )
;
if( i < 4 )
header[3] = 0.0;
if( i < 3 )
header[2] = 1.0;
if( i < 2 ) {
vips_error( "mask2vips", "%s", _( "no width / height" ) );
return( -1 );
}
if( VIPS_FLOOR( header[0] ) != header[0] ||
VIPS_FLOOR( header[1] ) != header[1] ) {
vips_error( "mask2vips", "%s", _( "width / height not int" ) );

View File

@ -181,7 +181,7 @@ vips_foreign_load_matrix_init( VipsForeignLoadMatrix *matrix )
* floating-point, and must use '.'
* as a decimal separator.
*
* Subsequent lines each hold one line of matrix data, with numbers again
* Subsequent lines each hold one row of matrix data, with numbers again
* separated by any mixture of spaces, commas,
* tabs and quotation marks ("). The numbers may be floating-point, and must
* use '.'