libpgf  7.15.32
PGF - Progressive Graphics File
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 class CDecoder {
51  class CMacroBlock {
52  public:
56  : m_header(0) // makes sure that IsCompletelyRead() returns true for an empty macro block
57 #pragma warning( suppress : 4351 )
58  , m_value()
59  , m_codeBuffer()
60  , m_valuePos(0)
61  , m_sigFlagVector()
62  {
63  }
64 
68  bool IsCompletelyRead() const { return m_valuePos >= m_header.rbh.bufferSize; }
69 
74  void BitplaneDecode();
75 
79  UINT32 m_valuePos;
80 
81  private:
82  UINT32 ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32* signBits);
83  UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32 sigPos, UINT32* refBits);
84  UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32 signPos);
85  void SetBitAtPos(UINT32 pos, DataT planeMask) { (m_value[pos] >= 0) ? m_value[pos] |= planeMask : m_value[pos] -= planeMask; }
86  void SetSign(UINT32 pos, bool sign) { m_value[pos] = -m_value[pos]*sign + m_value[pos]*(!sign); }
87 
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, UINT32 userDataPolicy); // throws IOException
106 
109  ~CDecoder();
110 
122  void Partition(CSubband* band, int quantParam, int width, int height, int startPos, int pitch);
123 
131  void DecodeInterleaved(CWaveletTransform* wtChannel, int level, int quantParam);
132 
137 
140  void SetStreamPosToStart() { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos); }
141 
145 
149  void Skip(UINT64 offset);
150 
157  void DequantizeValue(CSubband* band, UINT32 bandPos, int quantParam);
158 
165  UINT32 ReadEncodedData(UINT8* target, UINT32 len) const;
166 
170  void DecodeBuffer();
171 
175 
179  void GetNextMacroBlock();
180 
181 #ifdef __PGFROISUPPORT__
182  void SkipTileBuffer();
187 
190  void SetROI() { m_roi = true; }
191 #endif
192 
193 #ifdef TRACE
194  void DumpBuffer();
195 #endif
196 
197 private:
198  void ReadMacroBlock(CMacroBlock* block);
199 
201  UINT64 m_startPos;
204 
210 
211 #ifdef __PGFROISUPPORT__
212  bool m_roi;
213 #endif
214 };
215 
216 #endif //PGF_DECODER_H
struct ROIBlockHeader::RBH rbh
ROI block header.
UINT16 bufferSize
number of uncoded UINT32 values in a block
Definition: PGFtypes.h:195
UINT32 ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32 *sigBits, UINT32 *refBits, UINT32 *signBits)
Definition: Decoder.cpp:763
CMacroBlock ** m_macroBlocks
array of macroblocks
Definition: Decoder.h:205
Abstract stream base class.
Definition: PGFstream.h:39
INT32 DataT
Definition: PGFtypes.h:262
void SetBitAtPos(UINT32 pos, DataT planeMask)
Definition: Decoder.h:85
UINT32 m_valuePos
current position in m_value
Definition: Decoder.h:79
void DecodeInterleaved(CWaveletTransform *wtChannel, int level, int quantParam)
Definition: Decoder.cpp:333
#define BufferSize
must be a multiple of WordWidth, BufferSize <= UINT16_MAX
Definition: PGFtypes.h:84
CPGFStream * GetStream()
Definition: Decoder.h:174
~CDecoder()
Destructor.
Definition: Decoder.cpp:231
virtual void SetPos(short posMode, INT64 posOff)=0
void SetStreamPosToData()
Resets stream position to beginning of data block.
Definition: Decoder.h:144
UINT32 GetEncodedHeaderLength() const
Definition: Decoder.h:136
PGF pre-header.
Definition: PGFtypes.h:123
PGF wavelet subband class.
UINT32 m_encodedHeaderLength
stream offset from startPos to the beginning of the data part (highest level)
Definition: Decoder.h:203
Wavelet channel class.
Definition: Subband.h:42
void DecodeBuffer()
Definition: Decoder.cpp:494
int m_macroBlockLen
array length
Definition: Decoder.h:207
void Partition(CSubband *band, int quantParam, int width, int height, int startPos, int pitch)
Definition: Decoder.cpp:266
PGF wavelet transform.
DataT m_value[BufferSize]
output buffer of values with index m_valuePos
Definition: Decoder.h:77
void SetSign(UINT32 pos, bool sign)
Definition: Decoder.h:86
Block header used with ROI coding scheme.
Definition: PGFtypes.h:179
PGF header.
Definition: PGFtypes.h:150
int m_currentBlockIndex
index of current macro block
Definition: Decoder.h:206
CMacroBlock * m_currentBlock
current macro block (used by main thread)
Definition: Decoder.h:209
PGF decoder.
Definition: Decoder.h:46
bool IsCompletelyRead() const
Definition: Decoder.h:68
A macro block is a decoding unit of fixed size (uncoded)
Definition: Decoder.h:51
Optional PGF post-header.
Definition: PGFtypes.h:168
PGF wavelet transform class.
CPGFStream * m_stream
input PGF stream
Definition: Decoder.h:200
void Skip(UINT64 offset)
Definition: Decoder.cpp:449
int m_macroBlocksAvailable
number of decoded macro blocks (including currently used macro block)
Definition: Decoder.h:208
UINT64 m_startPos
stream position at the beginning of the PGF pre-header
Definition: Decoder.h:201
void GetNextMacroBlock()
Definition: Decoder.cpp:477
UINT32 ReadEncodedData(UINT8 *target, UINT32 len) const
Definition: Decoder.cpp:246
PGF stream class.
void ReadMacroBlock(CMacroBlock *block)
throws IOException
Definition: Decoder.cpp:535
CDecoder(CPGFStream *stream, PGFPreHeader &preHeader, PGFHeader &header, PGFPostHeader &postHeader, UINT32 *&levelLength, UINT64 &userDataPos, bool useOMP, UINT32 userDataPolicy)
Definition: Decoder.cpp:73
UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32 sigPos, UINT32 *refBits)
Definition: Decoder.cpp:824
CMacroBlock()
Constructor: Initializes new macro block.
Definition: Decoder.h:55
void DequantizeValue(CSubband *band, UINT32 bandPos, int quantParam)
Definition: Decoder.cpp:462
void SetStreamPosToStart()
Resets stream position to beginning of PGF pre-header.
Definition: Decoder.h:140
UINT64 m_streamSizeEstimation
estimation of stream size
Definition: Decoder.h:202
ROIBlockHeader m_header
block header
Definition: Decoder.h:76
#define CodeBufferLen
number of words in code buffer (CodeBufferLen > BufferLen)
Definition: Decoder.h:40
bool m_sigFlagVector[BufferSize+1]
Definition: Decoder.h:88
UINT32 m_codeBuffer[CodeBufferLen]
input buffer for encoded bitstream
Definition: Decoder.h:78