mirror of
https://github.com/crskycode/GARbro.git
synced 2026-06-08 06:39:05 +08:00
(HuffmanDecoder): class made public and moved to ArcCommon.cs
This commit is contained in:
@@ -269,4 +269,102 @@ namespace GameRes.Formats
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class HuffmanDecoder
|
||||
{
|
||||
byte[] m_src;
|
||||
byte[] m_dst;
|
||||
|
||||
ushort[] lhs = new ushort[512];
|
||||
ushort[] rhs = new ushort[512];
|
||||
ushort t1032 = 256;
|
||||
|
||||
int input_pos;
|
||||
int remaining;
|
||||
int t8;
|
||||
int t12;
|
||||
|
||||
public HuffmanDecoder (byte[] src, int index, int length, byte[] dst)
|
||||
{
|
||||
m_src = src;
|
||||
m_dst = dst;
|
||||
input_pos = index;
|
||||
remaining = length;
|
||||
t8 = 0;
|
||||
t12 = 0;
|
||||
}
|
||||
|
||||
public HuffmanDecoder (byte[] src, byte[] dst) : this (src, 0, src.Length, dst)
|
||||
{
|
||||
}
|
||||
|
||||
public byte[] Unpack ()
|
||||
{
|
||||
int a2 = 0;
|
||||
t1032 = 256;
|
||||
ushort v3 = sub_401540();
|
||||
ushort v13 = v3; // [sp+0h] [bp-4h]@1
|
||||
while (a2 < m_dst.Length)
|
||||
{
|
||||
ushort v6 = v3;
|
||||
if ( v6 >= 0x100u )
|
||||
{
|
||||
do
|
||||
{
|
||||
while ( 0 == t8 )
|
||||
{
|
||||
int v8 = m_src[input_pos++];
|
||||
int v9 = t12;
|
||||
t8 += 8;
|
||||
--remaining;
|
||||
t12 = v8 | (v9 << 8);
|
||||
}
|
||||
int v10 = t12;
|
||||
int v11 = --t8;
|
||||
uint v12 = (uint)t12;
|
||||
t12 = v10 & ~(-1 << v11);
|
||||
if ( 0 != (((-1 << v11) & v12) >> v11) )
|
||||
v6 = rhs[v6];
|
||||
else
|
||||
v6 = lhs[v6];
|
||||
}
|
||||
while ( v6 >= 0x100u );
|
||||
v3 = v13;
|
||||
}
|
||||
m_dst[a2++] = (byte)v6;
|
||||
}
|
||||
return m_dst;
|
||||
}
|
||||
|
||||
ushort sub_401540()
|
||||
{
|
||||
if ( 0 != GetBits (1) )
|
||||
{
|
||||
ushort v4 = t1032++;
|
||||
lhs[v4] = sub_401540();
|
||||
rhs[v4] = sub_401540();
|
||||
return v4;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (ushort)GetBits (8);
|
||||
}
|
||||
}
|
||||
|
||||
uint GetBits (int n)
|
||||
{
|
||||
while ( n > t8 )
|
||||
{
|
||||
int v4 = m_src[input_pos++];
|
||||
--remaining;
|
||||
t12 = v4 | (t12 << 8);
|
||||
t8 += 8;
|
||||
}
|
||||
int v7 = t12;
|
||||
uint v8 = (uint)t12;
|
||||
t8 -= n;
|
||||
t12 = v7 & ~(-1 << t8);
|
||||
return (uint)(((-1 << t8) & v8) >> t8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,98 +146,4 @@ namespace GameRes.Formats.NeXAS
|
||||
return decoder.Unpack();
|
||||
}
|
||||
}
|
||||
|
||||
internal class HuffmanDecoder
|
||||
{
|
||||
byte[] m_src;
|
||||
byte[] m_dst;
|
||||
|
||||
ushort[] lhs = new ushort[512];
|
||||
ushort[] rhs = new ushort[512];
|
||||
ushort t1032 = 256;
|
||||
|
||||
int t0;
|
||||
int remaining;
|
||||
int t8;
|
||||
int t12;
|
||||
|
||||
public HuffmanDecoder (byte[] src, byte[] dst)
|
||||
{
|
||||
m_src = src;
|
||||
m_dst = dst;
|
||||
t0 = 0;
|
||||
remaining = src.Length;
|
||||
t8 = 0;
|
||||
t12 = 0;
|
||||
}
|
||||
|
||||
public byte[] Unpack ()
|
||||
{
|
||||
int a2 = 0;
|
||||
t1032 = 256;
|
||||
ushort v3 = sub_401540();
|
||||
ushort v13 = v3; // [sp+0h] [bp-4h]@1
|
||||
while (a2 < m_dst.Length)
|
||||
{
|
||||
ushort v6 = v3;
|
||||
if ( v6 >= 0x100u )
|
||||
{
|
||||
do
|
||||
{
|
||||
while ( 0 == t8 )
|
||||
{
|
||||
int v8 = m_src[t0++];
|
||||
int v9 = t12;
|
||||
t8 += 8;
|
||||
--remaining;
|
||||
t12 = v8 | (v9 << 8);
|
||||
}
|
||||
int v10 = t12;
|
||||
int v11 = --t8;
|
||||
uint v12 = (uint)t12;
|
||||
t12 = v10 & ~(-1 << v11);
|
||||
if ( 0 != (((-1 << v11) & v12) >> v11) )
|
||||
v6 = rhs[v6];
|
||||
else
|
||||
v6 = lhs[v6];
|
||||
}
|
||||
while ( v6 >= 0x100u );
|
||||
v3 = v13;
|
||||
}
|
||||
m_dst[a2++] = (byte)v6;
|
||||
}
|
||||
return m_dst;
|
||||
}
|
||||
|
||||
ushort sub_401540()
|
||||
{
|
||||
if ( 0 != GetBits (1) )
|
||||
{
|
||||
ushort v4 = t1032++;
|
||||
lhs[v4] = sub_401540();
|
||||
rhs[v4] = sub_401540();
|
||||
return v4;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (ushort)GetBits (8);
|
||||
}
|
||||
}
|
||||
|
||||
uint GetBits (int n)
|
||||
{
|
||||
while ( n > t8 )
|
||||
{
|
||||
int v4 = m_src[t0++];
|
||||
--remaining;
|
||||
t12 = v4 | (t12 << 8);
|
||||
t8 += 8;
|
||||
}
|
||||
int v7 = t12;
|
||||
uint v8 = (uint)t12;
|
||||
t8 -= n;
|
||||
t12 = v7 & ~(-1 << t8);
|
||||
return (uint)(((-1 << t8) & v8) >> t8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user