Skip to content

Commit

Permalink
Added code to handle uncompressed blocks - thanks to Niklas Therning …
Browse files Browse the repository at this point in the history
…for the details
  • Loading branch information
dparnell committed Apr 7, 2011
1 parent f61d104 commit 90b70dd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.DS_Store
*.o
hu01
*.plain
49 changes: 28 additions & 21 deletions hu01_decompressor.c
Expand Up @@ -775,32 +775,39 @@ int decompress_hu01_data(const unsigned char* hu01_buffer, int hu01_buffer_size,
#endif

pos += block_header_size;

int result = build_decompression_table(pos, &table[0]);
hu01_buffer_size -= block_header_size;

if(!result) {
printf("ERROR: %d\n", result);
return HU_BAD_COMPRESSION_TABLE;

if(block_decompressed_size == block_size && block_size < 2048) {
// the block is not compressed, just copy the data in this block to the destination buffer
memcpy(dest, pos, block_size);
pos = pos + block_size;
dest = dest + block_size;
hu01_buffer_size -= block_size;
to_decompress -= block_size;
} else {
const unsigned char* block_end_pos = pos+block_size;
unsigned char* block_end_dest = dest+block_decompressed_size;
#ifdef DEBUG_HEADER
printf("TABLE SUCCESS:\n");
#endif
pos += 256;
int result = build_decompression_table(pos, &table[0]);

if(!result) {
printf("ERROR: %d\n", result);
return HU_BAD_COMPRESSION_TABLE;
} else {
const unsigned char* block_end_pos = pos+block_size;
unsigned char* block_end_dest = dest+block_decompressed_size;
#ifdef DEBUG_HEADER
printf("TABLE SUCCESS:\n");
#endif
pos += 256;

if(decompress_hu01_block(pos, block_end_pos, &table[0], dest, block_end_dest)==0) {
return HU_BLOCK_DECOMPRESS_FAILED;
}
hu01_buffer_size -= block_size;
to_decompress -= block_decompressed_size;
if(decompress_hu01_block(pos, block_end_pos, &table[0], dest, block_end_dest)==0) {
return HU_BLOCK_DECOMPRESS_FAILED;
}
hu01_buffer_size -= block_size;
to_decompress -= block_decompressed_size;

pos = block_end_pos;
dest = block_end_dest;
pos = block_end_pos;
dest = block_end_dest;
}
}

// break; // just for now
}
} else {
return HU_BAD_HEADER_SIZE;
Expand Down
Binary file added test7.hu01
Binary file not shown.

0 comments on commit 90b70dd

Please sign in to comment.