add vips_matrixprint()

This commit is contained in:
John Cupitt 2013-10-25 12:02:02 +01:00
parent e74a0b71d9
commit 33f978f0ca
8 changed files with 116 additions and 17 deletions

View File

@ -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

View File

@ -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 );

View File

@ -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.
*/

View File

@ -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 };

View File

@ -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[];

View File

@ -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();

View File

@ -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 );
}

View File

@ -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));