libpgf  6.14.12
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:
57  : m_header(0) // makes sure that IsCompletelyRead() returns true for an empty macro block
58 #pragma warning( suppress : 4351 )
59  , m_value()
60  , m_codeBuffer()
61  , m_valuePos(0)
62  , m_sigFlagVector()
63  {
64  }
65 
69  bool IsCompletelyRead() const { return m_valuePos >= m_header.rbh.bufferSize; }
70 
75  void BitplaneDecode();
76 
80  UINT32 m_valuePos;
81 
82  private:
83  UINT32 ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32* signBits);
84  UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32 sigPos, UINT32* refBits);
85  UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32 signPos);
86  void SetBitAtPos(UINT32 pos, DataT planeMask) { (m_value[pos] >= 0) ? m_value[pos] |= planeMask : m_value[pos] -= planeMask; }
87  void SetSign(UINT32 pos, bool sign) { m_value[pos] = -m_value[pos]*sign + m_value[pos]*(!sign); }
88 
89  bool m_sigFlagVector[BufferSize+1]; // see paper from Malvar, Fast Progressive Wavelet Coder
90  };
91 
92 public:
104  CDecoder(CPGFStream* stream, PGFPreHeader& preHeader, PGFHeader& header,
105  PGFPostHeader& postHeader, UINT32*& levelLength, UINT64& userDataPos,
106  bool useOMP, bool skipUserData) THROW_; // throws IOException
107 
110  ~CDecoder();
111 
123  void Partition(CSubband* band, int quantParam, int width, int height, int startPos, int pitch) THROW_;
124 
132  void DecodeInterleaved(CWaveletTransform* wtChannel, int level, int quantParam) THROW_;
133 
138 
141  void SetStreamPosToStart() THROW_ { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos); }
142 
145  void SetStreamPosToData() THROW_ { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos + m_encodedHeaderLength); }
146 
150  void Skip(UINT64 offset) THROW_;
151 
158  void DequantizeValue(CSubband* band, UINT32 bandPos, int quantParam) THROW_;
159 
166  UINT32 ReadEncodedData(UINT8* target, UINT32 len) const THROW_;
167 
171  void DecodeBuffer() THROW_;
172 
176 
179  bool MacroBlocksAvailable() const { return m_macroBlocksAvailable > 1; }
180 
181 #ifdef __PGFROISUPPORT__
182  void DecodeTileBuffer() THROW_;
186 
190  void SkipTileBuffer() THROW_;
191 
194  void SetROI() { m_roi = true; }
195 #endif
196 
197 #ifdef TRACE
198  void DumpBuffer();
199 #endif
200 
201 private:
202  void ReadMacroBlock(CMacroBlock* block) THROW_;
203 
205  UINT64 m_startPos;
208 
214 
215 #ifdef __PGFROISUPPORT__
216  bool m_roi;
217 #endif
218 };
219 
220 #endif //PGF_DECODER_H
ROIBlockHeader::RBH::bufferSize
UINT16 bufferSize
number of uncoded UINT32 values in a block
Definition: PGFtypes.h:167
CDecoder::DecodeBuffer
void DecodeBuffer() THROW_
Definition: Decoder.cpp:480
PGFPostHeader
Optional PGF post-header.
Definition: PGFtypes.h:141
WaveletTransform.h
PGF wavelet transform class.
CDecoder::ReadEncodedData
UINT32 ReadEncodedData(UINT8 *target, UINT32 len) const THROW_
Definition: Decoder.cpp:232
CDecoder::CMacroBlock::SetBitAtPos
void SetBitAtPos(UINT32 pos, DataT planeMask)
Definition: Decoder.h:86
CDecoder::CMacroBlock::m_codeBuffer
UINT32 m_codeBuffer[CodeBufferLen]
input buffer for encoded bitstream
Definition: Decoder.h:79
CDecoder::CMacroBlock::m_valuePos
UINT32 m_valuePos
current position in m_value
Definition: Decoder.h:80
CDecoder::CMacroBlock::ComposeBitplane
UINT32 ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32 *sigBits, UINT32 *refBits, UINT32 *signBits)
Definition: Decoder.cpp:735
CDecoder::DecodeInterleaved
void DecodeInterleaved(CWaveletTransform *wtChannel, int level, int quantParam) THROW_
Definition: Decoder.cpp:319
BufferSize
#define BufferSize
must be a multiple of WordWidth
Definition: PGFtypes.h:77
PGFHeader
PGF header.
Definition: PGFtypes.h:123
CDecoder::m_encodedHeaderLength
UINT32 m_encodedHeaderLength
stream offset from startPos to the beginning of the data part (highest level)
Definition: Decoder.h:207
CDecoder::CMacroBlock::m_value
DataT m_value[BufferSize]
output buffer of values with index m_valuePos
Definition: Decoder.h:78
CDecoder::Partition
void Partition(CSubband *band, int quantParam, int width, int height, int startPos, int pitch) THROW_
Definition: Decoder.cpp:252
CDecoder::DequantizeValue
void DequantizeValue(CSubband *band, UINT32 bandPos, int quantParam) THROW_
Definition: Decoder.cpp:448
CDecoder::ReadMacroBlock
void ReadMacroBlock(CMacroBlock *block) THROW_
throws IOException
Definition: Decoder.cpp:521
CDecoder::m_currentBlock
CMacroBlock * m_currentBlock
current macro block (used by main thread)
Definition: Decoder.h:213
ROIBlockHeader::rbh
struct ROIBlockHeader::RBH rbh
ROI block header.
BitStream.h
CDecoder::~CDecoder
~CDecoder()
Destructor.
Definition: Decoder.cpp:217
CDecoder::CMacroBlock::BitplaneDecode
void BitplaneDecode()
Definition: Decoder.cpp:620
DataT
INT32 DataT
Definition: PGFtypes.h:219
CDecoder::CMacroBlock::SetSign
void SetSign(UINT32 pos, bool sign)
Definition: Decoder.h:87
CDecoder::m_macroBlocks
CMacroBlock ** m_macroBlocks
array of macroblocks
Definition: Decoder.h:209
CDecoder::m_macroBlockLen
int m_macroBlockLen
array length
Definition: Decoder.h:211
CDecoder::m_macroBlocksAvailable
int m_macroBlocksAvailable
number of decoded macro blocks (including currently used macro block)
Definition: Decoder.h:212
Subband.h
PGF wavelet subband class.
CDecoder::CDecoder
CDecoder(CPGFStream *stream, PGFPreHeader &preHeader, PGFHeader &header, PGFPostHeader &postHeader, UINT32 *&levelLength, UINT64 &userDataPos, bool useOMP, bool skipUserData) THROW_
Definition: Decoder.cpp:73
CPGFStream::SetPos
virtual void SetPos(short posMode, INT64 posOff)=0
CWaveletTransform
PGF wavelet transform.
Definition: WaveletTransform.h:84
CDecoder::Skip
void Skip(UINT64 offset) THROW_
Definition: Decoder.cpp:435
CDecoder::CMacroBlock::IsCompletelyRead
bool IsCompletelyRead() const
Definition: Decoder.h:69
CDecoder::m_currentBlockIndex
int m_currentBlockIndex
index of current macro block
Definition: Decoder.h:210
PGFPreHeader
PGF pre-header.
Definition: PGFtypes.h:114
CDecoder::SetStreamPosToStart
void SetStreamPosToStart() THROW_
Reset stream position to beginning of PGF pre-header.
Definition: Decoder.h:141
CDecoder::m_startPos
UINT64 m_startPos
stream position at the beginning of the PGF pre-header
Definition: Decoder.h:205
CDecoder::CMacroBlock::m_sigFlagVector
bool m_sigFlagVector[BufferSize+1]
Definition: Decoder.h:89
CSubband
Wavelet channel class.
Definition: Subband.h:42
CDecoder::m_stream
CPGFStream * m_stream
input PGF stream
Definition: Decoder.h:204
CDecoder::CMacroBlock::CMacroBlock
CMacroBlock()
Definition: Decoder.h:56
CDecoder::CMacroBlock
A macro block is a decoding unit of fixed size (uncoded)
Definition: Decoder.h:51
CDecoder::GetStream
CPGFStream * GetStream()
Definition: Decoder.h:175
CDecoder::m_streamSizeEstimation
UINT64 m_streamSizeEstimation
estimation of stream size
Definition: Decoder.h:206
CodeBufferLen
#define CodeBufferLen
number of words in code buffer (CodeBufferLen > BufferLen)
Definition: Decoder.h:40
CDecoder
PGF decoder.
Definition: Decoder.h:46
CDecoder::SetStreamPosToData
void SetStreamPosToData() THROW_
Reset stream position to beginning of data block.
Definition: Decoder.h:145
CDecoder::MacroBlocksAvailable
bool MacroBlocksAvailable() const
Definition: Decoder.h:179
CDecoder::CMacroBlock::ComposeBitplaneRLD
UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32 sigPos, UINT32 *refBits)
Definition: Decoder.cpp:798
CPGFStream
Abstract stream base class.
Definition: PGFstream.h:39
ROIBlockHeader
Block header used with ROI coding scheme
Definition: PGFtypes.h:151
PGFstream.h
PGF stream class.
CDecoder::GetEncodedHeaderLength
UINT32 GetEncodedHeaderLength() const
Definition: Decoder.h:137
CDecoder::CMacroBlock::m_header
ROIBlockHeader m_header
block header
Definition: Decoder.h:77