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

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

Public Member Functions

 CMacroBlock ()
 Constructor: Initializes new macro block.
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_t m_codeBuffer [CodeBufferLen]
 input buffer for encoded bitstream
uint32_t m_valuePos
 current position in m_value

Private Member Functions

uint32_t ComposeBitplane (uint32_t bufferSize, DataT planeMask, uint32_t *sigBits, uint32_t *refBits, uint32_t *signBits)
uint32_t ComposeBitplaneRLD (uint32_t bufferSize, DataT planeMask, uint32_t sigPos, uint32_t *refBits)
uint32_t ComposeBitplaneRLD (uint32_t bufferSize, DataT planeMask, uint32_t *sigBits, uint32_t *refBits, uint32_t signPos)
void SetBitAtPos (uint32_t pos, DataT planeMask)
void SetSign (uint32_t 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 46 of file Decoder.h.

Constructor & Destructor Documentation

◆ CMacroBlock()

pgf::CDecoder::CMacroBlock::CMacroBlock ( )
inline

Constructor: Initializes new macro block.

Definition at line 50 of file Decoder.h.

51 : m_header(0) // makes sure that IsCompletelyRead() returns true for an empty macro block
52#pragma warning( suppress : 4351 )
53 , m_value()
54 , m_codeBuffer()
55 , m_valuePos(0)
57 {
58 }
DataT m_value[BufferSize]
output buffer of values with index m_valuePos
Definition Decoder.h:72
bool m_sigFlagVector[BufferSize+1]
Definition Decoder.h:83
uint32_t m_valuePos
current position in m_value
Definition Decoder.h:74
ROIBlockHeader m_header
block header
Definition Decoder.h:71
uint32_t m_codeBuffer[CodeBufferLen]
input buffer for encoded bitstream
Definition Decoder.h:73

Member Function Documentation

◆ BitplaneDecode()

void pgf::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 651 of file Decoder.cpp.

651 {
652 uint32_t bufferSize = m_header.rbh.bufferSize; ASSERT(bufferSize <= BufferSize);
653
654 // clear significance vector
655 for (uint32_t k = 0; k < bufferSize; k++) {
656 m_sigFlagVector[k] = false;
657 }
658 m_sigFlagVector[bufferSize] = true; // sentinel
659
660 // clear output buffer
661 for (uint32_t k = 0; k < BufferSize; k++) {
662 m_value[k] = 0;
663 }
664
665 // read number of bit planes
666 // <nPlanes>
667 uint32_t nPlanes = GetValueBlock(m_codeBuffer, 0, MaxBitPlanesLog);
668 uint32_t codePos = MaxBitPlanesLog;
669
670 // loop through all bit planes
671 if (nPlanes == 0) nPlanes = MaxBitPlanes + 1;
672 ASSERT(0 < nPlanes && nPlanes <= MaxBitPlanes + 1);
673 DataT planeMask = 1 << (nPlanes - 1);
674
675 for (int plane = nPlanes - 1; plane >= 0; plane--) {
676 uint32_t sigLen = 0;
677
678 // read RL code
679 if (GetBit(m_codeBuffer, codePos)) {
680 // RL coding of sigBits is used
681 // <1><codeLen><codedSigAndSignBits>_<refBits>
682 codePos++;
683
684 // read codeLen
685 uint32_t codeLen = GetValueBlock(m_codeBuffer, codePos, RLblockSizeLen); ASSERT(codeLen <= MaxCodeLen);
686
687 // position of encoded sigBits and signBits
688 uint32_t sigPos = codePos + RLblockSizeLen; ASSERT(sigPos < CodeBufferBitLen);
689
690 // refinement bits
691 codePos = AlignWordPos(sigPos + codeLen); ASSERT(codePos < CodeBufferBitLen);
692
693 // run-length decode significant bits and signs from m_codeBuffer and
694 // read refinement bits from m_codeBuffer and compose bit plane
695 sigLen = ComposeBitplaneRLD(bufferSize, planeMask, sigPos, &m_codeBuffer[codePos >> WordWidthLog]);
696
697 } else {
698 // no RL coding is used for sigBits and signBits together
699 // <0><sigLen>
700 codePos++;
701
702 // read sigLen
703 sigLen = GetValueBlock(m_codeBuffer, codePos, RLblockSizeLen); ASSERT(sigLen <= MaxCodeLen);
704 codePos += RLblockSizeLen; ASSERT(codePos < CodeBufferBitLen);
705
706 // read RL code for signBits
707 if (GetBit(m_codeBuffer, codePos)) {
708 // RL coding is used just for signBits
709 // <1><codeLen><codedSignBits>_<sigBits>_<refBits>
710 codePos++;
711
712 // read codeLen
713 uint32_t codeLen = GetValueBlock(m_codeBuffer, codePos, RLblockSizeLen); ASSERT(codeLen <= MaxCodeLen);
714
715 // sign bits
716 uint32_t signPos = codePos + RLblockSizeLen; ASSERT(signPos < CodeBufferBitLen);
717
718 // significant bits
719 uint32_t sigPos = AlignWordPos(signPos + codeLen); ASSERT(sigPos < CodeBufferBitLen);
720
721 // refinement bits
722 codePos = AlignWordPos(sigPos + sigLen); ASSERT(codePos < CodeBufferBitLen);
723
724 // read significant and refinement bitset from m_codeBuffer
725 sigLen = ComposeBitplaneRLD(bufferSize, planeMask, &m_codeBuffer[sigPos >> WordWidthLog], &m_codeBuffer[codePos >> WordWidthLog], signPos);
726
727 } else {
728 // RL coding of signBits was not efficient and therefore not used
729 // <0><signLen>_<signBits>_<sigBits>_<refBits>
730 codePos++;
731
732 // read signLen
733 uint32_t signLen = GetValueBlock(m_codeBuffer, codePos, RLblockSizeLen); ASSERT(signLen <= MaxCodeLen);
734
735 // sign bits
736 uint32_t signPos = AlignWordPos(codePos + RLblockSizeLen); ASSERT(signPos < CodeBufferBitLen);
737
738 // significant bits
739 uint32_t sigPos = AlignWordPos(signPos + signLen); ASSERT(sigPos < CodeBufferBitLen);
740
741 // refinement bits
742 codePos = AlignWordPos(sigPos + sigLen); ASSERT(codePos < CodeBufferBitLen);
743
744 // read significant and refinement bitset from m_codeBuffer
745 sigLen = ComposeBitplane(bufferSize, planeMask, &m_codeBuffer[sigPos >> WordWidthLog], &m_codeBuffer[codePos >> WordWidthLog], &m_codeBuffer[signPos >> WordWidthLog]);
746 }
747 }
748
749 // start of next chunk
750 codePos = AlignWordPos(codePos + bufferSize - sigLen); ASSERT(codePos < CodeBufferBitLen);
751
752 // next plane
753 planeMask >>= 1;
754 }
755
756 m_valuePos = 0;
757 }
constexpr uint32_t WordWidthLog
ld of WordWidth
Definition PGFplatform.h:74
uint32_t ComposeBitplane(uint32_t bufferSize, DataT planeMask, uint32_t *sigBits, uint32_t *refBits, uint32_t *signBits)
Definition Decoder.cpp:764
uint32_t ComposeBitplaneRLD(uint32_t bufferSize, DataT planeMask, uint32_t sigPos, uint32_t *refBits)
Definition Decoder.cpp:825
constexpr int MaxBitPlanes
maximum number of bit planes of m_value: 32 minus sign bit
Definition PGFtypes.h:91
constexpr uint32_t CodeBufferBitLen
max number of bits in m_codeBuffer
Definition Decoder.cpp:59
bool GetBit(uint32_t *stream, uint32_t pos)
Definition BitStream.h:79
uint32_t GetValueBlock(uint32_t *stream, uint32_t pos, uint32_t k)
Definition BitStream.h:142
uint32_t AlignWordPos(uint32_t pos)
Definition BitStream.h:328
int32_t DataT
Definition PGFtypes.h:367
constexpr int RLblockSizeLen
block size length (< 16): ld(BufferSize) < RLblockSizeLen <= 2*ld(BufferSize)
Definition PGFtypes.h:87
constexpr int MaxBitPlanesLog
number of bits to code the maximum number of bit planes (in 32 or 16 bit mode)
Definition PGFtypes.h:95
constexpr uint32_t MaxCodeLen
max length of RL encoded block
Definition Decoder.cpp:60
constexpr uint32_t BufferSize
must be a multiple of WordWidth, BufferSize <= UINT16_MAX
Definition PGFtypes.h:84
uint16_t bufferSize
number of uncoded uint32_t values in a block
Definition PGFtypes.h:219
struct pgf::ROIBlockHeader::RBH rbh
ROI block header.

◆ ComposeBitplane()

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

Definition at line 764 of file Decoder.cpp.

764 {
765 ASSERT(sigBits);
766 ASSERT(refBits);
767 ASSERT(signBits);
768
769 uint32_t valPos = 0, signPos = 0, refPos = 0, sigPos = 0;
770
771 while (valPos < bufferSize) {
772 // search next 1 in m_sigFlagVector using searching with sentinel
773 uint32_t sigEnd = valPos;
774 while (!m_sigFlagVector[sigEnd]) { sigEnd++; }
775 sigEnd -= valPos;
776 sigEnd += sigPos;
777
778 // search 1's in sigBits[sigPos..sigEnd)
779 // these 1's are significant bits
780 while (sigPos < sigEnd) {
781 // search 0's
782 uint32_t zerocnt = SeekBitRange(sigBits, sigPos, sigEnd - sigPos);
783 sigPos += zerocnt;
784 valPos += zerocnt;
785 if (sigPos < sigEnd) {
786 // write bit to m_value
787 SetBitAtPos(valPos, planeMask);
788
789 // copy sign bit
790 SetSign(valPos, GetBit(signBits, signPos++));
791
792 // update significance flag vector
793 m_sigFlagVector[valPos++] = true;
794 sigPos++;
795 }
796 }
797 // refinement bit
798 if (valPos < bufferSize) {
799 // write one refinement bit
800 if (GetBit(refBits, refPos)) {
801 SetBitAtPos(valPos, planeMask);
802 }
803 refPos++;
804 valPos++;
805 }
806 }
807 ASSERT(sigPos <= bufferSize);
808 ASSERT(refPos <= bufferSize);
809 ASSERT(signPos <= bufferSize);
810 ASSERT(valPos == bufferSize);
811
812 return sigPos;
813 }
void SetBitAtPos(uint32_t pos, DataT planeMask)
Definition Decoder.h:80
void SetSign(uint32_t pos, bool sign)
Definition Decoder.h:81
uint32_t SeekBitRange(uint32_t *stream, uint32_t pos, uint32_t len)
Definition BitStream.h:220

◆ ComposeBitplaneRLD() [1/2]

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

Definition at line 928 of file Decoder.cpp.

928 {
929 ASSERT(sigBits);
930 ASSERT(refBits);
931
932 uint32_t valPos = 0, refPos = 0;
933 uint32_t sigPos = 0, sigEnd;
934 uint32_t zerocnt, count = 0;
935 uint32_t k = 0;
936 uint32_t runlen = 1 << k; // = 2^k
937 bool signBit = false;
938 bool zeroAfterRun = false;
939
940 while (valPos < bufferSize) {
941 // search next 1 in m_sigFlagVector using searching with sentinel
942 sigEnd = valPos;
943 while (!m_sigFlagVector[sigEnd]) { sigEnd++; }
944 sigEnd -= valPos;
945 sigEnd += sigPos;
946
947 // search 1's in sigBits[sigPos..sigEnd)
948 // these 1's are significant bits
949 while (sigPos < sigEnd) {
950 // search 0's
951 zerocnt = SeekBitRange(sigBits, sigPos, sigEnd - sigPos);
952 sigPos += zerocnt;
953 valPos += zerocnt;
954 if (sigPos < sigEnd) {
955 // write bit to m_value
956 SetBitAtPos(valPos, planeMask);
957
958 // check sign bit
959 if (count == 0) {
960 // all 1's have been set
961 if (zeroAfterRun) {
962 // finish the run with a 0
963 signBit = false;
964 zeroAfterRun = false;
965 } else {
966 // decode next sign bit
967 if (GetBit(m_codeBuffer, signPos++)) {
968 // generate 1's run of length 2^k
969 count = runlen - 1;
970 signBit = true;
971
972 // adapt k (double run-length interval)
973 if (k < WordWidth) {
974 k++;
975 runlen <<= 1;
976 }
977 } else {
978 // extract counter and generate 1's run of length count
979 if (k > 0) {
980 // extract counter
981 count = GetValueBlock(m_codeBuffer, signPos, k);
982 signPos += k;
983
984 // adapt k (half run-length interval)
985 k--;
986 runlen >>= 1;
987 }
988 if (count > 0) {
989 count--;
990 signBit = true;
991 zeroAfterRun = true;
992 } else {
993 signBit = false;
994 }
995 }
996 }
997 } else {
998 ASSERT(count > 0);
999 ASSERT(signBit);
1000 count--;
1001 }
1002
1003 // copy sign bit
1004 SetSign(valPos, signBit);
1005
1006 // update significance flag vector
1007 m_sigFlagVector[valPos++] = true;
1008 sigPos++;
1009 }
1010 }
1011
1012 // refinement bit
1013 if (valPos < bufferSize) {
1014 // write one refinement bit
1015 if (GetBit(refBits, refPos)) {
1016 SetBitAtPos(valPos, planeMask);
1017 }
1018 refPos++;
1019 valPos++;
1020 }
1021 }
1022 ASSERT(sigPos <= bufferSize);
1023 ASSERT(refPos <= bufferSize);
1024 ASSERT(valPos == bufferSize);
1025
1026 return sigPos;
1027 }
constexpr uint32_t WordWidth
WordBytes*8.
Definition PGFplatform.h:73

◆ ComposeBitplaneRLD() [2/2]

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

Definition at line 825 of file Decoder.cpp.

825 {
826 ASSERT(refBits);
827
828 uint32_t valPos = 0, refPos = 0;
829 uint32_t sigPos = 0, sigEnd;
830 uint32_t k = 3;
831 uint32_t runlen = 1 << k; // = 2^k
832 uint32_t count = 0, rest = 0;
833 bool set1 = false;
834
835 while (valPos < bufferSize) {
836 // search next 1 in m_sigFlagVector using searching with sentinel
837 sigEnd = valPos;
838 while (!m_sigFlagVector[sigEnd]) { sigEnd++; }
839 sigEnd -= valPos;
840 sigEnd += sigPos;
841
842 while (sigPos < sigEnd) {
843 if (rest || set1) {
844 // rest of last run
845 sigPos += rest;
846 valPos += rest;
847 rest = 0;
848 } else {
849 // decode significant bits
850 if (GetBit(m_codeBuffer, codePos++)) {
851 // extract counter and generate zero run of length count
852 if (k > 0) {
853 // extract counter
854 count = GetValueBlock(m_codeBuffer, codePos, k);
855 codePos += k;
856 if (count > 0) {
857 sigPos += count;
858 valPos += count;
859 }
860
861 // adapt k (half run-length interval)
862 k--;
863 runlen >>= 1;
864 }
865
866 set1 = true;
867
868 } else {
869 // generate zero run of length 2^k
870 sigPos += runlen;
871 valPos += runlen;
872
873 // adapt k (double run-length interval)
874 if (k < WordWidth) {
875 k++;
876 runlen <<= 1;
877 }
878 }
879 }
880
881 if (sigPos < sigEnd) {
882 if (set1) {
883 set1 = false;
884
885 // write 1 bit
886 SetBitAtPos(valPos, planeMask);
887
888 // set sign bit
889 SetSign(valPos, GetBit(m_codeBuffer, codePos++));
890
891 // update significance flag vector
892 m_sigFlagVector[valPos++] = true;
893 sigPos++;
894 }
895 } else {
896 rest = sigPos - sigEnd;
897 sigPos = sigEnd;
898 valPos -= rest;
899 }
900
901 }
902
903 // refinement bit
904 if (valPos < bufferSize) {
905 // write one refinement bit
906 if (GetBit(refBits, refPos)) {
907 SetBitAtPos(valPos, planeMask);
908 }
909 refPos++;
910 valPos++;
911 }
912 }
913 ASSERT(sigPos <= bufferSize);
914 ASSERT(refPos <= bufferSize);
915 ASSERT(valPos == bufferSize);
916
917 return sigPos;
918 }

◆ IsCompletelyRead()

bool pgf::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 63 of file Decoder.h.

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

◆ SetBitAtPos()

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

Definition at line 80 of file Decoder.h.

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

◆ SetSign()

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

Definition at line 81 of file Decoder.h.

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

Member Data Documentation

◆ m_codeBuffer

uint32_t pgf::CDecoder::CMacroBlock::m_codeBuffer[CodeBufferLen]

input buffer for encoded bitstream

Definition at line 73 of file Decoder.h.

◆ m_header

ROIBlockHeader pgf::CDecoder::CMacroBlock::m_header

block header

Definition at line 71 of file Decoder.h.

◆ m_sigFlagVector

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

Definition at line 83 of file Decoder.h.

◆ m_value

DataT pgf::CDecoder::CMacroBlock::m_value[BufferSize]

output buffer of values with index m_valuePos

Definition at line 72 of file Decoder.h.

◆ m_valuePos

uint32_t pgf::CDecoder::CMacroBlock::m_valuePos

current position in m_value

Definition at line 74 of file Decoder.h.


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