libpgf  6.11.42
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 
41 
42 
43 
44 
45 class CDecoder {
50  class CMacroBlock {
51  public:
56  : m_header(0) // makes sure that IsCompletelyRead() returns true for an empty macro block
57  , m_valuePos(0)
58  , m_decoder(decoder)
59  {
60  ASSERT(m_decoder);
61  }
62 
66  bool IsCompletelyRead() const { return m_valuePos >= m_header.rbh.bufferSize; }
67 
72  void BitplaneDecode();
73 
77  UINT32 m_valuePos;
78 
79  private:
80  UINT32 ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32* signBits);
81  UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32 sigPos, UINT32* refBits);
82  UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32 signPos);
83  void SetBitAtPos(UINT32 pos, DataT planeMask) { (m_value[pos] >= 0) ? m_value[pos] |= planeMask : m_value[pos] -= planeMask; }
84  void SetSign(UINT32 pos, bool sign) { m_value[pos] = -m_value[pos]*sign + m_value[pos]*(!sign); }
85 
86  CDecoder *m_decoder; // outer class
87  bool m_sigFlagVector[BufferSize+1]; // see paper from Malvar, Fast Progressive Wavelet Coder
88  };
89 
90 public:
100  CDecoder(CPGFStream* stream, PGFPreHeader& preHeader, PGFHeader& header, PGFPostHeader& postHeader, UINT32*& levelLength, bool useOMP = true) THROW_; // throws IOException
101 
104  ~CDecoder();
105 
117  void Partition(CSubband* band, int quantParam, int width, int height, int startPos, int pitch) THROW_;
118 
126  void DecodeInterleaved(CWaveletTransform* wtChannel, int level, int quantParam) THROW_;
127 
132 
135  void SetStreamPosToStart() THROW_ { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos); }
136 
139  void SetStreamPosToData() THROW_ { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos + m_encodedHeaderLength); }
140 
144  void Skip(UINT64 offset) THROW_;
145 
152  void DequantizeValue(CSubband* band, UINT32 bandPos, int quantParam) THROW_;
153 
160  UINT32 ReadEncodedData(UINT8* target, UINT32 len) const THROW_;
161 
165  void DecodeBuffer() THROW_;
166 
167 #ifdef __PGFROISUPPORT__
168 
169 
170 
171  void DecodeTileBuffer() THROW_;
172 
176  void SkipTileBuffer() THROW_;
177 
180  void SetROI() { m_roi = true; }
181 #endif
182 
183 #ifdef TRACE
184  void DumpBuffer();
185 #endif
186 
187 private:
188  void ReadMacroBlock(CMacroBlock* block) THROW_;
189 
191  UINT64 m_startPos;
194 
200 
201 #ifdef __PGFROISUPPORT__
202  bool m_roi;
203 #endif
204 };
205 
206 #endif //PGF_DECODER_H