diff --git a/src/osgPlugins/rgb/ReaderWriterRGB.cpp b/src/osgPlugins/rgb/ReaderWriterRGB.cpp index 73cd97172..c22abd001 100644 --- a/src/osgPlugins/rgb/ReaderWriterRGB.cpp +++ b/src/osgPlugins/rgb/ReaderWriterRGB.cpp @@ -37,6 +37,7 @@ using namespace osg; +typedef unsigned int size_pos; struct rawImageRec : public osg::Referenced { @@ -208,7 +209,7 @@ static osg::ref_ptr RawImageOpen(std::istream& fin) raw->rowSize = 0; raw->bpc = (raw->type & 0x00FF); - raw->tmp = new unsigned char [static_cast(raw->sizeX) * 256 * static_cast(raw->bpc)]; + raw->tmp = new unsigned char [static_cast(raw->sizeX) * 256 * static_cast(raw->bpc)]; if (raw->tmp == NULL ) { OSG_FATAL<< "Out of memory!"<< std::endl; @@ -217,7 +218,7 @@ static osg::ref_ptr RawImageOpen(std::istream& fin) if( raw->sizeZ >= 1 ) { - if( (raw->tmpR = new unsigned char [static_cast(raw->sizeX) * static_cast(raw->bpc)]) == NULL ) + if( (raw->tmpR = new unsigned char [static_cast(raw->sizeX) * static_cast(raw->bpc)]) == NULL ) { OSG_FATAL<< "Out of memory!"<< std::endl; return NULL; @@ -225,7 +226,7 @@ static osg::ref_ptr RawImageOpen(std::istream& fin) } if( raw->sizeZ >= 2 ) { - if( (raw->tmpG = new unsigned char [static_cast(raw->sizeX) * static_cast(raw->bpc)]) == NULL ) + if( (raw->tmpG = new unsigned char [static_cast(raw->sizeX) * static_cast(raw->bpc)]) == NULL ) { OSG_FATAL<< "Out of memory!"<< std::endl; return NULL; @@ -233,7 +234,7 @@ static osg::ref_ptr RawImageOpen(std::istream& fin) } if( raw->sizeZ >= 3 ) { - if( (raw->tmpB = new unsigned char [static_cast(raw->sizeX) * static_cast(raw->bpc)]) == NULL ) + if( (raw->tmpB = new unsigned char [static_cast(raw->sizeX) * static_cast(raw->bpc)]) == NULL ) { OSG_FATAL<< "Out of memory!"<< std::endl; return NULL; @@ -241,7 +242,7 @@ static osg::ref_ptr RawImageOpen(std::istream& fin) } if (raw->sizeZ >= 4) { - if( (raw->tmpA = new unsigned char [static_cast(raw->sizeX) * static_cast(raw->bpc)]) == NULL ) + if( (raw->tmpA = new unsigned char [static_cast(raw->sizeX) * static_cast(raw->bpc)]) == NULL ) { OSG_FATAL<< "Out of memory!"<< std::endl; return NULL; @@ -250,7 +251,7 @@ static osg::ref_ptr RawImageOpen(std::istream& fin) if ((raw->type & 0xFF00) == 0x0100) { - unsigned int ybyz = static_cast(raw->sizeY) * static_cast(raw->sizeZ); + unsigned int ybyz = static_cast(raw->sizeY) * static_cast(raw->sizeZ); if ( (raw->rowStart = new GLuint [ybyz]) == NULL ) { OSG_FATAL<< "Out of memory!"<< std::endl; @@ -286,8 +287,12 @@ static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) if ((raw->type & 0xFF00) == 0x0100) { - raw->file->seekg((long) raw->rowStart[y+z*raw->sizeY], std::ios::beg); - raw->file->read((char*)raw->tmp, (unsigned int)raw->rowSize[y+z*raw->sizeY]); + size_pos pos = raw->rowStart[static_cast(y)+static_cast(z)*static_cast(raw->sizeY)]; + + size_pos amount = raw->rowSize[static_cast(y)+static_cast(z)*static_cast(raw->sizeY)]; + + raw->file->seekg(pos, std::ios::beg); + raw->file->read((char*)raw->tmp, amount); iPtr = raw->tmp; oPtr = buf; @@ -373,8 +378,14 @@ static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) } else { - raw->file->seekg(512+(y*raw->sizeX*raw->bpc)+(z*raw->sizeX*raw->sizeY*raw->bpc),std::ios::beg); - raw->file->read((char*)buf, raw->sizeX*raw->bpc); + size_pos pos = static_cast(512)+ + (static_cast(y)*static_cast(raw->sizeX)*static_cast(raw->bpc))+ + (static_cast(z)*static_cast(raw->sizeX)*static_cast(raw->sizeY)*static_cast(raw->bpc)); + + size_pos amount = static_cast(raw->sizeX)*static_cast(raw->bpc); + + raw->file->seekg(pos,std::ios::beg); + raw->file->read((char*)buf, amount); if(raw->swapFlag && raw->bpc != 1){ ConvertShort(reinterpret_cast(buf), raw->sizeX); }