Problem using TextureIO to convert DDS to PNG, with workaround

When I try to convert one of the DDS files that comes with World Wind Java to a PNG file I get this error:

PNG writer doesn’t support this pixel format / type (only GL_RGB/A + bytes)

Looks like TextureIO was getting the compressed bytes for the texture in my case. I changed the code to get the uncompressed bytes for the texture and then it worked fine. I’ve attached a context diff. If this is not the right place to submit this patch, please let me know the correct place. Thanks,

Robert

Oops, the attachment folder was full. Diff here:

— jogl/src/classes/com/sun/opengl/util/texture/TextureIO.java 2007-07-14 00:42:41.031124800 -0700
+++ moesol-worldwind/src/com/sun/opengl/util/texture/TextureIO.java 2007-07-14 01:44:17.015689600 -0700
@@ -598,15 +598,17 @@
int height = glGetTexLevelParameteri(GL.GL_TEXTURE_2D, 0, GL.GL_TEXTURE_HEIGHT);
int border = glGetTexLevelParameteri(GL.GL_TEXTURE_2D, 0, GL.GL_TEXTURE_BORDER);
TextureData data = null;

  • if (internalFormat == GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
  •    internalFormat == GL.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ||
    
  •    internalFormat == GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT ||
    
  •    internalFormat == GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) {
    

+// if (internalFormat == GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
+// internalFormat == GL.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ||
+// internalFormat == GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT ||
+// internalFormat == GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) {

  • if (false) {
    // Fetch using glGetCompressedTexImage
    int size = glGetTexLevelParameteri(GL.GL_TEXTURE_2D, 0, GL.GL_TEXTURE_COMPRESSED_IMAGE_SIZE);
    ByteBuffer res = ByteBuffer.allocate(size);
    gl.glGetCompressedTexImage(GL.GL_TEXTURE_2D, 0, res);
    data = new TextureData(internalFormat, width, height, border, internalFormat, GL.GL_UNSIGNED_BYTE,
    false, true, true, res, null);
    } else {
    int bytesPerPixel = 0;
    @@ -625,6 +627,19 @@
    bytesPerPixel = 4;
    fetchedFormat = GL.GL_RGBA;
    break;
  •    case GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
    
  •    	bytesPerPixel = 3;
    
  •    	fetchedFormat = GL.GL_RGB;
    
  •    	break;
    
  •    case GL.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
    
  •    case GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
    
  •    case GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
    
  •    	bytesPerPixel = 4;
    
  •    	fetchedFormat = GL.GL_RGBA;
    
  •    	break;
    
  •    default:
         throw new IOException("Unsupported texture internal format 0x" + Integer.toHexString(internalFormat));
     }

Some of the TextureIO internal classes need to be expanded to handle this case more generally. I’ve filed Issue 310 to track this.