libopenraw
huffman.cpp
1 /* -*- tab-width:4; c-basic-offset:4 -*- */
2 /*
3  * libopenraw - huffman.cpp
4  *
5  * Copyright (C) 2008 Rafael Avila de Espindola.
6  *
7  * This library is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation, either version 3 of
10  * the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library. If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 
22 #include <string>
23 #include <iostream>
24 #include "huffman.hpp"
25 #include "bititerator.hpp"
26 
27 namespace OpenRaw {
28 namespace Internals {
29 
30 void HuffmanDecoder::printTable_(std::string prefix, unsigned int pos) const
31 {
32  const HuffmanNode &cur = m_p[pos];
33  if (cur.isLeaf) {
34  std::cerr << prefix << " " << cur.data << "\n";
35  } else {
36  printTable_(prefix + "0", pos + 1);
37  printTable_(prefix + "1", cur.data);
38  }
39 }
40 
41 HuffmanDecoder::HuffmanDecoder(const HuffmanNode* const p) : m_p(p)
42 {
43 }
44 
45 void HuffmanDecoder::printTable() const
46 {
47  printTable_("", 0);
48 }
49 
50 unsigned int HuffmanDecoder::decode(BitIterator& i)
51 {
52  int cur = 0;
53  while (!m_p[cur].isLeaf) {
54  unsigned int bit = i.get(1);
55  if (bit)
56  cur = m_p[cur].data;
57  else
58  cur = cur + 1;
59  }
60  return m_p[cur].data;
61 }
62 
63 }
64 }
CIFF is the container for CRW files. It is an attempt from Canon to make this a standard. I guess it failed.
Definition: arwfile.cpp:30