diff options
Diffstat (limited to 'backends/platform/ds/arm9/source/compressor/lz.cpp')
-rw-r--r-- | backends/platform/ds/arm9/source/compressor/lz.cpp | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/backends/platform/ds/arm9/source/compressor/lz.cpp b/backends/platform/ds/arm9/source/compressor/lz.cpp index 1234bf7b3b..47a36646c6 100644 --- a/backends/platform/ds/arm9/source/compressor/lz.cpp +++ b/backends/platform/ds/arm9/source/compressor/lz.cpp @@ -105,7 +105,7 @@ inline static unsigned int _LZ_StringCompare( unsigned char * str1, { unsigned int len; - for( len = minlen; (len < maxlen) && (str1[len] == str2[len]); ++ len ); + for ( len = minlen; (len < maxlen) && (str1[len] == str2[len]); ++ len ); return len; } @@ -123,18 +123,18 @@ inline static int _LZ_WriteVarSize( unsigned int x, unsigned char * buf ) /* Determine number of bytes needed to store the number x */ y = x >> 3; - for( num_bytes = 5; num_bytes >= 2; -- num_bytes ) + for ( num_bytes = 5; num_bytes >= 2; -- num_bytes ) { - if( y & 0xfe000000 ) break; + if ( y & 0xfe000000 ) break; y <<= 7; } /* Write all bytes, seven bits in each, with 8:th bit set for all */ /* but the last byte. */ - for( i = num_bytes-1; i >= 0; -- i ) + for ( i = num_bytes-1; i >= 0; -- i ) { b = (x >> (i*7)) & 0x0000007f; - if( i > 0 ) + if ( i > 0 ) { b |= 0x00000080; } @@ -164,7 +164,7 @@ inline static int _LZ_ReadVarSize( unsigned int * x, unsigned char * buf ) y = (y << 7) | (b & 0x0000007f); ++ num_bytes; } - while( b & 0x00000080 ); + while ( b & 0x00000080 ); /* Store value in x */ *x = y; @@ -200,26 +200,26 @@ int LZ_Compress( unsigned char *in, unsigned char *out, unsigned char *ptr1, *ptr2; /* Do we have anything to compress? */ - if( insize < 1 ) + if ( insize < 1 ) { return 0; } /* Create histogram */ - for( i = 0; i < 256; ++ i ) + for ( i = 0; i < 256; ++ i ) { histogram[ i ] = 0; } - for( i = 0; i < insize; ++ i ) + for ( i = 0; i < insize; ++ i ) { ++ histogram[ in[ i ] ]; } /* Find the least common byte, and use it as the code marker */ marker = 0; - for( i = 1; i < 256; ++ i ) + for ( i = 1; i < 256; ++ i ) { - if( histogram[ i ] < histogram[ marker ] ) + if ( histogram[ i ] < histogram[ marker ] ) { marker = i; } @@ -237,7 +237,7 @@ int LZ_Compress( unsigned char *in, unsigned char *out, do { /* Determine most distant position */ - if( inpos > LZ_MAX_OFFSET ) maxoffset = LZ_MAX_OFFSET; + if ( inpos > LZ_MAX_OFFSET ) maxoffset = LZ_MAX_OFFSET; else maxoffset = inpos; /* Get pointer to current position */ @@ -246,13 +246,13 @@ int LZ_Compress( unsigned char *in, unsigned char *out, /* Search history window for maximum length string match */ bestlength = 3; bestoffset = 0; - for( offset = 3; offset <= maxoffset; ++ offset ) + for ( offset = 3; offset <= maxoffset; ++ offset ) { /* Get pointer to candidate string */ ptr2 = &ptr1[ -offset ]; /* Quickly determine if this is a candidate (for speed) */ - if( (ptr1[ 0 ] == ptr2[ 0 ]) && + if ( (ptr1[ 0 ] == ptr2[ 0 ]) && (ptr1[ bestlength ] == ptr2[ bestlength ]) ) { /* Determine maximum length for this offset */ @@ -262,7 +262,7 @@ int LZ_Compress( unsigned char *in, unsigned char *out, length = _LZ_StringCompare( ptr1, ptr2, 0, maxlength ); /* Better match than any previous match? */ - if( length > bestlength ) + if ( length > bestlength ) { bestlength = length; bestoffset = offset; @@ -271,7 +271,7 @@ int LZ_Compress( unsigned char *in, unsigned char *out, } /* Was there a good enough match? */ - if( (bestlength >= 8) || + if ( (bestlength >= 8) || ((bestlength == 4) && (bestoffset <= 0x0000007f)) || ((bestlength == 5) && (bestoffset <= 0x00003fff)) || ((bestlength == 6) && (bestoffset <= 0x001fffff)) || @@ -288,19 +288,19 @@ int LZ_Compress( unsigned char *in, unsigned char *out, /* Output single byte (or two bytes if marker byte) */ symbol = in[ inpos ++ ]; out[ outpos ++ ] = symbol; - if( symbol == marker ) + if ( symbol == marker ) { out[ outpos ++ ] = 0; } -- bytesleft; } } - while( bytesleft > 3 ); + while ( bytesleft > 3 ); /* Dump remaining bytes, if any */ - while( inpos < insize ) + while ( inpos < insize ) { - if( in[ inpos ] == marker ) + if ( in[ inpos ] == marker ) { out[ outpos ++ ] = marker; out[ outpos ++ ] = 0; @@ -338,7 +338,7 @@ int LZ_CompressFast( unsigned char *in, unsigned char *out, unsigned char *ptr1, *ptr2; /* Do we have anything to compress? */ - if( insize < 1 ) + if ( insize < 1 ) { return 0; } @@ -353,11 +353,11 @@ int LZ_CompressFast( unsigned char *in, unsigned char *out, in[i+1] == in[jumptable[i]+1]. Following the jump table gives a dramatic boost for the string search'n'match loop compared to doing a brute force search. */ - for( i = 0; i < 65536; ++ i ) + for ( i = 0; i < 65536; ++ i ) { lastindex[ i ] = 0xffffffff; } - for( i = 0; i < insize-1; ++ i ) + for ( i = 0; i < insize-1; ++ i ) { symbols = (((unsigned int)in[i]) << 8) | ((unsigned int)in[i+1]); index = lastindex[ symbols ]; @@ -367,20 +367,20 @@ int LZ_CompressFast( unsigned char *in, unsigned char *out, jumptable[ insize-1 ] = 0xffffffff; /* Create histogram */ - for( i = 0; i < 256; ++ i ) + for ( i = 0; i < 256; ++ i ) { histogram[ i ] = 0; } - for( i = 0; i < insize; ++ i ) + for ( i = 0; i < insize; ++ i ) { ++ histogram[ in[ i ] ]; } /* Find the least common byte, and use it as the code marker */ marker = 0; - for( i = 1; i < 256; ++ i ) + for ( i = 1; i < 256; ++ i ) { - if( histogram[ i ] < histogram[ marker ] ) + if ( histogram[ i ] < histogram[ marker ] ) { marker = i; } @@ -404,13 +404,13 @@ int LZ_CompressFast( unsigned char *in, unsigned char *out, bestlength = 3; bestoffset = 0; index = jumptable[ inpos ]; - while( index != 0xffffffff ) + while ( index != 0xffffffff ) { /* Get pointer to candidate string */ ptr2 = &in[ index ]; /* Quickly determine if this is a candidate (for speed) */ - if( ptr2[ bestlength ] == ptr1[ bestlength ] ) + if ( ptr2[ bestlength ] == ptr1[ bestlength ] ) { /* Determine maximum length for this offset */ offset = inpos - index; @@ -420,7 +420,7 @@ int LZ_CompressFast( unsigned char *in, unsigned char *out, length = _LZ_StringCompare( ptr1, ptr2, 2, maxlength ); /* Better match than any previous match? */ - if( length > bestlength ) + if ( length > bestlength ) { bestlength = length; bestoffset = offset; @@ -432,7 +432,7 @@ int LZ_CompressFast( unsigned char *in, unsigned char *out, } /* Was there a good enough match? */ - if( (bestlength >= 8) || + if ( (bestlength >= 8) || ((bestlength == 4) && (bestoffset <= 0x0000007f)) || ((bestlength == 5) && (bestoffset <= 0x00003fff)) || ((bestlength == 6) && (bestoffset <= 0x001fffff)) || @@ -449,19 +449,19 @@ int LZ_CompressFast( unsigned char *in, unsigned char *out, /* Output single byte (or two bytes if marker byte) */ symbol = in[ inpos ++ ]; out[ outpos ++ ] = symbol; - if( symbol == marker ) + if ( symbol == marker ) { out[ outpos ++ ] = 0; } -- bytesleft; } } - while( bytesleft > 3 ); + while ( bytesleft > 3 ); /* Dump remaining bytes, if any */ - while( inpos < insize ) + while ( inpos < insize ) { - if( in[ inpos ] == marker ) + if ( in[ inpos ] == marker ) { out[ outpos ++ ] = marker; out[ outpos ++ ] = 0; @@ -492,7 +492,7 @@ void LZ_Uncompress( unsigned char *in, unsigned char *out, unsigned int i, inpos, outpos, length, offset; /* Do we have anything to compress? */ - if( insize < 1 ) + if ( insize < 1 ) { return; } @@ -506,10 +506,10 @@ void LZ_Uncompress( unsigned char *in, unsigned char *out, do { symbol = in[ inpos ++ ]; - if( symbol == marker ) + if ( symbol == marker ) { /* We had a marker byte */ - if( in[ inpos ] == 0 ) + if ( in[ inpos ] == 0 ) { /* It was a single occurrence of the marker byte */ out[ outpos ++ ] = marker; @@ -522,7 +522,7 @@ void LZ_Uncompress( unsigned char *in, unsigned char *out, inpos += _LZ_ReadVarSize( &offset, &in[ inpos ] ); /* Copy corresponding data from history window */ - for( i = 0; i < length; ++ i ) + for ( i = 0; i < length; ++ i ) { out[ outpos ] = out[ outpos - offset ]; ++ outpos; @@ -535,5 +535,5 @@ void LZ_Uncompress( unsigned char *in, unsigned char *out, out[ outpos ++ ] = symbol; } } - while( inpos < insize ); + while ( inpos < insize ); } |