From ee118c872f1d4fa0ad2ab7a0b96bf2279bc3d925 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 11 Nov 2017 11:17:34 +0000 Subject: [PATCH] Restructed the ref counting of the rawImageRec structure so that it's done with a separate refImageRec struct so it doesn't interfer with the writing of the rawImageRec as a header when writing to .rgb --- src/osgPlugins/rgb/ReaderWriterRGB.cpp | 131 +++++++++++++------------ 1 file changed, 68 insertions(+), 63 deletions(-) diff --git a/src/osgPlugins/rgb/ReaderWriterRGB.cpp b/src/osgPlugins/rgb/ReaderWriterRGB.cpp index 63d144955..ffaad7026 100644 --- a/src/osgPlugins/rgb/ReaderWriterRGB.cpp +++ b/src/osgPlugins/rgb/ReaderWriterRGB.cpp @@ -39,7 +39,7 @@ using namespace osg; typedef unsigned int size_pos; -struct rawImageRec : public osg::Referenced +struct rawImageRec { rawImageRec(): imagic(0), @@ -59,7 +59,7 @@ struct rawImageRec : public osg::Referenced { } - virtual ~rawImageRec() + ~rawImageRec() { if (tmp) delete [] tmp; if (tmpR) delete [] tmpR; @@ -131,6 +131,11 @@ struct rawImageRec : public osg::Referenced } }; +struct refImageRec : public rawImageRec, public osg::Referenced +{ +}; + + static void ConvertShort(unsigned short *array, long length) { unsigned long b1, b2; @@ -163,7 +168,7 @@ static void ConvertLong(GLuint *array, long length) -static osg::ref_ptr RawImageOpen(std::istream& fin) +static osg::ref_ptr RawImageOpen(std::istream& fin) { union { @@ -173,7 +178,7 @@ static osg::ref_ptr RawImageOpen(std::istream& fin) int x; - osg::ref_ptr raw = new rawImageRec; + osg::ref_ptr raw = new refImageRec; if (raw == NULL) { OSG_WARN<< "Out of memory!"<< std::endl; @@ -278,27 +283,27 @@ static osg::ref_ptr RawImageOpen(std::istream& fin) } -static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) +static void RawImageGetRow(rawImageRec& raw, unsigned char *buf, int y, int z) { unsigned char *iPtr, *oPtr; unsigned short pixel; int count, done = 0; unsigned short *tempShort; - if ((raw->type & 0xFF00) == 0x0100) + if ((raw.type & 0xFF00) == 0x0100) { - size_pos pos = raw->rowStart[static_cast(y)+static_cast(z)*static_cast(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)]; + 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); + raw.file->seekg(pos, std::ios::beg); + raw.file->read((char*)raw.tmp, amount); - iPtr = raw->tmp; + iPtr = raw.tmp; oPtr = buf; while (!done) { - if (raw->bpc == 1) + if (raw.bpc == 1) pixel = *iPtr++; else { @@ -308,15 +313,15 @@ static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) iPtr = reinterpret_cast(tempShort); } - if(raw->bpc != 1) + if(raw.bpc != 1) ConvertShort(&pixel, 1); count = (int)(pixel & 0x7F); // limit the count value to the remiaing row size - if ((static_cast(raw->sizeX)*static_cast(raw->bpc)) <= (oPtr - buf)) + if ((static_cast(raw.sizeX)*static_cast(raw.bpc)) <= (oPtr - buf)) { - count = static_cast(raw->sizeX) - (oPtr - buf) / static_cast(raw->bpc); + count = static_cast(raw.sizeX) - (oPtr - buf) / static_cast(raw.bpc); } if (count<=0) @@ -329,7 +334,7 @@ static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) { while (count--) { - if(raw->bpc == 1) + if(raw.bpc == 1) *oPtr++ = *iPtr++; else{ tempShort = reinterpret_cast(iPtr); @@ -348,7 +353,7 @@ static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) } else { - if (raw->bpc == 1) + if (raw.bpc == 1) { pixel = *iPtr++; } @@ -359,11 +364,11 @@ static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) tempShort++; iPtr = reinterpret_cast(tempShort); } - if(raw->bpc != 1) + if(raw.bpc != 1) ConvertShort(&pixel, 1); while (count--) { - if(raw->bpc == 1) + if(raw.bpc == 1) *oPtr++ = pixel; else { @@ -379,87 +384,87 @@ static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) else { 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)); + (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); + 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); + 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); } } } -static void RawImageGetData(rawImageRec *raw, unsigned char **data ) +static void RawImageGetData(rawImageRec& raw, unsigned char **data ) { unsigned char *ptr; int i, j; unsigned short *tempShort; // // round the width to a factor 4 - // int width = (int)(floorf((float)raw->sizeX/4.0f)*4.0f); - // if (width!=raw->sizeX) width += 4; + // int width = (int)(floorf((float)raw.sizeX/4.0f)*4.0f); + // if (width!=raw.sizeX) width += 4; // byte aligned. - OSG_INFO<<"raw->sizeX = "<sizeX<sizeY = "<sizeY<sizeZ = "<sizeZ<bpc = "<bpc<