add vips_matrixprint()
This commit is contained in:
parent
e74a0b71d9
commit
33f978f0ca
@ -7,6 +7,7 @@
|
|||||||
- remove vips_image_copy_fields() and vips_demand_hint() and add
|
- remove vips_image_copy_fields() and vips_demand_hint() and add
|
||||||
vips_image_pipeline() to do both jobs
|
vips_image_pipeline() to do both jobs
|
||||||
- vipsthumbnail allows non-square bounding boxes, thanks seth
|
- vipsthumbnail allows non-square bounding boxes, thanks seth
|
||||||
|
- add vips_matrixprint()
|
||||||
|
|
||||||
18/10/13 started 7.36.3
|
18/10/13 started 7.36.3
|
||||||
- fix compiler warnings in ubuntu 13.10
|
- fix compiler warnings in ubuntu 13.10
|
||||||
|
@ -74,6 +74,11 @@ vips_conv_build( VipsObject *object )
|
|||||||
if( VIPS_OBJECT_CLASS( vips_conv_parent_class )->build( object ) )
|
if( VIPS_OBJECT_CLASS( vips_conv_parent_class )->build( object ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
|
/*
|
||||||
|
printf( "vips_conv_build: convolving with:\n" );
|
||||||
|
vips_matrixprint( convolution->M, NULL );
|
||||||
|
*/
|
||||||
|
|
||||||
if( !(imsk = im_vips2imask( convolution->M, class->nickname )) ||
|
if( !(imsk = im_vips2imask( convolution->M, class->nickname )) ||
|
||||||
!im_local_imask( convolution->out, imsk ) )
|
!im_local_imask( convolution->out, imsk ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
@ -1011,9 +1011,9 @@ im_conv_raw( IMAGE *in, IMAGE *out, INTMASK *mask )
|
|||||||
im_generate_fn generate;
|
im_generate_fn generate;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
#endif /*DEBUG*/
|
||||||
printf( "im_conv_raw: starting with matrix:\n" );
|
printf( "im_conv_raw: starting with matrix:\n" );
|
||||||
im_print_imask( mask );
|
im_print_imask( mask );
|
||||||
#endif /*DEBUG*/
|
|
||||||
|
|
||||||
/* Check parameters.
|
/* Check parameters.
|
||||||
*/
|
*/
|
||||||
|
@ -663,12 +663,11 @@ vips__matrix_body( char *whitemap, VipsImage *out, FILE *fp )
|
|||||||
}
|
}
|
||||||
|
|
||||||
VipsImage *
|
VipsImage *
|
||||||
vips__matrix_read( const char *filename )
|
vips__matrix_read_file( FILE *fp )
|
||||||
{
|
{
|
||||||
char whitemap[256];
|
char whitemap[256];
|
||||||
int i;
|
int i;
|
||||||
char *p;
|
char *p;
|
||||||
FILE *fp;
|
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
double scale;
|
double scale;
|
||||||
@ -680,13 +679,9 @@ vips__matrix_read( const char *filename )
|
|||||||
for( p = WHITESPACE; *p; p++ )
|
for( p = WHITESPACE; *p; p++ )
|
||||||
whitemap[(int) *p] = 1;
|
whitemap[(int) *p] = 1;
|
||||||
|
|
||||||
if( !(fp = vips__file_open_read( filename, NULL, TRUE )) )
|
|
||||||
return( NULL );
|
|
||||||
if( vips__matrix_header( whitemap, fp,
|
if( vips__matrix_header( whitemap, fp,
|
||||||
&width, &height, &scale, &offset ) ) {
|
&width, &height, &scale, &offset ) )
|
||||||
fclose( fp );
|
|
||||||
return( NULL );
|
return( NULL );
|
||||||
}
|
|
||||||
|
|
||||||
if( !(out = vips_image_new_matrix( width, height )) )
|
if( !(out = vips_image_new_matrix( width, height )) )
|
||||||
return( NULL );
|
return( NULL );
|
||||||
@ -695,28 +690,35 @@ vips__matrix_read( const char *filename )
|
|||||||
|
|
||||||
if( vips__matrix_body( whitemap, out, fp ) ) {
|
if( vips__matrix_body( whitemap, out, fp ) ) {
|
||||||
g_object_unref( out );
|
g_object_unref( out );
|
||||||
fclose( fp );
|
|
||||||
return( NULL );
|
return( NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 );
|
fclose( fp );
|
||||||
|
|
||||||
return( out );
|
return( out );
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
vips__matrix_write( VipsImage *in, const char *filename )
|
vips__matrix_write_file( VipsImage *in, FILE *fp )
|
||||||
{
|
{
|
||||||
VipsImage *mask;
|
VipsImage *mask;
|
||||||
FILE *fp;
|
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
if( vips_check_matrix( "vips2mask", in, &mask ) )
|
if( vips_check_matrix( "vips2mask", in, &mask ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
if( !(fp = vips__file_open_write( filename, TRUE )) ) {
|
|
||||||
g_object_unref( mask );
|
|
||||||
return( -1 );
|
|
||||||
}
|
|
||||||
fprintf( fp, "%d %d ", mask->Xsize, mask->Ysize );
|
fprintf( fp, "%d %d ", mask->Xsize, mask->Ysize );
|
||||||
if( vips_image_get_typeof( mask, "scale" ) &&
|
if( vips_image_get_typeof( mask, "scale" ) &&
|
||||||
vips_image_get_typeof( mask, "offset" ) )
|
vips_image_get_typeof( mask, "offset" ) )
|
||||||
@ -733,10 +735,23 @@ vips__matrix_write( VipsImage *in, const char *filename )
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref( mask );
|
g_object_unref( mask );
|
||||||
fclose( fp );
|
|
||||||
|
|
||||||
return( 0 );
|
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 };
|
const char *vips__foreign_matrix_suffs[] = { ".mat", NULL };
|
||||||
|
|
||||||
|
@ -48,8 +48,10 @@ int vips__csv_write( VipsImage *in, const char *filename,
|
|||||||
int vips__matrix_read_header( const char *filename,
|
int vips__matrix_read_header( const char *filename,
|
||||||
int *width, int *height, double *scale, double *offset );
|
int *width, int *height, double *scale, double *offset );
|
||||||
int vips__matrix_ismatrix( const char *filename );
|
int vips__matrix_ismatrix( const char *filename );
|
||||||
|
VipsImage *vips__matrix_read_file( FILE *fp );
|
||||||
VipsImage *vips__matrix_read( const char *filename );
|
VipsImage *vips__matrix_read( const char *filename );
|
||||||
int vips__matrix_write( VipsImage *in, 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[];
|
extern const char *vips__foreign_matrix_suffs[];
|
||||||
|
|
||||||
|
@ -1611,6 +1611,7 @@ vips_foreign_operation_init( void )
|
|||||||
extern GType vips_foreign_save_csv_get_type( void );
|
extern GType vips_foreign_save_csv_get_type( void );
|
||||||
extern GType vips_foreign_load_matrix_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_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_load_fits_get_type( void );
|
||||||
extern GType vips_foreign_save_fits_get_type( void );
|
extern GType vips_foreign_save_fits_get_type( void );
|
||||||
extern GType vips_foreign_load_analyze_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_save_csv_get_type();
|
||||||
vips_foreign_load_matrix_get_type();
|
vips_foreign_load_matrix_get_type();
|
||||||
vips_foreign_save_matrix_get_type();
|
vips_foreign_save_matrix_get_type();
|
||||||
|
vips_foreign_print_matrix_get_type();
|
||||||
vips_foreign_load_analyze_get_type();
|
vips_foreign_load_analyze_get_type();
|
||||||
vips_foreign_load_raw_get_type();
|
vips_foreign_load_raw_get_type();
|
||||||
vips_foreign_save_raw_get_type();
|
vips_foreign_save_raw_get_type();
|
||||||
|
@ -155,3 +155,75 @@ vips_matrixsave( VipsImage *in, const char *filename, ... )
|
|||||||
|
|
||||||
return( result );
|
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 );
|
||||||
|
}
|
||||||
|
@ -421,6 +421,8 @@ int vips_matrixload( const char *filename, VipsImage **out, ... )
|
|||||||
__attribute__((sentinel));
|
__attribute__((sentinel));
|
||||||
int vips_matrixsave( VipsImage *in, const char *filename, ... )
|
int vips_matrixsave( VipsImage *in, const char *filename, ... )
|
||||||
__attribute__((sentinel));
|
__attribute__((sentinel));
|
||||||
|
int vips_matrixprint( VipsImage *in, ... )
|
||||||
|
__attribute__((sentinel));
|
||||||
|
|
||||||
int vips_magickload( const char *filename, VipsImage **out, ... )
|
int vips_magickload( const char *filename, VipsImage **out, ... )
|
||||||
__attribute__((sentinel));
|
__attribute__((sentinel));
|
||||||
|
Loading…
Reference in New Issue
Block a user