From 878415e71e52382931b7c3651487c8b0edf6693e Mon Sep 17 00:00:00 2001 From: morkt Date: Sun, 28 Jan 2018 10:16:07 +0400 Subject: [PATCH] (Unity.Texture2D): added ARGB4444 textures. --- ArcFormats/Unity/Texture2D.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ArcFormats/Unity/Texture2D.cs b/ArcFormats/Unity/Texture2D.cs index a165a481..5d37a06e 100644 --- a/ArcFormats/Unity/Texture2D.cs +++ b/ArcFormats/Unity/Texture2D.cs @@ -44,6 +44,8 @@ namespace GameRes.Formats.Unity DXT5 = 12, RGBA4444 = 13, BGRA32 = 14, + DXT1Crunched = 28, + DXT5Crunched = 29, } internal class Texture2D @@ -205,6 +207,10 @@ namespace GameRes.Formats.Unity pixels = ConvertRgba (m_texture.m_Data); break; + case TextureFormat.ARGB4444: + pixels = ConvertArgb16 (m_texture.m_Data); + break; + default: throw new NotImplementedException (string.Format ("Not supported Unity Texture2D format '{0}'.", m_texture.m_TextureFormat)); } @@ -222,6 +228,21 @@ namespace GameRes.Formats.Unity return data; } + byte[] ConvertArgb16 (byte[] data) + { + var output = new byte[data.Length * 2]; + int dst = 0; + for (int i = 0; i < data.Length; i += 2) + { + ushort p = LittleEndian.ToUInt16 (data, i); + output[dst++] = (byte)( (p & 0xF) * 0x11); + output[dst++] = (byte)(((p >> 4) & 0xF) * 0x11); + output[dst++] = (byte)(((p >> 8) & 0xF) * 0x11); + output[dst++] = (byte)(((p >> 12) & 0xF) * 0x11); + } + return output; + } + byte[] ConvertRgba (byte[] data) { for (int i = 0; i < data.Length; i += 4)