fix up addr calcs on 64-bit machines with >2gb images and inplace ops

This commit is contained in:
John Cupitt 2009-10-08 11:17:23 +00:00
parent b8d2522907
commit cc68842434
5 changed files with 26 additions and 18 deletions

View File

@ -54,6 +54,8 @@
- meta, header, callback, error, REGION gtkdocs - meta, header, callback, error, REGION gtkdocs
- removed printlines tool, vips2csv is much better - removed printlines tool, vips2csv is much better
- removed other useless tools as well: debugim, binfile - removed other useless tools as well: debugim, binfile
- fix up addr calcs on 64-bit machines with >2gb images and inplace ops
(thanks Christoph)
25/3/09 started 7.18.0 25/3/09 started 7.18.0
- revised version numbers - revised version numbers

View File

@ -228,11 +228,14 @@ typedef struct _VipsImage {
/* Pixel address calculation macros. /* Pixel address calculation macros.
*/ */
#define IM_IMAGE_SIZEOF_ELEMENT(I) ((I)->Bbits >> 3) #define IM_IMAGE_SIZEOF_ELEMENT(I) \
#define IM_IMAGE_SIZEOF_PEL(I) \ ((size_t)((I)->Bbits >> 3))
(IM_IMAGE_SIZEOF_ELEMENT(I) * (I)->Bands) #define IM_IMAGE_SIZEOF_PEL(I) \
#define IM_IMAGE_SIZEOF_LINE(I) (IM_IMAGE_SIZEOF_PEL(I) * (I)->Xsize) ((size_t)(IM_IMAGE_SIZEOF_ELEMENT(I) * (I)->Bands))
#define IM_IMAGE_N_ELEMENTS(I) ((I)->Bands * (I)->Xsize) #define IM_IMAGE_SIZEOF_LINE(I) \
((size_t)(IM_IMAGE_SIZEOF_PEL(I) * (I)->Xsize))
#define IM_IMAGE_N_ELEMENTS(I) \
((size_t)((I)->Bands * (I)->Xsize))
/* If DEBUG is defined, add bounds checking. /* If DEBUG is defined, add bounds checking.
*/ */
@ -240,7 +243,8 @@ typedef struct _VipsImage {
#define IM_IMAGE_ADDR(I,X,Y) \ #define IM_IMAGE_ADDR(I,X,Y) \
( ((X) >= 0 && (X) < (I)->Xsize && \ ( ((X) >= 0 && (X) < (I)->Xsize && \
(Y) >= 0 && (Y) < (I)->Ysize) ? \ (Y) >= 0 && (Y) < (I)->Ysize) ? \
((I)->data + (Y) * IM_IMAGE_SIZEOF_LINE(I) + \ ((I)->data + \
(Y) * IM_IMAGE_SIZEOF_LINE(I) + \
(X) * IM_IMAGE_SIZEOF_PEL(I)) : \ (X) * IM_IMAGE_SIZEOF_PEL(I)) : \
(fprintf( stderr, \ (fprintf( stderr, \
"IM_IMAGE_ADDR: point out of bounds, " \ "IM_IMAGE_ADDR: point out of bounds, " \

View File

@ -131,18 +131,20 @@ int im_wrapmany( IMAGE **in, IMAGE *out,
* IM_REGION_SIZEOF_LINE() sizeof width of region * IM_REGION_SIZEOF_LINE() sizeof width of region
* IM_REGION_ADDR() address of pixel in region * IM_REGION_ADDR() address of pixel in region
*/ */
#define IM_REGION_LSKIP(R) ((R)->bpl) #define IM_REGION_LSKIP(R) \
#define IM_REGION_N_ELEMENTS(R) ((R)->valid.width*(R)->im->Bands) ((size_t)((R)->bpl))
#define IM_REGION_N_ELEMENTS(R) \
((size_t)((R)->valid.width * (R)->im->Bands))
#define IM_REGION_SIZEOF_LINE(R) \ #define IM_REGION_SIZEOF_LINE(R) \
((R)->valid.width * IM_IMAGE_SIZEOF_PEL((R)->im)) ((size_t)((R)->valid.width * IM_IMAGE_SIZEOF_PEL((R)->im)))
/* If DEBUG is defined, add bounds checking. /* If DEBUG is defined, add bounds checking.
*/ */
#ifdef DEBUG #ifdef DEBUG
#define IM_REGION_ADDR(B,X,Y) \ #define IM_REGION_ADDR(B,X,Y) \
( (im_rect_includespoint( &(B)->valid, (X), (Y) ))? \ ( (im_rect_includespoint( &(B)->valid, (X), (Y) ))? \
((B)->data + ((Y) - (B)->valid.top)*IM_REGION_LSKIP(B) + \ ((B)->data + ((Y) - (B)->valid.top) * IM_REGION_LSKIP(B) + \
((X) - (B)->valid.left)*IM_IMAGE_SIZEOF_PEL((B)->im)): \ ((X) - (B)->valid.left) * IM_IMAGE_SIZEOF_PEL((B)->im)): \
(fprintf( stderr, \ (fprintf( stderr, \
"IM_REGION_ADDR: point out of bounds, " \ "IM_REGION_ADDR: point out of bounds, " \
"file \"%s\", line %d\n" \ "file \"%s\", line %d\n" \

View File

@ -228,7 +228,7 @@
* IM_IMAGE_N_ELEMENTS: * IM_IMAGE_N_ELEMENTS:
* @I: a #VipsImage * @I: a #VipsImage
* *
* Returns: the number of band elements in a scanline. * Returns: The number of band elements in a scanline.
*/ */
/** /**
@ -243,7 +243,7 @@
* *
* If DEBUG is defined, you get a version that checks bounds for you. * If DEBUG is defined, you get a version that checks bounds for you.
* *
* Returns: the address of pixel (x,y) in the image. * Returns: The address of pixel (x,y) in the image.
*/ */
/** /**

View File

@ -132,21 +132,21 @@
* IM_REGION_LSKIP: * IM_REGION_LSKIP:
* @R: a #REGION * @R: a #REGION
* *
* Returns: the number of bytes to add to move down a scanline. * Returns: The number of bytes to add to move down a scanline.
*/ */
/** /**
* IM_REGION_N_ELEMENTS: * IM_REGION_N_ELEMENTS:
* @R: a #REGION * @R: a #REGION
* *
* Returns: the number of band elements across a region. * Returns: The number of band elements across a region.
*/ */
/** /**
* IM_REGION_SIZEOF_LINE: * IM_REGION_SIZEOF_LINE:
* @R: a #REGION * @R: a #REGION
* *
* Returns: the number of bytes across a region. * Returns: The number of bytes across a region.
*/ */
/** /**
@ -160,7 +160,7 @@
* *
* If DEBUG is defined, you get a version that checks bounds for you. * If DEBUG is defined, you get a version that checks bounds for you.
* *
* Returns: the address of pixel (x,y) in the region. * Returns: The address of pixel (x,y) in the region.
*/ */
/** /**
@ -170,7 +170,7 @@
* This macro returns a pointer to the top-left pixel in the #REGION, that is, * This macro returns a pointer to the top-left pixel in the #REGION, that is,
* the pixel at (@R->valid.left, @R->valid.top). * the pixel at (@R->valid.left, @R->valid.top).
* *
* Returns: the address of the top-left pixel in the region. * Returns: The address of the top-left pixel in the region.
*/ */
#ifdef DEBUG #ifdef DEBUG