2 Copyright (C) 2008, Francisco Claude, all rights reserved.
4 Wrapper for huff written by Gonzalo Navarro
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library 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 GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <huffman_codes.h>
25 huffman_codes::huffman_codes(uint * symb, uint n) {
28 max_v = max(max_v,symb[i]);
29 uint * occ = new uint[max_v+1];
30 for(uint i=0;i<max_v+1;i++)
34 huff_table = createHuff(occ, max_v);
38 huffman_codes::huffman_codes(uchar * symb, uint n) {
41 max_v = max(max_v,symb[i]);
42 uint * occ = new uint[max_v+1];
43 for(uint i=0;i<(uint)max_v+1;i++)
47 huff_table = createHuff(occ, max_v);
51 huffman_codes::huffman_codes() {
54 huffman_codes::~huffman_codes() {
58 uint huffman_codes::max_length() {
59 return huff_table.depth;
62 uint huffman_codes::size() {
63 return sizeof(huffman_codes)+sizeHuff(huff_table);
66 ulong huffman_codes::encode(uint symb, uint * stream, ulong pos) {
67 return encodeHuff(huff_table, symb, stream, pos);
70 ulong huffman_codes::decode(uint * symb, uint * stream, ulong pos) {
71 return decodeHuff(huff_table, symb, stream, pos);
74 uint huffman_codes::save(FILE *fp) {
75 saveHuff(huff_table,fp);
79 huffman_codes * huffman_codes::load(FILE * fp) {
80 huffman_codes * ret = new huffman_codes();
81 ret->huff_table = loadHuff(fp,1);