libpgf: Decoder.h Source File

| libpgf 7.21.2 PGF - Progressive Graphics File

Loading...
Searching...
No Matches
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
46 class CDecoder {
51 class CMacroBlock {
52 public:
55 CMacroBlock()
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
76 ROIBlockHeader m_header;
77 DataT m_value[BufferSize];
78 UINT32 m_codeBuffer[CodeBufferLen];
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
91public:
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
136 UINT32 GetEncodedHeaderLength() const { return m_encodedHeaderLength; }
137
140 void SetStreamPosToStart() { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos); }
141
144 void SetStreamPosToData() { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos + m_encodedHeaderLength); }
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
174 CPGFStream* GetStream() { return m_stream; }
175
179 void GetNextMacroBlock();
180
181#ifdef __PGFROISUPPORT__
186 void SkipTileBuffer();
187
190 void SetROI() { m_roi = true; }
191#endif
192
193#ifdef TRACE
194 void DumpBuffer();
195#endif
196
197private:
198 void ReadMacroBlock(CMacroBlock* block);
199
200 CPGFStream *m_stream;
201 UINT64 m_startPos;
202 UINT64 m_streamSizeEstimation;
203 UINT32 m_encodedHeaderLength;
204
205 CMacroBlock **m_macroBlocks;
206 int m_currentBlockIndex;
207 int m_macroBlockLen;
208 int m_macroBlocksAvailable;
209 CMacroBlock *m_currentBlock;
210
211#ifdef __PGFROISUPPORT__
212 bool m_roi;
213#endif
214};
215
216#endif //PGF_DECODER_H
BitStream.h
CodeBufferLen
#define CodeBufferLen
number of words in code buffer (CodeBufferLen > BufferLen)
Definition Decoder.h:40
PGFstream.h
PGF stream class.
BufferSize
#define BufferSize
must be a multiple of WordWidth, BufferSize <= UINT16_MAX
Definition PGFtypes.h:84
DataT
INT32 DataT
Definition PGFtypes.h:269
Subband.h
PGF wavelet subband class.
WaveletTransform.h
PGF wavelet transform class.
CDecoder::CMacroBlock
A macro block is a decoding unit of fixed size (uncoded).
Definition Decoder.h:51
CDecoder::CMacroBlock::IsCompletelyRead
bool IsCompletelyRead() const
Definition Decoder.h:68
CDecoder::CMacroBlock::m_header
ROIBlockHeader m_header
block header
Definition Decoder.h:76
CDecoder::CMacroBlock::m_valuePos
UINT32 m_valuePos
current position in m_value
Definition Decoder.h:79
CDecoder::CMacroBlock::SetBitAtPos
void SetBitAtPos(UINT32 pos, DataT planeMask)
Definition Decoder.h:85
CDecoder::CMacroBlock::ComposeBitplane
UINT32 ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32 *sigBits, UINT32 *refBits, UINT32 *signBits)
Definition Decoder.cpp:763
CDecoder::CMacroBlock::BitplaneDecode
void BitplaneDecode()
Definition Decoder.cpp:650
CDecoder::CMacroBlock::m_value
DataT m_value[BufferSize]
output buffer of values with index m_valuePos
Definition Decoder.h:77
CDecoder::CMacroBlock::SetSign
void SetSign(UINT32 pos, bool sign)
Definition Decoder.h:86
CDecoder::CMacroBlock::ComposeBitplaneRLD
UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32 sigPos, UINT32 *refBits)
Definition Decoder.cpp:824
CDecoder::CMacroBlock::CMacroBlock
CMacroBlock()
Constructor: Initializes new macro block.
Definition Decoder.h:55
CDecoder::CMacroBlock::m_codeBuffer
UINT32 m_codeBuffer[CodeBufferLen]
input buffer for encoded bitstream
Definition Decoder.h:78
CDecoder::CMacroBlock::m_sigFlagVector
bool m_sigFlagVector[BufferSize+1]
Definition Decoder.h:88
CDecoder::m_macroBlockLen
int m_macroBlockLen
array length
Definition Decoder.h:207
CDecoder::m_currentBlockIndex
int m_currentBlockIndex
index of current macro block
Definition Decoder.h:206
CDecoder::ReadEncodedData
UINT32 ReadEncodedData(UINT8 *target, UINT32 len) const
Definition Decoder.cpp:246
CDecoder::m_stream
CPGFStream * m_stream
input PGF stream
Definition Decoder.h:200
CDecoder::GetEncodedHeaderLength
UINT32 GetEncodedHeaderLength() const
Definition Decoder.h:136
CDecoder::m_macroBlocksAvailable
int m_macroBlocksAvailable
number of decoded macro blocks (including currently used macro block)
Definition Decoder.h:208
CDecoder::ReadMacroBlock
void ReadMacroBlock(CMacroBlock *block)
throws IOException
Definition Decoder.cpp:535
CDecoder::m_startPos
UINT64 m_startPos
stream position at the beginning of the PGF pre-header
Definition Decoder.h:201
CDecoder::Partition
void Partition(CSubband *band, int quantParam, int width, int height, int startPos, int pitch)
Definition Decoder.cpp:266
CDecoder::m_streamSizeEstimation
UINT64 m_streamSizeEstimation
estimation of stream size
Definition Decoder.h:202
CDecoder::DecodeInterleaved
void DecodeInterleaved(CWaveletTransform *wtChannel, int level, int quantParam)
Definition Decoder.cpp:333
CDecoder::DecodeBuffer
void DecodeBuffer()
Definition Decoder.cpp:494
CDecoder::m_macroBlocks
CMacroBlock ** m_macroBlocks
array of macroblocks
Definition Decoder.h:205
CDecoder::m_currentBlock
CMacroBlock * m_currentBlock
current macro block (used by main thread)
Definition Decoder.h:209
CDecoder::m_encodedHeaderLength
UINT32 m_encodedHeaderLength
stream offset from startPos to the beginning of the data part (highest level)
Definition Decoder.h:203
CDecoder::SetStreamPosToStart
void SetStreamPosToStart()
Resets stream position to beginning of PGF pre-header.
Definition Decoder.h:140
CDecoder::GetStream
CPGFStream * GetStream()
Definition Decoder.h:174
CDecoder::~CDecoder
~CDecoder()
Destructor.
Definition Decoder.cpp:231
CDecoder::Skip
void Skip(UINT64 offset)
Definition Decoder.cpp:449
CDecoder::CDecoder
CDecoder(CPGFStream *stream, PGFPreHeader &preHeader, PGFHeader &header, PGFPostHeader &postHeader, UINT32 *&levelLength, UINT64 &userDataPos, bool useOMP, UINT32 userDataPolicy)
Definition Decoder.cpp:73
CDecoder::DequantizeValue
void DequantizeValue(CSubband *band, UINT32 bandPos, int quantParam)
Definition Decoder.cpp:462
CDecoder::GetNextMacroBlock
void GetNextMacroBlock()
Definition Decoder.cpp:477
CDecoder::SetStreamPosToData
void SetStreamPosToData()
Resets stream position to beginning of data block.
Definition Decoder.h:144
CPGFStream
Abstract stream base class.
Definition PGFstream.h:39
CSubband
Wavelet channel class.
Definition Subband.h:42
CWaveletTransform
PGF wavelet transform.
Definition WaveletTransform.h:55
PGFHeader
PGF header.
Definition PGFtypes.h:151
PGFPostHeader
Optional PGF post-header.
Definition PGFtypes.h:169
PGFPreHeader
PGF pre-header.
Definition PGFtypes.h:123
ROIBlockHeader
Block header used with ROI coding scheme.
Definition PGFtypes.h:180