libopenraw
crwdecompressor.h
1 /*
2  * libopenraw - crwdecompressor.h
3  *
4  * Copyright (C) 2007 Hubert Figuiere
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
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.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef __OPENRAW_CRWDECOMPRESS_H__
22 #define __OPENRAW_CRWDECOMPRESS_H__
23 
24 #include <boost/noncopyable.hpp>
25 
26 #include <libopenraw/libopenraw.h>
27 
28 #include "decompressor.h"
29 
30 namespace OpenRaw {
31 
32  class RawData;
33 
34  namespace IO {
35  class Stream;
36  }
37 
38  namespace Internals {
39 
40  class RawContainer;
41 
43  : public Decompressor
44  {
45  public:
46  CrwDecompressor(IO::Stream * stream,
47  RawContainer * container);
48  virtual ~CrwDecompressor();
49 
57  virtual RawData *decompress(RawData *in = NULL);
58  void setDecoderTable(uint32_t t)
59  { m_table = t; }
60  void setOutputDimensions(uint32_t x, uint32_t y)
61  { m_height = y; m_width = x; }
62  private:
63 
64  struct decode_t {
65  decode_t *branch[2];
66  int leaf;
67  };
68 
69  uint32_t getbits(IO::Stream * s, int nbits);
70  void make_decoder(decode_t *dest, const uint8_t *source,
71  int level);
72  void init_tables(uint32_t table_idx);
73 
74  uint32_t m_table;
75  uint32_t m_height, m_width;
76 
77  decode_t m_first_decode[32];
78  decode_t m_second_decode[512];
79  // for make_decoder
80  decode_t *m_free; /* Next unused node */
81  int m_leaf; /* no. of leaves already added */
82  // for getbits
83  uint32_t m_bitbuf;
84  int m_vbits;
85  };
86 
87  }
88 }
89 
90 
91 #endif