libpgf  6.14.12
PGF - Progressive Graphics File
Decoder.h
Go to the documentation of this 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 #define CodeBufferLen           BufferSize                              ///< number of words in code buffer (CodeBufferLen > BufferLen)
00041 
00046 class CDecoder {
00051         class CMacroBlock {
00052         public:
00056                 CMacroBlock()
00057                 : m_header(0)                                                           // makes sure that IsCompletelyRead() returns true for an empty macro block
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];                     // see paper from Malvar, Fast Progressive Wavelet Coder
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_; // throws IOException
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__
00182 
00183 
00184 
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
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines