Pārlūkot izejas kodu

don't read full data when decoding mipmaps

Nicolas Cannasse 4 gadi atpakaļ
vecāks
revīzija
73818e6104
1 mainītis faili ar 12 papildinājumiem un 1 dzēšanām
  1. 12 1
      hxd/res/Image.hx

+ 12 - 1
hxd/res/Image.hx

@@ -328,11 +328,22 @@ class Image extends Resource {
 				}
 				pos += totSize * layer;
 			}
-			var bytes = entry.getBytes();
+			var bytes;
 			var w = inf.width >> mipLevel;
 			var h = inf.height >> mipLevel;
 			if( w == 0 ) w = 1;
 			if( h == 0 ) h = 1;
+			if( inf.mipLevels == 1 && !inf.flags.has(IsCube) ) {
+				bytes = entry.getBytes();
+			} else {
+				var size = hxd.Pixels.calcDataSize(w, h, inf.pixelFormat);
+				entry.open();
+				entry.skip(pos);
+				bytes = haxe.io.Bytes.alloc(size);
+				entry.read(bytes, 0, size);
+				entry.close();
+				pos = 0;
+			}
 			pixels = new hxd.Pixels(w, h, bytes, inf.pixelFormat, pos);
 		case Raw:
 			var bytes = entry.getBytes();