From 0ad6e6a456a63656088ec04b1f181f05152bec01 Mon Sep 17 00:00:00 2001 From: Perfare Date: Wed, 1 Feb 2017 15:03:15 +0800 Subject: [PATCH] Support R16 TextureFormat --- Unity Studio/Unity Classes/Texture2D.cs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Unity Studio/Unity Classes/Texture2D.cs b/Unity Studio/Unity Classes/Texture2D.cs index e89ff9e..8492ad1 100644 --- a/Unity Studio/Unity Classes/Texture2D.cs +++ b/Unity Studio/Unity Classes/Texture2D.cs @@ -201,7 +201,6 @@ namespace Unity_Studio } image_data = bytes; image_data_size = image_data_size * 4; - bytes = null; dwFlags2 = 0x41; dwRGBBitCount = 0x20; dwRBitMask = 0xFF00; @@ -281,7 +280,25 @@ namespace Unity_Studio break; } case TextureFormat.R16: - break; + { + //转BGRA32 + var BGRA32 = new byte[image_data.Length * 2]; + for (var i = 0; i < image_data.Length; i += 2) + { + float f = Half.ToHalf(image_data, i); + BGRA32[i * 2 + 2] = (byte)Math.Ceiling(f * 255);//R + BGRA32[i * 2 + 3] = 255;//A + } + image_data = BGRA32; + image_data_size *= 2; + dwFlags2 = 0x41; + dwRGBBitCount = 0x20; + dwRBitMask = 0xFF0000; + dwGBitMask = 0xFF00; + dwBBitMask = 0xFF; + dwABitMask = -16777216; + break; + } case TextureFormat.DXT1: //test pass { if (sourceFile.platform == 11) //X360 only, PS3 not @@ -575,6 +592,7 @@ namespace Unity_Studio case TextureFormat.RGBA32: case TextureFormat.ARGB32: case TextureFormat.RGB565: + case TextureFormat.R16: case TextureFormat.DXT1: case TextureFormat.DXT5: case TextureFormat.RGBA4444: @@ -658,6 +676,7 @@ namespace Unity_Studio case TextureFormat.RGBA32: case TextureFormat.ARGB32: case TextureFormat.RGB565: + case TextureFormat.R16: case TextureFormat.DXT1: case TextureFormat.DXT5: case TextureFormat.RGBA4444: @@ -788,6 +807,7 @@ namespace Unity_Studio case TextureFormat.RGBA32: case TextureFormat.ARGB32: case TextureFormat.RGB565: + case TextureFormat.R16: case TextureFormat.DXT1: case TextureFormat.DXT5: case TextureFormat.RGBA4444: