mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-06-20 05:29:35 +00:00
tidying
This commit is contained in:
parent
e7445bd5f2
commit
118a820406
|
@ -18,23 +18,20 @@ public class ExoBuffer
|
||||||
private static int PFLAG_BITS_ALIGN_START = (1 << PBIT_BITS_ALIGN_START);
|
private static int PFLAG_BITS_ALIGN_START = (1 << PBIT_BITS_ALIGN_START);
|
||||||
private static int PFLAG_4_OFFSET_TABLES = (1 << PBIT_4_OFFSET_TABLES);
|
private static int PFLAG_4_OFFSET_TABLES = (1 << PBIT_4_OFFSET_TABLES);
|
||||||
|
|
||||||
int inPos;
|
private byte[] inBuffer;
|
||||||
int inEnd;
|
private byte[] outBuffer = new byte[0x8000];
|
||||||
int outPos;
|
|
||||||
|
|
||||||
byte[] inBuffer;
|
private int inPos;
|
||||||
byte[] outBuffer = new byte[50000];
|
private int outPos;
|
||||||
|
|
||||||
int bitBuffer;
|
private int bitBuffer;
|
||||||
|
private int flags;
|
||||||
|
|
||||||
int bitsRead;
|
private int tableBit[] = new int[8];
|
||||||
int flagsProto;
|
private int tableOff[] = new int[8];
|
||||||
|
private int tableBi[] = new int[100];
|
||||||
int tableBit[] = new int[8];
|
private int tableLo[] = new int[100];
|
||||||
int tableOff[] = new int[8];
|
private int tableHi[] = new int[100];
|
||||||
int tableBi[] = new int[100];
|
|
||||||
int tableLo[] = new int[100];
|
|
||||||
int tableHi[] = new int[100];
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
public ExoBuffer (byte[] inBuffer)
|
public ExoBuffer (byte[] inBuffer)
|
||||||
|
@ -42,46 +39,42 @@ public class ExoBuffer
|
||||||
{
|
{
|
||||||
reverse (inBuffer);
|
reverse (inBuffer);
|
||||||
|
|
||||||
bitsRead = 0;
|
|
||||||
|
|
||||||
this.inBuffer = inBuffer;
|
this.inBuffer = inBuffer;
|
||||||
inEnd = inBuffer.length;
|
|
||||||
|
|
||||||
inPos = 2;
|
inPos = 2;
|
||||||
flagsProto = 23;
|
|
||||||
|
|
||||||
outPos = 0;
|
outPos = 0;
|
||||||
|
flags = 23;
|
||||||
|
|
||||||
if ((flagsProto & PFLAG_BITS_ALIGN_START) != 0)
|
if ((flags & PFLAG_BITS_ALIGN_START) != 0)
|
||||||
bitBuffer = 0;
|
bitBuffer = 0;
|
||||||
else
|
else
|
||||||
bitBuffer = getByte ();
|
bitBuffer = getByte ();
|
||||||
|
|
||||||
tableInit ();
|
tableInit ();
|
||||||
|
|
||||||
// tableDump (decCtx.table);
|
|
||||||
decrunch ();
|
decrunch ();
|
||||||
|
|
||||||
if (outPos != outBuffer.length)
|
if (outPos < outBuffer.length)
|
||||||
{
|
{
|
||||||
byte[] outBuffer2 = new byte[outPos];
|
byte[] outBuffer2 = new byte[outPos];
|
||||||
System.arraycopy (outBuffer, 0, outBuffer2, 0, outBuffer2.length);
|
System.arraycopy (outBuffer, 0, outBuffer2, 0, outPos);
|
||||||
outBuffer = outBuffer2;
|
outBuffer = outBuffer2;
|
||||||
}
|
}
|
||||||
|
|
||||||
reverse (outBuffer);
|
reverse (outBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
private void reverse (byte[] inBuffer)
|
private void reverse (byte[] buffer)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
int lo = 0;
|
int lo = 0;
|
||||||
int hi = inBuffer.length - 1;
|
int hi = buffer.length - 1;
|
||||||
|
|
||||||
while (lo < hi)
|
while (lo < hi)
|
||||||
{
|
{
|
||||||
byte temp = inBuffer[lo];
|
byte temp = buffer[lo];
|
||||||
inBuffer[lo++] = inBuffer[hi];
|
buffer[lo++] = buffer[hi];
|
||||||
inBuffer[hi--] = temp;
|
buffer[hi--] = temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +91,7 @@ public class ExoBuffer
|
||||||
{
|
{
|
||||||
int carryOut;
|
int carryOut;
|
||||||
|
|
||||||
if ((flagsProto & PFLAG_BITS_ORDER_BE) != 0)
|
if ((flags & PFLAG_BITS_ORDER_BE) != 0)
|
||||||
{
|
{
|
||||||
carryOut = (bitBuffer & 0x80) == 0 ? 0 : 1;
|
carryOut = (bitBuffer & 0x80) == 0 ? 0 : 1;
|
||||||
bitBuffer = (bitBuffer << 1) & 0xFF;
|
bitBuffer = (bitBuffer << 1) & 0xFF;
|
||||||
|
@ -122,9 +115,7 @@ public class ExoBuffer
|
||||||
private int getByte ()
|
private int getByte ()
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
bitsRead += 8;
|
return inBuffer[inPos++] & 0xFF;
|
||||||
int c = inBuffer[inPos++] & 0xFF;
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
@ -134,7 +125,7 @@ public class ExoBuffer
|
||||||
int byteCopy = 0;
|
int byteCopy = 0;
|
||||||
int value = 0;
|
int value = 0;
|
||||||
|
|
||||||
if ((flagsProto & PFLAG_BITS_COPY_GT_7) != 0)
|
if ((flags & PFLAG_BITS_COPY_GT_7) != 0)
|
||||||
{
|
{
|
||||||
while (count > 7)
|
while (count > 7)
|
||||||
{
|
{
|
||||||
|
@ -150,12 +141,10 @@ public class ExoBuffer
|
||||||
if (bitBuffer == 0)
|
if (bitBuffer == 0)
|
||||||
{
|
{
|
||||||
bitBuffer = getByte ();
|
bitBuffer = getByte ();
|
||||||
bitsRead -= 8;
|
|
||||||
carry = bitBufRotate (1);
|
carry = bitBufRotate (1);
|
||||||
}
|
}
|
||||||
value <<= 1;
|
value <<= 1;
|
||||||
value |= carry;
|
value |= carry;
|
||||||
bitsRead++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (byteCopy-- > 0)
|
while (byteCopy-- > 0)
|
||||||
|
@ -167,26 +156,6 @@ public class ExoBuffer
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
private int getGammaCode ()
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
{
|
|
||||||
int gammaCode = 0;
|
|
||||||
|
|
||||||
while (getBits (1) == 0)
|
|
||||||
++gammaCode;
|
|
||||||
|
|
||||||
return gammaCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
private int getCooked (int index)
|
|
||||||
// ---------------------------------------------------------------------------------//
|
|
||||||
{
|
|
||||||
int base = tableLo[index] | (tableHi[index] << 8);
|
|
||||||
return base + getBits (tableBi[index]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
private void tableInit ()
|
private void tableInit ()
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
@ -199,7 +168,7 @@ public class ExoBuffer
|
||||||
tableBit[1] = 4;
|
tableBit[1] = 4;
|
||||||
tableBit[2] = 4;
|
tableBit[2] = 4;
|
||||||
|
|
||||||
if ((flagsProto & PFLAG_4_OFFSET_TABLES) != 0)
|
if ((flags & PFLAG_4_OFFSET_TABLES) != 0)
|
||||||
{
|
{
|
||||||
end = 68;
|
end = 68;
|
||||||
|
|
||||||
|
@ -229,7 +198,7 @@ public class ExoBuffer
|
||||||
tableLo[i] = a & 0xFF;
|
tableLo[i] = a & 0xFF;
|
||||||
tableHi[i] = a >>> 8;
|
tableHi[i] = a >>> 8;
|
||||||
|
|
||||||
if ((flagsProto & PFLAG_BITS_COPY_GT_7) != 0)
|
if ((flags & PFLAG_BITS_COPY_GT_7) != 0)
|
||||||
{
|
{
|
||||||
b = getBits (3);
|
b = getBits (3);
|
||||||
b |= getBits (1) << 3;
|
b |= getBits (1) << 3;
|
||||||
|
@ -239,6 +208,7 @@ public class ExoBuffer
|
||||||
|
|
||||||
tableBi[i] = b;
|
tableBi[i] = b;
|
||||||
}
|
}
|
||||||
|
// tableDump ();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
@ -266,9 +236,9 @@ public class ExoBuffer
|
||||||
int len;
|
int len;
|
||||||
int srcPtr = 0;
|
int srcPtr = 0;
|
||||||
int literal;
|
int literal;
|
||||||
int threshold = (flagsProto & PFLAG_4_OFFSET_TABLES) != 0 ? 4 : 3;
|
int threshold = (flags & PFLAG_4_OFFSET_TABLES) != 0 ? 4 : 3;
|
||||||
|
|
||||||
if ((flagsProto & PFLAG_IMPL_1LITERAL) != 0)
|
if ((flags & PFLAG_IMPL_1LITERAL) != 0)
|
||||||
{
|
{
|
||||||
len = 1;
|
len = 1;
|
||||||
literal = 1;
|
literal = 1;
|
||||||
|
@ -277,8 +247,6 @@ public class ExoBuffer
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
literal = 0;
|
|
||||||
|
|
||||||
if (getBits (1) != 0)
|
if (getBits (1) != 0)
|
||||||
{
|
{
|
||||||
len = 1;
|
len = 1;
|
||||||
|
@ -299,6 +267,8 @@ public class ExoBuffer
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
len = getCooked (val);
|
len = getCooked (val);
|
||||||
|
literal = 0;
|
||||||
|
|
||||||
int i = (len > threshold ? threshold : len) - 1;
|
int i = (len > threshold ? threshold : len) - 1;
|
||||||
srcPtr = outPos - getCooked (tableOff[i] + getBits (tableBit[i]));
|
srcPtr = outPos - getCooked (tableOff[i] + getBits (tableBit[i]));
|
||||||
}
|
}
|
||||||
|
@ -307,6 +277,26 @@ public class ExoBuffer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
private int getGammaCode ()
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
{
|
||||||
|
int gammaCode = 0;
|
||||||
|
|
||||||
|
while (getBits (1) == 0)
|
||||||
|
++gammaCode;
|
||||||
|
|
||||||
|
return gammaCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
private int getCooked (int index)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
{
|
||||||
|
int base = tableLo[index] | (tableHi[index] << 8);
|
||||||
|
return base + getBits (tableBi[index]);
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
private int copy (int len, int literal, int src)
|
private int copy (int len, int literal, int src)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
|
Loading…
Reference in New Issue
Block a user