Subversion Repositories Games.Carmageddon

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
/**
2
        libsmacker - A C library for decoding .smk Smacker Video files
3
        Copyright (C) 2012-2017 Greg Kennedy
4
 
5
        See smacker.h for more information.
6
 
7
        smk_hufftree.h
8
                SMK huffmann trees.  There are two types:
9
                - a basic 8-bit tree, and
10
                - a "big" 16-bit tree which includes a cache for recently
11
                        searched values.
12
*/
13
 
14
#ifndef SMK_HUFFTREE_H
15
#define SMK_HUFFTREE_H
16
 
17
#include "smk_bitstream.h"
18
 
19
/** Tree node structures - Forward declaration */
20
struct smk_huff8_t;
21
struct smk_huff16_t;
22
 
23
/*********************** 8-BIT HUFF-TREE FUNCTIONS ***********************/
24
/** This macro checks return code from _smk_huff8_build and
25
        jumps to error label if problems occur. */
26
#define smk_huff8_build(bs,t) \
27
{ \
28
        if (!(t = _smk_huff8_build(bs))) \
29
        { \
30
                fprintf(stderr, "libsmacker::smk_huff8_build(" #bs ", " #t ") - ERROR (file: %s, line: %lu)\n", __FILE__, (unsigned long)__LINE__); \
31
                goto error; \
32
        } \
33
}
34
/** Build an 8-bit tree from a bitstream */
35
struct smk_huff8_t* _smk_huff8_build(struct smk_bit_t* bs);
36
 
37
/** This macro checks return code from _smk_huff8_lookup and
38
        jumps to error label if problems occur. */
39
#define smk_huff8_lookup(bs,t,s) \
40
{ \
41
        if ((short)(s = _smk_huff8_lookup(bs, t)) < 0) \
42
        { \
43
                fprintf(stderr, "libsmacker::smk_huff8_lookup(" #bs ", " #t ", " #s ") - ERROR (file: %s, line: %lu)\n", __FILE__, (unsigned long)__LINE__); \
44
                goto error; \
45
        } \
46
}
47
/** Look up an 8-bit value in the referenced tree by following a bitstream
48
        returns -1 on error */
49
short _smk_huff8_lookup(struct smk_bit_t* bs, const struct smk_huff8_t* t);
50
 
51
/** function to recursively delete an 8-bit huffman tree */
52
void smk_huff8_free(struct smk_huff8_t* t);
53
 
54
/************************ 16-BIT HUFF-TREE FUNCTIONS ************************/
55
/** This macro checks return code from _smk_huff16_build and
56
        jumps to error label if problems occur. */
57
#define smk_huff16_build(bs,t) \
58
{ \
59
        if (!(t = _smk_huff16_build(bs))) \
60
        { \
61
                fprintf(stderr, "libsmacker::smk_huff16_build(" #bs ", " #t ") - ERROR (file: %s, line: %lu)\n", __FILE__, (unsigned long)__LINE__); \
62
                goto error; \
63
        } \
64
}
65
/** Build a 16-bit tree from a bitstream */
66
struct smk_huff16_t* _smk_huff16_build(struct smk_bit_t* bs);
67
 
68
/** This macro checks return code from smk_huff16_lookup and
69
        jumps to error label if problems occur. */
70
#define smk_huff16_lookup(bs,t,s) \
71
{ \
72
        if ((s = _smk_huff16_lookup(bs, t)) < 0) \
73
        { \
74
                fprintf(stderr, "libsmacker::smk_huff16_lookup(" #bs ", " #t ", " #s ") - ERROR (file: %s, line: %lu)\n", __FILE__, (unsigned long)__LINE__); \
75
                goto error; \
76
        } \
77
}
78
/** Look up a 16-bit value in the bigtree by following a bitstream
79
        returns -1 on error */
80
long _smk_huff16_lookup(struct smk_bit_t* bs, struct smk_huff16_t* big);
81
 
82
/** Reset the cache in a 16-bit tree */
83
void smk_huff16_reset(struct smk_huff16_t* big);
84
 
85
/** function to recursively delete a 16-bit huffman tree */
86
void smk_huff16_free(struct smk_huff16_t* big);
87
 
88
#endif