PGF encoder.
More...
#include <Encoder.h>
List of all members.
Classes |
class | CMacroBlock |
| A macro block is an encoding unit of fixed size (uncoded) More...
|
Public Member Functions |
| CEncoder (CPGFStream *stream, PGFPreHeader preHeader, PGFHeader header, const PGFPostHeader &postHeader, UINT32 *&levelLength, bool useOMP=true) THROW_ |
| ~CEncoder () |
void | FavorSpeedOverSize () |
void | Flush () THROW_ |
UINT32 | WriteLevelLength () THROW_ |
void | Partition (CSubband *band, int width, int height, int startPos, int pitch) THROW_ |
void | SetEncodedLevel (int currentLevel) |
void | WriteValue (CSubband *band, int bandPos) THROW_ |
UINT32 | ComputeHeaderLength () const |
UINT32 | ComputeBufferLength () const |
void | SetBufferStartPos () |
void | EncodeTileBuffer () THROW_ |
void | SetROI () |
Private Member Functions |
void | EncodeBuffer (ROIBlockHeader h) THROW_ |
void | WriteMacroBlock (CMacroBlock *block) THROW_ |
Private Attributes |
CPGFStream * | m_stream |
UINT64 | m_startPosition |
| file position of PGF start (PreHeader)
|
UINT64 | m_levelLengthPos |
| file position of Metadata
|
UINT64 | m_bufferStartPos |
| file position of encoded buffer
|
CMacroBlock ** | m_macroBlocks |
| array of macroblocks
|
int | m_macroBlockLen |
| array length
|
int | m_lastMacroBlock |
| array index of the last created macro block
|
CMacroBlock * | m_currentBlock |
| current macro block (used by main thread)
|
UINT32 * | m_levelLength |
| temporary saves the level index
|
int | m_currLevelIndex |
| counts where (=index) to save next value
|
UINT8 | m_nLevels |
| number of levels
|
bool | m_favorSpeed |
| favor speed over size
|
bool | m_forceWriting |
| all macro blocks have to be written into the stream
|
bool | m_roi |
| true: ensures region of interest (ROI) encoding
|
Detailed Description
PGF encoder.
PGF encoder class.
- Author:
- C. Stamm
Constructor & Destructor Documentation
Write pre-header, header, postHeader, and levelLength. It might throw an IOException.
- Parameters:
-
stream | A PGF stream |
preHeader | A already filled in PGF pre header |
header | An already filled in PGF header |
postHeader | [in] A already filled in PGF post header (containing color table, user data, ...) |
levelLength | A reference to an integer array, large enough to save the relative file positions of all PGF levels |
useOMP | If true, then the encoder will use multi-threading based on openMP |
Definition at line 66 of file Encoder.cpp.
: m_stream(stream)
, m_startPosition(0)
, m_currLevelIndex(0)
, m_nLevels(header.nLevels)
, m_favorSpeed(false)
, m_forceWriting(false)
#ifdef __PGFROISUPPORT__
, m_roi(false)
#endif
{
ASSERT(m_stream);
int count;
#ifdef LIBPGF_USE_OPENMP
m_macroBlockLen = omp_get_num_procs();
#else
m_macroBlockLen = 1;
#endif
if (useOMP && m_macroBlockLen > 1) {
#ifdef LIBPGF_USE_OPENMP
omp_set_num_threads(m_macroBlockLen);
#endif
m_macroBlocks = new CMacroBlock*[m_macroBlockLen];
for (int i=0; i < m_macroBlockLen; i++) m_macroBlocks[i] = new CMacroBlock(this);
m_lastMacroBlock = 0;
m_currentBlock = m_macroBlocks[m_lastMacroBlock++];
} else {
m_macroBlocks = 0;
m_macroBlockLen = 1;
m_currentBlock = new CMacroBlock(this);
}
m_startPosition = m_stream->GetPos();
preHeader.hSize = __VAL(preHeader.hSize);
count = PreHeaderSize;
m_stream->Write(&count, &preHeader);
header.height = __VAL(header.height);
header.width = __VAL(header.width);
count = HeaderSize;
m_stream->Write(&count, &header);
if (header.mode == ImageModeIndexedColor) {
count = ColorTableSize;
m_stream->Write(&count, (void *)postHeader.clut);
}
if (postHeader.userData && postHeader.userDataLen) {
count = postHeader.userDataLen;
m_stream->Write(&count, postHeader.userData);
}
delete[] levelLength;
levelLength = new UINT32[m_nLevels];
for (UINT8 l = 0; l < m_nLevels; l++) levelLength[l] = 0;
m_levelLength = levelLength;
m_levelLengthPos = m_stream->GetPos();
count = m_nLevels*WordBytes;
m_stream->Write(&count, m_levelLength);
SetBufferStartPos();
}
Member Function Documentation
UINT32 CEncoder::ComputeBufferLength |
( |
| ) |
const [inline] |
Compute stream length of encoded buffer.
- Returns:
- encoded buffer length
Definition at line 161 of file Encoder.h.
UINT32 CEncoder::ComputeHeaderLength |
( |
| ) |
const [inline] |
Compute stream length of header.
- Returns:
- header length
Definition at line 156 of file Encoder.h.
void CEncoder::EncodeTileBuffer |
( |
| ) |
[inline] |
Encodes tile buffer and writes it into stream It might throw an IOException.
Definition at line 171 of file Encoder.h.
void CEncoder::FavorSpeedOverSize |
( |
| ) |
[inline] |
Encoder favors speed over compression size
Definition at line 116 of file Encoder.h.
void CEncoder::Partition |
( |
CSubband * |
band, |
|
|
int |
width, |
|
|
int |
height, |
|
|
int |
startPos, |
|
|
int |
pitch |
|
) |
| |
Partitions a rectangular region of a given subband. Partitioning scheme: The plane is partitioned in squares of side length LinBlockSize. Write wavelet coefficients into buffer. It might throw an IOException.
- Parameters:
-
band | A subband |
width | The width of the rectangle |
height | The height of the rectangle |
startPos | The buffer position of the top left corner of the rectangular region |
pitch | The number of bytes in row of the subband |
Definition at line 161 of file Encoder.cpp.
{
ASSERT(band);
const div_t hh = div(height, LinBlockSize);
const div_t ww = div(width, LinBlockSize);
const int ws = pitch - LinBlockSize;
const int wr = pitch - ww.rem;
int pos, base = startPos, base2;
for (int i=0; i < hh.quot; i++) {
base2 = base;
for (int j=0; j < ww.quot; j++) {
pos = base2;
for (int y=0; y < LinBlockSize; y++) {
for (int x=0; x < LinBlockSize; x++) {
WriteValue(band, pos);
pos++;
}
pos += ws;
}
base2 += LinBlockSize;
}
pos = base2;
for (int y=0; y < LinBlockSize; y++) {
for (int x=0; x < ww.rem; x++) {
WriteValue(band, pos);
pos++;
}
pos += wr;
base += pitch;
}
}
base2 = base;
for (int j=0; j < ww.quot; j++) {
pos = base2;
for (int y=0; y < hh.rem; y++) {
for (int x=0; x < LinBlockSize; x++) {
WriteValue(band, pos);
pos++;
}
pos += ws;
}
base2 += LinBlockSize;
}
pos = base2;
for (int y=0; y < hh.rem; y++) {
for (int x=0; x < ww.rem; x++) {
WriteValue(band, pos);
pos++;
}
pos += wr;
}
}
void CEncoder::SetBufferStartPos |
( |
| ) |
[inline] |
Save current stream position as beginning of current level.
Definition at line 165 of file Encoder.h.
void CEncoder::SetEncodedLevel |
( |
int |
currentLevel | ) |
[inline] |
Informs the encoder about the encoded level.
- Parameters:
-
currentLevel | encoded level [0, nLevels) |
Definition at line 144 of file Encoder.h.
void CEncoder::SetROI |
( |
| ) |
[inline] |
Enables region of interest (ROI) status.
Definition at line 175 of file Encoder.h.
UINT32 CEncoder::WriteLevelLength |
( |
| ) |
|
Write levelLength into header.
- Returns:
- number of bytes written into stream It might throw an IOException.
Definition at line 239 of file Encoder.cpp.
void CEncoder::WriteMacroBlock |
( |
CMacroBlock * |
block | ) |
[private] |
void CEncoder::WriteValue |
( |
CSubband * |
band, |
|
|
int |
bandPos |
|
) |
| |
Write a single value into subband at given position. It might throw an IOException.
- Parameters:
-
band | A subband |
bandPos | A valid position in subband band |
Definition at line 272 of file Encoder.cpp.
Member Data Documentation
file position of encoded buffer
Definition at line 189 of file Encoder.h.
current macro block (used by main thread)
Definition at line 194 of file Encoder.h.
counts where (=index) to save next value
Definition at line 197 of file Encoder.h.
favor speed over size
Definition at line 199 of file Encoder.h.
all macro blocks have to be written into the stream
Definition at line 200 of file Encoder.h.
array index of the last created macro block
Definition at line 193 of file Encoder.h.
temporary saves the level index
Definition at line 196 of file Encoder.h.
file position of Metadata
Definition at line 188 of file Encoder.h.
array of macroblocks
Definition at line 191 of file Encoder.h.
true: ensures region of interest (ROI) encoding
Definition at line 202 of file Encoder.h.
file position of PGF start (PreHeader)
Definition at line 187 of file Encoder.h.
The documentation for this class was generated from the following files: