add VIPS_IMAGE_N_PELS()

a macro to calculate the number of pels in an image, in 64 bits
This commit is contained in:
John Cupitt 2012-01-15 11:15:12 +00:00
parent 56bab17678
commit f98dbceb60
12 changed files with 47 additions and 33 deletions

20
TODO
View File

@ -1,13 +1,19 @@
- why is the cache operation only? it'd be useful to cache things like
interpolate as well, wouldn't it?
- perhaps Xsize and Ysize should become gint64
eg. easy to make an image that's 3gb and has xsize == 1 ... death!
also bands I guess
now everything that iterates over a dimension must be gint64 too
- Vips.Image has members like chain, __subclasshook__ etc etc, are we
really subclassing it correctly?
- have this warning:
im_histspec.c: In function 'im_histspec':
im_histspec.c:101:6: warning: 'px' may be used uninitialized in this function
[-Wuninitialized]
im_histspec.c:79:6: note: 'px' was declared here:n ../his
- add support for constants
how do boxed types work? confusing

View File

@ -99,7 +99,7 @@ typedef struct {
sum1 += a1[i]; \
a1 += in_lsk; \
} \
imean = sum1 / (ref->Xsize * ref->Ysize); \
imean = sum1 / VIPS_IMAGE_N_PELS( ref ); \
\
/* Loop over ir again, this time calculating \
* sum-of-squares-of-differences for this window on \
@ -202,7 +202,7 @@ static Spcor *
spcor_new( IMAGE *out, IMAGE *ref )
{
Spcor *spcor;
size_t sz = ref->Xsize * ref->Ysize;
guint64 sz = VIPS_IMAGE_N_PELS( ref );
VipsPel *p = ref->data;
double s;
size_t i;

View File

@ -229,7 +229,7 @@ mat2vips_get_data( mat_t *mat, matvar_t *var, VipsImage *im )
/* Matlab images are plane-separate, so we have to assemble bands in
* image-size chunks.
*/
const int is = es * im->Xsize * im->Ysize;
const guint64 is = es * VIPS_IMAGE_N_PELS( im );
if( Mat_VarReadDataAll( mat, var ) ) {
vips_error( "mat2vips", "%s",

View File

@ -85,7 +85,7 @@
static int
rfwfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
{
const int size = in->Xsize * in->Ysize;
const guint64 size = VIPS_IMAGE_N_PELS( in );
const int half_width = in->Xsize / 2 + 1;
/* Pack to double real here.
@ -241,7 +241,7 @@ cfwfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
/* Copy to out, normalise.
*/
for( p = (double *) cmplx->data, y = 0; y < out->Ysize; y++ ) {
int size = out->Xsize * out->Ysize;
guint64 size = VIPS_IMAGE_N_PELS( out );
q = buf;
@ -274,7 +274,7 @@ fwfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
static int
rfwfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
{
const int size = in->Xsize * in->Ysize;
const guint64 size = VIPS_IMAGE_N_PELS( in );
const int half_width = in->Xsize / 2 + 1;
/* Pack to double real here.
@ -289,7 +289,7 @@ rfwfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
/* We have to have a separate real buffer for the planner to work on.
*/
double *planner_scratch = IM_ARRAY( dummy,
in->Xsize * in->Ysize, double );
VIPS_IMAGE_N_PELS( in ), double );
fftw_plan plan;
double *buf, *q, *p;
@ -403,7 +403,7 @@ cfwfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
/* We have to have a separate buffer for the planner to work on.
*/
double *planner_scratch = IM_ARRAY( dummy,
in->Xsize * in->Ysize * 2, double );
VIPS_IMAGE_N_PELS( in ) * 2, double );
/* Make dp complex image.
*/
@ -448,7 +448,7 @@ cfwfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
/* Copy to out, normalise.
*/
for( p = (double *) cmplx->data, y = 0; y < out->Ysize; y++ ) {
int size = out->Xsize * out->Ysize;
guint64 size = VIPS_IMAGE_N_PELS( out );
q = buf;
@ -480,7 +480,7 @@ fwfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
static int
fwfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
{
int size = in->Xsize * in->Ysize;
int size = VIPS_IMAGE_N_PELS( in );
int bpx = im_ispoweroftwo( in->Xsize );
int bpy = im_ispoweroftwo( in->Ysize );
float *buf, *q, *p1, *p2;

View File

@ -125,7 +125,7 @@ invfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
/* We have to have a separate buffer for the planner to work on.
*/
double *planner_scratch = IM_ARRAY( dummy,
in->Xsize * in->Ysize * 2, double );
VIPS_IMAGE_N_PELS( in ) * 2, double );
/* Make dp complex image.
*/

View File

@ -100,7 +100,7 @@ invfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
*/
q = half_complex;
for( y = 0; y < cmplx->Ysize; y++ ) {
p = ((double *) cmplx->data) + y * in->Xsize * 2;
p = ((double *) cmplx->data) + (guint64) y * in->Xsize * 2;
for( x = 0; x < half_width; x++ ) {
q[0] = p[0];
@ -182,7 +182,7 @@ invfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
*/
q = half_complex;
for( y = 0; y < cmplx->Ysize; y++ ) {
p = ((double *) cmplx->data) + y * in->Xsize * 2;
p = ((double *) cmplx->data) + (guint64) y * in->Xsize * 2;
for( x = 0; x < half_width; x++ ) {
q[0] = p[0];

View File

@ -85,13 +85,13 @@
int
im_histcum( IMAGE *in, IMAGE *out )
{
const int px = in->Xsize * in->Ysize;
const guint64 px = VIPS_IMAGE_N_PELS( in );
const int nb = vips_bandfmt_iscomplex( in->BandFmt ) ?
in->Bands * 2 : in->Bands;
const int mx = px * nb;
const guint64 mx = px * nb;
VipsPel *outbuf;
int b, x;
guint64 b, x;
if( im_check_uncoded( "im_histcum", in ) ||
im_check_hist( "im_histcum", in ) ||
@ -159,7 +159,7 @@ im_histcum( IMAGE *in, IMAGE *out )
int
im_histnorm( IMAGE *in, IMAGE *out )
{
const int px = in->Xsize * in->Ysize;
const guint64 px = VIPS_IMAGE_N_PELS( in );
DOUBLEMASK *stats;
double *a, *b;
int i;

View File

@ -64,8 +64,8 @@
static int
match( IMAGE *in, IMAGE *ref, IMAGE *out )
{
const guint64 inpx = (guint64) in->Xsize * in->Ysize;
const guint64 refpx = (guint64) ref->Xsize * ref->Ysize;
const guint64 inpx = VIPS_IMAGE_N_PELS( in );
const guint64 refpx = VIPS_IMAGE_N_PELS( ref );
const int bands = in->Bands;
unsigned int *inbuf; /* in and ref, padded to same size */
@ -175,7 +175,7 @@ int
im_histspec( IMAGE *in, IMAGE *ref, IMAGE *out )
{
IMAGE *t[5];
int px;
guint64 px;
int fmt;
if( im_check_uint( "im_histspec", in ) ||
@ -194,7 +194,7 @@ im_histspec( IMAGE *in, IMAGE *ref, IMAGE *out )
/* Clip type down.
*/
px = t[4]->Xsize * t[4]->Ysize;
px = VIPS_IMAGE_N_PELS( t[4] );
if( px <= 256 )
fmt = IM_BANDFMT_UCHAR;
else if( px <= 65536 )

View File

@ -429,6 +429,8 @@ extern const guint64 vips__image_sizeof_bandformat[];
(VIPS_IMAGE_SIZEOF_LINE( I ) * (I)->Ysize)
#define VIPS_IMAGE_N_ELEMENTS( I ) \
((I)->Bands * (I)->Xsize)
#define VIPS_IMAGE_N_PELS( I ) \
((guint64) (I)->Xsize * (I)->Ysize)
/* If VIPS_DEBUG is defined, add bounds checking.
*/

View File

@ -1089,7 +1089,7 @@ vips_check_hist( const char *domain, VipsImage *im )
_( "histograms must have width or height 1" ) );
return( -1 );
}
if( im->Xsize * im->Ysize > 65536 ) {
if( VIPS_IMAGE_N_PELS( im ) > 65536 ) {
vips_error( domain, "%s",
_( "histograms must have not have more than "
"65536 elements" ) );

View File

@ -126,6 +126,13 @@
* Returns: The number of band elements in a scanline.
*/
/**
* VIPS_IMAGE_N_PELS:
* @I: a #VipsImage
*
* Returns: The number of pels in an image. A 64-bit unsigned int.
*/
/**
* VIPS_IMAGE_ADDR:
* @I: a #VipsImage
@ -1086,7 +1093,7 @@ vips_progress_add( VipsImage *image )
g_timer_start( progress->start );
progress->run = 0;
progress->eta = 0;
progress->tpels = (gint64) image->Xsize * image->Ysize;
progress->tpels = VIPS_IMAGE_N_PELS( image );
progress->npels = 0;
progress->percent = 0;

View File

@ -1005,7 +1005,7 @@ count_nonzero( IMAGE *in, gint64 *count )
if( im_avg( in, &avg ) )
return( -1 );
*count = (avg * in->Xsize * in->Ysize ) / 255.0;
*count = (avg * VIPS_IMAGE_N_PELS( in )) / 255.0;
return( 0 );
}
@ -1041,8 +1041,7 @@ find_image_stats( IMAGE *in, IMAGE *mask, Rect *area )
/* And scale masked average to match.
*/
stats->coeff[4] *= (double) count /
((double) mask->Xsize * mask->Ysize);
stats->coeff[4] *= (double) count / VIPS_IMAGE_N_PELS( mask );
/* Yuk! Zap the deviation column with the pixel count. Used later to
* determine if this is likely to be a significant overlap.