58#define CodeBufferBitLen (CodeBufferLen*WordWidth)
59#define MaxCodeLen ((1 << RLblockSizeLen) - 1)
74 PGFPostHeader& postHeader, UINT32*& levelLength, UINT64& userDataPos,
75 bool useOMP, UINT32 userDataPolicy)
78, m_streamSizeEstimation(0)
79, m_encodedHeaderLength(0)
80, m_currentBlockIndex(0)
81, m_macroBlocksAvailable(0)
96 if (count != expected) ReturnWithError(MissingData);
101 count = expected = 4;
103 count = expected = 2;
106 if (count != expected) ReturnWithError(MissingData);
114 ReturnWithError(FormatCannotRead);
120 if (count != expected) ReturnWithError(MissingData);
128#ifndef __PGFROISUPPORT__
130 if (preHeader.
version &
PGFROI) ReturnWithError(FormatCannotRead);
133 UINT32 size = preHeader.
hSize;
145 if (count != expected) ReturnWithError(MissingData);
148 if (size > (UINT32)count) {
165 if (!postHeader.
userData) ReturnWithError(InsufficientMemory);
170 if (count != expected) ReturnWithError(MissingData);
179 levelLength =
new(std::nothrow) UINT32[header.
nLevels];
180 if (!levelLength) ReturnWithError(InsufficientMemory);
185 if (count != expected) ReturnWithError(MissingData);
187#ifdef PGF_USE_BIG_ENDIAN
189 for (
int i=0; i < header.
nLevels; i++) {
190 levelLength[i] =
__VAL(levelLength[i]);
195 for (
int i=0; i < header.
nLevels; i++) {
205#ifdef LIBPGF_USE_OPENMP
212#ifdef LIBPGF_USE_OPENMP
272 const int wr = pitch - ww.rem;
273 int pos, base = startPos, base2;
276 for (
int i=0; i < hh.quot; i++) {
279 for (
int j=0; j < ww.quot; j++) {
293 for (
int x=0; x < ww.rem; x++) {
303 for (
int j=0; j < ww.quot; j++) {
306 for (
int y=0; y < hh.rem; y++) {
317 for (
int y=0; y < hh.rem; y++) {
319 for (
int x=0; x < ww.rem; x++) {
339 const int hlwr = hlBand->
GetWidth() - hlW.rem;
341 const int lhwr = lhBand->
GetWidth() - hlW.rem;
343 int hlBase = 0, lhBase = 0, hlBase2, lhBase2;
348 if (!hlBand->
AllocMemory()) ReturnWithError(InsufficientMemory);
349 if (!lhBand->
AllocMemory()) ReturnWithError(InsufficientMemory);
353 if (quantParam < 0) quantParam = 0;
356 for (
int i=0; i < lhH.quot; i++) {
360 for (
int j=0; j < hlW.quot; j++) {
380 for (
int x=0; x < hlW.rem; x++) {
399 for (
int j=0; j < hlW.quot; j++) {
403 for (
int y=0; y < lhH.rem; y++) {
419 for (
int y=0; y < lhH.rem; y++) {
421 for (
int x=0; x < hlW.rem; x++) {
439 for (
int j=0; j < hlBand->
GetWidth(); j++) {
511 if (ex.
error == MissingData || ex.
error == FormatCannotRead) {
518#ifdef LIBPGF_USE_OPENMP
520 #pragma omp parallel for default(shared)
548 count = expected =
sizeof(UINT16);
550 if (count != expected) ReturnWithError(MissingData);
551 wordLen =
__VAL(wordLen);
552 if (wordLen >
BufferSize) ReturnWithError(FormatCannotRead);
554#ifdef __PGFROISUPPORT__
559 if (count != expected) ReturnWithError(MissingData);
569 if (count != expected) ReturnWithError(MissingData);
571#ifdef PGF_USE_BIG_ENDIAN
574 for (
int i=0; i < count; i++) {
579#ifdef __PGFROISUPPORT__
586#ifdef __PGFROISUPPORT__
594void CDecoder::SkipTileBuffer() {
622 count = expected =
sizeof(wordLen);
624 if (count != expected) ReturnWithError(MissingData);
625 wordLen =
__VAL(wordLen);
626 if (wordLen >
BufferSize) ReturnWithError(FormatCannotRead);
631 if (count != expected) ReturnWithError(MissingData);
632 h.val =
__VAL(h.val);
636 }
while (!h.rbh.tileEnd);
654 for (UINT32 k=0; k < bufferSize; k++) {
672 DataT planeMask = 1 << (nPlanes - 1);
674 for (
int plane = nPlanes - 1; plane >= 0; plane--) {
768 UINT32 valPos = 0, signPos = 0, refPos = 0, sigPos = 0;
770 while (valPos < bufferSize) {
772 UINT32 sigEnd = valPos;
773 while(!m_sigFlagVector[sigEnd]) { sigEnd++; }
779 while (sigPos < sigEnd) {
781 UINT32 zerocnt =
SeekBitRange(sigBits, sigPos, sigEnd - sigPos);
784 if (sigPos < sigEnd) {
786 SetBitAtPos(valPos, planeMask);
789 SetSign(valPos,
GetBit(signBits, signPos++));
792 m_sigFlagVector[valPos++] =
true;
797 if (valPos < bufferSize) {
799 if (
GetBit(refBits, refPos)) {
800 SetBitAtPos(valPos, planeMask);
806 ASSERT(sigPos <= bufferSize);
807 ASSERT(refPos <= bufferSize);
808 ASSERT(signPos <= bufferSize);
809 ASSERT(valPos == bufferSize);
827 UINT32 valPos = 0, refPos = 0;
828 UINT32 sigPos = 0, sigEnd;
830 UINT32 runlen = 1 << k;
831 UINT32 count = 0, rest = 0;
834 while (valPos < bufferSize) {
837 while(!m_sigFlagVector[sigEnd]) { sigEnd++; }
841 while (sigPos < sigEnd) {
849 if (
GetBit(m_codeBuffer, codePos++)) {
880 if (sigPos < sigEnd) {
885 SetBitAtPos(valPos, planeMask);
888 SetSign(valPos,
GetBit(m_codeBuffer, codePos++));
891 m_sigFlagVector[valPos++] =
true;
895 rest = sigPos - sigEnd;
903 if (valPos < bufferSize) {
905 if (
GetBit(refBits, refPos)) {
906 SetBitAtPos(valPos, planeMask);
912 ASSERT(sigPos <= bufferSize);
913 ASSERT(refPos <= bufferSize);
914 ASSERT(valPos == bufferSize);
931 UINT32 valPos = 0, refPos = 0;
932 UINT32 sigPos = 0, sigEnd;
933 UINT32 zerocnt, count = 0;
935 UINT32 runlen = 1 << k;
936 bool signBit =
false;
937 bool zeroAfterRun =
false;
939 while (valPos < bufferSize) {
942 while(!m_sigFlagVector[sigEnd]) { sigEnd++; }
948 while (sigPos < sigEnd) {
950 zerocnt =
SeekBitRange(sigBits, sigPos, sigEnd - sigPos);
953 if (sigPos < sigEnd) {
955 SetBitAtPos(valPos, planeMask);
963 zeroAfterRun =
false;
966 if (
GetBit(m_codeBuffer, signPos++)) {
1003 SetSign(valPos, signBit);
1006 m_sigFlagVector[valPos++] =
true;
1012 if (valPos < bufferSize) {
1014 if (
GetBit(refBits, refPos)) {
1015 SetBitAtPos(valPos, planeMask);
1021 ASSERT(sigPos <= bufferSize);
1022 ASSERT(refPos <= bufferSize);
1023 ASSERT(valPos == bufferSize);
1030void 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, BufferSize <= UINT16_MAX
#define Version6
hSize in PGFPreHeader uses 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)
bool IsCompletelyRead() const
ROIBlockHeader m_header
block header
UINT32 m_valuePos
current position in m_value
UINT32 ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32 *sigBits, UINT32 *refBits, UINT32 *signBits)
DataT m_value[BufferSize]
output buffer of values with index m_valuePos
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
UINT32 ReadEncodedData(UINT8 *target, UINT32 len) const
CPGFStream * m_stream
input PGF stream
int m_macroBlocksAvailable
number of decoded macro blocks (including currently used macro block)
void ReadMacroBlock(CMacroBlock *block)
throws IOException
UINT64 m_startPos
stream position at the beginning of the PGF pre-header
void Partition(CSubband *band, int quantParam, int width, int height, int startPos, int pitch)
UINT64 m_streamSizeEstimation
estimation of stream size
void DecodeInterleaved(CWaveletTransform *wtChannel, int level, int quantParam)
CMacroBlock ** m_macroBlocks
array of macroblocks
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)
CDecoder(CPGFStream *stream, PGFPreHeader &preHeader, PGFHeader &header, PGFPostHeader &postHeader, UINT32 *&levelLength, UINT64 &userDataPos, bool useOMP, UINT32 userDataPolicy)
void DequantizeValue(CSubband *band, UINT32 bandPos, int quantParam)
Abstract stream base class.
virtual void SetPos(short posMode, INT64 posOff)=0
virtual UINT64 GetPos() const =0
virtual void Read(int *count, void *buffer)=0
void SetData(UINT32 pos, DataT v)
OSError error
operating system error code
char magic[3]
PGF identification = "PGF".
UINT8 version
PGF version.