more array->matrix renaming
This commit is contained in:
parent
7490da07a6
commit
7312fd4ed4
@ -85,10 +85,6 @@ typedef VipsOperationClass VipsMeasureClass;
|
||||
|
||||
G_DEFINE_TYPE( VipsMeasure, vips_measure, VIPS_TYPE_OPERATION );
|
||||
|
||||
/* Address a double in our array image.
|
||||
*/
|
||||
#define ARY( im, x, y ) ((double *) VIPS_IMAGE_ADDR( im, x, y ))
|
||||
|
||||
static int
|
||||
vips_measure_build( VipsObject *object )
|
||||
{
|
||||
@ -166,8 +162,8 @@ vips_measure_build( VipsObject *object )
|
||||
"avg = %g, sdev = %g" ),
|
||||
i, j, b, avg, dev );
|
||||
|
||||
*ARY( measure->out, b, i + j * measure->h ) =
|
||||
avg;
|
||||
*VIPS_MATRIX( measure->out,
|
||||
b, i + j * measure->h ) = avg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -102,10 +102,6 @@ enum {
|
||||
COL_LAST = 10
|
||||
};
|
||||
|
||||
/* Address a double in our array image.
|
||||
*/
|
||||
#define ARY( im, x, y ) ((double *) VIPS_IMAGE_ADDR( im, x, y ))
|
||||
|
||||
static int
|
||||
vips_stats_build( VipsObject *object )
|
||||
{
|
||||
@ -135,13 +131,13 @@ vips_stats_build( VipsObject *object )
|
||||
vips_image_get_height( statistic->in );
|
||||
vals = pels * vips_image_get_bands( statistic->in );
|
||||
|
||||
row0 = ARY( stats->out, 0, 0 );
|
||||
row = ARY( stats->out, 0, 1 );
|
||||
row0 = VIPS_MATRIX( stats->out, 0, 0 );
|
||||
row = VIPS_MATRIX( stats->out, 0, 1 );
|
||||
for( i = 0; i < COL_LAST; i++ )
|
||||
row0[i] = row[i];
|
||||
|
||||
for( b = 1; b < vips_image_get_bands( statistic->in ); b++ ) {
|
||||
row = ARY( stats->out, 0, b + 1 );
|
||||
row = VIPS_MATRIX( stats->out, 0, b + 1 );
|
||||
|
||||
if( row[COL_MIN] < row0[COL_MIN] ) {
|
||||
row0[COL_MIN] = row[COL_MIN];
|
||||
@ -160,7 +156,7 @@ vips_stats_build( VipsObject *object )
|
||||
}
|
||||
|
||||
for( y = 1; y < vips_image_get_height( stats->out ); y++ ) {
|
||||
double *row = ARY( stats->out, 0, y );
|
||||
double *row = VIPS_MATRIX( stats->out, 0, y );
|
||||
|
||||
row[COL_AVG] = row[COL_SUM] / pels;
|
||||
row[COL_SD] = sqrt( fabs( row[COL_SUM2] -
|
||||
@ -187,8 +183,8 @@ vips_stats_stop( VipsStatistic *statistic, void *seq )
|
||||
|
||||
if( local->set && !global->set ) {
|
||||
for( b = 0; b < bands; b++ ) {
|
||||
double *p = ARY( local->out, 0, b + 1 );
|
||||
double *q = ARY( global->out, 0, b + 1 );
|
||||
double *p = VIPS_MATRIX( local->out, 0, b + 1 );
|
||||
double *q = VIPS_MATRIX( global->out, 0, b + 1 );
|
||||
|
||||
int i;
|
||||
|
||||
@ -200,8 +196,8 @@ vips_stats_stop( VipsStatistic *statistic, void *seq )
|
||||
}
|
||||
else if( local->set && global->set ) {
|
||||
for( b = 0; b < bands; b++ ) {
|
||||
double *p = ARY( local->out, 0, b + 1 );
|
||||
double *q = ARY( global->out, 0, b + 1 );
|
||||
double *p = VIPS_MATRIX( local->out, 0, b + 1 );
|
||||
double *q = VIPS_MATRIX( global->out, 0, b + 1 );
|
||||
|
||||
if( p[COL_MIN] < q[COL_MIN] ) {
|
||||
q[COL_MIN] = p[COL_MIN];
|
||||
@ -251,7 +247,7 @@ vips_stats_start( VipsStatistic *statistic )
|
||||
#define LOOP( TYPE ) { \
|
||||
for( b = 0; b < bands; b++ ) { \
|
||||
TYPE *p = ((TYPE *) in) + b; \
|
||||
double *q = ARY( local->out, 0, b + 1 ); \
|
||||
double *q = VIPS_MATRIX( local->out, 0, b + 1 ); \
|
||||
TYPE small, big; \
|
||||
double sum, sum2; \
|
||||
int xmin, ymin; \
|
||||
@ -315,7 +311,7 @@ vips_stats_start( VipsStatistic *statistic )
|
||||
#define LOOPF( TYPE ) { \
|
||||
for( b = 0; b < bands; b++ ) { \
|
||||
TYPE *p = ((TYPE *) in) + b; \
|
||||
double *q = ARY( local->out, 0, b + 1 ); \
|
||||
double *q = VIPS_MATRIX( local->out, 0, b + 1 ); \
|
||||
TYPE small, big; \
|
||||
double sum, sum2; \
|
||||
int xmin, ymin; \
|
||||
|
@ -60,9 +60,9 @@ typedef struct _VipsRecomb {
|
||||
VipsImage *in;
|
||||
VipsImage *m;
|
||||
|
||||
/* m converted to a one-band double.
|
||||
/* Our input matrix as a one-band double.
|
||||
*/
|
||||
double *coeff;
|
||||
VipsImage *coeff;
|
||||
|
||||
} VipsRecomb;
|
||||
|
||||
@ -77,9 +77,7 @@ G_DEFINE_TYPE( VipsRecomb, vips_recomb, VIPS_TYPE_CONVERSION );
|
||||
OUT *q = (OUT *) out; \
|
||||
\
|
||||
for( x = 0; x < or->valid.width; x++ ) { \
|
||||
double *m; \
|
||||
\
|
||||
m = recomb->coeff; \
|
||||
double *m = VIPS_MATRIX( recomb->coeff, 0, 0 ); \
|
||||
\
|
||||
for( v = 0; v < mheight; v++ ) { \
|
||||
double t; \
|
||||
@ -163,10 +161,9 @@ vips_recomb_build( VipsObject *object )
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if( vips_cast( recomb->m, &t[0], VIPS_FORMAT_DOUBLE, NULL ) ||
|
||||
vips_image_wio_input( t[0] ) )
|
||||
return( -1 );
|
||||
recomb->coeff = (double *) VIPS_IMAGE_ADDR( t[0], 0, 0 );
|
||||
if( vips_check_matrix( class->nickname, recomb->m, &t[0] ) )
|
||||
return( -1 );
|
||||
recomb->coeff = t[0];
|
||||
|
||||
if( vips_image_copy_fields( conversion->out, recomb->in ) )
|
||||
return( -1 );
|
||||
|
@ -74,8 +74,6 @@ typedef VipsConversionClass VipsScaleClass;
|
||||
|
||||
G_DEFINE_TYPE( VipsScale, vips_scale, VIPS_TYPE_CONVERSION );
|
||||
|
||||
#define ARY( im, x, y ) *((double *) VIPS_IMAGE_ADDR( im, x, y ))
|
||||
|
||||
static int
|
||||
vips_scale_build( VipsObject *object )
|
||||
{
|
||||
@ -91,8 +89,8 @@ vips_scale_build( VipsObject *object )
|
||||
|
||||
if( vips_stats( scale->in, &t[0], NULL ) )
|
||||
return( -1 );
|
||||
mn = ARY( t[0], 0, 0 );
|
||||
mx = ARY( t[0], 1, 0 );
|
||||
mn = *VIPS_MATRIX( t[0], 0, 0 );
|
||||
mx = *VIPS_MATRIX( t[0], 1, 0 );
|
||||
|
||||
if( mn == mx ) {
|
||||
/* Range of zero: just return black.
|
||||
|
@ -26,7 +26,7 @@
|
||||
* 23/2/12
|
||||
* - report positions for EOF/EOL errors
|
||||
* 2/7/13
|
||||
* - add array read/write
|
||||
* - add matrix read/write
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -500,7 +500,7 @@ read_ascii_double( FILE *fp, const char whitemap[256], double *out )
|
||||
* numbers for scale and offset.
|
||||
*/
|
||||
static int
|
||||
vips__array_header( char *whitemap, FILE *fp,
|
||||
vips__matrix_header( char *whitemap, FILE *fp,
|
||||
int *width, int *height, double *scale, double *offset )
|
||||
{
|
||||
double header[4];
|
||||
@ -548,13 +548,13 @@ vips__array_header( char *whitemap, FILE *fp,
|
||||
|
||||
#define WHITESPACE " \"\t\n;,"
|
||||
|
||||
/* Get the header from an array file.
|
||||
/* Get the header from an matrix file.
|
||||
*
|
||||
* Also read the first line and make sure there are the right number of
|
||||
* entries.
|
||||
*/
|
||||
int
|
||||
vips__array_read_header( const char *filename,
|
||||
vips__matrix_read_header( const char *filename,
|
||||
int *width, int *height, double *scale, double *offset )
|
||||
{
|
||||
char whitemap[256];
|
||||
@ -571,7 +571,7 @@ vips__array_read_header( const char *filename,
|
||||
|
||||
if( !(fp = vips__file_open_read( filename, NULL, TRUE )) )
|
||||
return( -1 );
|
||||
if( vips__array_header( whitemap, fp,
|
||||
if( vips__matrix_header( whitemap, fp,
|
||||
width, height, scale, offset ) ) {
|
||||
fclose( fp );
|
||||
return( -1 );
|
||||
@ -596,7 +596,7 @@ vips__array_read_header( const char *filename,
|
||||
}
|
||||
|
||||
static int
|
||||
vips__array_body( char *whitemap, VipsImage *out, FILE *fp )
|
||||
vips__matrix_body( char *whitemap, VipsImage *out, FILE *fp )
|
||||
{
|
||||
int x, y;
|
||||
|
||||
@ -612,7 +612,7 @@ vips__array_body( char *whitemap, VipsImage *out, FILE *fp )
|
||||
_( "line %d too short" ), y + 1 );
|
||||
return( -1 );
|
||||
}
|
||||
*((double *) VIPS_IMAGE_ADDR( out, x, y )) = d;
|
||||
*VIPS_MATRIX( out, x, y ) = d;
|
||||
|
||||
/* Deliberately don't check for line too long.
|
||||
*/
|
||||
@ -625,7 +625,7 @@ vips__array_body( char *whitemap, VipsImage *out, FILE *fp )
|
||||
}
|
||||
|
||||
VipsImage *
|
||||
vips__array_read( const char *filename )
|
||||
vips__matrix_read( const char *filename )
|
||||
{
|
||||
char whitemap[256];
|
||||
int i;
|
||||
@ -644,7 +644,7 @@ vips__array_read( const char *filename )
|
||||
|
||||
if( !(fp = vips__file_open_read( filename, NULL, TRUE )) )
|
||||
return( NULL );
|
||||
if( vips__array_header( whitemap, fp,
|
||||
if( vips__matrix_header( whitemap, fp,
|
||||
&width, &height, &scale, &offset ) ) {
|
||||
fclose( fp );
|
||||
return( NULL );
|
||||
@ -655,7 +655,7 @@ vips__array_read( const char *filename )
|
||||
vips_image_set_double( out, "scale", scale );
|
||||
vips_image_set_double( out, "offset", offset );
|
||||
|
||||
if( vips__array_body( whitemap, out, fp ) ) {
|
||||
if( vips__matrix_body( whitemap, out, fp ) ) {
|
||||
g_object_unref( out );
|
||||
fclose( fp );
|
||||
return( NULL );
|
||||
@ -666,7 +666,7 @@ vips__array_read( const char *filename )
|
||||
}
|
||||
|
||||
int
|
||||
vips__array_write( VipsImage *in, const char *filename )
|
||||
vips__matrix_write( VipsImage *in, const char *filename )
|
||||
{
|
||||
VipsImage *mask;
|
||||
FILE *fp;
|
||||
@ -689,8 +689,7 @@ vips__array_write( VipsImage *in, const char *filename )
|
||||
|
||||
for( y = 0; y < mask->Ysize; y++ ) {
|
||||
for( x = 0; x < mask->Xsize; x++ )
|
||||
fprintf( fp, "%g ",
|
||||
*((double *) VIPS_IMAGE_ADDR( mask, x, y )) );
|
||||
fprintf( fp, "%g ", *VIPS_MATRIX( mask, x, y ) );
|
||||
|
||||
fprintf( fp, "\n" );
|
||||
}
|
||||
|
@ -45,10 +45,10 @@ int vips__csv_read_header( const char *filename, VipsImage *out,
|
||||
int vips__csv_write( VipsImage *in, const char *filename,
|
||||
const char *separator );
|
||||
|
||||
int vips__array_read_header( const char *filename,
|
||||
int vips__matrix_read_header( const char *filename,
|
||||
int *width, int *height, double *scale, double *offset );
|
||||
VipsImage *vips__array_read( const char *filename );
|
||||
int vips__array_write( VipsImage *in, const char *filename );
|
||||
VipsImage *vips__matrix_read( const char *filename );
|
||||
int vips__matrix_write( VipsImage *in, const char *filename );
|
||||
|
||||
extern const char *vips__foreign_matrix_suffs[];
|
||||
|
||||
|
@ -88,7 +88,7 @@ vips_foreign_load_matrix_header( VipsForeignLoad *load )
|
||||
double scale;
|
||||
double offset;
|
||||
|
||||
if( vips__array_read_header( matrix->filename,
|
||||
if( vips__matrix_read_header( matrix->filename,
|
||||
&width, &height, &scale, &offset ) )
|
||||
return( -1 );
|
||||
|
||||
@ -109,7 +109,7 @@ vips_foreign_load_matrix_load( VipsForeignLoad *load )
|
||||
|
||||
VipsImage *out;
|
||||
|
||||
if( !(out = vips__array_read( matrix->filename )) )
|
||||
if( !(out = vips__matrix_read( matrix->filename )) )
|
||||
return( -1 );
|
||||
if( vips_image_write( out, load->real ) ) {
|
||||
g_object_unref( out );
|
||||
|
@ -73,7 +73,7 @@ vips_foreign_save_matrix_build( VipsObject *object )
|
||||
build( object ) )
|
||||
return( -1 );
|
||||
|
||||
if( vips__array_write( save->ready, matrix->filename ) )
|
||||
if( vips__matrix_write( save->ready, matrix->filename ) )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
|
@ -484,6 +484,17 @@ extern const guint64 vips__image_sizeof_bandformat[];
|
||||
(X) * VIPS_IMAGE_SIZEOF_PEL( I ))
|
||||
#endif /*VIPS_DEBUG*/
|
||||
|
||||
#ifdef VIPS_DEBUG
|
||||
#define VIPS_MATRIX( I, X, Y ) \
|
||||
(((I)->BandFmt == VIPS_FORMAT_DOUBLE && (I)->Bands == 1) ? \
|
||||
((double *) VIPS_IMAGE_ADDR( I, X, Y )) : \
|
||||
(fprintf( stderr, "VIPS_MATRIX: not a matrix image\n" ), \
|
||||
(VipsPel *) NULL))
|
||||
#else /*!VIPS_DEBUG*/
|
||||
#define VIPS_MATRIX( I, X, Y ) \
|
||||
((double *) VIPS_IMAGE_ADDR( I, X, Y ))
|
||||
#endif /*VIPS_DEBUG*/
|
||||
|
||||
int vips_image_written( VipsImage *image );
|
||||
|
||||
void vips_image_invalidate_all( VipsImage *image );
|
||||
|
@ -142,7 +142,8 @@
|
||||
* @X: x coordinate
|
||||
* @Y: y coordinate
|
||||
*
|
||||
* This macro returns a pointer to a pixel in an image. It only works for
|
||||
* This macro returns a pointer to a pixel in an image, cast to a #VipsPel *.
|
||||
* It only works for
|
||||
* images which are fully available in memory, so memory buffers and small
|
||||
* mapped images only.
|
||||
*
|
||||
@ -153,6 +154,25 @@
|
||||
* Returns: The address of pixel (x,y) in the image.
|
||||
*/
|
||||
|
||||
/**
|
||||
* VIPS_MATRIX:
|
||||
* @I: a #VipsImage
|
||||
* @X: x coordinate
|
||||
* @Y: y coordinate
|
||||
*
|
||||
* This macro returns a pointer to a pixel in an image, cast to a double*. The
|
||||
* image must have a single band, be #VIPS_FORMAT_DOUBLE and be
|
||||
* fully available in memory, so memory buffers and small
|
||||
* mapped images only.
|
||||
*
|
||||
* If VIPS_DEBUG is defined, you get a version that checks bounds and image
|
||||
* type for you.
|
||||
*
|
||||
* See also: VIPS_IMAGE_ADDR().
|
||||
*
|
||||
* Returns: The address of pixel (x,y) in the image.
|
||||
*/
|
||||
|
||||
/* Our signals.
|
||||
*/
|
||||
enum {
|
||||
@ -1623,7 +1643,7 @@ vips_image_new_from_memory( void *buffer,
|
||||
* This convenience function makes an image which is a matrix: a one-band
|
||||
* VIPS_FORMAT_DOUBLE image held in memory.
|
||||
*
|
||||
* Use VIPS_IMAGE_ADDR() to address pixels in the image.
|
||||
* Use VIPS_IMAGE_ADDR(), or VIPS_MATRIX() to address pixels in the image.
|
||||
*
|
||||
* Returns: the new #VipsImage, or %NULL on error.
|
||||
*/
|
||||
|
@ -131,7 +131,7 @@ vips_quadratic_gen( VipsRegion *or, void *vseq,
|
||||
|
||||
const int ps = VIPS_IMAGE_SIZEOF_PEL( in );
|
||||
|
||||
double *vec = (double *) VIPS_IMAGE_ADDR( quadratic->mat, 0, 0 );
|
||||
double *vec = VIPS_MATRIX( quadratic->mat, 0, 0 );
|
||||
|
||||
int clip_width = resample->in->Xsize;
|
||||
int clip_height = resample->in->Ysize;
|
||||
|
Loading…
Reference in New Issue
Block a user