libpgf  6.12.24
PGF - Progressive Graphics File
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Decoder.h
Go to the documentation of this file.
1 /*
2  * The Progressive Graphics File; http://www.libpgf.org
3  *
4  * $Date: 2006-06-04 22:05:59 +0200 (So, 04 Jun 2006) $
5  * $Revision: 229 $
6  *
7  * This file Copyright (C) 2006 xeraina GmbH, Switzerland
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  */
23 
28 
29 #ifndef PGF_DECODER_H
30 #define PGF_DECODER_H
31 
32 #include "PGFstream.h"
33 #include "BitStream.h"
34 #include "Subband.h"
35 #include "WaveletTransform.h"
36 
38 // Constants
39 #define BufferLen (BufferSize/WordWidth)
40 #define CodeBufferLen BufferSize
41 
42 
43 
44 
45 
46 class CDecoder {
51  class CMacroBlock {
52  public:
57  : m_header(0) // makes sure that IsCompletelyRead() returns true for an empty macro block
58  , m_valuePos(0)
59  , m_decoder(decoder)
60  {
61  ASSERT(m_decoder);
62  }
63 
67  bool IsCompletelyRead() const { return m_valuePos >= m_header.rbh.bufferSize; }
68 
73  void BitplaneDecode();
74 
78  UINT32 m_valuePos;
79 
80  private:
81  UINT32 ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32* signBits);
82  UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32 sigPos, UINT32* refBits);
83  UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32 signPos);
84  void SetBitAtPos(UINT32 pos, DataT planeMask) { (m_value[pos] >= 0) ? m_value[pos] |= planeMask : m_value[pos] -= planeMask; }
85  void SetSign(UINT32 pos, bool sign) { m_value[pos] = -m_value[pos]*sign + m_value[pos]*(!sign); }
86 
87  CDecoder *m_decoder; // outer class
88  bool m_sigFlagVector[BufferSize+1]; // see paper from Malvar, Fast Progressive Wavelet Coder
89  };
90 
91 public:
103  CDecoder(CPGFStream* stream, PGFPreHeader& preHeader, PGFHeader& header,
104  PGFPostHeader& postHeader, UINT32*& levelLength, UINT64& userDataPos,
105  bool useOMP, bool skipUserData) THROW_; // throws IOException
106 
109  ~CDecoder();
110 
122  void Partition(CSubband* band, int quantParam, int width, int height, int startPos, int pitch) THROW_;
123 
131  void DecodeInterleaved(CWaveletTransform* wtChannel, int level, int quantParam) THROW_;
132 
137 
140  void SetStreamPosToStart() THROW_ { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos); }
141 
144  void SetStreamPosToData() THROW_ { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos + m_encodedHeaderLength); }
145 
149  void Skip(UINT64 offset) THROW_;
150 
157  void DequantizeValue(CSubband* band, UINT32 bandPos, int quantParam) THROW_;
158 
165  UINT32 ReadEncodedData(UINT8* target, UINT32 len) const THROW_;
166 
170  void DecodeBuffer() THROW_;
171 
175 
178  bool MacroBlocksAvailable() const { return m_macroBlocksAvailable > 1; }
179 
180 #ifdef __PGFROISUPPORT__
181 
182 
183 
184  void DecodeTileBuffer() THROW_;
185 
189  void SkipTileBuffer() THROW_;
190 
193  void SetROI() { m_roi = true; }
194 #endif
195 
196 #ifdef TRACE
197  void DumpBuffer();
198 #endif
199 
200 private:
201  void ReadMacroBlock(CMacroBlock* block) THROW_;
202 
204  UINT64 m_startPos;
207 
213 
214 #ifdef __PGFROISUPPORT__
215  bool m_roi;
216 #endif
217 };
218 
219 #endif //PGF_DECODER_H