libpgf: Encoder.h Source File

| libpgf 7.21.2 PGF - Progressive Graphics File

Loading...
Searching...
No Matches
Encoder.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_ENCODER_H
30#define PGF_ENCODER_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 CEncoder {
51 class CMacroBlock {
52 public:
56 CMacroBlock(CEncoder *encoder)
57#pragma warning( suppress : 4351 )
58 : m_value()
59 , m_codeBuffer()
60 , m_header(0)
61 , m_encoder(encoder)
62 , m_sigFlagVector()
63 {
64 ASSERT(m_encoder);
65 Init(-1);
66 }
67
71 void Init(int lastLevelIndex) { // initialize for reusage
72 m_valuePos = 0;
73 m_maxAbsValue = 0;
74 m_codePos = 0;
75 m_lastLevelIndex = lastLevelIndex;
76 }
77
82 void BitplaneEncode();
83
84 DataT m_value[BufferSize];
85 UINT32 m_codeBuffer[CodeBufferLen];
86 ROIBlockHeader m_header;
87 UINT32 m_valuePos;
88 UINT32 m_maxAbsValue;
89 UINT32 m_codePos;
90 int m_lastLevelIndex;
91
92 private:
93 UINT32 RLESigns(UINT32 codePos, UINT32* signBits, UINT32 signLen);
94 UINT32 DecomposeBitplane(UINT32 bufferSize, UINT32 planeMask, UINT32 codePos, UINT32* sigBits, UINT32* refBits, UINT32* signBits, UINT32& signLen, UINT32& codeLen);
95 UINT8 NumberOfBitplanes();
96 bool GetBitAtPos(UINT32 pos, UINT32 planeMask) const { return (abs(m_value[pos]) & planeMask) > 0; }
97
98 CEncoder *m_encoder; // encoder instance
99 bool m_sigFlagVector[BufferSize+1]; // see paper from Malvar, Fast Progressive Wavelet Coder
100 };
101
102public:
112 CEncoder(CPGFStream* stream, PGFPreHeader preHeader, PGFHeader header, const PGFPostHeader& postHeader,
113 UINT64& userDataPos, bool useOMP); // throws IOException
114
117 ~CEncoder();
118
121 void FavorSpeedOverSize() { m_favorSpeed = true; }
122
126 void Flush();
127
132 void UpdatePostHeaderSize(PGFPreHeader preHeader);
133
139 UINT32 WriteLevelLength(UINT32*& levelLength);
140
145 UINT32 UpdateLevelLength();
146
157 void Partition(CSubband* band, int width, int height, int startPos, int pitch);
158
162 void SetEncodedLevel(int currentLevel) { ASSERT(currentLevel >= 0); m_currentBlock->m_lastLevelIndex = m_nLevels - currentLevel - 1; m_forceWriting = true; }
163
169 void WriteValue(CSubband* band, int bandPos);
170
174 INT64 ComputeHeaderLength() const { return m_levelLengthPos - m_startPosition; }
175
179 INT64 ComputeBufferLength() const { return m_stream->GetPos() - m_bufferStartPos; }
180
184 INT64 ComputeOffset() const { return m_stream->GetPos() - m_levelLengthPos; }
185
188 void SetStreamPosToStart() { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPosition); }
189
192 void SetBufferStartPos() { m_bufferStartPos = m_stream->GetPos(); }
193
194#ifdef __PGFROISUPPORT__
198 void EncodeTileBuffer() { ASSERT(m_currentBlock && m_currentBlock->m_valuePos >= 0 && m_currentBlock->m_valuePos <= BufferSize); EncodeBuffer(ROIBlockHeader(m_currentBlock->m_valuePos, true)); }
199
202 void SetROI() { m_roi = true; }
203#endif
204
205#ifdef TRACE
206 void DumpBuffer() const;
207#endif
208
209private:
210 void EncodeBuffer(ROIBlockHeader h); // throws IOException
211 void WriteMacroBlock(CMacroBlock* block); // throws IOException
212
213 CPGFStream *m_stream;
214 UINT64 m_startPosition;
215 UINT64 m_levelLengthPos;
216 UINT64 m_bufferStartPos;
217
218 CMacroBlock **m_macroBlocks;
219 int m_macroBlockLen;
220 int m_lastMacroBlock;
221 CMacroBlock *m_currentBlock;
222
223 UINT32* m_levelLength;
224 int m_currLevelIndex;
225 UINT8 m_nLevels;
226 bool m_favorSpeed;
227 bool m_forceWriting;
228#ifdef __PGFROISUPPORT__
229 bool m_roi;
230#endif
231};
232
233#endif //PGF_ENCODER
BitStream.h
CodeBufferLen
#define CodeBufferLen
number of words in code buffer (CodeBufferLen > BufferLen)
Definition Encoder.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.
CEncoder::CMacroBlock
A macro block is an encoding unit of fixed size (uncoded).
Definition Encoder.h:51
CEncoder::CMacroBlock::m_value
DataT m_value[BufferSize]
input buffer of values with index m_valuePos
Definition Encoder.h:84
CEncoder::CMacroBlock::NumberOfBitplanes
UINT8 NumberOfBitplanes()
Definition Encoder.cpp:750
CEncoder::CMacroBlock::DecomposeBitplane
UINT32 DecomposeBitplane(UINT32 bufferSize, UINT32 planeMask, UINT32 codePos, UINT32 *sigBits, UINT32 *refBits, UINT32 *signBits, UINT32 &signLen, UINT32 &codeLen)
Definition Encoder.cpp:634
CEncoder::CMacroBlock::RLESigns
UINT32 RLESigns(UINT32 codePos, UINT32 *signBits, UINT32 signLen)
Definition Encoder.cpp:774
CEncoder::CMacroBlock::m_codeBuffer
UINT32 m_codeBuffer[CodeBufferLen]
output buffer for encoded bitstream
Definition Encoder.h:85
CEncoder::CMacroBlock::m_lastLevelIndex
int m_lastLevelIndex
index of last encoded level: [0, nLevels); used because a level-end can occur before a buffer is full
Definition Encoder.h:90
CEncoder::CMacroBlock::m_codePos
UINT32 m_codePos
current position in encoded bitstream
Definition Encoder.h:89
CEncoder::CMacroBlock::CMacroBlock
CMacroBlock(CEncoder *encoder)
Definition Encoder.h:56
CEncoder::CMacroBlock::m_valuePos
UINT32 m_valuePos
current buffer position
Definition Encoder.h:87
CEncoder::CMacroBlock::m_sigFlagVector
bool m_sigFlagVector[BufferSize+1]
Definition Encoder.h:99
CEncoder::CMacroBlock::GetBitAtPos
bool GetBitAtPos(UINT32 pos, UINT32 planeMask) const
Definition Encoder.h:96
CEncoder::CMacroBlock::m_maxAbsValue
UINT32 m_maxAbsValue
maximum absolute coefficient in each buffer
Definition Encoder.h:88
CEncoder::CMacroBlock::m_header
ROIBlockHeader m_header
block header
Definition Encoder.h:86
CEncoder::CMacroBlock::m_encoder
CEncoder * m_encoder
Definition Encoder.h:98
CEncoder::CMacroBlock::Init
void Init(int lastLevelIndex)
Definition Encoder.h:71
CEncoder::CMacroBlock::BitplaneEncode
void BitplaneEncode()
Definition Encoder.cpp:482
CEncoder::SetBufferStartPos
void SetBufferStartPos()
Save current stream position as beginning of current level.
Definition Encoder.h:192
CEncoder::m_bufferStartPos
UINT64 m_bufferStartPos
stream position of encoded buffer
Definition Encoder.h:216
CEncoder::m_favorSpeed
bool m_favorSpeed
favor speed over size
Definition Encoder.h:226
CEncoder::Partition
void Partition(CSubband *band, int width, int height, int startPos, int pitch)
Definition Encoder.cpp:246
CEncoder::m_startPosition
UINT64 m_startPosition
stream position of PGF start (PreHeader)
Definition Encoder.h:214
CEncoder::ComputeBufferLength
INT64 ComputeBufferLength() const
Definition Encoder.h:179
CEncoder::EncodeBuffer
void EncodeBuffer(ROIBlockHeader h)
Definition Encoder.cpp:341
CEncoder::m_forceWriting
bool m_forceWriting
all macro blocks have to be written into the stream
Definition Encoder.h:227
CEncoder::m_levelLengthPos
UINT64 m_levelLengthPos
stream position of Metadata
Definition Encoder.h:215
CEncoder::m_currentBlock
CMacroBlock * m_currentBlock
current macro block (used by main thread)
Definition Encoder.h:221
CEncoder::WriteValue
void WriteValue(CSubband *band, int bandPos)
Definition Encoder.cpp:326
CEncoder::CEncoder
CEncoder(CPGFStream *stream, PGFPreHeader preHeader, PGFHeader header, const PGFPostHeader &postHeader, UINT64 &userDataPos, bool useOMP)
Definition Encoder.cpp:70
CEncoder::ComputeHeaderLength
INT64 ComputeHeaderLength() const
Definition Encoder.h:174
CEncoder::m_levelLength
UINT32 * m_levelLength
temporary saves the level index
Definition Encoder.h:223
CEncoder::m_macroBlocks
CMacroBlock ** m_macroBlocks
array of macroblocks
Definition Encoder.h:218
CEncoder::m_nLevels
UINT8 m_nLevels
number of levels
Definition Encoder.h:225
CEncoder::m_currLevelIndex
int m_currLevelIndex
counts where (=index) to save next value
Definition Encoder.h:224
CEncoder::ComputeOffset
INT64 ComputeOffset() const
Definition Encoder.h:184
CEncoder::Flush
void Flush()
Definition Encoder.cpp:310
CEncoder::UpdateLevelLength
UINT32 UpdateLevelLength()
Definition Encoder.cpp:202
CEncoder::FavorSpeedOverSize
void FavorSpeedOverSize()
Encoder favors speed over compression size.
Definition Encoder.h:121
CEncoder::~CEncoder
~CEncoder()
Destructor.
Definition Encoder.cpp:147
CEncoder::m_lastMacroBlock
int m_lastMacroBlock
array index of the last created macro block
Definition Encoder.h:220
CEncoder::WriteMacroBlock
void WriteMacroBlock(CMacroBlock *block)
Definition Encoder.cpp:406
CEncoder::SetEncodedLevel
void SetEncodedLevel(int currentLevel)
Definition Encoder.h:162
CEncoder::m_stream
CPGFStream * m_stream
output PMF stream
Definition Encoder.h:213
CEncoder::WriteLevelLength
UINT32 WriteLevelLength(UINT32 *&levelLength)
Definition Encoder.cpp:177
CEncoder::UpdatePostHeaderSize
void UpdatePostHeaderSize(PGFPreHeader preHeader)
Definition Encoder.cpp:160
CEncoder::SetStreamPosToStart
void SetStreamPosToStart()
Resets stream position to beginning of PGF pre-header.
Definition Encoder.h:188
CEncoder::m_macroBlockLen
int m_macroBlockLen
array length
Definition Encoder.h:219
CPGFStream
Abstract stream base class.
Definition PGFstream.h:39
CSubband
Wavelet channel class.
Definition Subband.h:42
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