CEncoder_CMacroBlock - Man Page
A macro block is an encoding unit of fixed size (uncoded)
Synopsis
Public Member Functions
CMacroBlock (CEncoder *encoder)
void Init (int lastLevelIndex)
void BitplaneEncode ()
Public Attributes
DataT m_value [BufferSize]
input buffer of values with index m_valuePos
UINT32 m_codeBuffer [CodeBufferLen]
output buffer for encoded bitstream
ROIBlockHeader m_header
block header
UINT32 m_valuePos
current buffer position
UINT32 m_maxAbsValue
maximum absolute coefficient in each buffer
UINT32 m_codePos
current position in encoded bitstream
int m_lastLevelIndex
index of last encoded level: [0, nLevels); used because a level-end can occur before a buffer is full
Private Member Functions
UINT32 RLESigns (UINT32 codePos, UINT32 *signBits, UINT32 signLen)
UINT32 DecomposeBitplane (UINT32 bufferSize, UINT32 planeMask, UINT32 codePos, UINT32 *sigBits, UINT32 *refBits, UINT32 *signBits, UINT32 &signLen, UINT32 &codeLen)
UINT8 NumberOfBitplanes ()
bool GetBitAtPos (UINT32 pos, UINT32 planeMask) const
Private Attributes
CEncoder * m_encoder
bool m_sigFlagVector [BufferSize+1]
Detailed Description
A macro block is an encoding unit of fixed size (uncoded)
PGF encoder macro block class.
- Author
C. Stamm, I. Bauersachs
Definition at line 51 of file Encoder.h.
Constructor & Destructor Documentation
CEncoder::CMacroBlock::CMacroBlock (CEncoder * encoder) [inline]
Constructor: Initializes new macro block.
- Parameters
encoder Pointer to outer class.
Definition at line 56 of file Encoder.h.
57 : 4351 ) 58 : m_value() 59 , m_codeBuffer() 60 , m_header(0) 61 , m_encoder(encoder) 62 , m_sigFlagVector() 63 { 64 ASSERT(m_encoder); 65 Init(-1); 66 }
Member Function Documentation
void CEncoder::CMacroBlock::BitplaneEncode ()
Encodes this macro block into internal code buffer. Several macro blocks can be encoded in parallel. Call CEncoder::WriteMacroBlock after this method.
Definition at line 480 of file Encoder.cpp.
480 { 481 UINT8 nPlanes; 482 UINT32 sigLen, codeLen = 0, wordPos, refLen, signLen; 483 UINT32 sigBits[BufferLen] = { 0 }; 484 UINT32 refBits[BufferLen] = { 0 }; 485 UINT32 signBits[BufferLen] = { 0 }; 486 UINT32 planeMask; 487 UINT32 bufferSize = m_header.rbh.bufferSize; ASSERT(bufferSize <= BufferSize); 488 bool useRL; 489 490 #ifdef TRACE 491 //printf("which thread: %d0, omp_get_thread_num()); 492 #endif 493 494 // clear significance vector 495 for (UINT32 k=0; k < bufferSize; k++) { 496 m_sigFlagVector[k] = false; 497 } 498 m_sigFlagVector[bufferSize] = true; // sentinel 499 500 // clear output buffer 501 for (UINT32 k=0; k < bufferSize; k++) { 502 m_codeBuffer[k] = 0; 503 } 504 m_codePos = 0; 505 506 // compute number of bit planes and split buffer into separate bit planes 507 nPlanes = NumberOfBitplanes(); 508 509 // write number of bit planes to m_codeBuffer 510 // <nPlanes> 511 SetValueBlock(m_codeBuffer, 0, nPlanes, MaxBitPlanesLog); 512 m_codePos += MaxBitPlanesLog; 513 514 // loop through all bit planes 515 if (nPlanes == 0) nPlanes = MaxBitPlanes + 1; 516 planeMask = 1 << (nPlanes - 1); 517 518 for (int plane = nPlanes - 1; plane >= 0; plane--) { 519 // clear significant bitset 520 for (UINT32 k=0; k < BufferLen; k++) { 521 sigBits[k] = 0; 522 } 523 524 // split bitplane in significant bitset and refinement bitset 525 sigLen = DecomposeBitplane(bufferSize, planeMask, m_codePos + RLblockSizeLen + 1, sigBits, refBits, signBits, signLen, codeLen); 526 527 if (sigLen > 0 && codeLen <= MaxCodeLen && codeLen < AlignWordPos(sigLen) + AlignWordPos(signLen) + 2*RLblockSizeLen) { 528 // set RL code bit 529 // <1><codeLen> 530 SetBit(m_codeBuffer, m_codePos++); 531 532 // write length codeLen to m_codeBuffer 533 SetValueBlock(m_codeBuffer, m_codePos, codeLen, RLblockSizeLen); 534 m_codePos += RLblockSizeLen + codeLen; 535 } else { 536 #ifdef TRACE 537 //printf("new0); 538 //for (UINT32 i=0; i < bufferSize; i++) { 539 // printf("%s", (GetBit(sigBits, i)) ? "1" : "_"); 540 // if (i%120 == 119) printf("0); 541 //} 542 //printf("0); 543 #endif // TRACE 544 545 // run-length coding wasn't efficient enough 546 // we don't use RL coding for sigBits 547 // <0><sigLen> 548 ClearBit(m_codeBuffer, m_codePos++); 549 550 // write length sigLen to m_codeBuffer 551 ASSERT(sigLen <= MaxCodeLen); 552 SetValueBlock(m_codeBuffer, m_codePos, sigLen, RLblockSizeLen); 553 m_codePos += RLblockSizeLen; 554 555 if (m_encoder->m_favorSpeed || signLen == 0) { 556 useRL = false; 557 } else { 558 // overwrite m_codeBuffer 559 useRL = true; 560 // run-length encode m_sign and append them to the m_codeBuffer 561 codeLen = RLESigns(m_codePos + RLblockSizeLen + 1, signBits, signLen); 562 } 563 564 if (useRL && codeLen <= MaxCodeLen && codeLen < signLen) { 565 // RL encoding of m_sign was efficient 566 // <1><codeLen><codedSignBits>_ 567 // write RL code bit 568 SetBit(m_codeBuffer, m_codePos++); 569 570 // write codeLen to m_codeBuffer 571 SetValueBlock(m_codeBuffer, m_codePos, codeLen, RLblockSizeLen); 572 573 // compute position of sigBits 574 wordPos = NumberOfWords(m_codePos + RLblockSizeLen + codeLen); 575 ASSERT(0 <= wordPos && wordPos < CodeBufferLen); 576 } else { 577 // RL encoding of signBits wasn't efficient 578 // <0><signLen>_<signBits>_ 579 // clear RL code bit 580 ClearBit(m_codeBuffer, m_codePos++); 581 582 // write signLen to m_codeBuffer 583 ASSERT(signLen <= MaxCodeLen); 584 SetValueBlock(m_codeBuffer, m_codePos, signLen, RLblockSizeLen); 585 586 // write signBits to m_codeBuffer 587 wordPos = NumberOfWords(m_codePos + RLblockSizeLen); 588 ASSERT(0 <= wordPos && wordPos < CodeBufferLen); 589 codeLen = NumberOfWords(signLen); 590 591 for (UINT32 k=0; k < codeLen; k++) { 592 m_codeBuffer[wordPos++] = signBits[k]; 593 } 594 } 595 596 // write sigBits 597 // <sigBits>_ 598 ASSERT(0 <= wordPos && wordPos < CodeBufferLen); 599 refLen = NumberOfWords(sigLen); 600 601 for (UINT32 k=0; k < refLen; k++) { 602 m_codeBuffer[wordPos++] = sigBits[k]; 603 } 604 m_codePos = wordPos << WordWidthLog; 605 } 606 607 // append refinement bitset (aligned to word boundary) 608 // _<refBits> 609 wordPos = NumberOfWords(m_codePos); 610 ASSERT(0 <= wordPos && wordPos < CodeBufferLen); 611 refLen = NumberOfWords(bufferSize - sigLen); 612 613 for (UINT32 k=0; k < refLen; k++) { 614 m_codeBuffer[wordPos++] = refBits[k]; 615 } 616 m_codePos = wordPos << WordWidthLog; 617 planeMask >>= 1; 618 } 619 ASSERT(0 <= m_codePos && m_codePos <= CodeBufferBitLen); 620 }
UINT32 CEncoder::CMacroBlock::DecomposeBitplane (UINT32 bufferSize, UINT32 planeMask, UINT32 codePos, UINT32 * sigBits, UINT32 * refBits, UINT32 * signBits, UINT32 & signLen, UINT32 & codeLen) [private]
Definition at line 632 of file Encoder.cpp.
632 { 633 ASSERT(sigBits); 634 ASSERT(refBits); 635 ASSERT(signBits); 636 ASSERT(codePos < CodeBufferBitLen); 637 638 UINT32 sigPos = 0; 639 UINT32 valuePos = 0, valueEnd; 640 UINT32 refPos = 0; 641 642 // set output value 643 signLen = 0; 644 645 // prepare RLE of Sigs and Signs 646 const UINT32 outStartPos = codePos; 647 UINT32 k = 3; 648 UINT32 runlen = 1 << k; // = 2^k 649 UINT32 count = 0; 650 651 while (valuePos < bufferSize) { 652 // search next 1 in m_sigFlagVector using searching with sentinel 653 valueEnd = valuePos; 654 while(!m_sigFlagVector[valueEnd]) { valueEnd++; } 655 656 // search 1's in m_value[plane][valuePos..valueEnd) 657 // these 1's are significant bits 658 while (valuePos < valueEnd) { 659 if (GetBitAtPos(valuePos, planeMask)) { 660 // RLE encoding 661 // encode run of count 0's followed by a 1 662 // with codeword: 1<count>(signBits[signPos]) 663 SetBit(m_codeBuffer, codePos++); 664 if (k > 0) { 665 SetValueBlock(m_codeBuffer, codePos, count, k); 666 codePos += k; 667 668 // adapt k (half the zero run-length) 669 k--; 670 runlen >>= 1; 671 } 672 673 // copy and write sign bit 674 if (m_value[valuePos] < 0) { 675 SetBit(signBits, signLen++); 676 SetBit(m_codeBuffer, codePos++); 677 } else { 678 ClearBit(signBits, signLen++); 679 ClearBit(m_codeBuffer, codePos++); 680 } 681 682 // write a 1 to sigBits 683 SetBit(sigBits, sigPos++); 684 685 // update m_sigFlagVector 686 m_sigFlagVector[valuePos] = true; 687 688 // prepare for next run 689 count = 0; 690 } else { 691 // RLE encoding 692 count++; 693 if (count == runlen) { 694 // encode run of 2^k zeros by a single 0 695 ClearBit(m_codeBuffer, codePos++); 696 // adapt k (double the zero run-length) 697 if (k < WordWidth) { 698 k++; 699 runlen <<= 1; 700 } 701 702 // prepare for next run 703 count = 0; 704 } 705 706 // write 0 to sigBits 707 sigPos++; 708 } 709 valuePos++; 710 } 711 // refinement bit 712 if (valuePos < bufferSize) { 713 // write one refinement bit 714 if (GetBitAtPos(valuePos++, planeMask)) { 715 SetBit(refBits, refPos); 716 } else { 717 ClearBit(refBits, refPos); 718 } 719 refPos++; 720 } 721 } 722 // RLE encoding of the rest of the plane 723 // encode run of count 0's followed by a 1 724 // with codeword: 1<count>(signBits[signPos]) 725 SetBit(m_codeBuffer, codePos++); 726 if (k > 0) { 727 SetValueBlock(m_codeBuffer, codePos, count, k); 728 codePos += k; 729 } 730 // write dmmy sign bit 731 SetBit(m_codeBuffer, codePos++); 732 733 // write word filler zeros 734 735 ASSERT(sigPos <= bufferSize); 736 ASSERT(refPos <= bufferSize); 737 ASSERT(signLen <= bufferSize); 738 ASSERT(valuePos == bufferSize); 739 ASSERT(codePos >= outStartPos && codePos < CodeBufferBitLen); 740 codeLen = codePos - outStartPos; 741 742 return sigPos; 743 }
bool CEncoder::CMacroBlock::GetBitAtPos (UINT32 pos, UINT32 planeMask) const [inline], [private]
Definition at line 96 of file Encoder.h.
96 { return (abs(m_value[pos]) & planeMask) > 0; }
void CEncoder::CMacroBlock::Init (int lastLevelIndex) [inline]
Reinitialzes this macro block (allows reusage).
- Parameters
lastLevelIndex Level length directory index of last encoded level: [0, nLevels)
Definition at line 71 of file Encoder.h.
71 { // initialize for reusage 72 m_valuePos = 0; 73 m_maxAbsValue = 0; 74 m_codePos = 0; 75 m_lastLevelIndex = lastLevelIndex; 76 }
UINT8 CEncoder::CMacroBlock::NumberOfBitplanes () [private]
Definition at line 748 of file Encoder.cpp.
748 { 749 UINT8 cnt = 0; 750 751 // determine number of bitplanes for max value 752 if (m_maxAbsValue > 0) { 753 while (m_maxAbsValue > 0) { 754 m_maxAbsValue >>= 1; cnt++; 755 } 756 if (cnt == MaxBitPlanes + 1) cnt = 0; 757 // end cs 758 ASSERT(cnt <= MaxBitPlanes); 759 ASSERT((cnt >> MaxBitPlanesLog) == 0); 760 return cnt; 761 } else { 762 return 1; 763 } 764 }
UINT32 CEncoder::CMacroBlock::RLESigns (UINT32 codePos, UINT32 * signBits, UINT32 signLen) [private]
Definition at line 772 of file Encoder.cpp.
772 { 773 ASSERT(signBits); 774 ASSERT(0 <= codePos && codePos < CodeBufferBitLen); 775 ASSERT(0 < signLen && signLen <= BufferSize); 776 777 const UINT32 outStartPos = codePos; 778 UINT32 k = 0; 779 UINT32 runlen = 1 << k; // = 2^k 780 UINT32 count = 0; 781 UINT32 signPos = 0; 782 783 while (signPos < signLen) { 784 // search next 0 in signBits starting at position signPos 785 count = SeekBit1Range(signBits, signPos, __min(runlen, signLen - signPos)); 786 // count 1's found 787 if (count == runlen) { 788 // encode run of 2^k ones by a single 1 789 signPos += count; 790 SetBit(m_codeBuffer, codePos++); 791 // adapt k (double the 1's run-length) 792 if (k < WordWidth) { 793 k++; 794 runlen <<= 1; 795 } 796 } else { 797 // encode run of count 1's followed by a 0 798 // with codeword: 0(count) 799 signPos += count + 1; 800 ClearBit(m_codeBuffer, codePos++); 801 if (k > 0) { 802 SetValueBlock(m_codeBuffer, codePos, count, k); 803 codePos += k; 804 } 805 // adapt k (half the 1's run-length) 806 if (k > 0) { 807 k--; 808 runlen >>= 1; 809 } 810 } 811 } 812 ASSERT(signPos == signLen || signPos == signLen + 1); 813 ASSERT(codePos >= outStartPos && codePos < CodeBufferBitLen); 814 return codePos - outStartPos; 815 }
Member Data Documentation
UINT32 CEncoder::CMacroBlock::m_codeBuffer[CodeBufferLen]
output buffer for encoded bitstream
Definition at line 85 of file Encoder.h.
UINT32 CEncoder::CMacroBlock::m_codePos
current position in encoded bitstream
Definition at line 89 of file Encoder.h.
CEncoder* CEncoder::CMacroBlock::m_encoder [private]
Definition at line 98 of file Encoder.h.
ROIBlockHeader CEncoder::CMacroBlock::m_header
block header
Definition at line 86 of file Encoder.h.
int CEncoder::CMacroBlock::m_lastLevelIndex
index of last encoded level: [0, nLevels); used because a level-end can occur before a buffer is full
Definition at line 90 of file Encoder.h.
UINT32 CEncoder::CMacroBlock::m_maxAbsValue
maximum absolute coefficient in each buffer
Definition at line 88 of file Encoder.h.
bool CEncoder::CMacroBlock::m_sigFlagVector[BufferSize+1] [private]
Definition at line 99 of file Encoder.h.
DataT CEncoder::CMacroBlock::m_value[BufferSize]
input buffer of values with index m_valuePos
Definition at line 84 of file Encoder.h.
UINT32 CEncoder::CMacroBlock::m_valuePos
current buffer position
Definition at line 87 of file Encoder.h.
Author
Generated automatically by Doxygen for libpgf from the source code.