diff --git a/ChangeLog b/ChangeLog index 0acacfca..d7cc19d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ - remove vips_image_copy_fields() and vips_demand_hint() and add vips_image_pipeline() to do both jobs - vipsthumbnail allows non-square bounding boxes, thanks seth +- add vips_matrixprint() 18/10/13 started 7.36.3 - fix compiler warnings in ubuntu 13.10 diff --git a/libvips/convolution/conv.c b/libvips/convolution/conv.c index 74d79a76..441cb550 100644 --- a/libvips/convolution/conv.c +++ b/libvips/convolution/conv.c @@ -74,6 +74,11 @@ vips_conv_build( VipsObject *object ) if( VIPS_OBJECT_CLASS( vips_conv_parent_class )->build( object ) ) return( -1 ); + /* + printf( "vips_conv_build: convolving with:\n" ); + vips_matrixprint( convolution->M, NULL ); + */ + if( !(imsk = im_vips2imask( convolution->M, class->nickname )) || !im_local_imask( convolution->out, imsk ) ) return( -1 ); diff --git a/libvips/convolution/im_conv.c b/libvips/convolution/im_conv.c index efa8136e..7c0a0db2 100644 --- a/libvips/convolution/im_conv.c +++ b/libvips/convolution/im_conv.c @@ -1011,9 +1011,9 @@ im_conv_raw( IMAGE *in, IMAGE *out, INTMASK *mask ) im_generate_fn generate; #ifdef DEBUG +#endif /*DEBUG*/ printf( "im_conv_raw: starting with matrix:\n" ); im_print_imask( mask ); -#endif /*DEBUG*/ /* Check parameters. */ diff --git a/libvips/foreign/csv.c b/libvips/foreign/csv.c index eed5d08c..75a85c6f 100644 --- a/libvips/foreign/csv.c +++ b/libvips/foreign/csv.c @@ -663,12 +663,11 @@ vips__matrix_body( char *whitemap, VipsImage *out, FILE *fp ) } VipsImage * -vips__matrix_read( const char *filename ) +vips__matrix_read_file( FILE *fp ) { char whitemap[256]; int i; char *p; - FILE *fp; int width; int height; double scale; @@ -680,13 +679,9 @@ vips__matrix_read( const char *filename ) for( p = WHITESPACE; *p; p++ ) whitemap[(int) *p] = 1; - if( !(fp = vips__file_open_read( filename, NULL, TRUE )) ) - return( NULL ); if( vips__matrix_header( whitemap, fp, - &width, &height, &scale, &offset ) ) { - fclose( fp ); + &width, &height, &scale, &offset ) ) return( NULL ); - } if( !(out = vips_image_new_matrix( width, height )) ) return( NULL ); @@ -695,28 +690,35 @@ vips__matrix_read( const char *filename ) if( vips__matrix_body( whitemap, out, fp ) ) { g_object_unref( out ); - fclose( fp ); return( NULL ); } - fclose( fp ); return( out ); } +VipsImage * +vips__matrix_read( const char *filename ) +{ + FILE *fp; + VipsImage *out; + + if( !(fp = vips__file_open_read( filename, NULL, TRUE )) ) + return( NULL ); + out = vips__matrix_read_file( fp ); + fclose( fp ); + + return( out ); +} + int -vips__matrix_write( VipsImage *in, const char *filename ) +vips__matrix_write_file( VipsImage *in, FILE *fp ) { VipsImage *mask; - FILE *fp; int x, y; if( vips_check_matrix( "vips2mask", in, &mask ) ) return( -1 ); - if( !(fp = vips__file_open_write( filename, TRUE )) ) { - g_object_unref( mask ); - return( -1 ); - } fprintf( fp, "%d %d ", mask->Xsize, mask->Ysize ); if( vips_image_get_typeof( mask, "scale" ) && vips_image_get_typeof( mask, "offset" ) ) @@ -733,10 +735,23 @@ vips__matrix_write( VipsImage *in, const char *filename ) } g_object_unref( mask ); - fclose( fp ); return( 0 ); } +int +vips__matrix_write( VipsImage *in, const char *filename ) +{ + FILE *fp; + int result; + + if( !(fp = vips__file_open_write( filename, TRUE )) ) + return( -1 ); + result = vips__matrix_write_file( in, fp ); + fclose( fp ); + + return( result ); +} + const char *vips__foreign_matrix_suffs[] = { ".mat", NULL }; diff --git a/libvips/foreign/csv.h b/libvips/foreign/csv.h index 7f868c3c..15d1e090 100644 --- a/libvips/foreign/csv.h +++ b/libvips/foreign/csv.h @@ -48,8 +48,10 @@ 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_file( FILE *fp ); VipsImage *vips__matrix_read( const char *filename ); int vips__matrix_write( VipsImage *in, const char *filename ); +int vips__matrix_write_file( VipsImage *in, FILE *fp ); extern const char *vips__foreign_matrix_suffs[]; diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index e9bb5048..830b6240 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -1611,6 +1611,7 @@ vips_foreign_operation_init( void ) extern GType vips_foreign_save_csv_get_type( void ); extern GType vips_foreign_load_matrix_get_type( void ); extern GType vips_foreign_save_matrix_get_type( void ); + extern GType vips_foreign_print_matrix_get_type( void ); extern GType vips_foreign_load_fits_get_type( void ); extern GType vips_foreign_save_fits_get_type( void ); extern GType vips_foreign_load_analyze_get_type( void ); @@ -1643,6 +1644,7 @@ vips_foreign_operation_init( void ) vips_foreign_save_csv_get_type(); vips_foreign_load_matrix_get_type(); vips_foreign_save_matrix_get_type(); + vips_foreign_print_matrix_get_type(); vips_foreign_load_analyze_get_type(); vips_foreign_load_raw_get_type(); vips_foreign_save_raw_get_type(); diff --git a/libvips/foreign/matrixsave.c b/libvips/foreign/matrixsave.c index dd36e045..d3e1934b 100644 --- a/libvips/foreign/matrixsave.c +++ b/libvips/foreign/matrixsave.c @@ -155,3 +155,75 @@ vips_matrixsave( VipsImage *in, const char *filename, ... ) return( result ); } + +typedef struct _VipsForeignPrintMatrix { + VipsForeignSave parent_object; + +} VipsForeignPrintMatrix; + +typedef VipsForeignSaveClass VipsForeignPrintMatrixClass; + +G_DEFINE_TYPE( VipsForeignPrintMatrix, vips_foreign_print_matrix, + VIPS_TYPE_FOREIGN_SAVE ); + +static int +vips_foreign_print_matrix_build( VipsObject *object ) +{ + VipsForeignSave *save = (VipsForeignSave *) object; + + if( VIPS_OBJECT_CLASS( vips_foreign_print_matrix_parent_class )-> + build( object ) ) + return( -1 ); + + if( vips__matrix_write_file( save->ready, stdout ) ) + return( -1 ); + + return( 0 ); +} + +static void +vips_foreign_print_matrix_class_init( VipsForeignPrintMatrixClass *class ) +{ + VipsObjectClass *object_class = (VipsObjectClass *) class; + VipsForeignClass *foreign_class = (VipsForeignClass *) class; + VipsForeignSaveClass *save_class = (VipsForeignSaveClass *) class; + + object_class->nickname = "matrixprint"; + object_class->description = _( "print matrix" ); + object_class->build = vips_foreign_print_matrix_build; + + foreign_class->suffs = vips__foreign_matrix_suffs; + + save_class->saveable = VIPS_SAVEABLE_MONO; + save_class->format_table = bandfmt_matrix; +} + +static void +vips_foreign_print_matrix_init( VipsForeignPrintMatrix *matrix ) +{ +} + +/** + * vips_matrixprint: + * @in: image to print + * @...: %NULL-terminated list of optional named arguments + * + * Print @in to %stdout in matrix format. See vips_matrixload() for a + * description of the format. + * + * See also: vips_matrixload(). + * + * Returns: 0 on success, -1 on error. + */ +int +vips_matrixprint( VipsImage *in, ... ) +{ + va_list ap; + int result; + + va_start( ap, in ); + result = vips_call_split( "matrixprint", ap, in ); + va_end( ap ); + + return( result ); +} diff --git a/libvips/include/vips/foreign.h b/libvips/include/vips/foreign.h index b3b1e79d..80dc7d32 100644 --- a/libvips/include/vips/foreign.h +++ b/libvips/include/vips/foreign.h @@ -421,6 +421,8 @@ int vips_matrixload( const char *filename, VipsImage **out, ... ) __attribute__((sentinel)); int vips_matrixsave( VipsImage *in, const char *filename, ... ) __attribute__((sentinel)); +int vips_matrixprint( VipsImage *in, ... ) + __attribute__((sentinel)); int vips_magickload( const char *filename, VipsImage **out, ... ) __attribute__((sentinel));