From 1cc89ba4fea018740e38e7145c7f119fb693be80 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 1 Feb 2005 09:38:07 +0000 Subject: [PATCH] Added conversion of dataType to GL_UNSIGNED in raw data reading path. --- examples/osgvolume/osgvolume.cpp | 64 ++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/examples/osgvolume/osgvolume.cpp b/examples/osgvolume/osgvolume.cpp index 147dc5bb0..878c8717a 100644 --- a/examples/osgvolume/osgvolume.cpp +++ b/examples/osgvolume/osgvolume.cpp @@ -977,30 +977,64 @@ osg::Image* readRaw(int sizeX, int sizeY, int sizeZ, int numberBytesPerComponent } } - // compute range of values - FindRangeOperator rangeOp; - for(int r=0;rdata(0,t,r), rangeOp); + for(int t=0;tdata(0,t,r), rangeOp); + } + } + + // scale the values + for(int r=0;rdata(0,t,r), ScaleOperator(1.0f/rangeOp._rmax)); + } } } - - // scale the values - for(int r=0;rdata(0,t,r), ScaleOperator(1.0f/rangeOp._rmax)); - } - } - + + fin.close(); if (dataType!=GL_UNSIGNED_BYTE) { // need to convert to ubyte + + osg::ref_ptr new_image = new osg::Image; + new_image->allocateImage(sizeS, sizeT, sizeR, pixelFormat, GL_UNSIGNED_BYTE); + + RecordRowOperator readOp(sizeS); + WriteRowOperator writeOp; + + for(int r=0;rdata(0,t,r), readOp); + + // pass readOp's _colour array contents over to writeOp (note this is just a pointer swap). + writeOp._colours.swap(readOp._colours); + + modifyRow(sizeS, pixelFormat, GL_UNSIGNED_BYTE, new_image->data(0,t,r), writeOp); + + // return readOp's _colour array contents back to its rightful owner. + writeOp._colours.swap(readOp._colours); + } + } + + image = new_image; } return image.release();