diff --git a/examples/osgphotoalbum/ImageReaderWriter.cpp b/examples/osgphotoalbum/ImageReaderWriter.cpp index 4716e0eec..6eb9e88bc 100644 --- a/examples/osgphotoalbum/ImageReaderWriter.cpp +++ b/examples/osgphotoalbum/ImageReaderWriter.cpp @@ -170,6 +170,7 @@ osgDB::ReaderWriter::ReadResult ImageReaderWriter::local_readNode(const std::str // set up the texture. osg::Texture2D* texture = new osg::Texture2D; texture->setImage(image); + texture->setResizeNonPowerOfTwoHint(false); texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); diff --git a/include/osg/Image b/include/osg/Image index b6bdc928e..7edec777c 100644 --- a/include/osg/Image +++ b/include/osg/Image @@ -365,7 +365,7 @@ class OSG_EXPORT Image : public BufferData static unsigned int computeNumComponents(GLenum pixelFormat); static unsigned int computePixelSizeInBits(GLenum pixelFormat,GLenum type); static unsigned int computeRowWidthInBytes(int width,GLenum pixelFormat,GLenum type,int packing); - static unsigned int computeImageSizeInBytes(int width,int height, int depth, GLenum pixelFormat,GLenum type,int packing); + static unsigned int computeImageSizeInBytes(int width,int height, int depth, GLenum pixelFormat, GLenum type, int packing = 1, int slice_packing = 1, int image_packing = 1); static int computeNearestPowerOfTwo(int s,float bias=0.5f); static int computeNumberOfMipmapLevels(int s,int t = 1, int r = 1); diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index 65f2ad3ab..885338edf 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -722,14 +722,49 @@ unsigned int Image::computeRowWidthInBytes(int width,GLenum pixelFormat,GLenum t return (widthInBits/packingInBits + ((widthInBits%packingInBits)?1:0))*packing; } -unsigned int Image::computeImageSizeInBytes(int width,int height, int depth, GLenum pixelFormat,GLenum type,int packing) +unsigned int Image::computeImageSizeInBytes(int width,int height, int depth, GLenum pixelFormat,GLenum type,int packing, int slice_packing, int image_packing) { - if (width==0 || height==0 || depth==0) return 0; + if (width<=0 || height<=0 || depth<=0) return 0; - return osg::maximum( - Image::computeRowWidthInBytes(width,pixelFormat,type,packing)*height*depth, - computeBlockSize(pixelFormat, packing) - ); + // Taking advantage of the fact that + // DXT formats are defined as 4 successive numbers: + // GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 + // GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 + // GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 + // GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 + if( pixelFormat >= GL_COMPRESSED_RGB_S3TC_DXT1_EXT && + pixelFormat <= GL_COMPRESSED_RGBA_S3TC_DXT5_EXT ) + { + width = (width + 3) & ~3; + height = (height + 3) & ~3; + } + + // 3dc ATI formats + // GL_COMPRESSED_RED_RGTC1_EXT 0x8DBB + // GL_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC + // GL_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD + // GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE + if( pixelFormat >= GL_COMPRESSED_RED_RGTC1_EXT && + pixelFormat <= GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT ) + { + width = (width + 3) & ~3; + height = (height + 3) & ~3; + } + + // compute size of one row + unsigned int size = osg::Image::computeRowWidthInBytes( width, pixelFormat, type, packing ); + + // now compute size of slice + size *= height; + size += slice_packing - 1; + size -= size % slice_packing; + + // compute size of whole image + size *= depth; + size += image_packing - 1; + size -= size % image_packing; + + return osg::maximum( size, computeBlockSize(pixelFormat, packing) ); } int Image::computeNearestPowerOfTwo(int s,float bias) diff --git a/src/osgPlugins/dds/ReaderWriterDDS.cpp b/src/osgPlugins/dds/ReaderWriterDDS.cpp index cffb0aa26..a5cd0eb52 100644 --- a/src/osgPlugins/dds/ReaderWriterDDS.cpp +++ b/src/osgPlugins/dds/ReaderWriterDDS.cpp @@ -400,53 +400,15 @@ typedef struct { UI32 reserved; } OSG_DDS_HEADER_DXT10; -static unsigned int ComputeImageSizeInBytes - ( int width, int height, int depth, - unsigned int pixelFormat, unsigned int pixelType, - int packing = 1, int slice_packing = 1, int image_packing = 1 ) +static unsigned int ComputeImageSizeInBytes( int width, int height, int depth, + unsigned int pixelFormat, unsigned int pixelType, + int packing = 1, int slice_packing = 1, int image_packing = 1 ) { if( width < 1 ) width = 1; if( height < 1 ) height = 1; if( depth < 1 ) depth = 1; - - // Taking advantage of the fact that - // DXT formats are defined as 4 successive numbers: - // GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 - // GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 - // GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 - // GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 - if( pixelFormat >= GL_COMPRESSED_RGB_S3TC_DXT1_EXT && - pixelFormat <= GL_COMPRESSED_RGBA_S3TC_DXT5_EXT ) - { - width = (width + 3) & ~3; - height = (height + 3) & ~3; - } - // 3dc ATI formats - // GL_COMPRESSED_RED_RGTC1_EXT 0x8DBB - // GL_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC - // GL_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD - // GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE - if( pixelFormat >= GL_COMPRESSED_RED_RGTC1_EXT && - pixelFormat <= GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT ) - { - width = (width + 3) & ~3; - height = (height + 3) & ~3; - } - // compute size of one row - unsigned int size = osg::Image::computeRowWidthInBytes - ( width, pixelFormat, pixelType, packing ); - - // now compute size of slice - size *= height; - size += slice_packing - 1; - size -= size % slice_packing; - - // compute size of whole image - size *= depth; - size += image_packing - 1; - size -= size % image_packing; - - return size; + + return osg::Image::computeImageSizeInBytes(width, height, depth, packing, slice_packing, image_packing); } osg::Image* ReadDDSFile(std::istream& _istream, bool flipDDSRead)