Hi Marcin,
I have now got on to do a second review your proposed changes for
osg::computeImageSizeInBytes(..) and have now merged these with a some
small changes to retain some of the original functionality - such as
catching dimensions such as 0 and below. This is would produce
different behavior than the original dds plugin version of this code
so I've left the original dds plugin function in place but implemented
the bulk of it via calling the osg::computeImageSizeInBytes(..)
method, the only part that is return is the clamp of dimensions <1 to
1.
The changes are now provided below. Could you test out svn/trunk and
let me know if this works fine with your datasets now.
Cheers,
Robert.
-- $ svn diff
Index: examples/osgphotoalbum/ImageReaderWriter.cpp
===================================================================
--- examples/osgphotoalbum/ImageReaderWriter.cpp (revision 13440)
+++ examples/osgphotoalbum/ImageReaderWriter.cpp (working copy)
@@ -170,6 +170,7 @@
// 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);
Index: src/osg/Image.cpp
===================================================================
--- src/osg/Image.cpp (revision 13445)
+++ src/osg/Image.cpp (working copy)
@@ -722,14 +722,49 @@
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)
Index: src/osgPlugins/dds/ReaderWriterDDS.cpp
===================================================================
--- src/osgPlugins/dds/ReaderWriterDDS.cpp (revision 13448)
+++ src/osgPlugins/dds/ReaderWriterDDS.cpp (working copy)
@@ -400,53 +400,15 @@
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)
Index: include/osg/Image
===================================================================
--- include/osg/Image (revision 13440)
+++ include/osg/Image (working copy)
@@ -365,7 +365,7 @@
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);
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org