libpgf  6.12.24
PGF - Progressive Graphics File
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CDecoder::CMacroBlock Class Reference

A macro block is a decoding unit of fixed size (uncoded) More...

Public Member Functions

 CMacroBlock (CDecoder *decoder)
 
bool IsCompletelyRead () const
 
void BitplaneDecode ()
 

Public Attributes

ROIBlockHeader m_header
 block header More...
 
DataT m_value [BufferSize]
 output buffer of values with index m_valuePos More...
 
UINT32 m_codeBuffer [CodeBufferLen]
 input buffer for encoded bitstream More...
 
UINT32 m_valuePos
 current position in m_value More...
 

Private Member Functions

UINT32 ComposeBitplane (UINT32 bufferSize, DataT planeMask, UINT32 *sigBits, UINT32 *refBits, UINT32 *signBits)
 
UINT32 ComposeBitplaneRLD (UINT32 bufferSize, DataT planeMask, UINT32 sigPos, UINT32 *refBits)
 
UINT32 ComposeBitplaneRLD (UINT32 bufferSize, DataT planeMask, UINT32 *sigBits, UINT32 *refBits, UINT32 signPos)
 
void SetBitAtPos (UINT32 pos, DataT planeMask)
 
void SetSign (UINT32 pos, bool sign)
 

Private Attributes

CDecoderm_decoder
 
bool m_sigFlagVector [BufferSize+1]
 

Detailed Description

A macro block is a decoding unit of fixed size (uncoded)

PGF decoder macro block class.

Author
C. Stamm, I. Bauersachs

Definition at line 51 of file Decoder.h.

Constructor & Destructor Documentation

CDecoder::CMacroBlock::CMacroBlock ( CDecoder decoder)
inline

Constructor: Initializes new macro block.

Parameters
decoderPointer to outer class.

Definition at line 56 of file Decoder.h.

57  : m_header(0) // makes sure that IsCompletelyRead() returns true for an empty macro block
58  , m_valuePos(0)
59  , m_decoder(decoder)
60  {
61  ASSERT(m_decoder);
62  }
UINT32 m_valuePos
current position in m_value
Definition: Decoder.h:78
ROIBlockHeader m_header
block header
Definition: Decoder.h:75
CDecoder * m_decoder
Definition: Decoder.h:87

Member Function Documentation

void CDecoder::CMacroBlock::BitplaneDecode ( )

Decodes already read input data into this macro block. Several macro blocks can be decoded in parallel. Call CDecoder::ReadMacroBlock before this method.

Definition at line 618 of file Decoder.cpp.

618  {
619  UINT32 bufferSize = m_header.rbh.bufferSize; ASSERT(bufferSize <= BufferSize);
620 
621  UINT32 nPlanes;
622  UINT32 codePos = 0, codeLen, sigLen, sigPos, signLen, signPos;
623  DataT planeMask;
624 
625  // clear significance vector
626  for (UINT32 k=0; k < bufferSize; k++) {
627  m_sigFlagVector[k] = false;
628  }
629  m_sigFlagVector[bufferSize] = true; // sentinel
630 
631  // clear output buffer
632  for (UINT32 k=0; k < BufferSize; k++) {
633  m_value[k] = 0;
634  }
635 
636  // read number of bit planes
637  // <nPlanes>
639  codePos += MaxBitPlanesLog;
640 
641  // loop through all bit planes
642  if (nPlanes == 0) nPlanes = MaxBitPlanes + 1;
643  ASSERT(0 < nPlanes && nPlanes <= MaxBitPlanes + 1);
644  planeMask = 1 << (nPlanes - 1);
645 
646  for (int plane = nPlanes - 1; plane >= 0; plane--) {
647  // read RL code
648  if (GetBit(m_codeBuffer, codePos)) {
649  // RL coding of sigBits is used
650  // <1><codeLen><codedSigAndSignBits>_<refBits>
651  codePos++;
652 
653  // read codeLen
654  codeLen = GetValueBlock(m_codeBuffer, codePos, RLblockSizeLen); ASSERT(codeLen <= MaxCodeLen);
655 
656  // position of encoded sigBits and signBits
657  sigPos = codePos + RLblockSizeLen; ASSERT(sigPos < CodeBufferBitLen);
658 
659  // refinement bits
660  codePos = AlignWordPos(sigPos + codeLen); ASSERT(codePos < CodeBufferBitLen);
661 
662  // run-length decode significant bits and signs from m_codeBuffer and
663  // read refinement bits from m_codeBuffer and compose bit plane
664  sigLen = ComposeBitplaneRLD(bufferSize, planeMask, sigPos, &m_codeBuffer[codePos >> WordWidthLog]);
665 
666  } else {
667  // no RL coding is used for sigBits and signBits together
668  // <0><sigLen>
669  codePos++;
670 
671  // read sigLen
672  sigLen = GetValueBlock(m_codeBuffer, codePos, RLblockSizeLen); ASSERT(sigLen <= MaxCodeLen);
673  codePos += RLblockSizeLen; ASSERT(codePos < CodeBufferBitLen);
674 
675  // read RL code for signBits
676  if (GetBit(m_codeBuffer, codePos)) {
677  // RL coding is used just for signBits
678  // <1><codeLen><codedSignBits>_<sigBits>_<refBits>
679  codePos++;
680 
681  // read codeLen
682  codeLen = GetValueBlock(m_codeBuffer, codePos, RLblockSizeLen); ASSERT(codeLen <= MaxCodeLen);
683 
684  // sign bits
685  signPos = codePos + RLblockSizeLen; ASSERT(signPos < CodeBufferBitLen);
686 
687  // significant bits
688  sigPos = AlignWordPos(signPos + codeLen); ASSERT(sigPos < CodeBufferBitLen);
689 
690  // refinement bits
691  codePos = AlignWordPos(sigPos + sigLen); ASSERT(codePos < CodeBufferBitLen);
692 
693  // read significant and refinement bitset from m_codeBuffer
694  sigLen = ComposeBitplaneRLD(bufferSize, planeMask, &m_codeBuffer[sigPos >> WordWidthLog], &m_codeBuffer[codePos >> WordWidthLog], signPos);
695 
696  } else {
697  // RL coding of signBits was not efficient and therefore not used
698  // <0><signLen>_<signBits>_<sigBits>_<refBits>
699  codePos++;
700 
701  // read signLen
702  signLen = GetValueBlock(m_codeBuffer, codePos, RLblockSizeLen); ASSERT(signLen <= MaxCodeLen);
703 
704  // sign bits
705  signPos = AlignWordPos(codePos + RLblockSizeLen); ASSERT(signPos < CodeBufferBitLen);
706 
707  // significant bits
708  sigPos = AlignWordPos(signPos + signLen); ASSERT(sigPos < CodeBufferBitLen);
709 
710  // refinement bits
711  codePos = AlignWordPos(sigPos + sigLen); ASSERT(codePos < CodeBufferBitLen);
712 
713  // read significant and refinement bitset from m_codeBuffer
714  sigLen = ComposeBitplane(bufferSize, planeMask, &m_codeBuffer[sigPos >> WordWidthLog], &m_codeBuffer[codePos >> WordWidthLog], &m_codeBuffer[signPos >> WordWidthLog]);
715  }
716  }
717 
718  // start of next chunk
719  codePos = AlignWordPos(codePos + bufferSize - sigLen); ASSERT(codePos < CodeBufferBitLen);
720 
721  // next plane
722  planeMask >>= 1;
723  }
724 
725  m_valuePos = 0;
726 }
bool GetBit(UINT32 *stream, UINT32 pos)
Definition: BitStream.h:65
struct ROIBlockHeader::RBH rbh
ROI block header.
UINT16 bufferSize
number of uncoded UINT32 values in a block
Definition: PGFtypes.h:167
UINT32 ComposeBitplane(UINT32 bufferSize, DataT planeMask, UINT32 *sigBits, UINT32 *refBits, UINT32 *signBits)
Definition: Decoder.cpp:733
#define MaxCodeLen
max length of RL encoded block
Definition: Decoder.cpp:59
UINT32 AlignWordPos(UINT32 pos)
Definition: BitStream.h:260
INT32 DataT
Definition: PGFtypes.h:219
UINT32 m_valuePos
current position in m_value
Definition: Decoder.h:78
#define BufferSize
must be a multiple of WordWidth
Definition: PGFtypes.h:77
#define RLblockSizeLen
block size length (&lt; 16): ld(BufferSize) &lt; RLblockSizeLen &lt;= 2*ld(BufferSize)
Definition: PGFtypes.h:78
DataT m_value[BufferSize]
output buffer of values with index m_valuePos
Definition: Decoder.h:76
#define WordWidthLog
ld of WordWidth
Definition: PGFplatform.h:74
#define MaxBitPlanesLog
number of bits to code the maximum number of bit planes (in 32 or 16 bit mode)
Definition: PGFtypes.h:86
UINT32 GetValueBlock(UINT32 *stream, UINT32 pos, UINT32 k)
Definition: BitStream.h:128
#define MaxBitPlanes
maximum number of bit planes of m_value: 32 minus sign bit
Definition: PGFtypes.h:82
UINT32 ComposeBitplaneRLD(UINT32 bufferSize, DataT planeMask, UINT32 sigPos, UINT32 *refBits)
Definition: Decoder.cpp:796
ROIBlockHeader m_header
block header
Definition: Decoder.h:75
#define CodeBufferBitLen
max number of bits in m_codeBuffer
Definition: Decoder.cpp:58
bool m_sigFlagVector[BufferSize+1]
Definition: Decoder.h:88
UINT32 m_codeBuffer[CodeBufferLen]
input buffer for encoded bitstream
Definition: Decoder.h:77
UINT32 CDecoder::CMacroBlock::ComposeBitplane ( UINT32  bufferSize,
DataT  planeMask,
UINT32 *  sigBits,
UINT32 *  refBits,
UINT32 *  signBits 
)
private

Definition at line 733 of file Decoder.cpp.

733  {
734  ASSERT(sigBits);
735  ASSERT(refBits);
736  ASSERT(signBits);
737 
738  UINT32 valPos = 0, signPos = 0, refPos = 0;
739  UINT32 sigPos = 0, sigEnd;
740  UINT32 zerocnt;
741 
742  while (valPos < bufferSize) {
743  // search next 1 in m_sigFlagVector using searching with sentinel
744  sigEnd = valPos;
745  while(!m_sigFlagVector[sigEnd]) { sigEnd++; }
746  sigEnd -= valPos;
747  sigEnd += sigPos;
748 
749  // search 1's in sigBits[sigPos..sigEnd)
750  // these 1's are significant bits
751  while (sigPos < sigEnd) {
752  // search 0's
753  zerocnt = SeekBitRange(sigBits, sigPos, sigEnd - sigPos);
754  sigPos += zerocnt;
755  valPos += zerocnt;
756  if (sigPos < sigEnd) {
757  // write bit to m_value
758  SetBitAtPos(valPos, planeMask);
759 
760  // copy sign bit
761  SetSign(valPos, GetBit(signBits, signPos++));
762 
763  // update significance flag vector
764  m_sigFlagVector[valPos++] = true;
765  sigPos++;
766  }
767  }
768  // refinement bit
769  if (valPos < bufferSize) {
770  // write one refinement bit
771  if (GetBit(refBits, refPos)) {
772  SetBitAtPos(valPos, planeMask);
773  }
774  refPos++;
775  valPos++;
776  }
777  }
778  ASSERT(sigPos <= bufferSize);
779  ASSERT(refPos <= bufferSize);
780  ASSERT(signPos <= bufferSize);
781  ASSERT(valPos == bufferSize);
782 
783  return sigPos;
784 }
bool GetBit(UINT32 *stream, UINT32 pos)
Definition: BitStream.h:65
void SetBitAtPos(UINT32 pos, DataT planeMask)
Definition: Decoder.h:84
void SetSign(UINT32 pos, bool sign)
Definition: Decoder.h:85
UINT32 SeekBitRange(UINT32 *stream, UINT32 pos, UINT32 len)
Definition: BitStream.h:206
bool m_sigFlagVector[BufferSize+1]
Definition: Decoder.h:88
UINT32 CDecoder::CMacroBlock::ComposeBitplaneRLD ( UINT32  bufferSize,
DataT  planeMask,
UINT32  sigPos,
UINT32 *  refBits 
)
private

Definition at line 796 of file Decoder.cpp.

796  {
797  ASSERT(refBits);
798 
799  UINT32 valPos = 0, refPos = 0;
800  UINT32 sigPos = 0, sigEnd;
801  UINT32 k = 3;
802  UINT32 runlen = 1 << k; // = 2^k
803  UINT32 count = 0, rest = 0;
804  bool set1 = false;
805 
806  while (valPos < bufferSize) {
807  // search next 1 in m_sigFlagVector using searching with sentinel
808  sigEnd = valPos;
809  while(!m_sigFlagVector[sigEnd]) { sigEnd++; }
810  sigEnd -= valPos;
811  sigEnd += sigPos;
812 
813  while (sigPos < sigEnd) {
814  if (rest || set1) {
815  // rest of last run
816  sigPos += rest;
817  valPos += rest;
818  rest = 0;
819  } else {
820  // decode significant bits
821  if (GetBit(m_codeBuffer, codePos++)) {
822  // extract counter and generate zero run of length count
823  if (k > 0) {
824  // extract counter
825  count = GetValueBlock(m_codeBuffer, codePos, k);
826  codePos += k;
827  if (count > 0) {
828  sigPos += count;
829  valPos += count;
830  }
831 
832  // adapt k (half run-length interval)
833  k--;
834  runlen >>= 1;
835  }
836 
837  set1 = true;
838 
839  } else {
840  // generate zero run of length 2^k
841  sigPos += runlen;
842  valPos += runlen;
843 
844  // adapt k (double run-length interval)
845  if (k < WordWidth) {
846  k++;
847  runlen <<= 1;
848  }
849  }
850  }
851 
852  if (sigPos < sigEnd) {
853  if (set1) {
854  set1 = false;
855 
856  // write 1 bit
857  SetBitAtPos(valPos, planeMask);
858 
859  // set sign bit
860  SetSign(valPos, GetBit(m_codeBuffer, codePos++));
861 
862  // update significance flag vector
863  m_sigFlagVector[valPos++] = true;
864  sigPos++;
865  }
866  } else {
867  rest = sigPos - sigEnd;
868  sigPos = sigEnd;
869  valPos -= rest;
870  }
871 
872  }
873 
874  // refinement bit
875  if (valPos < bufferSize) {
876  // write one refinement bit
877  if (GetBit(refBits, refPos)) {
878  SetBitAtPos(valPos, planeMask);
879  }
880  refPos++;
881  valPos++;
882  }
883  }
884  ASSERT(sigPos <= bufferSize);
885  ASSERT(refPos <= bufferSize);
886  ASSERT(valPos == bufferSize);
887 
888  return sigPos;
889 }
bool GetBit(UINT32 *stream, UINT32 pos)
Definition: BitStream.h:65
void SetBitAtPos(UINT32 pos, DataT planeMask)
Definition: Decoder.h:84
void SetSign(UINT32 pos, bool sign)
Definition: Decoder.h:85
UINT32 GetValueBlock(UINT32 *stream, UINT32 pos, UINT32 k)
Definition: BitStream.h:128
bool m_sigFlagVector[BufferSize+1]
Definition: Decoder.h:88
#define WordWidth
WordBytes*8.
Definition: PGFplatform.h:73
UINT32 m_codeBuffer[CodeBufferLen]
input buffer for encoded bitstream
Definition: Decoder.h:77
UINT32 CDecoder::CMacroBlock::ComposeBitplaneRLD ( UINT32  bufferSize,
DataT  planeMask,
UINT32 *  sigBits,
UINT32 *  refBits,
UINT32  signPos 
)
private

Definition at line 899 of file Decoder.cpp.

899  {
900  ASSERT(sigBits);
901  ASSERT(refBits);
902 
903  UINT32 valPos = 0, refPos = 0;
904  UINT32 sigPos = 0, sigEnd;
905  UINT32 zerocnt, count = 0;
906  UINT32 k = 0;
907  UINT32 runlen = 1 << k; // = 2^k
908  bool signBit = false;
909  bool zeroAfterRun = false;
910 
911  while (valPos < bufferSize) {
912  // search next 1 in m_sigFlagVector using searching with sentinel
913  sigEnd = valPos;
914  while(!m_sigFlagVector[sigEnd]) { sigEnd++; }
915  sigEnd -= valPos;
916  sigEnd += sigPos;
917 
918  // search 1's in sigBits[sigPos..sigEnd)
919  // these 1's are significant bits
920  while (sigPos < sigEnd) {
921  // search 0's
922  zerocnt = SeekBitRange(sigBits, sigPos, sigEnd - sigPos);
923  sigPos += zerocnt;
924  valPos += zerocnt;
925  if (sigPos < sigEnd) {
926  // write bit to m_value
927  SetBitAtPos(valPos, planeMask);
928 
929  // check sign bit
930  if (count == 0) {
931  // all 1's have been set
932  if (zeroAfterRun) {
933  // finish the run with a 0
934  signBit = false;
935  zeroAfterRun = false;
936  } else {
937  // decode next sign bit
938  if (GetBit(m_codeBuffer, signPos++)) {
939  // generate 1's run of length 2^k
940  count = runlen - 1;
941  signBit = true;
942 
943  // adapt k (double run-length interval)
944  if (k < WordWidth) {
945  k++;
946  runlen <<= 1;
947  }
948  } else {
949  // extract counter and generate 1's run of length count
950  if (k > 0) {
951  // extract counter
952  count = GetValueBlock(m_codeBuffer, signPos, k);
953  signPos += k;
954 
955  // adapt k (half run-length interval)
956  k--;
957  runlen >>= 1;
958  }
959  if (count > 0) {
960  count--;
961  signBit = true;
962  zeroAfterRun = true;
963  } else {
964  signBit = false;
965  }
966  }
967  }
968  } else {
969  ASSERT(count > 0);
970  ASSERT(signBit);
971  count--;
972  }
973 
974  // copy sign bit
975  SetSign(valPos, signBit);
976 
977  // update significance flag vector
978  m_sigFlagVector[valPos++] = true;
979  sigPos++;
980  }
981  }
982 
983  // refinement bit
984  if (valPos < bufferSize) {
985  // write one refinement bit
986  if (GetBit(refBits, refPos)) {
987  SetBitAtPos(valPos, planeMask);
988  }
989  refPos++;
990  valPos++;
991  }
992  }
993  ASSERT(sigPos <= bufferSize);
994  ASSERT(refPos <= bufferSize);
995  ASSERT(valPos == bufferSize);
996 
997  return sigPos;
998 }
bool GetBit(UINT32 *stream, UINT32 pos)
Definition: BitStream.h:65
void SetBitAtPos(UINT32 pos, DataT planeMask)
Definition: Decoder.h:84
void SetSign(UINT32 pos, bool sign)
Definition: Decoder.h:85
UINT32 SeekBitRange(UINT32 *stream, UINT32 pos, UINT32 len)
Definition: BitStream.h:206
UINT32 GetValueBlock(UINT32 *stream, UINT32 pos, UINT32 k)
Definition: BitStream.h:128
bool m_sigFlagVector[BufferSize+1]
Definition: Decoder.h:88
#define WordWidth
WordBytes*8.
Definition: PGFplatform.h:73
UINT32 m_codeBuffer[CodeBufferLen]
input buffer for encoded bitstream
Definition: Decoder.h:77
bool CDecoder::CMacroBlock::IsCompletelyRead ( ) const
inline

Returns true if this macro block has been completely read.

Returns
true if current value position is at block end

Definition at line 67 of file Decoder.h.

67 { return m_valuePos >= m_header.rbh.bufferSize; }
struct ROIBlockHeader::RBH rbh
ROI block header.
UINT16 bufferSize
number of uncoded UINT32 values in a block
Definition: PGFtypes.h:167
UINT32 m_valuePos
current position in m_value
Definition: Decoder.h:78
ROIBlockHeader m_header
block header
Definition: Decoder.h:75
void CDecoder::CMacroBlock::SetBitAtPos ( UINT32  pos,
DataT  planeMask 
)
inlineprivate

Definition at line 84 of file Decoder.h.

84 { (m_value[pos] >= 0) ? m_value[pos] |= planeMask : m_value[pos] -= planeMask; }
DataT m_value[BufferSize]
output buffer of values with index m_valuePos
Definition: Decoder.h:76
void CDecoder::CMacroBlock::SetSign ( UINT32  pos,
bool  sign 
)
inlineprivate

Definition at line 85 of file Decoder.h.

85 { m_value[pos] = -m_value[pos]*sign + m_value[pos]*(!sign); }
DataT m_value[BufferSize]
output buffer of values with index m_valuePos
Definition: Decoder.h:76

Member Data Documentation

UINT32 CDecoder::CMacroBlock::m_codeBuffer[CodeBufferLen]

input buffer for encoded bitstream

Definition at line 77 of file Decoder.h.

CDecoder* CDecoder::CMacroBlock::m_decoder
private

Definition at line 87 of file Decoder.h.

ROIBlockHeader CDecoder::CMacroBlock::m_header

block header

Definition at line 75 of file Decoder.h.

bool CDecoder::CMacroBlock::m_sigFlagVector[BufferSize+1]
private

Definition at line 88 of file Decoder.h.

DataT CDecoder::CMacroBlock::m_value[BufferSize]

output buffer of values with index m_valuePos

Definition at line 76 of file Decoder.h.

UINT32 CDecoder::CMacroBlock::m_valuePos

current position in m_value

Definition at line 78 of file Decoder.h.


The documentation for this class was generated from the following files: