[lcrash/cckernel] FIX: Add support for fixed huffman compression
This commit is contained in:
parent
d81dd11837
commit
fc7520c16f
@ -150,16 +150,21 @@ uptr GzipDecompress(c8* Input, uptr InputSize, c8* Output) {
|
|||||||
case 0: { // NO COMPRESSION
|
case 0: { // NO COMPRESSION
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1: {
|
case 1: // FIXED HUFFMAN
|
||||||
// FIXED HUFFMAN
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 2: { // DYNAMIC HUFFMAN
|
case 2: { // DYNAMIC HUFFMAN
|
||||||
// Get huffman code counts
|
// Get huffman code counts
|
||||||
u64 OperationCount = GzipFetchBits(Stream, &BitLocation, 5) + 257;
|
u64 OperationCount = (head & 2) ? 288 : GzipFetchBits(Stream, &BitLocation, 5) + 257;
|
||||||
u64 DistanceCount = GzipFetchBits(Stream, &BitLocation, 5) + 1;
|
u64 DistanceCount = (head & 2) ? 31 : GzipFetchBits(Stream, &BitLocation, 5) + 1;
|
||||||
u64 CodeCount = GzipFetchBits(Stream, &BitLocation, 4) + 4;
|
u64 CodeCount = (head & 2) ? 0 : GzipFetchBits(Stream, &BitLocation, 4) + 4;
|
||||||
|
u8 Lengths[OperationCount + DistanceCount] = {};
|
||||||
|
|
||||||
|
if (head & 2) { // Build fixed huffman lengths
|
||||||
|
for (int i = 0; i <= 143; i++) Lengths[i] = 8;
|
||||||
|
for (int i = 143; i <= 255; i++) Lengths[i] = 9;
|
||||||
|
for (int i = 256; i <= 279; i++) Lengths[i] = 7;
|
||||||
|
for (int i = 280; i <= 287; i++) Lengths[i] = 8;
|
||||||
|
for (int i = 288; i <= 319; i++) Lengths[i] = 5;
|
||||||
|
} else { // Build dynamic huffman lengths
|
||||||
const u8 CodeLengthLengthOffset[19] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
|
const u8 CodeLengthLengthOffset[19] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
|
||||||
u8 CodeLengthLengthProto[19] = {};
|
u8 CodeLengthLengthProto[19] = {};
|
||||||
for (int i = 0; i < CodeCount; i++) {
|
for (int i = 0; i < CodeCount; i++) {
|
||||||
@ -172,7 +177,6 @@ uptr GzipDecompress(c8* Input, uptr InputSize, c8* Output) {
|
|||||||
GzipPopulateTable(CodeLengthLengthProto, 19, CodeLengthLengths, CodeLengthSymbols, 0x80, 7);
|
GzipPopulateTable(CodeLengthLengthProto, 19, CodeLengthLengths, CodeLengthSymbols, 0x80, 7);
|
||||||
|
|
||||||
// Collect lengths
|
// Collect lengths
|
||||||
u8 Lengths[OperationCount + DistanceCount] = {};
|
|
||||||
uptr CurrentLen = 0;
|
uptr CurrentLen = 0;
|
||||||
while (CurrentLen < OperationCount + DistanceCount) {
|
while (CurrentLen < OperationCount + DistanceCount) {
|
||||||
// Fetch the next op
|
// Fetch the next op
|
||||||
@ -201,6 +205,7 @@ uptr GzipDecompress(c8* Input, uptr InputSize, c8* Output) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Build operation table
|
// Build operation table
|
||||||
u32 OperationMaxBits = 0;
|
u32 OperationMaxBits = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user