From e2cb4424c7712a604a55bf98fa3812df14582a69 Mon Sep 17 00:00:00 2001 From: morkt Date: Sat, 16 Jan 2016 17:14:24 +0400 Subject: [PATCH] (ParallelCbgDecoder): implement IDisposable interface. --- ArcFormats/Ethornell/ImageBGI.cs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/ArcFormats/Ethornell/ImageBGI.cs b/ArcFormats/Ethornell/ImageBGI.cs index 7ca97c5c..995216d6 100644 --- a/ArcFormats/Ethornell/ImageBGI.cs +++ b/ArcFormats/Ethornell/ImageBGI.cs @@ -190,7 +190,12 @@ namespace GameRes.Formats.BGI if (m_info.Version < 2) UnpackV1(); else if (2 == m_info.Version) - UnpackV2(); + { + if (m_info.EncLength < 0x80) + throw new InvalidFormatException(); + using (var decoder = new ParallelCbgDecoder (m_info, ReadEncoded())) + UnpackV2 (decoder); + } else throw new NotSupportedException ("Not supported CompressedBG version"); } @@ -330,11 +335,8 @@ namespace GameRes.Formats.BGI } } - void UnpackV2 () + void UnpackV2 (ParallelCbgDecoder decoder) { - if (m_info.EncLength < 0x80) - throw new InvalidFormatException(); - var decoder = new ParallelCbgDecoder (m_info, ReadEncoded()); var base_offset = Input.Position; decoder.Tree1 = new HuffmanTree (ReadWeightTable (Input, 0x10), true); decoder.Tree2 = new HuffmanTree (ReadWeightTable (Input, 0xB0), true); @@ -470,7 +472,7 @@ namespace GameRes.Formats.BGI } } - internal class ParallelCbgDecoder + internal sealed class ParallelCbgDecoder : IDisposable { public byte[] Input; public byte[] Output; @@ -802,5 +804,18 @@ namespace GameRes.Formats.BGI return 0; return (byte)f; } + + #region IDisposable Members + bool _disposed = false; + public void Dispose () + { + if (!_disposed) + { + s_YCbCr_block.Dispose(); + s_tmp.Dispose(); + _disposed = true; + } + } + #endregion } }