mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-27 07:34:00 +08:00
(WipFormat.Reader): cleanup.
This commit is contained in:
parent
7133aa5ea8
commit
d0ef693a2a
@ -92,9 +92,7 @@ namespace GameRes.Formats.Will
|
|||||||
|
|
||||||
public override ImageData Read (Stream file, ImageMetaData info)
|
public override ImageData Read (Stream file, ImageMetaData info)
|
||||||
{
|
{
|
||||||
var meta = info as WipMetaData;
|
var meta = (WipMetaData)info;
|
||||||
if (null == meta)
|
|
||||||
throw new ArgumentException ("WipFormat.Read should be supplied with WipMetaData", "info");
|
|
||||||
file.Position = 8 + 24 * meta.FrameCount;
|
file.Position = 8 + 24 * meta.FrameCount;
|
||||||
Color[] palette = null;
|
Color[] palette = null;
|
||||||
if (8 == meta.BPP)
|
if (8 == meta.BPP)
|
||||||
@ -149,51 +147,47 @@ namespace GameRes.Formats.Will
|
|||||||
// int stride = (int)info.Width*((info.BPP+7)/8);
|
// int stride = (int)info.Width*((info.BPP+7)/8);
|
||||||
int stride = (int)info.Width*4;
|
int stride = (int)info.Width*4;
|
||||||
m_data = new byte[stride * (int)info.Height];
|
m_data = new byte[stride * (int)info.Height];
|
||||||
m_input = new BinaryReader (file, Encoding.ASCII, true);
|
m_input = new ArcView.Reader (file);
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] m_window = new byte[0x1000];
|
private byte[] m_window = new byte[0x1000];
|
||||||
|
|
||||||
public void Unpack ()
|
public void Unpack ()
|
||||||
{
|
{
|
||||||
int current = 0;
|
int dst = 0;
|
||||||
int window_index = 1;
|
int window_index = 1;
|
||||||
int control = 0;
|
int control = 0;
|
||||||
byte input = 0;
|
for (int length = (int)m_length; length > 0; )
|
||||||
for (uint length = m_length; length > 0; )
|
|
||||||
{
|
{
|
||||||
control >>= 1;
|
control >>= 1;
|
||||||
if (0 == (control & 0x100))
|
if (0 == (control & 0x100))
|
||||||
{
|
{
|
||||||
input = m_input.ReadByte();
|
control = m_input.ReadByte() | 0xFF00;
|
||||||
--length;
|
--length;
|
||||||
control = input | 0xff00;
|
|
||||||
}
|
}
|
||||||
if (0 != (control & 1))
|
if (0 != (control & 1))
|
||||||
{
|
{
|
||||||
if (length < 1)
|
if (length < 1)
|
||||||
throw new InvalidFormatException();
|
throw new InvalidFormatException();
|
||||||
input = m_input.ReadByte();
|
byte b = m_input.ReadByte();
|
||||||
--length;
|
--length;
|
||||||
m_data[current++] = input;
|
m_data[dst++] = b;
|
||||||
m_window[window_index++] = input;
|
m_window[window_index++] = b;
|
||||||
window_index &= 0xfff;
|
window_index &= 0xfff;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (length < 2)
|
if (length < 2)
|
||||||
throw new InvalidFormatException();
|
throw new InvalidFormatException();
|
||||||
int di = m_input.ReadByte();
|
int hi = m_input.ReadByte();
|
||||||
input = m_input.ReadByte();
|
int lo = m_input.ReadByte();
|
||||||
length -= 2;
|
length -= 2;
|
||||||
int offset = ((di << 8) | input) >> 4;
|
int offset = hi << 4 | lo >> 4;
|
||||||
int count = (input & 0xf) + 2;
|
for (int count = (lo & 0xF) + 2; count > 0; --count)
|
||||||
for (int i = 0; i < count; ++i)
|
|
||||||
{
|
{
|
||||||
int src = (i + offset) & 0xfff;
|
byte b = m_window[offset++ & 0xfff];
|
||||||
input = m_window[src];
|
m_data[dst++] = b;
|
||||||
m_data[current++] = input;
|
m_window[window_index++] = b;
|
||||||
m_window[window_index++] = input;
|
|
||||||
window_index &= 0xfff;
|
window_index &= 0xfff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user