58#define CodeBufferBitLen (CodeBufferLen*WordWidth)
59#define MaxCodeLen ((1 << RLblockSizeLen) - 1)
74 PGFPostHeader& postHeader, UINT32*& levelLength, UINT64& userDataPos,
75 bool useOMP,
bool skipUserData) THROW_
82#ifdef __PGFROISUPPORT__
96 if (count != expected) ReturnWithError(MissingData);
101 count = expected = 4;
103 count = expected = 2;
106 if (count != expected) ReturnWithError(MissingData);
109 preHeader.hSize =
__VAL(preHeader.hSize);
112 if (memcmp(preHeader.magic,
PGFMagic, 3) != 0) {
114 ReturnWithError(FormatCannotRead);
120 if (count != expected) ReturnWithError(MissingData);
123 header.height =
__VAL(UINT32(header.height));
124 header.width =
__VAL(UINT32(header.width));
127 if (preHeader.version > 0) {
128#ifndef __PGFROISUPPORT__
130 if (preHeader.version &
PGFROI) ReturnWithError(FormatCannotRead);
141 m_stream->Read(&count, postHeader.clut);
142 if (count != expected) ReturnWithError(MissingData);
148 postHeader.userDataLen = size;
153 postHeader.userData =
new(std::nothrow) UINT8[postHeader.userDataLen];
154 if (!postHeader.userData) ReturnWithError(InsufficientMemory);
157 count = expected = postHeader.userDataLen;
158 m_stream->Read(&count, postHeader.userData);
159 if (count != expected) ReturnWithError(MissingData);
165 levelLength =
new(std::nothrow) UINT32[header.nLevels];
166 if (!levelLength) ReturnWithError(InsufficientMemory);
169 count = expected = header.nLevels*
WordBytes;
170 m_stream->Read(&count, levelLength);
171 if (count != expected) ReturnWithError(MissingData);
173#ifdef PGF_USE_BIG_ENDIAN
175 for (
int i=0; i < header.nLevels; i++) {
176 levelLength[i] =
__VAL(levelLength[i]);
181 for (
int i=0; i < header.nLevels; i++) {
191#ifdef LIBPGF_USE_OPENMP
198#ifdef LIBPGF_USE_OPENMP
258 const int wr = pitch - ww.rem;
259 int pos, base = startPos, base2;
262 for (
int i=0; i < hh.quot; i++) {
265 for (
int j=0; j < ww.quot; j++) {
279 for (
int x=0; x < ww.rem; x++) {
289 for (
int j=0; j < ww.quot; j++) {
292 for (
int y=0; y < hh.rem; y++) {
303 for (
int y=0; y < hh.rem; y++) {
305 for (
int x=0; x < ww.rem; x++) {
320 CSubband* hlBand = wtChannel->GetSubband(level,
HL);
321 CSubband* lhBand = wtChannel->GetSubband(level,
LH);
325 const int hlwr = hlBand->
GetWidth() - hlW.rem;
327 const int lhwr = lhBand->
GetWidth() - hlW.rem;
329 int hlBase = 0, lhBase = 0, hlBase2, lhBase2;
334 if (!hlBand->
AllocMemory()) ReturnWithError(InsufficientMemory);
335 if (!lhBand->
AllocMemory()) ReturnWithError(InsufficientMemory);
339 if (quantParam < 0) quantParam = 0;
342 for (
int i=0; i < lhH.quot; i++) {
346 for (
int j=0; j < hlW.quot; j++) {
366 for (
int x=0; x < hlW.rem; x++) {
385 for (
int j=0; j < hlW.quot; j++) {
389 for (
int y=0; y < lhH.rem; y++) {
405 for (
int y=0; y < lhH.rem; y++) {
407 for (
int x=0; x < hlW.rem; x++) {
425 for (
int j=0; j < hlBand->
GetWidth(); j++) {
436 m_stream->SetPos(FSFromCurrent, offset);
463void CDecoder::DecodeTileBuffer() THROW_ {
497 if (ex.
error == MissingData) {
504#ifdef LIBPGF_USE_OPENMP
506 #pragma omp parallel for default(shared)
534 count = expected =
sizeof(UINT16);
536 if (count != expected) ReturnWithError(MissingData);
537 wordLen =
__VAL(wordLen);
539 ReturnWithError(FormatCannotRead);
541#ifdef __PGFROISUPPORT__
545 if (count != expected) ReturnWithError(MissingData);
556 m_stream->Read(&count, block->m_codeBuffer);
557 if (count != expected) ReturnWithError(MissingData);
559#ifdef PGF_USE_BIG_ENDIAN
562 for (
int i=0; i < count; i++) {
563 block->m_codeBuffer[i] =
__VAL(block->m_codeBuffer[i]);
567#ifdef __PGFROISUPPORT__
579void CDecoder::SkipTileBuffer() THROW_ {
593 count = expected =
sizeof(wordLen);
595 if (count != expected) ReturnWithError(MissingData);
596 wordLen =
__VAL(wordLen);
599#ifdef __PGFROISUPPORT__
602 m_stream->SetPos(FSFromCurrent,
sizeof(ROIBlockHeader));
624 UINT32 codePos = 0, codeLen, sigLen, sigPos, signLen, signPos;
628 for (UINT32 k=0; k < bufferSize; k++) {
646 planeMask = 1 << (nPlanes - 1);
648 for (
int plane = nPlanes - 1; plane >= 0; plane--) {
740 UINT32 valPos = 0, signPos = 0, refPos = 0;
741 UINT32 sigPos = 0, sigEnd;
744 while (valPos < bufferSize) {
753 while (sigPos < sigEnd) {
755 zerocnt =
SeekBitRange(sigBits, sigPos, sigEnd - sigPos);
758 if (sigPos < sigEnd) {
771 if (valPos < bufferSize) {
773 if (
GetBit(refBits, refPos)) {
780 ASSERT(sigPos <= bufferSize);
781 ASSERT(refPos <= bufferSize);
782 ASSERT(signPos <= bufferSize);
783 ASSERT(valPos == bufferSize);
801 UINT32 valPos = 0, refPos = 0;
802 UINT32 sigPos = 0, sigEnd;
804 UINT32 runlen = 1 << k;
805 UINT32 count = 0, rest = 0;
808 while (valPos < bufferSize) {
815 while (sigPos < sigEnd) {
854 if (sigPos < sigEnd) {
869 rest = sigPos - sigEnd;
877 if (valPos < bufferSize) {
879 if (
GetBit(refBits, refPos)) {
886 ASSERT(sigPos <= bufferSize);
887 ASSERT(refPos <= bufferSize);
888 ASSERT(valPos == bufferSize);
905 UINT32 valPos = 0, refPos = 0;
906 UINT32 sigPos = 0, sigEnd;
907 UINT32 zerocnt, count = 0;
909 UINT32 runlen = 1 << k;
910 bool signBit =
false;
911 bool zeroAfterRun =
false;
913 while (valPos < bufferSize) {
922 while (sigPos < sigEnd) {
924 zerocnt =
SeekBitRange(sigBits, sigPos, sigEnd - sigPos);
927 if (sigPos < sigEnd) {
937 zeroAfterRun =
false;
986 if (valPos < bufferSize) {
988 if (
GetBit(refBits, refPos)) {
995 ASSERT(sigPos <= bufferSize);
996 ASSERT(refPos <= bufferSize);
997 ASSERT(valPos == bufferSize);
1004void CDecoder::DumpBuffer() {
UINT32 AlignWordPos(UINT32 pos)
bool GetBit(UINT32 *stream, UINT32 pos)
UINT32 GetValueBlock(UINT32 *stream, UINT32 pos, UINT32 k)
UINT32 SeekBitRange(UINT32 *stream, UINT32 pos, UINT32 len)
#define CodeBufferBitLen
max number of bits in m_codeBuffer
#define MaxCodeLen
max length of RL encoded block
#define MaxBitPlanesLog
number of bits to code the maximum number of bit planes (in 32 or 16 bit mode)
#define PGFROI
supports Regions Of Interest
#define InterBlockSize
side length of a coefficient block in a HL or LH subband
#define LinBlockSize
side length of a coefficient block in a HH or LL subband
#define PGFMagic
PGF identification.
#define BufferSize
must be a multiple of WordWidth
#define Version6
new HeaderSize: 32 bits instead of 16 bits
#define RLblockSizeLen
block size length (< 16): ld(BufferSize) < RLblockSizeLen <= 2*ld(BufferSize)
#define MaxBitPlanes
maximum number of bit planes of m_value: 32 minus sign bit
A macro block is a decoding unit of fixed size (uncoded)
ROIBlockHeader m_header
block header
UINT32 m_valuePos
current position in m_value
void SetBitAtPos(UINT32 pos, DataT planeMask)
UINT32 ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32 *sigBits, UINT32 *refBits, UINT32 *signBits)
DataT m_value[BufferSize]
output buffer of values with index m_valuePos
void SetSign(UINT32 pos, bool sign)
UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32 sigPos, UINT32 *refBits)
UINT32 m_codeBuffer[CodeBufferLen]
input buffer for encoded bitstream
bool m_sigFlagVector[BufferSize+1]
int m_macroBlockLen
array length
int m_currentBlockIndex
index of current macro block
CPGFStream * m_stream
input PGF stream
int m_macroBlocksAvailable
number of decoded macro blocks (including currently used macro block)
void DecodeInterleaved(CWaveletTransform *wtChannel, int level, int quantParam) THROW_
UINT64 m_startPos
stream position at the beginning of the PGF pre-header
void ReadMacroBlock(CMacroBlock *block) THROW_
throws IOException
UINT64 m_streamSizeEstimation
estimation of stream size
void DecodeBuffer() THROW_
CMacroBlock ** m_macroBlocks
array of macroblocks
UINT32 ReadEncodedData(UINT8 *target, UINT32 len) const THROW_
CMacroBlock * m_currentBlock
current macro block (used by main thread)
UINT32 m_encodedHeaderLength
stream offset from startPos to the beginning of the data part (highest level)
void Partition(CSubband *band, int quantParam, int width, int height, int startPos, int pitch) THROW_
void Skip(UINT64 offset) THROW_
CDecoder(CPGFStream *stream, PGFPreHeader &preHeader, PGFHeader &header, PGFPostHeader &postHeader, UINT32 *&levelLength, UINT64 &userDataPos, bool useOMP, bool skipUserData) THROW_
void DequantizeValue(CSubband *band, UINT32 bandPos, int quantParam) THROW_
Abstract stream base class.
OSError error
operating system error code