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
46class CDecoder {
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)
63 {
64 }
65
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
92public:
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__
185 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
201private:
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
#define CodeBufferLen
number of words in code buffer (CodeBufferLen > BufferLen)
Definition: Decoder.h:40
PGF stream class.
#define BufferSize
must be a multiple of WordWidth
Definition: PGFtypes.h:77
INT32 DataT
Definition: PGFtypes.h:219
PGF wavelet subband class.
PGF wavelet transform class.
A macro block is a decoding unit of fixed size (uncoded)
Definition: Decoder.h:51
bool IsCompletelyRead() const
Definition: Decoder.h:69
ROIBlockHeader m_header
block header
Definition: Decoder.h:77
UINT32 m_valuePos
current position in m_value
Definition: Decoder.h:80
void SetBitAtPos(UINT32 pos, DataT planeMask)
Definition: Decoder.h:86
UINT32 ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32 *sigBits, UINT32 *refBits, UINT32 *signBits)
Definition: Decoder.cpp:735
DataT m_value[BufferSize]
output buffer of values with index m_valuePos
Definition: Decoder.h:78
void SetSign(UINT32 pos, bool sign)
Definition: Decoder.h:87
UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32 sigPos, UINT32 *refBits)
Definition: Decoder.cpp:798
UINT32 m_codeBuffer[CodeBufferLen]
input buffer for encoded bitstream
Definition: Decoder.h:79
bool m_sigFlagVector[BufferSize+1]
Definition: Decoder.h:89
PGF decoder.
Definition: Decoder.h:46
void SetStreamPosToData() THROW_
Reset stream position to beginning of data block.
Definition: Decoder.h:145
int m_macroBlockLen
array length
Definition: Decoder.h:211
int m_currentBlockIndex
index of current macro block
Definition: Decoder.h:210
void SetStreamPosToStart() THROW_
Reset stream position to beginning of PGF pre-header.
Definition: Decoder.h:141
CPGFStream * m_stream
input PGF stream
Definition: Decoder.h:204
UINT32 GetEncodedHeaderLength() const
Definition: Decoder.h:137
int m_macroBlocksAvailable
number of decoded macro blocks (including currently used macro block)
Definition: Decoder.h:212
void DecodeInterleaved(CWaveletTransform *wtChannel, int level, int quantParam) THROW_
Definition: Decoder.cpp:319
UINT64 m_startPos
stream position at the beginning of the PGF pre-header
Definition: Decoder.h:205
void ReadMacroBlock(CMacroBlock *block) THROW_
throws IOException
Definition: Decoder.cpp:521
UINT64 m_streamSizeEstimation
estimation of stream size
Definition: Decoder.h:206
void DecodeBuffer() THROW_
Definition: Decoder.cpp:480
CMacroBlock ** m_macroBlocks
array of macroblocks
Definition: Decoder.h:209
UINT32 ReadEncodedData(UINT8 *target, UINT32 len) const THROW_
Definition: Decoder.cpp:232
CMacroBlock * m_currentBlock
current macro block (used by main thread)
Definition: Decoder.h:213
UINT32 m_encodedHeaderLength
stream offset from startPos to the beginning of the data part (highest level)
Definition: Decoder.h:207
void Partition(CSubband *band, int quantParam, int width, int height, int startPos, int pitch) THROW_
Definition: Decoder.cpp:252
void Skip(UINT64 offset) THROW_
Definition: Decoder.cpp:435
CPGFStream * GetStream()
Definition: Decoder.h:175
bool MacroBlocksAvailable() const
Definition: Decoder.h:179
~CDecoder()
Destructor.
Definition: Decoder.cpp:217
CDecoder(CPGFStream *stream, PGFPreHeader &preHeader, PGFHeader &header, PGFPostHeader &postHeader, UINT32 *&levelLength, UINT64 &userDataPos, bool useOMP, bool skipUserData) THROW_
Definition: Decoder.cpp:73
void DequantizeValue(CSubband *band, UINT32 bandPos, int quantParam) THROW_
Definition: Decoder.cpp:448
Abstract stream base class.
Definition: PGFstream.h:39
virtual void SetPos(short posMode, INT64 posOff)=0
Wavelet channel class.
Definition: Subband.h:42
PGF wavelet transform.
PGF header.
Definition: PGFtypes.h:123
Optional PGF post-header.
Definition: PGFtypes.h:141
PGF pre-header.
Definition: PGFtypes.h:114
UINT16 bufferSize
number of uncoded UINT32 values in a block
Definition: PGFtypes.h:167
Block header used with ROI coding scheme
Definition: PGFtypes.h:151
struct ROIBlockHeader::RBH rbh
ROI block header.