Browse Source

Image viewer: add native format & clean errors

lviguier 1 năm trước cách đây
mục cha
commit
a4359c20b9
1 tập tin đã thay đổi với 30 bổ sung7 xóa
  1. 30 7
      hide/view/Image.hx

+ 30 - 7
hide/view/Image.hx

@@ -119,6 +119,12 @@ class Image extends FileView {
 		}
 
 		var compressionInfo = element.find(".compression-infos");
+		var nativeFormat = new Element('<div class="field">
+		<label>Native format :</label>
+		<label class="native-format">Unknown</label>
+		</div>');
+		compressionInfo.append(nativeFormat);
+
 		addField(compressionInfo, "Format :", "Compression format used to compress texture", "select-format", ["none", "BC1", "BC2", "BC3", "RGBA", "R16F", "RG16F", "RGBA16F", "R32F", "RG32F", "RGBA32F", "R16U", "RG16U", "RGBA16U"] );
 
 		var alphaField = new Element('<div class="field alpha">
@@ -383,13 +389,12 @@ class Image extends FileView {
 		// have been changed
 		@:privateAccess fs.fileCache.remove(state.path);
 
-		var onFail = () -> Ide.inst.quickError('Can\'t load texture with this compression parameters, original texture is loaded instead!');
 		scene.onReady = function() {
 			scene.loadTexture(state.path, state.path, function(compressedTexture) {
 				scene.loadTexture(state.path, state.path, function(uncompressedTexture) {
 					onTexturesLoaded(compressedTexture, uncompressedTexture);
-				}, onFail, false, true);
-			}, onFail, false);
+				}, onError, false, true);
+			}, onError, false);
 		};
 	}
 
@@ -584,6 +589,7 @@ class Image extends FileView {
 		var useAlpha = compressionInfo.find(".use-alpha");
 		var alpha = compressionInfo.find(".alpha-threshold");
 		var maxSize = compressionInfo.find(".max-size");
+		var nativeFormat = compressionInfo.find(".native-format");
 
 		var dirPos = state.path.lastIndexOf("/");
 		var name = dirPos < 0 ? state.path : state.path.substr(dirPos + 1);
@@ -594,7 +600,11 @@ class Image extends FileView {
 		@:privateAccess fs.convert.loadConfig(state.path);
 
 		var localEntry = @:privateAccess new hxd.fs.LocalFileSystem.LocalEntry(fs, name, state.path, Ide.inst.getPath(state.path));
-		fs.convert.run(localEntry);
+
+		try {
+			fs.convert.run(localEntry);
+		}
+		catch (e) onError();
 
 		@:privateAccess var texConvRule = fs.convert.getConvertRule(state.path);
 		var convertRuleEmpty = texConvRule == null || texConvRule.cmd == null || texConvRule.cmd.params == null;
@@ -638,6 +648,8 @@ class Image extends FileView {
 
 		var uncompTWeight = element.find(".uncomp-tex-weight");
 		uncompTWeight.text('Uncompressed texture weight : ${getTextureMemSize(state.path)} mb');
+
+		nativeFormat.text(getTextureNativeFormat(state.path).getName());
 	}
 
 	public function replaceImage(path : String) {
@@ -717,9 +729,7 @@ class Image extends FileView {
 			try {
 				comp.convert();
 			}
-			catch(e) {
-				Ide.inst.quickError('Can\'t load texture with this compression parameters, original texture is loaded instead!');
-			}
+			catch(e) onError();
 		}
 		else {
 			tmpPath = state.path;
@@ -747,6 +757,15 @@ class Image extends FileView {
 		return @:privateAccess floatToStringPrecision(t.mem.memSize(t) / (1024 * 1024));
 	}
 
+	public function getTextureNativeFormat(path: String) {
+		var p = ide.getPath(path);
+		var bytes = sys.io.File.getBytes(p);
+		var res = hxd.res.Any.fromBytes(p, bytes);
+		var t = res.toTexture();
+
+		return t.format;
+	}
+
 	public function floatToStringPrecision(number:Float, ?precision=2) {
 		number *= Math.pow(10, precision);
 		return Math.round(number) / Math.pow(10, precision);
@@ -776,6 +795,10 @@ class Image extends FileView {
 		updateSliderVisual();
 	}
 
+	public function onError() {
+		Ide.inst.quickError('Can\'t load texture with this compression parameters, original texture is loaded instead!');
+	}
+
 	static var _ = FileTree.registerExtension(Image,hide.Ide.IMG_EXTS.concat(["envd","envs"]),{ icon : "picture-o" });
 
 }