Scribus
Open source desktop publishing at your fingertips
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 
42 class CDecoder {
51  class CMacroBlock {
52  public:
56  CMacroBlock()
57  : m_header(0) // makes sure that IsCompletelyRead() returns true for an empty macro block
58 #if defined(WIN32) || defined(WINCE) || defined(WIN64)
59 #pragma warning( suppress : 4351 )
60 #endif
61  , m_value()
62  , m_codeBuffer()
63  , m_valuePos(0)
64  , m_sigFlagVector()
65  {
66  }
67 
71  bool IsCompletelyRead() const { return m_valuePos >= m_header.rbh.bufferSize; }
72 
77  void BitplaneDecode();
78 
79  ROIBlockHeader m_header;
80  DataT m_value[BufferSize];
81  UINT32 m_codeBuffer[CodeBufferLen];
82  UINT32 m_valuePos;
83 
84  private:
85  UINT32 ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32* signBits);
86  UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32 sigPos, UINT32* refBits);
87  UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32* sigBits, UINT32* refBits, UINT32 signPos);
88  void SetBitAtPos(UINT32 pos, DataT planeMask) { (m_value[pos] >= 0) ? m_value[pos] |= planeMask : m_value[pos] -= planeMask; }
89  void SetSign(UINT32 pos, bool sign) { m_value[pos] = -m_value[pos]*sign + m_value[pos]*(!sign); }
90 
91  bool m_sigFlagVector[BufferSize+1]; // see paper from Malvar, Fast Progressive Wavelet Coder
92  };
93 
94 public:
106  CDecoder(CPGFStream* stream, PGFPreHeader& preHeader, PGFHeader& header,
107  PGFPostHeader& postHeader, UINT32*& levelLength, UINT64& userDataPos,
108  bool useOMP, bool skipUserData) THROW_; // throws IOException
109 
112  ~CDecoder();
113 
125  void Partition(CSubband* band, int quantParam, int width, int height, int startPos, int pitch) THROW_;
126 
134  void DecodeInterleaved(CWaveletTransform* wtChannel, int level, int quantParam) THROW_;
135 
139  UINT32 GetEncodedHeaderLength() const { return m_encodedHeaderLength; }
140 
143  void SetStreamPosToStart() THROW_ { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos); }
144 
147  void SetStreamPosToData() THROW_ { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPos + m_encodedHeaderLength); }
148 
152  void Skip(UINT64 offset) THROW_;
153 
160  void DequantizeValue(CSubband* band, UINT32 bandPos, int quantParam) THROW_;
161 
168  UINT32 ReadEncodedData(UINT8* target, UINT32 len) const THROW_;
169 
173  void DecodeBuffer() THROW_;
174 
177  CPGFStream* GetStream() { return m_stream; }
178 
181  bool MacroBlocksAvailable() const { return m_macroBlocksAvailable > 1; }
182 
183 #ifdef __PGFROISUPPORT__
184  void DecodeTileBuffer() THROW_;
188 
192  void SkipTileBuffer() THROW_;
193 
196  void SetROI() { m_roi = true; }
197 #endif
198 
199 #ifdef TRACE
200  void DumpBuffer();
201 #endif
202 
203 private:
204  void ReadMacroBlock(CMacroBlock* block) THROW_;
205 
206  CPGFStream *m_stream;
207  UINT64 m_startPos;
208  UINT64 m_streamSizeEstimation;
209  UINT32 m_encodedHeaderLength;
210 
211  CMacroBlock **m_macroBlocks;
212  int m_currentBlockIndex;
213  int m_macroBlockLen;
214  int m_macroBlocksAvailable;
215  CMacroBlock *m_currentBlock;
216 
217 #ifdef __PGFROISUPPORT__
218  bool m_roi;
219 #endif
220 };
221 
222 #endif //PGF_DECODER_H
PGF decoder.
Definition: Decoder.h:46
PGF stream class.
~CDecoder()
Destructor.
Definition: Decoder.cpp:216
virtual void SetPos(short posMode, INT64 posOff)=0
void DequantizeValue(CSubband *band, UINT32 bandPos, int quantParam) THROW_
Definition: Decoder.cpp:447
#define BufferSize
must be a multiple of WordWidth
Definition: PGFtypes.h:77
PGF wavelet transform.
Definition: WaveletTransform.h:84
Abstract stream base class.
Definition: PGFstream.h:39
PGF wavelet transform class.
CDecoder(CPGFStream *stream, PGFPreHeader &preHeader, PGFHeader &header, PGFPostHeader &postHeader, UINT32 *&levelLength, UINT64 &userDataPos, bool useOMP, bool skipUserData) THROW_
Definition: Decoder.cpp:73
bool MacroBlocksAvailable() const
Definition: Decoder.h:181
UINT32 GetEncodedHeaderLength() const
Definition: Decoder.h:139
PGF header.
Definition: PGFtypes.h:123
void SkipTileBuffer() THROW_
Definition: Decoder.cpp:578
Wavelet channel class.
Definition: Subband.h:42
void Skip(UINT64 offset) THROW_
Definition: Decoder.cpp:434
void SetStreamPosToData() THROW_
Reset stream position to beginning of data block.
Definition: Decoder.h:147
Block header used with ROI coding scheme.
Definition: PGFtypes.h:151
void DecodeTileBuffer() THROW_
Definition: Decoder.cpp:462
void SetStreamPosToStart() THROW_
Reset stream position to beginning of PGF pre-header.
Definition: Decoder.h:143
PGF wavelet subband class.
void DecodeBuffer() THROW_
Definition: Decoder.cpp:479
void DecodeInterleaved(CWaveletTransform *wtChannel, int level, int quantParam) THROW_
Definition: Decoder.cpp:318
PGF bit-stream operations.
void Partition(CSubband *band, int quantParam, int width, int height, int startPos, int pitch) THROW_
Definition: Decoder.cpp:251
PGF pre-header.
Definition: PGFtypes.h:114
Optional PGF post-header.
Definition: PGFtypes.h:141
#define CodeBufferLen
number of words in code buffer (CodeBufferLen > BufferLen)
Definition: Decoder.h:40
CPGFStream * GetStream()
Definition: Decoder.h:177
UINT32 ReadEncodedData(UINT8 *target, UINT32 len) const THROW_
Definition: Decoder.cpp:231
void SetROI()
Enables region of interest (ROI) status.
Definition: Decoder.h:196