89#ifdef LIBPGF_USE_OPENMP
96#ifdef LIBPGF_USE_OPENMP
180 delete[] levelLength;
181 levelLength =
new(std::nothrow) uint32_t[
m_nLevels];
182 if (!levelLength) ReturnWithError(InsufficientMemory);
183 for (uint8_t l = 0; l <
m_nLevels; l++) levelLength[l] = 0;
210#ifdef PGF_USE_BIG_ENDIAN
211 uint32_t levelLength;
253 const int wr = pitch - ww.rem;
254 int pos, base = startPos, base2;
257 for (
int i = 0; i < hh.quot; i++) {
260 for (
int j = 0; j < ww.quot; j++) {
274 for (
int x = 0; x < ww.rem; x++) {
284 for (
int j = 0; j < ww.quot; j++) {
287 for (
int y = 0; y < hh.rem; y++) {
298 for (
int y = 0; y < hh.rem; y++) {
300 for (
int x = 0; x < ww.rem; x++) {
332 uint32_t v = abs(val);
344#ifdef __PGFROISUPPORT__
384#ifdef LIBPGF_USE_OPENMP
385#pragma omp parallel for default(shared)
409#ifdef __PGFROISUPPORT__
413 int count =
sizeof(uint16_t);
420#ifdef PGF_USE_BIG_ENDIAN
422 uint16_t wl =
__VAL(wordLen);
423 m_stream->
Write(&count, &wl); ASSERT(count ==
sizeof(uint16_t));
425#ifdef __PGFROISUPPORT__
435 for (
int i = 0; i < wordLen; i++) {
440 m_stream->
Write(&count, &wordLen); ASSERT(count ==
sizeof(uint16_t));
442#ifdef __PGFROISUPPORT__
485 uint32_t sigLen, codeLen = 0, wordPos, refLen, signLen;
498 for (uint32_t k = 0; k < bufferSize; k++) {
504 for (uint32_t k = 0; k < bufferSize; k++) {
519 planeMask = 1 << (nPlanes - 1);
521 for (
int plane = nPlanes - 1; plane >= 0; plane--) {
523 for (uint32_t k = 0; k <
BufferLen; k++) {
567 if (useRL && codeLen <=
MaxCodeLen && codeLen < signLen) {
594 for (uint32_t k = 0; k < codeLen; k++) {
604 for (uint32_t k = 0; k < refLen; k++) {
616 for (uint32_t k = 0; k < refLen; k++) {
642 uint32_t valuePos = 0, valueEnd;
649 const uint32_t outStartPos = codePos;
651 uint32_t runlen = 1 << k;
654 while (valuePos < bufferSize) {
661 while (valuePos < valueEnd) {
678 SetBit(signBits, signLen++);
686 SetBit(sigBits, sigPos++);
696 if (count == runlen) {
715 if (valuePos < bufferSize) {
738 ASSERT(sigPos <= bufferSize);
739 ASSERT(refPos <= bufferSize);
740 ASSERT(signLen <= bufferSize);
741 ASSERT(valuePos == bufferSize);
743 codeLen = codePos - outStartPos;
780 const uint32_t outStartPos = codePos;
782 uint32_t runlen = 1 << k;
784 uint32_t signPos = 0;
786 while (signPos < signLen) {
790 if (count == runlen) {
802 signPos += count + 1;
815 ASSERT(signPos == signLen || signPos == signLen + 1);
817 return codePos - outStartPos;
822 void CEncoder::DumpBuffer()
const {
A macro block is an encoding unit of fixed size (uncoded).
uint32_t m_valuePos
current buffer position
uint32_t RLESigns(uint32_t codePos, uint32_t *signBits, uint32_t signLen)
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)
uint32_t m_codePos
current position in encoded bitstream
uint32_t m_maxAbsValue
maximum absolute coefficient in each buffer
bool GetBitAtPos(uint32_t pos, uint32_t planeMask) const
bool m_sigFlagVector[BufferSize+1]
void Init(int lastLevelIndex)
int m_lastLevelIndex
index of last encoded level: [0, nLevels); used because a level-end can occur before a buffer is full
ROIBlockHeader m_header
block header
DataT m_value[BufferSize]
input buffer of values with index m_valuePos
CMacroBlock(CEncoder *encoder)
uint8_t NumberOfBitplanes()
uint32_t m_codeBuffer[CodeBufferLen]
output buffer for encoded bitstream
CEncoder(CPGFStream *stream, PGFPreHeader preHeader, PGFHeader header, const PGFPostHeader &postHeader, uint64_t &userDataPos, bool useOMP)
CPGFStream * m_stream
output PMF stream
void EncodeBuffer(ROIBlockHeader h)
uint32_t WriteLevelLength(uint32_t *&levelLength)
uint32_t * m_levelLength
temporary saves the level index
void SetStreamPosToStart()
Resets stream position to beginning of PGF pre-header.
uint8_t m_nLevels
number of levels
uint32_t UpdateLevelLength()
void WriteMacroBlock(CMacroBlock *block)
int m_lastMacroBlock
array index of the last created macro block
void WriteValue(CSubband *band, int bandPos)
void Partition(CSubband *band, int width, int height, int startPos, int pitch)
int m_macroBlockLen
array length
uint64_t m_bufferStartPos
stream position of encoded buffer
void UpdatePostHeaderSize(PGFPreHeader preHeader)
int64_t ComputeBufferLength() const
uint64_t m_startPosition
stream position of PGF start (PreHeader)
bool m_forceWriting
all macro blocks have to be written into the stream
uint64_t m_levelLengthPos
stream position of Metadata
CMacroBlock * m_currentBlock
current macro block (used by main thread)
CMacroBlock ** m_macroBlocks
array of macroblocks
int m_currLevelIndex
counts where (=index) to save next value
bool m_favorSpeed
favor speed over size
void SetBufferStartPos()
Save current stream position as beginning of current level.
Abstract stream base class.
virtual void Write(int *count, void *buffer)=0
virtual uint64_t GetPos() const =0
virtual void SetPos(short posMode, int64_t posOff)=0
DataT GetData(uint32_t pos) const
void ClearBit(uint32_t *stream, uint32_t pos)
constexpr int MaxBitPlanes
maximum number of bit planes of m_value: 32 minus sign bit
constexpr size_t HeaderSize
constexpr uint32_t CodeBufferBitLen
max number of bits in m_codeBuffer
constexpr int LinBlockSize
side length of a coefficient block in a HH or LL subband
void SetBit(uint32_t *stream, uint32_t pos)
constexpr size_t PreHeaderSize
void SetValueBlock(uint32_t *stream, uint32_t pos, uint32_t val, uint32_t k)
uint32_t AlignWordPos(uint32_t pos)
constexpr int RLblockSizeLen
block size length (< 16): ld(BufferSize) < RLblockSizeLen <= 2*ld(BufferSize)
constexpr uint32_t CodeBufferLen
number of words in code buffer (CodeBufferLen > BufferLen)
constexpr size_t DataTSize
constexpr int MaxBitPlanesLog
number of bits to code the maximum number of bit planes (in 32 or 16 bit mode)
constexpr uint32_t MaxCodeLen
max length of RL encoded block
uint32_t NumberOfWords(uint32_t pos)
constexpr uint32_t BufferLen
number of words per buffer
constexpr size_t ColorTableSize
constexpr uint32_t BufferSize
must be a multiple of WordWidth, BufferSize <= UINT16_MAX
uint32_t SeekBit1Range(uint32_t *stream, uint32_t pos, uint32_t len)