1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * huffman.h -- Huffman coding functions
|
---|
4 | * Copyright (C) 1994 Neil Sharman
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | *
|
---|
20 | **************************************************************************/
|
---|
21 |
|
---|
22 | #ifndef H_HUFFMAN
|
---|
23 | #define H_HUFFMAN
|
---|
24 |
|
---|
25 | #include "sysfuncs.h"
|
---|
26 | #include "bitio_m_abstract.h"
|
---|
27 |
|
---|
28 | #define MAX_HUFFCODE_LEN 31
|
---|
29 |
|
---|
30 | struct huff_data {
|
---|
31 | int num_codes;
|
---|
32 | int mincodelen;
|
---|
33 | int maxcodelen;
|
---|
34 | int lencount[MAX_HUFFCODE_LEN + 1];
|
---|
35 | unsigned long min_code[MAX_HUFFCODE_LEN + 1];
|
---|
36 | char *clens;
|
---|
37 | };
|
---|
38 |
|
---|
39 |
|
---|
40 | huff_data *Generate_Huffman_Data (int num, long *freqs, huff_data * data,
|
---|
41 | u_long * mem);
|
---|
42 |
|
---|
43 | unsigned long *Generate_Huffman_Codes (huff_data * data, u_long * mem);
|
---|
44 |
|
---|
45 | unsigned long **Generate_Huffman_Vals (huff_data * data, u_long * mem);
|
---|
46 |
|
---|
47 | int Write_Huffman_Data (FILE * f, huff_data * hd);
|
---|
48 |
|
---|
49 | int Read_Huffman_Data (FILE * f, huff_data * hd, u_long * mem, u_long * disk);
|
---|
50 |
|
---|
51 | /* Calculate the number of bits required to code the data with the
|
---|
52 | specified frequencies. Normally freqs and counts should point to
|
---|
53 | the same array. */
|
---|
54 | double Calculate_Huffman_Size (int num, long *freqs, long *counts);
|
---|
55 |
|
---|
56 |
|
---|
57 | #endif
|
---|