libpgf 6.14.12
PGF - Progressive Graphics File
Loading...
Searching...
No Matches
CDecoder::CMacroBlock Class Reference

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

Public Member Functions

 CMacroBlock ()
 
bool IsCompletelyRead () const
 
void BitplaneDecode ()
 

Public Attributes

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

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

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

◆ CMacroBlock()

CDecoder::CMacroBlock::CMacroBlock ( )
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#pragma warning( suppress : 4351 )
59 , m_value()
60 , m_codeBuffer()
61 , m_valuePos(0)
63 {
64 }
ROIBlockHeader m_header
block header
Definition: Decoder.h:77
UINT32 m_valuePos
current position in m_value
Definition: Decoder.h:80
DataT m_value[BufferSize]
output buffer of values with index m_valuePos
Definition: Decoder.h:78
UINT32 m_codeBuffer[CodeBufferLen]
input buffer for encoded bitstream
Definition: Decoder.h:79
bool m_sigFlagVector[BufferSize+1]
Definition: Decoder.h:89

Member Function Documentation

◆ BitplaneDecode()

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 620 of file Decoder.cpp.

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

◆ ComposeBitplane()

UINT32 CDecoder::CMacroBlock::ComposeBitplane ( UINT32  bufferSize,
DataT  planeMask,
UINT32 *  sigBits,
UINT32 *  refBits,
UINT32 *  signBits 
)
private

Definition at line 735 of file Decoder.cpp.

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

◆ ComposeBitplaneRLD() [1/2]

UINT32 CDecoder::CMacroBlock::ComposeBitplaneRLD ( UINT32  bufferSize,
DataT  planeMask,
UINT32 *  sigBits,
UINT32 *  refBits,
UINT32  signPos 
)
private

Definition at line 901 of file Decoder.cpp.

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

◆ ComposeBitplaneRLD() [2/2]

UINT32 CDecoder::CMacroBlock::ComposeBitplaneRLD ( UINT32  bufferSize,
DataT  planeMask,
UINT32  sigPos,
UINT32 *  refBits 
)
private

Definition at line 798 of file Decoder.cpp.

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

◆ IsCompletelyRead()

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 69 of file Decoder.h.

69{ return m_valuePos >= m_header.rbh.bufferSize; }

◆ SetBitAtPos()

void CDecoder::CMacroBlock::SetBitAtPos ( UINT32  pos,
DataT  planeMask 
)
inlineprivate

Definition at line 86 of file Decoder.h.

86{ (m_value[pos] >= 0) ? m_value[pos] |= planeMask : m_value[pos] -= planeMask; }

◆ SetSign()

void CDecoder::CMacroBlock::SetSign ( UINT32  pos,
bool  sign 
)
inlineprivate

Definition at line 87 of file Decoder.h.

87{ m_value[pos] = -m_value[pos]*sign + m_value[pos]*(!sign); }

Member Data Documentation

◆ m_codeBuffer

UINT32 CDecoder::CMacroBlock::m_codeBuffer[CodeBufferLen]

input buffer for encoded bitstream

Definition at line 79 of file Decoder.h.

◆ m_header

ROIBlockHeader CDecoder::CMacroBlock::m_header

block header

Definition at line 77 of file Decoder.h.

◆ m_sigFlagVector

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

Definition at line 89 of file Decoder.h.

◆ m_value

DataT CDecoder::CMacroBlock::m_value[BufferSize]

output buffer of values with index m_valuePos

Definition at line 78 of file Decoder.h.

◆ m_valuePos

UINT32 CDecoder::CMacroBlock::m_valuePos

current position in m_value

Definition at line 80 of file Decoder.h.


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