From 99ab258678a465aa6f5e78df4954fe79cff4badd Mon Sep 17 00:00:00 2001 From: morkt Date: Tue, 26 Sep 2017 21:20:21 +0400 Subject: [PATCH] (ERI): fixed incremental images with different stride. (#96) --- ArcFormats/Entis/EriReader.cs | 30 ++++++++++++++++++++++++++++++ ArcFormats/Entis/ImageERI.cs | 21 +-------------------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/ArcFormats/Entis/EriReader.cs b/ArcFormats/Entis/EriReader.cs index 5e58b4f0..5bd91a48 100644 --- a/ArcFormats/Entis/EriReader.cs +++ b/ArcFormats/Entis/EriReader.cs @@ -73,6 +73,7 @@ namespace GameRes.Formats.Entis PtrProcedure[] m_pfnColorOperation; byte[] m_src_frame; + public EriMetaData Info { get { return m_info; } } public byte[] Data { get { return m_output; } } public PixelFormat Format { get; private set; } public int Stride { get { return Math.Abs (m_dwBytesPerLine); } } @@ -150,6 +151,35 @@ namespace GameRes.Formats.Entis }; } + internal void AddImageBuffer (EriReader src_reader) + { + var dst_reader = this; + var dst_img = dst_reader.Data; + var src_img = src_reader.Data; + int src_bpp = (src_reader.Info.BPP + 7) / 8; + int dst_bpp = (dst_reader.Info.BPP + 7) / 8; + bool has_alpha = src_bpp == 4 && src_bpp == dst_bpp; + int src_stride = src_reader.Stride; + int dst_stride = dst_reader.Stride; + int height = (int)dst_reader.Info.Height; + int width = (int)dst_reader.Info.Width; + for (int y = 0; y < height; ++y) + { + int src = src_stride * y; + int dst = dst_stride * y; + for (int x = 0; x < width; ++x) + { + dst_img[dst ] += src_img[src ]; + dst_img[dst+1] += src_img[src+1]; + dst_img[dst+2] += src_img[src+2]; + if (has_alpha) + dst_img[dst+3] += src_img[src+3]; + dst += dst_bpp; + src += src_bpp; + } + } + } + private void InitializeLossless () { if (0 != m_info.BlockingDegree) diff --git a/ArcFormats/Entis/ImageERI.cs b/ArcFormats/Entis/ImageERI.cs index 27cbab21..9928f14d 100644 --- a/ArcFormats/Entis/ImageERI.cs +++ b/ArcFormats/Entis/ImageERI.cs @@ -296,7 +296,7 @@ namespace GameRes.Formats.Entis throw new FileNotFoundException ("Referenced image not found", ref_file); ref_info.FileName = ref_file; var ref_reader = ReadImageData (ref_src, ref_info); - AddImageBuffer (meta, reader.Data, ref_info, ref_reader.Data); + reader.AddImageBuffer (ref_reader); } } } @@ -304,25 +304,6 @@ namespace GameRes.Formats.Entis return reader; } - void AddImageBuffer (EriMetaData dst_info, byte[] dst_img, EriMetaData src_info, byte[] src_img) - { - int src_bpp = (src_info.BPP + 7) / 8; - int dst_bpp = (dst_info.BPP + 7) / 8; - bool has_alpha = src_bpp == 4 && src_bpp == dst_bpp; - int dst = 0; - int src = 0; - while (dst < dst_img.Length) - { - dst_img[dst ] += src_img[src ]; - dst_img[dst+1] += src_img[src+1]; - dst_img[dst+2] += src_img[src+2]; - if (has_alpha) - dst_img[dst+3] += src_img[src+3]; - dst += dst_bpp; - src += src_bpp; - } - } - static readonly Regex s_TagRe = new Regex (@"^\s*#\s*(\S+)"); Dictionary ParseTagInfo (string desc)