From 63e321ca62b9ff936f11a574fc76d37596ce347d Mon Sep 17 00:00:00 2001 From: morkt Date: Fri, 2 Nov 2018 06:14:02 +0400 Subject: [PATCH] (HG3): fixed Jpeg reader (#214) --- ArcFormats/CatSystem/ImageHG3.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ArcFormats/CatSystem/ImageHG3.cs b/ArcFormats/CatSystem/ImageHG3.cs index 9d0fc540..0f7d0f2c 100644 --- a/ArcFormats/CatSystem/ImageHG3.cs +++ b/ArcFormats/CatSystem/ImageHG3.cs @@ -288,9 +288,12 @@ namespace GameRes.Formats.CatSystem m_input.ReadInt32(); var jpeg_size = m_input.ReadInt32(); long next_section = Source.Position + jpeg_size; - var decoder = new JpegBitmapDecoder (Source, - BitmapCreateOptions.None, BitmapCacheOption.OnLoad); - var frame = decoder.Frames[0]; + BitmapSource frame; + using (var jpeg = new StreamRegion (Source, Source.Position, jpeg_size, true)) + { + var decoder = new JpegBitmapDecoder (jpeg, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); + frame = decoder.Frames[0]; + } if (frame.Format.BitsPerPixel < 24) throw new NotSupportedException ("Not supported HG-3 JPEG color depth"); int src_pixel_size = frame.Format.BitsPerPixel/8; @@ -303,9 +306,9 @@ namespace GameRes.Formats.CatSystem int dst = 0; for (uint i = 0; i < total; ++i) { - output[dst++] = pixels[src]; - output[dst++] = pixels[src+1]; output[dst++] = pixels[src+2]; + output[dst++] = pixels[src+1]; + output[dst++] = pixels[src]; output[dst++] = 0xFF; src += src_pixel_size; }