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

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

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

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

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

◆ 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: