From fd18f21b4066f91114a1320232145eab45a6011f Mon Sep 17 00:00:00 2001 From: morkt Date: Sun, 6 Dec 2015 22:24:14 +0400 Subject: [PATCH] (TgaStream): added Create method for images with non-default stride. --- ArcFormats/ArcCommon.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ArcFormats/ArcCommon.cs b/ArcFormats/ArcCommon.cs index 1764c8ac..5e82ecb4 100644 --- a/ArcFormats/ArcCommon.cs +++ b/ArcFormats/ArcCommon.cs @@ -426,6 +426,25 @@ namespace GameRes.Formats header[0x11] = 0x20; return new PrefixStream (header, new MemoryStream (pixels)); } + + public static Stream Create (ImageMetaData info, int stride, byte[] pixels, bool flipped = false) + { + int tga_stride = (int)info.Width * info.BPP / 8; + if (stride != tga_stride) + { + var adjusted = new byte[tga_stride * (int)info.Height]; + int src = 0; + int dst = 0; + for (uint y = 0; y < info.Height; ++y) + { + Buffer.BlockCopy (pixels, src, adjusted, dst, tga_stride); + src += stride; + dst += tga_stride; + } + pixels = adjusted; + } + return Create (info, pixels, flipped); + } } public static class MMX