From 961042451650e47dea86ebdfe90e26c5354d202c Mon Sep 17 00:00:00 2001 From: morkt Date: Sun, 26 Mar 2017 04:06:44 +0400 Subject: [PATCH] (Csystem): another image format. --- ArcFormats/Cyberworks/ImageTINK.cs | 36 +++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/ArcFormats/Cyberworks/ImageTINK.cs b/ArcFormats/Cyberworks/ImageTINK.cs index f75ba94e..5993c6c2 100644 --- a/ArcFormats/Cyberworks/ImageTINK.cs +++ b/ArcFormats/Cyberworks/ImageTINK.cs @@ -111,8 +111,10 @@ namespace GameRes.Formats.Cyberworks else UnpackV6 (bits_size, data_offset, data_offset + header[6]); } + else if (0 == bits_size) + CopyV0 (unpacked_size); else - throw new InvalidFormatException(); + UnpackV1 (bits_size, unpacked_size); } void CopyV0 (int data_size) @@ -152,6 +154,38 @@ namespace GameRes.Formats.Cyberworks } } + void UnpackV1 (int alpha_size, int rgb_size) + { + var alpha_map = m_input.ReadBytes (alpha_size); + if (alpha_map.Length != alpha_size) + throw new InvalidFormatException(); + + Info.BPP = 32; + int plane_size = (int)Info.Width * (int)Info.Height; + m_output = new byte[plane_size * 4]; + int bit = 1; + int bit_src = 0; + int dst = 0; + for (int i = 0; i < plane_size; ++i) + { + if ((bit & alpha_map[bit_src]) != 0) + { + m_input.Read (m_output, dst, 3); + m_output[dst+3] = 0xFF; + } + else + m_output[dst+3] = 0; + dst += 4; + if (0x80 == bit) + { + ++bit_src; + bit = 1; + } + else + bit <<= 1; + } + } + void UnpackV2 (int offset1, int rgb_offset) { Info.BPP = 24;