(ERI): fixed incremental images with different stride. (#96)

This commit is contained in:
morkt 2017-09-26 21:20:21 +04:00
parent c29aee53b8
commit 99ab258678
2 changed files with 31 additions and 20 deletions

View File

@ -73,6 +73,7 @@ namespace GameRes.Formats.Entis
PtrProcedure[] m_pfnColorOperation; PtrProcedure[] m_pfnColorOperation;
byte[] m_src_frame; byte[] m_src_frame;
public EriMetaData Info { get { return m_info; } }
public byte[] Data { get { return m_output; } } public byte[] Data { get { return m_output; } }
public PixelFormat Format { get; private set; } public PixelFormat Format { get; private set; }
public int Stride { get { return Math.Abs (m_dwBytesPerLine); } } 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 () private void InitializeLossless ()
{ {
if (0 != m_info.BlockingDegree) if (0 != m_info.BlockingDegree)

View File

@ -296,7 +296,7 @@ namespace GameRes.Formats.Entis
throw new FileNotFoundException ("Referenced image not found", ref_file); throw new FileNotFoundException ("Referenced image not found", ref_file);
ref_info.FileName = ref_file; ref_info.FileName = ref_file;
var ref_reader = ReadImageData (ref_src, ref_info); 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; 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+)"); static readonly Regex s_TagRe = new Regex (@"^\s*#\s*(\S+)");
Dictionary<string, string> ParseTagInfo (string desc) Dictionary<string, string> ParseTagInfo (string desc)