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 |
UINT64 | m_levelLengthPos |
UINT64 | m_bufferStartPos |
CMacroBlock ** | m_macroBlocks |
int | m_macroBlockLen |
int | m_lastMacroBlock |
CMacroBlock * | m_currentBlock |
UINT32 * | m_levelLength |
int | m_currLevelIndex |
UINT8 | m_nLevels |
bool | m_favorSpeed |
bool | m_forceWriting |
bool | m_roi |
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
The documentation for this class was generated from the following files: