00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00028
00029 #ifndef PGF_DECODER_H
00030 #define PGF_DECODER_H
00031
00032 #include "PGFstream.h"
00033 #include "BitStream.h"
00034 #include "Subband.h"
00035 #include "WaveletTransform.h"
00036
00038
00039 #define BufferLen (BufferSize/WordWidth)
00040 #define CodeBufferLen BufferSize
00041
00046 class CDecoder {
00051 class CMacroBlock {
00052 public:
00056 CMacroBlock()
00057 : m_header(0)
00058 #pragma warning( suppress : 4351 )
00059 , m_value()
00060 , m_codeBuffer()
00061 , m_valuePos(0)
00062 , m_sigFlagVector()
00063 {
00064 }
00065
00069 bool IsCompletelyRead() const { return m_valuePos >= m_header.rbh.bufferSize; }
00070
00075 void BitplaneDecode();
00076
00077 ROIBlockHeader m_header;
00078 DataT m_value[BufferSize];
00079 UINT32 m_codeBuffer[CodeBufferLen];
00080 UINT32 m_valuePos;
00081
00082 private:
00083 UINT32 ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32* signBits);
00084 UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32 sigPos, UINT32* refBits);
00085 UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32 signPos);
00086 void SetBitAtPos(UINT32 pos, DataT planeMask) { (m_value[pos] >= 0) ? m_value[pos] |= planeMask : m_value[pos] -= planeMask; }
00087 void SetSign(UINT32 pos, bool sign) { m_value[pos] = -m_value[pos]*sign + m_value[pos]*(!sign); }
00088
00089 bool m_sigFlagVector[BufferSize+1];
00090 };
00091
00092 public:
00104 CDecoder(CPGFStream* stream, PGFPreHeader& preHeader, PGFHeader& header,
00105 PGFPostHeader& postHeader, UINT32*& levelLength, UINT64& userDataPos,
00106 bool useOMP, bool skipUserData) THROW_;
00107
00110 ~CDecoder();
00111
00123 void Partition(CSubband* band, int quantParam, int width, int height, int startPos, int pitch) THROW_;
00124
00132 void DecodeInterleaved(CWaveletTransform* wtChannel, int level, int quantParam) THROW_;
00133
00137 UINT32 GetEncodedHeaderLength() const { return m_encodedHeaderLength; }
00138
00141 void SetStreamPosToStart() THROW_ { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos); }
00142
00145 void SetStreamPosToData() THROW_ { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos + m_encodedHeaderLength); }
00146
00150 void Skip(UINT64 offset) THROW_;
00151
00158 void DequantizeValue(CSubband* band, UINT32 bandPos, int quantParam) THROW_;
00159
00166 UINT32 ReadEncodedData(UINT8* target, UINT32 len) const THROW_;
00167
00171 void DecodeBuffer() THROW_;
00172
00175 CPGFStream* GetStream() { return m_stream; }
00176
00179 bool MacroBlocksAvailable() const { return m_macroBlocksAvailable > 1; }
00180
00181 #ifdef __PGFROISUPPORT__
00185 void DecodeTileBuffer() THROW_;
00186
00190 void SkipTileBuffer() THROW_;
00191
00194 void SetROI() { m_roi = true; }
00195 #endif
00196
00197 #ifdef TRACE
00198 void DumpBuffer();
00199 #endif
00200
00201 private:
00202 void ReadMacroBlock(CMacroBlock* block) THROW_;
00203
00204 CPGFStream *m_stream;
00205 UINT64 m_startPos;
00206 UINT64 m_streamSizeEstimation;
00207 UINT32 m_encodedHeaderLength;
00208
00209 CMacroBlock **m_macroBlocks;
00210 int m_currentBlockIndex;
00211 int m_macroBlockLen;
00212 int m_macroBlocksAvailable;
00213 CMacroBlock *m_currentBlock;
00214
00215 #ifdef __PGFROISUPPORT__
00216 bool m_roi;
00217 #endif
00218 };
00219
00220 #endif //PGF_DECODER_H