- [FIX] uncompress() cleanup
This commit is contained in:
39
gif.h
39
gif.h
@@ -22,19 +22,12 @@ struct dictionary_entry_t
|
|||||||
|
|
||||||
void uncompress( int code_length, const uint8_t *input, int input_length, uint8_t *out )
|
void uncompress( int code_length, const uint8_t *input, int input_length, uint8_t *out )
|
||||||
{
|
{
|
||||||
int i, bit;
|
|
||||||
int code, prev = -1;
|
|
||||||
dictionary_entry_t *dictionary;
|
dictionary_entry_t *dictionary;
|
||||||
int dictionary_ind;
|
int dictionary_ind;
|
||||||
uint32_t mask = 0x01;
|
|
||||||
int reset_code_length;
|
|
||||||
int clear_code; // This varies depending on code_length
|
|
||||||
int stop_code; // one more than clear code
|
|
||||||
int match_len;
|
|
||||||
|
|
||||||
clear_code = 1 << ( code_length );
|
const int clear_code = 1 << ( code_length );
|
||||||
stop_code = clear_code + 1;
|
const int stop_code = clear_code + 1;
|
||||||
reset_code_length = code_length;
|
const int reset_code_length = code_length;
|
||||||
|
|
||||||
dictionary = ( dictionary_entry_t * )
|
dictionary = ( dictionary_entry_t * )
|
||||||
malloc( sizeof( dictionary_entry_t ) * ( 1 << ( code_length + 1 ) ) );
|
malloc( sizeof( dictionary_entry_t ) * ( 1 << ( code_length + 1 ) ) );
|
||||||
@@ -47,12 +40,15 @@ void uncompress( int code_length, const uint8_t *input, int input_length, uint8_
|
|||||||
}
|
}
|
||||||
dictionary_ind+=2;
|
dictionary_ind+=2;
|
||||||
|
|
||||||
|
int prev = -1;
|
||||||
|
uint32_t mask = 0x01;
|
||||||
while ( input_length )
|
while ( input_length )
|
||||||
{
|
{
|
||||||
code = 0x0;
|
int code = 0x0;
|
||||||
for (i=0; i<(code_length + 1); i++)
|
|
||||||
|
for (int i=0; i<(code_length + 1); i++)
|
||||||
{
|
{
|
||||||
bit = ( *input & mask ) ? 1 : 0;
|
const int bit = ( *input & mask ) ? 1 : 0;
|
||||||
mask <<= 1;
|
mask <<= 1;
|
||||||
|
|
||||||
if ( mask == 0x100 )
|
if ( mask == 0x100 )
|
||||||
@@ -90,18 +86,9 @@ void uncompress( int code_length, const uint8_t *input, int input_length, uint8_
|
|||||||
exit( 0 );
|
exit( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( code == dictionary_ind )
|
int ptr = (code == dictionary_ind) ? prev : code;
|
||||||
{
|
while ( dictionary[ ptr ].prev != -1 ) ptr = dictionary[ ptr ].prev;
|
||||||
int ptr = prev;
|
dictionary[ dictionary_ind ].byte = dictionary[ ptr ].byte;
|
||||||
while ( dictionary[ ptr ].prev != -1 ) ptr = dictionary[ ptr ].prev;
|
|
||||||
dictionary[ dictionary_ind ].byte = dictionary[ ptr ].byte;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int ptr = code;
|
|
||||||
while ( dictionary[ ptr ].prev != -1 ) ptr = dictionary[ ptr ].prev;
|
|
||||||
dictionary[ dictionary_ind ].byte = dictionary[ ptr ].byte;
|
|
||||||
}
|
|
||||||
|
|
||||||
dictionary[ dictionary_ind ].prev = prev;
|
dictionary[ dictionary_ind ].prev = prev;
|
||||||
dictionary[ dictionary_ind ].len = dictionary[ prev ].len + 1;
|
dictionary[ dictionary_ind ].len = dictionary[ prev ].len + 1;
|
||||||
@@ -116,7 +103,7 @@ void uncompress( int code_length, const uint8_t *input, int input_length, uint8_
|
|||||||
|
|
||||||
prev = code;
|
prev = code;
|
||||||
|
|
||||||
match_len = dictionary[ code ].len;
|
const int match_len = dictionary[ code ].len;
|
||||||
while ( code != -1 )
|
while ( code != -1 )
|
||||||
{
|
{
|
||||||
out[ dictionary[ code ].len - 1 ] = dictionary[ code ].byte;
|
out[ dictionary[ code ].len - 1 ] = dictionary[ code ].byte;
|
||||||
|
|||||||
Reference in New Issue
Block a user