Added a osg::DegreesToRadians() and osg::RadiansToDegrees() method to osg/Math,

updated the ReaderWriterBMP.cpp (mods sent in my Geoff Michel) and
moved the osgUtil::Statistics to osg::Statistics in preperation to adding it
to the the Drawable base class.
This commit is contained in:
Robert Osfield
2001-10-06 20:29:42 +00:00
parent c56a1b8c31
commit 3da57d6d22
10 changed files with 55 additions and 39 deletions

View File

@@ -75,7 +75,7 @@ bmp_error(char *buffer, int bufferlen)
}
/* byte order workarounds *sigh* */
void swapbyte(long *i)
void swapbyte(long &i)
{
char *vv=(char *)i;
char tmp=vv[0];
@@ -85,7 +85,7 @@ void swapbyte(long *i)
vv[1]=vv[2];
vv[2]=tmp;
}
void swapbyte(unsigned long *i)
void swapbyte(unsigned long &i)
{
char *vv=(char *)i;
char tmp=vv[0];
@@ -105,14 +105,14 @@ void swapbyte(float *i)
vv[1]=vv[2];
vv[2]=tmp;
}
void swapbyte(unsigned short *i)
void swapbyte(unsigned short &i)
{
char *vv=(char *)i;
char tmp=vv[0];
vv[0]=vv[1];
vv[1]=tmp;
}
void swapbyte(short *i)
void swapbyte(short &i)
{
char *vv=(char *)i;
char tmp=vv[0];
@@ -132,7 +132,7 @@ int *numComponents_ret)
// It is extremely expensive on disk space - every RGB pixel uses 3 bytes plus a header!
// BMP - sponsored by Seagate.
// unsigned char palette[256][3];
unsigned char * buffer;
unsigned char *buffer, *imbuff; // returned to sender & as read from the disk
bmperror = ERROR_NO_FILE;
@@ -149,7 +149,7 @@ int *numComponents_ret)
fread((char *)&hd, sizeof(bmpheader), 1, fp);
fread((char *)&inf, sizeof(BMPInfo), 1, fp);
if (hd.FileType != MB) {
swapbyte(&(hd.FileType));
swapbyte((hd.FileType));
swap=true;
if (hd.FileType != MB) {
bmperror=ERROR_READING_HEADER;
@@ -158,11 +158,12 @@ int *numComponents_ret)
}
if (hd.FileType == MB) {
if (swap) { // inverse the field of the header which need swapping
swapbyte(&hd.siz[0]);
swapbyte(&hd.siz[1]);
swapbyte(&inf.Colorbits);
swapbyte(&inf.width);
swapbyte(&inf.height);
swapbyte(hd.siz[0]);
swapbyte(hd.siz[1]);
swapbyte(inf.Colorbits);
swapbyte(inf.width);
swapbyte(inf.height);
swapbyte(inf.ImageSize);
}
long size = hd.siz[1]*65536+hd.siz[0];
size -= sizeof(bmpheader)+sizeof(BMPInfo);
@@ -181,25 +182,32 @@ int *numComponents_ret)
ncomp = RGBA;
break;
}
buffer = (unsigned char *)malloc( ncomp*inf.width*inf.height);
osg::notify(osg::NOTICE)<<"BMP file: "<<filename << endl;
osg::notify(osg::NOTICE)<<"sizes: "<< inf.width << " " << inf.height <<endl;
imbuff = (unsigned char *)malloc( inf.ImageSize); // read from disk
buffer = (unsigned char *)malloc( ncomp*inf.width*inf.height*sizeof(unsigned char)); //
if (ncomp==BW) {
osg::notify(osg::NOTICE)<<"BMP file: "<<filename << " sz " << inf.ImageSize <<endl;
osg::notify(osg::NOTICE)<<"sizes: "<< inf.width << " " << inf.height << " = " << ncomp*inf.width*inf.height << endl;
}
unsigned long off=0;
unsigned long doff=(ncomp*sizeof(unsigned char)*inf.width)/4;
unsigned long rowbytes=ncomp*sizeof(unsigned char)*inf.width;
unsigned long doff=(rowbytes)/4;
if ((rowbytes%4)) doff++; // round up if needed
doff*=4; // to find dword alignment
doff=fread((char *)buffer, sizeof(unsigned char),ncomp*inf.width*inf.height, fp);
if (ncomp>2) { // yes bill, colours are usually BGR aren't they
for(int j=0; j<inf.height; j++) {
if (j<5) osg::notify(osg::NOTICE)<<"row: "<< j << " offset " << off <<endl;
off+=doff;
fread((char *)imbuff, sizeof(unsigned char),inf.ImageSize, fp);
for(int j=0; j<inf.height; j++) {
memcpy(buffer+j*rowbytes, imbuff+off, rowbytes); // pack bytes closely
off+=doff;
if (ncomp>2) { // yes bill, colours are usually BGR aren't they
for(int i=0; i<inf.width; i++) {
unsigned char blu=buffer[3*(i*inf.height+j)+0];
buffer[3*(i*inf.height+j)+0]=buffer[3*(i*inf.height+j)+2]; // swap order of colours
buffer[3*(i*inf.height+j)+2]=blu;
int ijw=i+j*inf.width;
unsigned char blu=buffer[3*ijw+0];
buffer[3*ijw+0]=buffer[3*ijw+2]; // swap order of colours
buffer[3*ijw+2]=blu;
}
}
}
delete [] imbuff; // free the on-disk storage
} // else error in header
fclose(fp);
@@ -234,6 +242,7 @@ class ReaderWriterBMP : public osgDB::ReaderWriter
int r = 1;
int internalFormat = numComponents_ret;
unsigned int pixelFormat =
numComponents_ret == 1 ? GL_LUMINANCE :
@@ -241,6 +250,9 @@ class ReaderWriterBMP : public osgDB::ReaderWriter
numComponents_ret == 3 ? GL_RGB :
numComponents_ret == 4 ? GL_RGBA : (GLenum)-1;
cout << "internalFormat="<<internalFormat<<endl;
cout << "pixelFormat="<<pixelFormat<<endl;
unsigned int dataType = GL_UNSIGNED_BYTE;
osg::Image* pOsgImage = new osg::Image;