From c2413b63f7f7adc1b8bc32339a285cc16ca194d9 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 2 Dec 2013 19:56:30 +1300 Subject: [PATCH] Remove duplicated Format2 implementation. --- OpenRA.FileFormats/FileFormats/Format2.cs | 15 ++++++--------- OpenRA.FileFormats/Graphics/ShpD2Reader.cs | 4 ++-- OpenRA.FileFormats/Graphics/ShpTSReader.cs | 15 +-------------- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/OpenRA.FileFormats/FileFormats/Format2.cs b/OpenRA.FileFormats/FileFormats/Format2.cs index a043755c18..b584d3b9a3 100644 --- a/OpenRA.FileFormats/FileFormats/Format2.cs +++ b/OpenRA.FileFormats/FileFormats/Format2.cs @@ -12,25 +12,22 @@ namespace OpenRA.FileFormats { public static class Format2 { - public static int DecodeInto(byte[] src, byte[] dest) + public static void DecodeInto(byte[] src, byte[] dest, int destIndex) { - FastByteReader r = new FastByteReader(src); + var r = new FastByteReader(src); - int i = 0; while (!r.Done()) { - byte cmd = r.ReadByte(); + var cmd = r.ReadByte(); if (cmd == 0) { - byte count = r.ReadByte(); + var count = r.ReadByte(); while (count-- > 0) - dest[i++] = 0; + dest[destIndex++] = 0; } else - dest[i++] = cmd; + dest[destIndex++] = cmd; } - - return i; } } } diff --git a/OpenRA.FileFormats/Graphics/ShpD2Reader.cs b/OpenRA.FileFormats/Graphics/ShpD2Reader.cs index aa21efc521..928e68da55 100644 --- a/OpenRA.FileFormats/Graphics/ShpD2Reader.cs +++ b/OpenRA.FileFormats/Graphics/ShpD2Reader.cs @@ -73,10 +73,10 @@ namespace OpenRA.FileFormats { var tempData = new byte[dataSize]; Format80.DecodeInto(imgData, tempData); - Format2.DecodeInto(tempData, Data); + Format2.DecodeInto(tempData, Data, 0); } else - Format2.DecodeInto(imgData, Data); + Format2.DecodeInto(imgData, Data, 0); // Lookup values in lookup table for (var j = 0; j < Data.Length; j++) diff --git a/OpenRA.FileFormats/Graphics/ShpTSReader.cs b/OpenRA.FileFormats/Graphics/ShpTSReader.cs index 90c45aa85a..5c2f3c15db 100644 --- a/OpenRA.FileFormats/Graphics/ShpTSReader.cs +++ b/OpenRA.FileFormats/Graphics/ShpTSReader.cs @@ -89,21 +89,8 @@ namespace OpenRA.FileFormats for (var j = 0; j < f.Size.Height; j++) { - var k = j * f.Size.Width; var length = stream.ReadUInt16() - 2; - while (length > 0) - { - var b = stream.ReadUInt8(); - length--; - - if (b == 0) - { - k += stream.ReadUInt8(); - length--; - } - else - f.Data[k++] = b; - } + Format2.DecodeInto(stream.ReadBytes(length), f.Data, j * f.Size.Width); } } }