Patch for DDSLoader

Because of using of DDSD_LINEARSIZE for compressed DDS texture is not mandatory, some textures will not load.



If there is no DDSD_LINEARSIZE flag used, we have to auto calculate texture size.

If this flag is set, we should read size from header linear size field and check if it matches our size calculation (same as with previous behaviour).



Here is patch for JME 2.0:



### Eclipse Workspace Patch 1.0
#P JME2
Index: src/com/jme/image/util/DDSLoader.java
===================================================================
--- src/com/jme/image/util/DDSLoader.java   (revision 4009)
+++ src/com/jme/image/util/DDSLoader.java   (working copy)
@@ -176,10 +176,6 @@
             int flags = in_.readInt();
 
             if (is(flags, DDPF_FOURCC)) {
-                if (!is(flags_, DDSD_LINEARSIZE)) {
-                    throw new IOException("Must use linear size with fourcc");
-                }
-
                 compressed_ = true;
                 int fourcc = in_.readInt();
                 in_.skipBytes(20);
@@ -204,11 +200,18 @@
                 default:
                     throw new IOException("Unknown fourcc: " + string(fourcc));
                 }
-
-                int size = ((width_ + 3) / 4) * ((height_ + 3) / 4) * bpp_ * 2;
-                if (pitchOrSize_ != size) {
-                    throw new IOException("Expected size = " + size
-                            + ", real = " + pitchOrSize_);
+               
+               int size = ((width_ + 3) / 4) * ((height_ + 3) / 4) * bpp_ * 2;
+               
+                if (is(flags_, DDSD_LINEARSIZE)) {
+                   if (pitchOrSize_ == 0) {
+                      throw new IOException("Must use linear size with fourcc");
+                   } else if (pitchOrSize_ != size) {
+                      throw new IOException("Expected size = " + size
+                            + ", real = " + pitchOrSize_);
+                   }
+                } else {
+                   pitchOrSize_ = size;
                 }
             } else {
                 compressed_ = false;



Hope it'll be useful,

Konrad

Sounds good. I also noticed that in some cases LINEAR_SIZE is not provided. I am going to post a huge patch for DDSLoader soon so I ask the devs to not apply this patch until I make the post (with this patch included).



EDIT: I applied the patch, and I am testing it now on my sample of DDS images.

Great. Keep up good job!



Konrad.