From abe08cd45765acb2e6196bf2c3b85d64fe9c7ebe Mon Sep 17 00:00:00 2001 From: morkt Date: Mon, 30 Nov 2015 03:41:20 +0400 Subject: [PATCH] (TgaStream): new static class. create TGA image stream from the given image meta-data and pixels array. --- ArcFormats/ArcCommon.cs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/ArcFormats/ArcCommon.cs b/ArcFormats/ArcCommon.cs index 060ded7a..3182cd8d 100644 --- a/ArcFormats/ArcCommon.cs +++ b/ArcFormats/ArcCommon.cs @@ -23,12 +23,11 @@ // IN THE SOFTWARE. // +using GameRes.Utility; using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; -using System.Text; namespace GameRes.Formats { @@ -409,6 +408,26 @@ namespace GameRes.Formats } } + /// + /// Create stream in TGA format from the given image pixels. + /// + public static class TgaStream + { + public static Stream Create (ImageMetaData info, byte[] pixels, bool flipped = false) + { + var header = new byte[0x12]; + header[2] = 2; + LittleEndian.Pack ((short)info.OffsetX, header, 8); + LittleEndian.Pack ((short)info.OffsetY, header, 0xa); + LittleEndian.Pack ((ushort)info.Width, header, 0xc); + LittleEndian.Pack ((ushort)info.Height, header, 0xe); + header[0x10] = (byte)info.BPP; + if (!flipped) + header[0x11] = 0x20; + return new PrefixStream (header, new MemoryStream (pixels)); + } + } + public static class MMX { public static ulong PAddB (ulong x, ulong y)