#include <LZHLEncoder.hpp>
Public Types | |
| enum | { maxMatchOver = 517, maxRaw = 64 } |
Public Methods | |
| LZHLEncoder (LZHLEncoderStat *stat_, BYTE *dst_) | |
| ~LZHLEncoder () | |
| size_t | flush () |
| void | putRaw (const BYTE *src, size_t sz) |
| void | putMatch (const BYTE *src, size_t nRaw, size_t matchOver, size_t disp) |
Static Public Methods | |
| size_t | calcMaxBuf (size_t rawSz) |
Private Methods | |
| void | _callStat () |
| void | _put (UINT16 symbol) |
| void | _put (UINT16 symbol, int codeBits, UINT32 code) |
| void | _putBits (int codeBits, UINT32 code) |
Private Attributes | |
| LZHLEncoderStat * | stat |
| HUFFINT * | sstat |
| int & | nextStat |
| BYTE * | dst |
| BYTE * | dstBegin |
| UINT32 | bits |
| int | nBits |
|
|
Definition at line 6 of file LZHLEncoder.hpp. 00006 { maxMatchOver = 517, maxRaw = 64 };
|
|
||||||||||||
|
Definition at line 4 of file LZHLEncoder.cpp. |
|
|
Definition at line 14 of file LZHLEncoder.cpp. 00014 { }
|
|
|
Definition at line 4 of file LZHLEncoder2.cpp. Referenced by _put().
00004 {
00005 nextStat = 2; // to avoid recursion, >=2
00006
00007 _put( NHUFFSYMBOLS - 2 );
00008
00009 int groups[ 16 ];
00010 stat->calcStat( groups );
00011
00012 int lastNBits = 0;
00013
00014 for( int i=0; i < 16 ; ++i ) {
00015 int nBits = groups[ i ];
00016 assert( nBits >= lastNBits && nBits <= 8 );
00017 int delta = nBits - lastNBits;
00018 lastNBits = nBits;
00019 _putBits( delta + 1, 1 );
00020 }
00021 }
|
|
||||||||||||||||
|
Definition at line 45 of file LZHLEncoder.cpp. 00045 {
00046 assert( symbol < NHUFFSYMBOLS );
00047 assert( codeBits <= 4 );
00048
00049 if ( --nextStat <= 0 ) {
00050 _callStat();
00051 }
00052
00053 ++sstat[ symbol ];
00054
00055 LZHLEncoderStat::Symbol* item = &stat->symbolTable[ symbol ];
00056 assert( item->nBits >= 0 );
00057
00058 int nBits = item->nBits;
00059 _putBits( nBits + codeBits, ( item->code << codeBits ) | code );
00060 }
|
|
|
Definition at line 30 of file LZHLEncoder.cpp. Referenced by _callStat(), putMatch(), and putRaw().
00030 {
00031 assert( symbol < NHUFFSYMBOLS );
00032
00033 if ( --nextStat <= 0 ) {
00034 _callStat();
00035 }
00036
00037 ++sstat[ symbol ];
00038
00039 LZHLEncoderStat::Symbol* item = &stat->symbolTable[ symbol ];
00040 assert( item->nBits >= 0 );
00041
00042 _putBits( item->nBits, item->code );
00043 }
|
|
||||||||||||
|
Definition at line 16 of file LZHLEncoder.cpp. Referenced by _callStat(), _put(), and putMatch().
00016 {
00017 assert( codeBits <= 16 );
00018 bits |= ( code << ( 32 - nBits - codeBits ) );
00019 nBits += codeBits;
00020
00021 if ( nBits >= 16 ) {
00022 *dst++ = (BYTE)( bits >> 24 );
00023 *dst++ = (BYTE)( bits >> 16 );
00024
00025 nBits -= 16;
00026 bits <<= 16;
00027 }
00028 }
|
|
|
Definition at line 19 of file LZHLEncoder.hpp. Referenced by LZHLCompressor::calcMaxBuf().
00019 {
00020 return rawSz + ( rawSz >> 1 ) + 32;
00021 }
|
|
|
Definition at line 228 of file LZHLEncoder2.cpp. Referenced by LZHLCompressor::compress().
|
|
||||||||||||||||||||
|
Definition at line 29 of file LZHLEncoder2.cpp. Referenced by LZHLCompressor::compress().
00030 {
00031 assert( nRaw <= maxRaw );
00032 assert( matchOver <= maxMatchOver );
00033 assert( disp >= 0 && disp < LZBUFSIZE );
00034 putRaw( src, nRaw );
00035 struct MatchOverItem { int symbol; int nBits; UINT16 bits; };
00036
00037 static MatchOverItem _matchOverTable[] = {
00038 { 264, 1, 0x00 },
00039
00040 { 265, 2, 0x00 },
00041 { 265, 2, 0x02 },
00042
00043 { 266, 3, 0x00 },
00044 { 266, 3, 0x02 },
00045 { 266, 3, 0x04 },
00046 { 266, 3, 0x06 },
00047
00048 { 267, 4, 0x00 },
00049 { 267, 4, 0x02 },
00050 { 267, 4, 0x04 },
00051 { 267, 4, 0x06 },
00052 { 267, 4, 0x08 },
00053 { 267, 4, 0x0A },
00054 { 267, 4, 0x0C },
00055 { 267, 4, 0x0E },
00056 };
00057
00058 if ( matchOver < 8 ) {
00059 _put( 256 + matchOver );
00060
00061 } else if ( matchOver < 38 ) {
00062 matchOver -= 8;
00063 MatchOverItem* item = &_matchOverTable[ matchOver >> 1 ];
00064 _put( item->symbol, item->nBits, item->bits | (matchOver & 0x01) );
00065
00066 } else {
00067 matchOver -= 38;
00068 MatchOverItem* item = &_matchOverTable[ matchOver >> 5 ];
00069 _put( item->symbol + 4 );
00070 _putBits( item->nBits + 4, ( item->bits << 4 ) | (matchOver & 0x1F) );
00071 }
00072
00073 static struct DispItem { int nBits; UINT16 bits; } _dispTable[] = {
00074 #include <j2k/LZH/Table/hdisp.tbl>
00075 };
00076
00077 #if LZBUFBITS < 8
00078 #error
00079 #endif
00080
00081 DispItem* item = &_dispTable[ disp >> (LZBUFBITS - 7) ];
00082 int nBits = item->nBits + (LZBUFBITS - 7);
00083 UINT32 bits = ( ((UINT32)item->bits) << (LZBUFBITS - 7) ) | ( disp & ( ( 1 << (LZBUFBITS - 7) ) - 1 ) );
00084
00085 #if LZBUFBITS >= 15
00086 if ( nBits > 16 ) {
00087 assert( nBits <= 32 );
00088 _putBits( nBits - 16, bits >> 16 );
00089 _putBits( 16, bits & 0xFFFF );
00090
00091 } else
00092 #endif
00093
00094 {
00095 assert( nBits <= 16 );
00096 _putBits( nBits, bits );
00097 }
00098 }
00099
00100 size_t LZHLEncoder::flush() {
00101 _put( NHUFFSYMBOLS - 1 );
00102
00103 while( nBits > 0 ) {
00104 *dst++ = (BYTE)( bits >> 24 );
00105 nBits -= 8;
00106 bits <<= 8;
00107 }
00108
00109 return dst - dstBegin;
00110 }
00111
00112 #endif
|
|
||||||||||||
|
Definition at line 23 of file LZHLEncoder2.cpp. Referenced by LZHLCompressor::compress(), and putMatch().
00023 {
00024 for( const BYTE* srcEnd = src + sz; src < srcEnd ; ++src ) {
00025 _put( *src );
00026 }
00027 }
|
|
|
Definition at line 15 of file LZHLEncoder.hpp. |
|
|
Definition at line 13 of file LZHLEncoder.hpp. |
|
|
Definition at line 14 of file LZHLEncoder.hpp. |
|
|
Definition at line 16 of file LZHLEncoder.hpp. |
|
|
Definition at line 11 of file LZHLEncoder.hpp. |
|
|
Definition at line 10 of file LZHLEncoder.hpp. |
|
|
Definition at line 9 of file LZHLEncoder.hpp. |
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001