From a7d01559153dd79b8cb09ec1cf6dd5f9c49a807f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 31 Jan 2005 20:09:24 +0000 Subject: [PATCH] Added support for raw image formats --- examples/osgvolume/osgvolume.cpp | 275 +++++++++++++++++++++++++++++-- 1 file changed, 263 insertions(+), 12 deletions(-) diff --git a/examples/osgvolume/osgvolume.cpp b/examples/osgvolume/osgvolume.cpp index 04107668e..8ed868728 100644 --- a/examples/osgvolume/osgvolume.cpp +++ b/examples/osgvolume/osgvolume.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -24,6 +25,89 @@ typedef std::vector< osg::ref_ptr > ImageList; + +struct ReadOperator +{ + inline void luminance(float l) const { rgba(l,l,l,1.0f); } + inline void alpha(float a) const { rgba(1.0f,1.0f,1.0f,a); } + inline void luminance_alpha(float l,float a) const { rgba(l,l,l,a); } + inline void rgb(float r,float g,float b) const { rgba(r,g,b,1.0f); } + inline void rgba(float r,float g,float b,float a) const { std::cout<<"pixel("< +void _readRow(unsigned int num, GLenum pixelFormat, T* data,float scale, const O& operation) +{ + switch(pixelFormat) + { + case(GL_LUMINANCE): { for(unsigned int i=0;i +void readRow(unsigned int num, GLenum pixelFormat, GLenum dataType, unsigned char* data, const O& operation) +{ + switch(dataType) + { + case(GL_BYTE): _readRow(num,pixelFormat, (char*)data, 1.0f/128.0f, operation); break; + case(GL_UNSIGNED_BYTE): _readRow(num,pixelFormat, (unsigned char*)data, 1.0f/255.0f, operation); break; + case(GL_SHORT): _readRow(num,pixelFormat, (short*) data, 1.0f/32768.0f, operation); break; + case(GL_UNSIGNED_SHORT): _readRow(num,pixelFormat, (unsigned short*)data, 1.0f/65535.0f, operation); break; + case(GL_INT): _readRow(num,pixelFormat, (int*) data, 1.0f/2147483648.0f, operation); break; + case(GL_UNSIGNED_INT): _readRow(num,pixelFormat, (unsigned int*) data, 1.0f/4294967295.0f, operation); break; + case(GL_FLOAT): _readRow(num,pixelFormat, (float*) data, 1.0f, operation); break; + } +} + + + +struct ModifyOperator +{ + inline void luminance(float& l) const {} + inline void alpha(float& a) const {} + inline void luminance_alpha(float& l,float& a) const {} + inline void rgb(float& r,float& g,float& b) const {} + inline void rgba(float& r,float& g,float& b,float& a) const {} +}; + + +template +void _modifyRow(unsigned int num, GLenum pixelFormat, T* data,float scale, const M& operation) +{ + float inv_scale = 1.0f/scale; + switch(pixelFormat) + { + case(GL_LUMINANCE): { for(unsigned int i=0;i +void modifyRow(unsigned int num, GLenum pixelFormat, GLenum dataType, unsigned char* data, const M& operation) +{ + switch(dataType) + { + case(GL_BYTE): _modifyRow(num,pixelFormat, (char*)data, 1.0f/128.0f, operation); break; + case(GL_UNSIGNED_BYTE): _modifyRow(num,pixelFormat, (unsigned char*)data, 1.0f/255.0f, operation); break; + case(GL_SHORT): _modifyRow(num,pixelFormat, (short*) data, 1.0f/32768.0f, operation); break; + case(GL_UNSIGNED_SHORT): _modifyRow(num,pixelFormat, (unsigned short*)data, 1.0f/65535.0f, operation); break; + case(GL_INT): _modifyRow(num,pixelFormat, (int*) data, 1.0f/2147483648.0f, operation); break; + case(GL_UNSIGNED_INT): _modifyRow(num,pixelFormat, (unsigned int*) data, 1.0f/4294967295.0f, operation); break; + case(GL_FLOAT): _modifyRow(num,pixelFormat, (float*) data, 1.0f, operation); break; + } +} + + struct PassThroughTransformFunction { unsigned char operator() (unsigned char c) const { return c; } @@ -255,6 +339,23 @@ struct ProcessRow }; +void clampToNearestValidPowerOfTwo(int& sizeX, int& sizeY, int& sizeZ, int s_maximumTextureSize, int t_maximumTextureSize, int r_maximumTextureSize) +{ + // compute nearest powers of two for each axis. + int s_nearestPowerOfTwo = 1; + while(s_nearestPowerOfTwo& image_3d, osg::ref_ptrdata(0,t,r+r_offset); + for(int s=0;saddCommandLineOption("-h or --help","Display this information"); arguments.getApplicationUsage()->addCommandLineOption("-n","Create normal map for per voxel lighting."); - arguments.getApplicationUsage()->addCommandLineOption("-s","Number of slices to create."); - arguments.getApplicationUsage()->addCommandLineOption("--xSize","Relative width of rendered brick."); - arguments.getApplicationUsage()->addCommandLineOption("--ySize","Relative length of rendered brick."); - arguments.getApplicationUsage()->addCommandLineOption("--zSize","Relative height of rendered brick."); - arguments.getApplicationUsage()->addCommandLineOption("--xMultiplier","Tex coord x mulitplier."); - arguments.getApplicationUsage()->addCommandLineOption("--yMultiplier","Tex coord y mulitplier."); - arguments.getApplicationUsage()->addCommandLineOption("--zMultiplier","Tex coord z mulitplier."); - arguments.getApplicationUsage()->addCommandLineOption("--clip","clip volume as a ratio, 0.0 clip all, 1.0 clip none."); - arguments.getApplicationUsage()->addCommandLineOption("--maxTextureSize","Set the texture maximum resolution in the s,t,r (x,y,z) dimensions."); - arguments.getApplicationUsage()->addCommandLineOption("--s_maxTextureSize","Set the texture maximum resolution in the s (x) dimension."); - arguments.getApplicationUsage()->addCommandLineOption("--t_maxTextureSize","Set the texture maximum resolution in the t (y) dimension."); - arguments.getApplicationUsage()->addCommandLineOption("--r_maxTextureSize","Set the texture maximum resolution in the r (z) dimension."); + arguments.getApplicationUsage()->addCommandLineOption("-s ","Number of slices to create."); + arguments.getApplicationUsage()->addCommandLineOption("--xSize ","Relative width of rendered brick."); + arguments.getApplicationUsage()->addCommandLineOption("--ySize ","Relative length of rendered brick."); + arguments.getApplicationUsage()->addCommandLineOption("--zSize ","Relative height of rendered brick."); + arguments.getApplicationUsage()->addCommandLineOption("--xMultiplier ","Tex coord x mulitplier."); + arguments.getApplicationUsage()->addCommandLineOption("--yMultiplier ","Tex coord y mulitplier."); + arguments.getApplicationUsage()->addCommandLineOption("--zMultiplier ","Tex coord z mulitplier."); + arguments.getApplicationUsage()->addCommandLineOption("--clip ","clip volume as a ratio, 0.0 clip all, 1.0 clip none."); + arguments.getApplicationUsage()->addCommandLineOption("--maxTextureSize ","Set the texture maximum resolution in the s,t,r (x,y,z) dimensions."); + arguments.getApplicationUsage()->addCommandLineOption("--s_maxTextureSize ","Set the texture maximum resolution in the s (x) dimension."); + arguments.getApplicationUsage()->addCommandLineOption("--t_maxTextureSize ","Set the texture maximum resolution in the t (y) dimension."); + arguments.getApplicationUsage()->addCommandLineOption("--r_maxTextureSize ","Set the texture maximum resolution in the r (z) dimension."); arguments.getApplicationUsage()->addCommandLineOption("--compressed","Enable the usage of compressed textures"); arguments.getApplicationUsage()->addCommandLineOption("--compressed-arb","Enable the usage of OpenGL ARB compressed textures"); arguments.getApplicationUsage()->addCommandLineOption("--compressed-dxt1","Enable the usage of S3TC DXT1 compressed textures"); arguments.getApplicationUsage()->addCommandLineOption("--compressed-dxt3","Enable the usage of S3TC DXT3 compressed textures"); arguments.getApplicationUsage()->addCommandLineOption("--compressed-dxt5","Enable the usage of S3TC DXT5 compressed textures"); +// arguments.getApplicationUsage()->addCommandLineOption("--raw ","read a raw image data"); // construct the viewer. osgProducer::Viewer viewer(arguments); @@ -833,7 +1071,19 @@ int main( int argc, char **argv ) while(arguments.read("--compressed-dxt5")) { internalFormatMode = osg::Texture::USE_S3TC_DXT5_COMPRESSION; } osg::ref_ptr image_3d; + + std::cout<<"about to read raw"<