Fix 32bits issues in ImageIO

Those issues were detected by the compilation flag `-Wconversion` of
g++-5.3.

That changes the ABI of CGAL_ImageIO.
This commit is contained in:
Laurent Rineau 2016-04-22 12:05:46 +02:00
parent 7a12fa8556
commit 810538d221
8 changed files with 57 additions and 32 deletions

View File

@ -516,7 +516,7 @@ CGAL_IMAGEIO_EXPORT char *ImageIO_gets( const _image *im, char *str, int size );
/** replaces fseek function
*/
CGAL_IMAGEIO_EXPORT int ImageIO_seek( const _image *im, long offset, int whence );
CGAL_IMAGEIO_EXPORT long ImageIO_seek( const _image *im, long offset, int whence );
/** replaces ferror function
*/

View File

@ -111,6 +111,11 @@ void ImageIO_free(void *m) {
unsigned int ImageIO_limit_len(size_t to_be_read)
{
return (unsigned int)(std::min)(to_be_read, size_t(1u<<30));
}
/* mimics fwrite() function.
According to _openWriteImage(), openMode will has one
of the following value:
@ -120,6 +125,9 @@ void ImageIO_free(void *m) {
*/
CGAL_INLINE_FUNCTION
size_t ImageIO_write(const _image *im, const void *buf, size_t len) {
size_t to_be_written = len;
int l = -1;
char *b = (char*)buf;
switch(im->openMode) {
default :
@ -127,23 +135,40 @@ size_t ImageIO_write(const _image *im, const void *buf, size_t len) {
return 0;
case OM_STD :
#ifdef CGAL_USE_ZLIB
return gzwrite(im->fd, (void *) buf, len);
while ( (to_be_written > 0) && ((l = gzwrite(im->fd, (void *) b, ImageIO_limit_len(to_be_written))) > 0) ) {
to_be_written -= l;
b += l;
}
#else
return fwrite(buf, 1, len, im->fd);
while ( (to_be_written > 0) && ((l = fwrite( b, 1, ImageIO_limit_len(to_be_written), im->fd )) > 0) ) {
to_be_written -= l;
b += l;
}
#endif
return ( len - to_be_written );
#ifdef CGAL_USE_ZLIB
case OM_GZ :
return gzwrite(im->fd, (void *) buf, len);
#endif
case OM_FILE:
return fwrite(buf, 1, len, (FILE*)im->fd);
while ( (to_be_written > 0) && ((l = gzwrite(im->fd, (void *) b, ImageIO_limit_len(to_be_written))) > 0) ) {
to_be_written -= l;
b += l;
}
if(l<0)
{
int errnum;
fprintf(stderr, "zlib error: %s\n", gzerror(im->fd, &errnum));
}
return ( len - to_be_written );
#else
case OM_FILE :
while ( (to_be_written > 0) && ((l = fwrite( b, 1, ImageIO_limit_len(to_be_written), im->fd )) > 0) ) {
to_be_written -= l;
b += l;
}
return ( len - to_be_written );
#endif
}
//return 0;
}
size_t ImageIO_limit_read(size_t to_be_read)
{
return (std::min)(to_be_read, size_t(1u<<30));
//return 0;
}
/* mimics fread() function.
@ -165,12 +190,12 @@ size_t ImageIO_read(const _image *im, void *buf, size_t len)
return 0;
case OM_STD :
#ifdef CGAL_USE_ZLIB
while ( (to_be_read > 0) && ((l = gzread(im->fd, (void *) b, ImageIO_limit_read(to_be_read))) > 0) ) {
while ( (to_be_read > 0) && ((l = gzread(im->fd, (void *) b, ImageIO_limit_len(to_be_read))) > 0) ) {
to_be_read -= l;
b += l;
}
#else
while ( (to_be_read > 0) && ((l = fread( b, 1, ImageIO_limit_read(to_be_read), im->fd )) > 0) ) {
while ( (to_be_read > 0) && ((l = fread( b, 1, ImageIO_limit_len(to_be_read), im->fd )) > 0) ) {
to_be_read -= l;
b += l;
}
@ -178,7 +203,7 @@ size_t ImageIO_read(const _image *im, void *buf, size_t len)
return ( len - to_be_read );
#ifdef CGAL_USE_ZLIB
case OM_GZ :
while ( (to_be_read > 0) && ((l = gzread(im->fd, (void *) b, ImageIO_limit_read(to_be_read))) > 0) ) {
while ( (to_be_read > 0) && ((l = gzread(im->fd, (void *) b, ImageIO_limit_len(to_be_read))) > 0) ) {
to_be_read -= l;
b += l;
}
@ -190,7 +215,7 @@ size_t ImageIO_read(const _image *im, void *buf, size_t len)
return ( len - to_be_read );
#else
case OM_FILE :
while ( (to_be_read > 0) && ((l = fread( b, 1, ImageIO_limit_read(to_be_read), im->fd )) > 0) ) {
while ( (to_be_read > 0) && ((l = fread( b, 1, ImageIO_limit_len(to_be_read), im->fd )) > 0) ) {
to_be_read -= l;
b += l;
}
@ -240,7 +265,7 @@ char *ImageIO_gets( const _image *im, char *str, int size )
CGAL_INLINE_FUNCTION
int ImageIO_seek( const _image *im, long offset, int whence ) {
long ImageIO_seek( const _image *im, long offset, int whence ) {
switch(im->openMode) {
case OM_CLOSE :
default :
@ -790,7 +815,7 @@ CGAL_INLINE_FUNCTION
int _writeImage(_image *im, const char *name_to_be_written ) {
int r = ImageIO_NO_ERROR;
int length = 0;
std::size_t length = 0;
char *name = NULL;
char *baseName = NULL;
@ -814,7 +839,7 @@ int _writeImage(_image *im, const char *name_to_be_written ) {
if ( name == NULL ) {
im->imageFormat = InrimageFormat;
} else {
int i,extLength;
std::size_t i,extLength;
PTRIMAGE_FORMAT f;
char ext[IMAGE_FORMAT_NAME_LENGTH];
char *ptr;
@ -1054,11 +1079,11 @@ static void _swapImageData( _image *im )
unsigned char *ptr1, *ptr2, b[8];
unsigned short int si, *ptr3, *ptr4;
unsigned int i, *ptr5, *ptr6;
int size, length;
std::size_t size, length;
if( _getEndianness() != im->endianness) {
size = im->xdim * im->ydim * im->zdim * im->vdim * im->wdim;
size = std::size_t(im->xdim) * im->ydim * im->zdim * im->vdim * im->wdim;
if ( size <= 0 ) return;
length = size / im->wdim;

View File

@ -61,7 +61,7 @@ void Image_3::gl_draw(const float point_size,
glColor3ub(r,g,b);
glBegin(GL_POINTS);
unsigned char *pData = (unsigned char*)image_ptr->data;
unsigned int xy = image_ptr->xdim * image_ptr->ydim;
std::size_t xy = image_ptr->xdim * image_ptr->ydim;
for(unsigned int i=0;i<image_ptr->xdim;i+=5)
for(unsigned int j=0;j<image_ptr->ydim;j+=5)
for(unsigned int k=0;k<image_ptr->zdim;k+=5)

View File

@ -790,9 +790,9 @@ writeAnalyzeHeader( const _image* im )
/* Writes the given image body in an already opened file.*/
CGAL_INLINE_FUNCTION
int writeAnalyzeData(const _image *im) {
unsigned int lineSize = im->wdim * im->xdim * im->vdim ;
unsigned long size = lineSize * im->ydim * im->zdim;
unsigned int nwrt ;
std::size_t lineSize = std::size_t(im->wdim) * im->xdim * im->vdim ;
std::size_t size = lineSize * im->ydim * im->zdim;
std::size_t nwrt ;
if(im->openMode != OM_CLOSE) {

View File

@ -134,7 +134,7 @@ int gif89 = 0;
byte ch, ch1;
byte *ptr, *ptr1;
int i, block;
int npixels, maxpixels, aspect, filesize;
int npixels, maxpixels, aspect;
float normaspect;
int OutCount = 0, /* Decompressor output 'stack count' */
RWidth, RHeight, /* screen dimensions */
@ -186,7 +186,7 @@ int gif89 = 0;
}
/* find the size of the file */
fseek(fp, 0L, 2);
filesize = ftell(fp);
long filesize = ftell(fp);
fseek(fp, 0L, 0);
/* the +256's are so we can read truncated GIF files without fear of

View File

@ -75,7 +75,7 @@ static void concatStringElement(const stringListHead *strhead,
/* Writes the given inrimage header in an already opened file.*/
CGAL_INLINE_FUNCTION
int _writeInrimageHeader(const _image *im, ENDIANNESS end) {
unsigned int pos, i;
std::size_t pos, i;
char type[30], endianness[5], buf[257], scale[20];
std::ostringstream oss;

View File

@ -565,9 +565,9 @@ int writePgmImage(char *name,_image *im )
ImageIO_write( im, string, strlen( string ) );
if ( im->dataMode == DM_ASCII ) {
int i, j, n, size;
std::size_t i, j, n, size;
char *str = (char*)ImageIO_alloc( _LGTH_STRING_+1 );
size = im->xdim * im->ydim * im->zdim * im->vdim;
size = std::size_t(im->xdim) * im->ydim * im->zdim * im->vdim;
n = ( im->xdim < 16 ) ? im->xdim : 16;
i = 0;
switch( im->wdim ) {

View File

@ -343,11 +343,11 @@ endif()
# CGAL-4.6 : 11.0.0 (int->size_t in CGAL_ImageIO)
# CGAL-4.7 : 11.0.1 (Nothing different in CGAL compiled libraries.)
# CGAL-4.8 : 11.0.2 (Nothing different in CGAL compiled libraries.)
# CGAL-4.9 : 11.0.3 (Nothing different in CGAL compiled libraries.)
# CGAL-4.9 : 12.0.0 (Change the API/ABI in CGAL_ImageIO, but issue with 4GB images.)
# ¹) According to http://upstream-tracker.org/versions/cgal.html
set( CGAL_SONAME_VERSION "11" )
set( CGAL_SOVERSION "11.0.3" )
set( CGAL_SONAME_VERSION "12" )
set( CGAL_SOVERSION "12.0.0" )
message( STATUS "CGAL_SONAME_VERSION=${CGAL_SONAME_VERSION}" )
message( STATUS "CGAL_SOVERSION =${CGAL_SOVERSION}" )