From 86c6a88c986403c23ccfa1a8eb0659f8186c2b85 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 7 Nov 2006 12:02:37 +0000 Subject: [PATCH] From Mathias Froehlich, workaround fix for problematic run length encoded RGB files. Robert Osfield ammend workaround to support multi-byte colour channels. --- src/osgPlugins/rgb/ReaderWriterRGB.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/osgPlugins/rgb/ReaderWriterRGB.cpp b/src/osgPlugins/rgb/ReaderWriterRGB.cpp index ba70d6bba..259fbcf84 100644 --- a/src/osgPlugins/rgb/ReaderWriterRGB.cpp +++ b/src/osgPlugins/rgb/ReaderWriterRGB.cpp @@ -257,9 +257,11 @@ static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) int count, done = 0; unsigned short *tempShort; + osg::notify(osg::NOTICE)<type & 0xFF00) == 0x0100) { - raw->file->seekg((long) raw->rowStart[y+z*raw->sizeY], std::ios::beg); + 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]); iPtr = raw->tmp; @@ -275,14 +277,24 @@ static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) tempShort++; iPtr = reinterpret_cast(tempShort); } + if(raw->bpc != 1) ConvertShort(&pixel, 1); + count = (int)(pixel & 0x7F); - if (!count) + + // limit the count value to the remiaing row size + if (oPtr + count*raw->bpc > buf + raw->sizeX*raw->bpc) + { + count = ( (buf + raw->sizeX*raw->bpc) - oPtr ) / raw->bpc; + } + + if (count<=0) { done = 1; return; } + if (pixel & 0x80) { while (count--) @@ -356,6 +368,12 @@ static void RawImageGetData(rawImageRec *raw, unsigned char **data ) // if (width!=raw->sizeX) width += 4; // byte aligned. + + osg::notify(osg::NOTICE)<<"raw->sizeX = "<sizeX<sizeY = "<sizeY<sizeZ = "<sizeZ<bpc = "<bpc<sizeX)*(raw->sizeY)*(raw->sizeZ)*(raw->bpc)]; ptr = *data;