libpgf
6.11.42
PGF - Progressive Graphics File
|
00001 /* 00002 * The Progressive Graphics File; http://www.libpgf.org 00003 * 00004 * $Date: 2006-06-04 22:05:59 +0200 (So, 04 Jun 2006) $ 00005 * $Revision: 229 $ 00006 * 00007 * This file Copyright (C) 2006 xeraina GmbH, Switzerland 00008 * 00009 * This program is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE 00011 * as published by the Free Software Foundation; either version 2.1 00012 * of the License, or (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 // Constants 00039 #define BufferLen (BufferSize/WordWidth) ///< number of words per buffer 00040 00045 class CDecoder { 00050 class CMacroBlock { 00051 public: 00055 CMacroBlock(CDecoder *decoder) 00056 : m_header(0) // makes sure that IsCompletelyRead() returns true for an empty macro block 00057 , m_valuePos(0) 00058 , m_decoder(decoder) 00059 { 00060 ASSERT(m_decoder); 00061 } 00062 00066 bool IsCompletelyRead() const { return m_valuePos >= m_header.rbh.bufferSize; } 00067 00072 void BitplaneDecode(); 00073 00074 ROIBlockHeader m_header; 00075 DataT m_value[BufferSize]; 00076 UINT32 m_codeBuffer[BufferSize]; 00077 UINT32 m_valuePos; 00078 00079 private: 00080 UINT32 ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32* signBits); 00081 UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32 sigPos, UINT32* refBits); 00082 UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32 signPos); 00083 void SetBitAtPos(UINT32 pos, DataT planeMask) { (m_value[pos] >= 0) ? m_value[pos] |= planeMask : m_value[pos] -= planeMask; } 00084 void SetSign(UINT32 pos, bool sign) { m_value[pos] = -m_value[pos]*sign + m_value[pos]*(!sign); } 00085 00086 CDecoder *m_decoder; // outer class 00087 bool m_sigFlagVector[BufferSize+1]; // see paper from Malvar, Fast Progressive Wavelet Coder 00088 }; 00089 00090 public: 00100 CDecoder(CPGFStream* stream, PGFPreHeader& preHeader, PGFHeader& header, PGFPostHeader& postHeader, UINT32*& levelLength, bool useOMP = true) THROW_; // throws IOException 00101 00104 ~CDecoder(); 00105 00117 void Partition(CSubband* band, int quantParam, int width, int height, int startPos, int pitch) THROW_; 00118 00126 void DecodeInterleaved(CWaveletTransform* wtChannel, int level, int quantParam) THROW_; 00127 00131 UINT32 GetEncodedHeaderLength() const { return m_encodedHeaderLength; } 00132 00135 void SetStreamPosToStart() THROW_ { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos); } 00136 00139 void SetStreamPosToData() THROW_ { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos + m_encodedHeaderLength); } 00140 00144 void Skip(UINT64 offset) THROW_; 00145 00152 void DequantizeValue(CSubband* band, UINT32 bandPos, int quantParam) THROW_; 00153 00160 UINT32 ReadEncodedData(UINT8* target, UINT32 len) const THROW_; 00161 00165 void DecodeBuffer() THROW_; 00166 00167 #ifdef __PGFROISUPPORT__ 00168 00169 00170 00171 void DecodeTileBuffer() THROW_; 00172 00176 void SkipTileBuffer() THROW_; 00177 00180 void SetROI() { m_roi = true; } 00181 #endif 00182 00183 #ifdef TRACE 00184 void DumpBuffer(); 00185 #endif 00186 00187 private: 00188 void ReadMacroBlock(CMacroBlock* block) THROW_; 00189 00190 CPGFStream *m_stream; 00191 UINT64 m_startPos; 00192 UINT64 m_streamSizeEstimation; 00193 UINT32 m_encodedHeaderLength; 00194 00195 CMacroBlock **m_macroBlocks; 00196 int m_currentBlockIndex; 00197 int m_macroBlockLen; 00198 int m_macroBlocksAvailable; 00199 CMacroBlock *m_currentBlock; 00200 00201 #ifdef __PGFROISUPPORT__ 00202 bool m_roi; 00203 #endif 00204 }; 00205 00206 #endif //PGF_DECODER_H