libpgf 7.26.45
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#pragma once
30
31#include "PGFstream.h"
32#include "BitStream.h"
33#include "Subband.h"
34#include "WaveletTransform.h"
35
36namespace pgf {
41 class CEncoder {
47 public:
52#pragma warning( suppress : 4351 )
53 : m_value()
54 , m_codeBuffer()
55 , m_header(0)
56 , m_encoder(encoder)
58 {
59 ASSERT(m_encoder);
60 Init(-1);
61 }
62
66 void Init(int lastLevelIndex) { // initialize for reusage
67 m_valuePos = 0;
68 m_maxAbsValue = 0;
69 m_codePos = 0;
70 m_lastLevelIndex = lastLevelIndex;
71 }
72
77 void BitplaneEncode();
78
82 uint32_t m_valuePos;
83 uint32_t m_maxAbsValue;
84 uint32_t m_codePos;
86
87 private:
88 uint32_t RLESigns(uint32_t codePos, uint32_t* signBits, uint32_t signLen);
89 uint32_t DecomposeBitplane(uint32_t bufferSize, uint32_t planeMask, uint32_t codePos, uint32_t* sigBits, uint32_t* refBits, uint32_t* signBits, uint32_t& signLen, uint32_t& codeLen);
90 uint8_t NumberOfBitplanes();
91 bool GetBitAtPos(uint32_t pos, uint32_t planeMask) const { return (abs(m_value[pos]) & planeMask) > 0; }
92
93 CEncoder* m_encoder; // encoder instance
94 bool m_sigFlagVector[BufferSize+1]; // see paper from Malvar, Fast Progressive Wavelet Coder
95 };
96
97 public:
107 CEncoder(CPGFStream* stream, PGFPreHeader preHeader, PGFHeader header, const PGFPostHeader& postHeader,
108 uint64_t& userDataPos, bool useOMP); // throws IOException
109
112 ~CEncoder();
113
117
121 void Flush();
122
127 void UpdatePostHeaderSize(PGFPreHeader preHeader);
128
134 uint32_t WriteLevelLength(uint32_t*& levelLength);
135
140 uint32_t UpdateLevelLength();
141
152 void Partition(CSubband* band, int width, int height, int startPos, int pitch);
153
157 void SetEncodedLevel(int currentLevel) { ASSERT(currentLevel >= 0); m_currentBlock->m_lastLevelIndex = m_nLevels - currentLevel - 1; m_forceWriting = true; }
158
164 void WriteValue(CSubband* band, int bandPos);
165
170
174 int64_t ComputeBufferLength() const { return m_stream->GetPos() - m_bufferStartPos; }
175
179 int64_t ComputeOffset() const { return m_stream->GetPos() - m_levelLengthPos; }
180
183 void SetStreamPosToStart() { ASSERT(m_stream); m_stream->SetPos(FSFromStart, m_startPosition); }
184
188
189#ifdef __PGFROISUPPORT__
194
197 void SetROI() { m_roi = true; }
198#endif
199
200#ifdef TRACE
201 void DumpBuffer() const;
202#endif
203
204 private:
205 void EncodeBuffer(ROIBlockHeader h); // throws IOException
206 void WriteMacroBlock(CMacroBlock* block); // throws IOException
207
212
217
218 uint32_t* m_levelLength;
220 uint8_t m_nLevels;
223#ifdef __PGFROISUPPORT__
224 bool m_roi;
225#endif
226 };
227}
PGF stream class.
PGF wavelet subband class.
PGF wavelet transform class.
A macro block is an encoding unit of fixed size (uncoded).
Definition Encoder.h:46
uint32_t m_valuePos
current buffer position
Definition Encoder.h:82
uint32_t RLESigns(uint32_t codePos, uint32_t *signBits, uint32_t signLen)
Definition Encoder.cpp:775
uint32_t DecomposeBitplane(uint32_t bufferSize, uint32_t planeMask, uint32_t codePos, uint32_t *sigBits, uint32_t *refBits, uint32_t *signBits, uint32_t &signLen, uint32_t &codeLen)
Definition Encoder.cpp:635
uint32_t m_codePos
current position in encoded bitstream
Definition Encoder.h:84
uint32_t m_maxAbsValue
maximum absolute coefficient in each buffer
Definition Encoder.h:83
bool GetBitAtPos(uint32_t pos, uint32_t planeMask) const
Definition Encoder.h:91
bool m_sigFlagVector[BufferSize+1]
Definition Encoder.h:94
void Init(int lastLevelIndex)
Definition Encoder.h:66
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:85
ROIBlockHeader m_header
block header
Definition Encoder.h:81
DataT m_value[BufferSize]
input buffer of values with index m_valuePos
Definition Encoder.h:79
CMacroBlock(CEncoder *encoder)
Definition Encoder.h:51
uint32_t m_codeBuffer[CodeBufferLen]
output buffer for encoded bitstream
Definition Encoder.h:80
CEncoder(CPGFStream *stream, PGFPreHeader preHeader, PGFHeader header, const PGFPostHeader &postHeader, uint64_t &userDataPos, bool useOMP)
Definition Encoder.cpp:71
void FavorSpeedOverSize()
Encoder favors speed over compression size.
Definition Encoder.h:116
CPGFStream * m_stream
output PMF stream
Definition Encoder.h:208
void EncodeBuffer(ROIBlockHeader h)
Definition Encoder.cpp:342
int64_t ComputeHeaderLength() const
Definition Encoder.h:169
uint32_t WriteLevelLength(uint32_t *&levelLength)
Definition Encoder.cpp:178
void SetEncodedLevel(int currentLevel)
Definition Encoder.h:157
uint32_t * m_levelLength
temporary saves the level index
Definition Encoder.h:218
void SetStreamPosToStart()
Resets stream position to beginning of PGF pre-header.
Definition Encoder.h:183
uint8_t m_nLevels
number of levels
Definition Encoder.h:220
uint32_t UpdateLevelLength()
Definition Encoder.cpp:203
void WriteMacroBlock(CMacroBlock *block)
Definition Encoder.cpp:407
int m_lastMacroBlock
array index of the last created macro block
Definition Encoder.h:215
void WriteValue(CSubband *band, int bandPos)
Definition Encoder.cpp:327
void Partition(CSubband *band, int width, int height, int startPos, int pitch)
Definition Encoder.cpp:247
int m_macroBlockLen
array length
Definition Encoder.h:214
uint64_t m_bufferStartPos
stream position of encoded buffer
Definition Encoder.h:211
void UpdatePostHeaderSize(PGFPreHeader preHeader)
Definition Encoder.cpp:161
int64_t ComputeBufferLength() const
Definition Encoder.h:174
uint64_t m_startPosition
stream position of PGF start (PreHeader)
Definition Encoder.h:209
int64_t ComputeOffset() const
Definition Encoder.h:179
bool m_forceWriting
all macro blocks have to be written into the stream
Definition Encoder.h:222
uint64_t m_levelLengthPos
stream position of Metadata
Definition Encoder.h:210
CMacroBlock * m_currentBlock
current macro block (used by main thread)
Definition Encoder.h:216
CMacroBlock ** m_macroBlocks
array of macroblocks
Definition Encoder.h:213
int m_currLevelIndex
counts where (=index) to save next value
Definition Encoder.h:219
bool m_favorSpeed
favor speed over size
Definition Encoder.h:221
void SetBufferStartPos()
Save current stream position as beginning of current level.
Definition Encoder.h:187
Abstract stream base class.
Definition PGFstream.h:39
virtual uint64_t GetPos() const =0
virtual void SetPos(short posMode, int64_t posOff)=0
Wavelet channel class.
Definition Subband.h:42
Definition PGFimage.h:33
int32_t DataT
Definition PGFtypes.h:367
constexpr uint32_t CodeBufferLen
number of words in code buffer (CodeBufferLen > BufferLen)
Definition PGFtypes.h:86
constexpr uint32_t BufferSize
must be a multiple of WordWidth, BufferSize <= UINT16_MAX
Definition PGFtypes.h:84
PGF header.
Definition PGFtypes.h:169
Optional PGF post-header.
Definition PGFtypes.h:199
PGF pre-header.
Definition PGFtypes.h:136
Block header used with ROI coding scheme.
Definition PGFtypes.h:211
ROIBlockHeader(uint16_t v)
Definition PGFtypes.h:227