From 67a5a020bf096ec6fa20c2a20616148bd87ec967 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 25 Jan 2005 22:15:40 +0000 Subject: [PATCH] From Donn Mielcarek, change of long and unsigned long to int32 and uint32 to avoid 32bit vs 64bit issues. --- src/osgPlugins/bmp/ReaderWriterBMP.cpp | 60 ++++++++++++++------------ 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/osgPlugins/bmp/ReaderWriterBMP.cpp b/src/osgPlugins/bmp/ReaderWriterBMP.cpp index 888fc17c1..51a56a5eb 100644 --- a/src/osgPlugins/bmp/ReaderWriterBMP.cpp +++ b/src/osgPlugins/bmp/ReaderWriterBMP.cpp @@ -8,6 +8,11 @@ #include #include +#include + +typedef int32_t int32; +typedef uint32_t uint32; + /**************************************************************************** * * Follows is code written by GWM and translated to fit with the OSG Ethos. @@ -47,16 +52,16 @@ struct bmpheader { }; struct BMPInfo { - long width; //width of the image in pixels - long height; // height of the image in pixels + int32 width; //width of the image in pixels + int32 height; // height of the image in pixels short planes; //:word: number of planes (always 1) short Colorbits; //word: number of bits used to describe color in each pixel - long compression; //compression used - long ImageSize; //image size in bytes - long XpixPerMeter; //pixels per meter in X - long YpixPerMeter; //pixels per meter in Y - long ColorUsed; //number of colors used - long Important; //number of "important" colors + int32 compression; //compression used + int32 ImageSize; //image size in bytes + int32 XpixPerMeter; //pixels per meter in X + int32 YpixPerMeter; //pixels per meter in Y + int32 ColorUsed; //number of colors used + int32 Important; //number of "important" colors // unsigned char rgbquad[4]; // long os2stuff[6]; // storage for os2.1 with 64 bytes to be read. Dont know what these are yet. }; @@ -86,7 +91,7 @@ bmp_error(char *buffer, int bufferlen) } /* byte order workarounds *sigh* */ -void swapbyte(long *i) +void swapbyte(int32 *i) { char *vv=(char *)i; char tmp=vv[0]; @@ -96,7 +101,7 @@ void swapbyte(long *i) vv[1]=vv[2]; vv[2]=tmp; } -void swapbyte(unsigned long *i) +void swapbyte(uint32 *i) { char *vv=(char *)i; char tmp=vv[0]; @@ -131,8 +136,7 @@ void swapbyte(short *i) vv[1]=tmp; } -unsigned char * -bmp_load(const char *filename, +unsigned char *bmp_load(const char *filename, int *width_ret, int *height_ret, int *numComponents_ret) @@ -171,14 +175,14 @@ int *numComponents_ret) } } if (hd.FileType == MB) { - long infsize; //size of BMPinfo in bytes + int32 infsize; //size of BMPinfo in bytes unsigned char *cols=NULL; // dynamic colour palette unsigned char *imbuff; // returned to sender & as read from the disk - fread((char *)&infsize, sizeof(long), 1, fp); // insert inside 'the file is bmp' clause + fread((char *)&infsize, sizeof(int32), 1, fp); // insert inside 'the file is bmp' clause if (swap) swapbyte(&infsize); unsigned char *hdr=new unsigned char[infsize]; // to hold the new header - fread((char *)hdr, 1,infsize-sizeof(long), fp); - long hsiz=sizeof(inf); // minimum of structure size & + fread((char *)hdr, 1,infsize-sizeof(int32), fp); + int32 hsiz=sizeof(inf); // minimum of structure size & if(infsize<=hsiz) hsiz=infsize; memcpy(&inf,hdr, hsiz/*-sizeof(long)*/); // copy only the bytes I can cope with delete [] hdr; @@ -200,16 +204,16 @@ int *numComponents_ret) inf.height=ht; inf.planes=npln; inf.Colorbits=cbits; - inf.ColorUsed=(long)pow(2.0,(double)inf.Colorbits); // infer the colours + inf.ColorUsed=(int32)pow(2.0,(double)inf.Colorbits); // infer the colours } osg::notify(osg::INFO) << "readbmp " <