Ignore:
Timestamp:
10/17/06 13:52:34 (16 years ago)
Author:
r2d
Message:
  • removed tools.c
File:
1 edited

Legend:

Unmodified
Added
Removed
  • mppenc/branches/r2d/libmpcenc/huffsv7.c

    r72 r76  
    332332#endif
    333333
    334 
    335 // FIXME : remove the functions from tools.c
    336 void Make_HuffTable ( Huffman_t* dst, const HuffSrc_t* src, mpc_size_t len );
    337 void Resort_HuffTable ( Huffman_t* const Table, const mpc_size_t elements, mpc_int_t offset );
    338 void Make_LookupTable ( mpc_uint8_t* LUT, mpc_size_t LUT_len, const Huffman_t* const Table, const mpc_size_t elements );
     334/*
     335 *  Fills out the items Code and Length (but not Value) of a Huffman table
     336 *  from a bit packed Huffman table 'src'. Table is not sorted, so this is
     337 *  the table which is suitable for an encoder. Be careful: To get a table
     338 *  usable for a decoder you must use Resort_HuffTable() after this
     339 *  function. It's a little bit dangerous to divide the functionality, maybe
     340 *  there is a more secure and handy solution to this problem.
     341 */
     342
     343void Make_HuffTable ( Huffman_t* dst, const HuffSrc_t* src, mpc_size_t len )
     344{
     345        mpc_size_t  i;
     346
     347        for ( i = 0; i < len; i++,src++,dst++ ) {
     348                dst->Code   = src->Code  ;
     349                dst->Length = src->Length;
     350        }
     351}
     352
     353
     354/*
     355 *  Generates a Lookup table for quick Huffman decoding. This table must
     356 *  have a size of a power of 2. Input is the pre-sorted Huffman table,
     357 *  sorted by Resort_HuffTable() and its length, and the length of the
     358 *  lookup table. Output is the Lookup table. It can be used for table based
     359 *  decoding (Huffman_decode_fastest) which fully decodes by means of the
     360 *  LUT. This is only handy for small huffman codes up to 9...10 bit
     361 *  maximum length. For longer codes partial lookup is possible with
     362 *  Huffman_decode_faster() which first estimates possible codes by means
     363 *  of LUT and then searches the exact code like the tableless version
     364 *  Huffman_decode().
     365 */
     366
     367void Make_LookupTable ( mpc_uint8_t* LUT,
     368                                                mpc_size_t LUT_len,
     369                                                const Huffman_t* const Table,
     370                                                const mpc_size_t elements )
     371{
     372        mpc_size_t    i;
     373        mpc_size_t    idx  = elements;
     374        mpc_uint32_t  dval = (mpc_uint32_t)0x80000000L / LUT_len * 2;
     375        mpc_uint32_t  val  = dval - 1;
     376
     377        for ( i = 0; i < LUT_len; i++, val += dval ) {
     378                while ( idx > 0  &&  val >= Table[idx-1].Code )
     379                        idx--;
     380                *LUT++ = (mpc_uint8_t)idx;
     381        }
     382
     383        return;
     384}
    339385
    340386#define MAKE(d,s)     Make_HuffTable   ( (d), (s), sizeof(s)/sizeof(*(s)) )
    341 #define SORT(x,o)     Resort_HuffTable ( (x), sizeof(x)/sizeof(*(x)), -(Int)(o) )
    342387#define LOOKUP(x,q)   Make_LookupTable ( (q), sizeof(q), (x), sizeof(x)/sizeof(*(x)) )
    343388
Note: See TracChangeset for help on using the changeset viewer.