Changeset 296 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComTrQuant.cpp
- Timestamp:
- 20 Feb 2013, 22:07:43 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibCommon/TComTrQuant.cpp
r56 r296 180 180 181 181 182 #if H0736_AVC_STYLE_QP_RANGE183 182 /** Set qP for Quantization. 184 183 * \param qpy QPy … … 214 213 m_cQP.setQpParam( qpScaled, bLowpass, eSliceType ); 215 214 } 216 #else217 /// Including Chroma QP Parameter setting218 Void TComTrQuant::setQPforQuant( Int iQP, Bool bLowpass, SliceType eSliceType, TextType eTxtType, Int Shift)219 {220 iQP = Clip3( MIN_QP, MAX_QP, iQP + Shift );221 222 if(eTxtType != TEXT_LUMA) //Chroma223 {224 iQP = g_aucChromaScale[ iQP ];225 }226 227 m_cQP.setQpParam( iQP, bLowpass, eSliceType );228 }229 #endif230 215 231 216 #if MATRIX_MULT … … 421 406 * \param shift specifies right shift after 1D transform 422 407 */ 423 #if !UNIFIED_TRANSFORM424 void partialButterfly4(short src[4][4],short dst[4][4],int shift)425 {426 int j;427 int E[2],O[2];428 int add = 1<<(shift-1);429 430 for (j=0; j<4; j++)431 {432 /* E and O */433 E[0] = src[j][0] + src[j][3];434 O[0] = src[j][0] - src[j][3];435 E[1] = src[j][1] + src[j][2];436 O[1] = src[j][1] - src[j][2];437 438 dst[0][j] = (g_aiT4[0][0]*E[0] + g_aiT4[0][1]*E[1] + add)>>shift;439 dst[2][j] = (g_aiT4[2][0]*E[0] + g_aiT4[2][1]*E[1] + add)>>shift;440 dst[1][j] = (g_aiT4[1][0]*O[0] + g_aiT4[1][1]*O[1] + add)>>shift;441 dst[3][j] = (g_aiT4[3][0]*O[0] + g_aiT4[3][1]*O[1] + add)>>shift;442 }443 }444 #endif445 408 446 409 void partialButterfly4(short *src,short *dst,int shift, int line) … … 470 433 // Fast DST Algorithm. Full matrix multiplication for DST and Fast DST algorithm 471 434 // give identical results 472 #if UNIFIED_TRANSFORM473 435 void fastForwardDst(short *block,short *coeff,int shift) // input block, output coeff 474 #else475 void fastForwardDst(short block[4][4],short coeff[4][4],int shift) // input block, output coeff476 #endif477 436 { 478 437 int i, c[4]; … … 481 440 { 482 441 // Intermediate Variables 483 #if UNIFIED_TRANSFORM484 442 c[0] = block[4*i+0] + block[4*i+3]; 485 443 c[1] = block[4*i+1] + block[4*i+3]; … … 491 449 coeff[ 8+i] = ( 29 * c[2] + 55 * c[0] - c[3] + rnd_factor ) >> shift; 492 450 coeff[12+i] = ( 55 * c[2] - 29 * c[1] + c[3] + rnd_factor ) >> shift; 493 #else 494 c[0] = block[i][0] + block[i][3]; 495 c[1] = block[i][1] + block[i][3]; 496 c[2] = block[i][0] - block[i][1]; 497 c[3] = 74* block[i][2]; 498 499 coeff[0][i] = ( 29 * c[0] + 55 * c[1] + c[3] + rnd_factor ) >> shift; 500 coeff[1][i] = ( 74 * (block[i][0]+ block[i][1] - block[i][3]) + rnd_factor ) >> shift; 501 coeff[2][i] = ( 29 * c[2] + 55 * c[0] - c[3] + rnd_factor ) >> shift; 502 coeff[3][i] = ( 55 * c[2] - 29 * c[1] + c[3] + rnd_factor ) >> shift; 503 #endif 504 } 505 } 506 507 #if UNIFIED_TRANSFORM 451 } 452 } 453 508 454 void fastInverseDst(short *tmp,short *block,int shift) // input tmp, output block 509 #else510 void fastInverseDst(short tmp[4][4],short block[4][4],int shift) // input tmp, output block511 #endif512 455 { 513 456 int i, c[4]; … … 516 459 { 517 460 // Intermediate Variables 518 #if UNIFIED_TRANSFORM519 461 c[0] = tmp[ i] + tmp[ 8+i]; 520 462 c[1] = tmp[8+i] + tmp[12+i]; … … 526 468 block[4*i+2] = Clip3( -32768, 32767, ( 74 * (tmp[i] - tmp[8+i] + tmp[12+i]) + rnd_factor ) >> shift ); 527 469 block[4*i+3] = Clip3( -32768, 32767, ( 55 * c[0] + 29 * c[2] - c[3] + rnd_factor ) >> shift ); 528 #else 529 c[0] = tmp[0][i] + tmp[2][i]; 530 c[1] = tmp[2][i] + tmp[3][i]; 531 c[2] = tmp[0][i] - tmp[3][i]; 532 c[3] = 74* tmp[1][i]; 533 534 block[i][0] = Clip3( -32768, 32767, ( 29 * c[0] + 55 * c[1] + c[3] + rnd_factor ) >> shift ); 535 block[i][1] = Clip3( -32768, 32767, ( 55 * c[2] - 29 * c[1] + c[3] + rnd_factor ) >> shift ); 536 block[i][2] = Clip3( -32768, 32767, ( 74 * (tmp[0][i] - tmp[2][i] + tmp[3][i]) + rnd_factor ) >> shift ); 537 block[i][3] = Clip3( -32768, 32767, ( 55 * c[0] + 29 * c[2] - c[3] + rnd_factor ) >> shift ); 538 #endif 539 } 540 } 541 #if !UNIFIED_TRANSFORM 542 /** 4x4 forward transform (2D) 543 * \param block input data (residual) 544 * \param coeff output data (transform coefficients) 545 * \param uiMode is Intra Prediction mode used in Mode-Dependent DCT/DST only 546 */ 547 void xTr4(short block[4][4],short coeff[4][4],UInt uiMode) 548 { 549 #if FULL_NBIT 550 int shift_1st = 1 + g_uiBitDepth - 8; // log2(4) - 1 + g_uiBitDepth - 8 551 #else 552 int shift_1st = 1 + g_uiBitIncrement; // log2(4) - 1 + g_uiBitIncrement 553 #endif 554 int shift_2nd = 8; // log2(4) + 6 555 short tmp[4][4]; 556 #if LOGI_INTRA_NAME_3MPM 557 if (uiMode != REG_DCT && (!uiMode || (uiMode>=2 && uiMode <= 25))) // Check for DCT or DST 558 #else 559 if (uiMode != REG_DCT && g_aucDCTDSTMode_Hor[uiMode])// Check for DCT or DST 560 #endif 561 { 562 fastForwardDst(block,tmp,shift_1st); // Forward DST BY FAST ALGORITHM, block input, tmp output 563 } 564 else 565 { 566 partialButterfly4(block,tmp,shift_1st); 567 } 568 569 #if LOGI_INTRA_NAME_3MPM 570 if (uiMode != REG_DCT && (!uiMode || (uiMode>=11 && uiMode <= 34))) // Check for DCT or DST 571 #else 572 if (uiMode != REG_DCT && g_aucDCTDSTMode_Vert[uiMode] ) // Check for DCT or DST 573 #endif 574 { 575 fastForwardDst(tmp,coeff,shift_2nd); // Forward DST BY FAST ALGORITHM, tmp input, coeff output 576 } 577 else 578 { 579 partialButterfly4(tmp,coeff,shift_2nd); 580 } 581 } 582 583 /** 4x4 inverse transform implemented using partial butterfly structure (1D) 584 * \param src input data (transform coefficients) 585 * \param dst output data (residual) 586 * \param shift specifies right shift after 1D transform 587 */ 588 void partialButterflyInverse4(short src[4][4],short dst[4][4],int shift) 589 { 590 int j; 591 int E[2],O[2]; 592 int add = 1<<(shift-1); 593 594 for (j=0; j<4; j++) 595 { 596 /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */ 597 O[0] = g_aiT4[1][0]*src[1][j] + g_aiT4[3][0]*src[3][j]; 598 O[1] = g_aiT4[1][1]*src[1][j] + g_aiT4[3][1]*src[3][j]; 599 E[0] = g_aiT4[0][0]*src[0][j] + g_aiT4[2][0]*src[2][j]; 600 E[1] = g_aiT4[0][1]*src[0][j] + g_aiT4[2][1]*src[2][j]; 601 602 /* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */ 603 dst[j][0] = Clip3( -32768, 32767, (E[0] + O[0] + add)>>shift ); 604 dst[j][1] = Clip3( -32768, 32767, (E[1] + O[1] + add)>>shift ); 605 dst[j][2] = Clip3( -32768, 32767, (E[1] - O[1] + add)>>shift ); 606 dst[j][3] = Clip3( -32768, 32767, (E[0] - O[0] + add)>>shift ); 607 } 608 } 609 #endif 470 } 471 } 610 472 611 473 void partialButterflyInverse4(short *src,short *dst,int shift, int line) … … 634 496 } 635 497 636 #if !UNIFIED_TRANSFORM637 /** 4x4 inverse transform (2D)638 * \param coeff input data (transform coefficients)639 * \param block output data (residual)640 * \param uiMode is Intra Prediction mode used in Mode-Dependent DCT/DST only641 */642 void xITr4(short coeff[4][4],short block[4][4], UInt uiMode)643 {644 int shift_1st = SHIFT_INV_1ST;645 #if FULL_NBIT646 int shift_2nd = SHIFT_INV_2ND - ((short)g_uiBitDepth - 8);647 #else648 int shift_2nd = SHIFT_INV_2ND - g_uiBitIncrement;649 #endif650 short tmp[4][4];651 652 #if LOGI_INTRA_NAME_3MPM653 if (uiMode != REG_DCT && (!uiMode || (uiMode>=11 && uiMode <= 34))) // Check for DCT or DST654 #else655 if (uiMode != REG_DCT && g_aucDCTDSTMode_Vert[uiMode] ) // Check for DCT or DST656 #endif657 {658 fastInverseDst(coeff,tmp,shift_1st); // Inverse DST by FAST Algorithm, coeff input, tmp output659 }660 else661 {662 partialButterflyInverse4(coeff,tmp,shift_1st);663 }664 #if LOGI_INTRA_NAME_3MPM665 if (uiMode != REG_DCT && (!uiMode || (uiMode>=2 && uiMode <= 25))) // Check for DCT or DST666 #else667 if (uiMode != REG_DCT && g_aucDCTDSTMode_Hor[uiMode] ) // Check for DCT or DST668 #endif669 {670 fastInverseDst(tmp,block,shift_2nd); // Inverse DST by FAST Algorithm, tmp input, coeff output671 }672 else673 {674 partialButterflyInverse4(tmp,block,shift_2nd);675 }676 }677 678 /** 8x8 forward transform implemented using partial butterfly structure (1D)679 * \param src input data (residual)680 * \param dst output data (transform coefficients)681 * \param shift specifies right shift after 1D transform682 */683 void partialButterfly8(short src[8][8],short dst[8][8],int shift)684 {685 int j,k;686 int E[4],O[4];687 int EE[2],EO[2];688 int add = 1<<(shift-1);689 690 for (j=0; j<8; j++)691 {692 /* E and O*/693 for (k=0;k<4;k++)694 {695 E[k] = src[j][k] + src[j][7-k];696 O[k] = src[j][k] - src[j][7-k];697 }698 /* EE and EO */699 EE[0] = E[0] + E[3];700 EO[0] = E[0] - E[3];701 EE[1] = E[1] + E[2];702 EO[1] = E[1] - E[2];703 704 dst[0][j] = (g_aiT8[0][0]*EE[0] + g_aiT8[0][1]*EE[1] + add)>>shift;705 dst[4][j] = (g_aiT8[4][0]*EE[0] + g_aiT8[4][1]*EE[1] + add)>>shift;706 dst[2][j] = (g_aiT8[2][0]*EO[0] + g_aiT8[2][1]*EO[1] + add)>>shift;707 dst[6][j] = (g_aiT8[6][0]*EO[0] + g_aiT8[6][1]*EO[1] + add)>>shift;708 709 dst[1][j] = (g_aiT8[1][0]*O[0] + g_aiT8[1][1]*O[1] + g_aiT8[1][2]*O[2] + g_aiT8[1][3]*O[3] + add)>>shift;710 dst[3][j] = (g_aiT8[3][0]*O[0] + g_aiT8[3][1]*O[1] + g_aiT8[3][2]*O[2] + g_aiT8[3][3]*O[3] + add)>>shift;711 dst[5][j] = (g_aiT8[5][0]*O[0] + g_aiT8[5][1]*O[1] + g_aiT8[5][2]*O[2] + g_aiT8[5][3]*O[3] + add)>>shift;712 dst[7][j] = (g_aiT8[7][0]*O[0] + g_aiT8[7][1]*O[1] + g_aiT8[7][2]*O[2] + g_aiT8[7][3]*O[3] + add)>>shift;713 }714 }715 #endif716 498 717 499 void partialButterfly8(short *src,short *dst,int shift, int line) … … 751 533 } 752 534 753 #if !UNIFIED_TRANSFORM 754 /** 8x8 forward transform (2D) 755 * \param block input data (residual) 756 * \param coeff output data (transform coefficients) 757 */ 758 void xTr8(short block[8][8],short coeff[8][8]) 759 { 760 #if FULL_NBIT 761 int shift_1st = 2 + g_uiBitDepth - 8; // log2(8) - 1 + g_uiBitDepth - 8 762 #else 763 int shift_1st = 2 + g_uiBitIncrement; // log2(8) - 1 + g_uiBitIncrement 764 #endif 765 int shift_2nd = 9; // log2(8) + 6 766 short tmp[8][8]; 767 768 partialButterfly8(block,tmp,shift_1st); 769 partialButterfly8(tmp,coeff,shift_2nd); 770 } 771 772 /** 8x8 inverse transform implemented using partial butterfly structure (1D) 773 * \param src input data (transform coefficients) 774 * \param dst output data (residual) 775 * \param shift specifies right shift after 1D transform 776 */ 777 void partialButterflyInverse8(short src[8][8],short dst[8][8],int shift) 535 536 void partialButterflyInverse8(short *src,short *dst,int shift, int line) 778 537 { 779 538 int j,k; … … 782 541 int add = 1<<(shift-1); 783 542 784 for (j=0; j< 8; j++)543 for (j=0; j<line; j++) 785 544 { 786 545 /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */ 787 546 for (k=0;k<4;k++) 788 547 { 789 O[k] = g_aiT8[ 1][k]*src[ 1][j] + g_aiT8[ 3][k]*src[ 3][j] + g_aiT8[ 5][k]*src[ 5][j] + g_aiT8[ 7][k]*src[ 7][j];790 } 791 792 EO[0] = g_aiT8[2][0]*src[ 2][j] + g_aiT8[6][0]*src[6][j];793 EO[1] = g_aiT8[2][1]*src[ 2][j] + g_aiT8[6][1]*src[6][j];794 EE[0] = g_aiT8[0][0]*src[ 0][j] + g_aiT8[4][0]*src[4][j];795 EE[1] = g_aiT8[0][1]*src[ 0][j] + g_aiT8[4][1]*src[4][j];548 O[k] = g_aiT8[ 1][k]*src[line] + g_aiT8[ 3][k]*src[3*line] + g_aiT8[ 5][k]*src[5*line] + g_aiT8[ 7][k]*src[7*line]; 549 } 550 551 EO[0] = g_aiT8[2][0]*src[ 2*line ] + g_aiT8[6][0]*src[ 6*line ]; 552 EO[1] = g_aiT8[2][1]*src[ 2*line ] + g_aiT8[6][1]*src[ 6*line ]; 553 EE[0] = g_aiT8[0][0]*src[ 0 ] + g_aiT8[4][0]*src[ 4*line ]; 554 EE[1] = g_aiT8[0][1]*src[ 0 ] + g_aiT8[4][1]*src[ 4*line ]; 796 555 797 556 /* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */ … … 802 561 for (k=0;k<4;k++) 803 562 { 804 dst[j][k] = Clip3( -32768, 32767, (E[k] + O[k] + add)>>shift );805 dst[j][k+4] = Clip3( -32768, 32767, (E[3-k] - O[3-k] + add)>>shift );806 }807 }808 }809 #endif810 811 void partialButterflyInverse8(short *src,short *dst,int shift, int line)812 {813 int j,k;814 int E[4],O[4];815 int EE[2],EO[2];816 int add = 1<<(shift-1);817 818 for (j=0; j<line; j++)819 {820 /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */821 for (k=0;k<4;k++)822 {823 O[k] = g_aiT8[ 1][k]*src[line] + g_aiT8[ 3][k]*src[3*line] + g_aiT8[ 5][k]*src[5*line] + g_aiT8[ 7][k]*src[7*line];824 }825 826 EO[0] = g_aiT8[2][0]*src[ 2*line ] + g_aiT8[6][0]*src[ 6*line ];827 EO[1] = g_aiT8[2][1]*src[ 2*line ] + g_aiT8[6][1]*src[ 6*line ];828 EE[0] = g_aiT8[0][0]*src[ 0 ] + g_aiT8[4][0]*src[ 4*line ];829 EE[1] = g_aiT8[0][1]*src[ 0 ] + g_aiT8[4][1]*src[ 4*line ];830 831 /* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */832 E[0] = EE[0] + EO[0];833 E[3] = EE[0] - EO[0];834 E[1] = EE[1] + EO[1];835 E[2] = EE[1] - EO[1];836 for (k=0;k<4;k++)837 {838 563 dst[ k ] = Clip3( -32768, 32767, (E[k] + O[k] + add)>>shift ); 839 564 dst[ k+4 ] = Clip3( -32768, 32767, (E[3-k] - O[3-k] + add)>>shift ); … … 844 569 } 845 570 846 #if !UNIFIED_TRANSFORM 847 /** 8x8 inverse transform (2D) 848 * \param coeff input data (transform coefficients) 849 * \param block output data (residual) 850 */ 851 void xITr8(short coeff[8][8],short block[8][8]) 571 572 void partialButterfly16(short *src,short *dst,int shift, int line) 573 { 574 int j,k; 575 int E[8],O[8]; 576 int EE[4],EO[4]; 577 int EEE[2],EEO[2]; 578 int add = 1<<(shift-1); 579 580 for (j=0; j<line; j++) 581 { 582 /* E and O*/ 583 for (k=0;k<8;k++) 584 { 585 E[k] = src[k] + src[15-k]; 586 O[k] = src[k] - src[15-k]; 587 } 588 /* EE and EO */ 589 for (k=0;k<4;k++) 590 { 591 EE[k] = E[k] + E[7-k]; 592 EO[k] = E[k] - E[7-k]; 593 } 594 /* EEE and EEO */ 595 EEE[0] = EE[0] + EE[3]; 596 EEO[0] = EE[0] - EE[3]; 597 EEE[1] = EE[1] + EE[2]; 598 EEO[1] = EE[1] - EE[2]; 599 600 dst[ 0 ] = (g_aiT16[ 0][0]*EEE[0] + g_aiT16[ 0][1]*EEE[1] + add)>>shift; 601 dst[ 8*line ] = (g_aiT16[ 8][0]*EEE[0] + g_aiT16[ 8][1]*EEE[1] + add)>>shift; 602 dst[ 4*line ] = (g_aiT16[ 4][0]*EEO[0] + g_aiT16[ 4][1]*EEO[1] + add)>>shift; 603 dst[ 12*line] = (g_aiT16[12][0]*EEO[0] + g_aiT16[12][1]*EEO[1] + add)>>shift; 604 605 for (k=2;k<16;k+=4) 606 { 607 dst[ k*line ] = (g_aiT16[k][0]*EO[0] + g_aiT16[k][1]*EO[1] + g_aiT16[k][2]*EO[2] + g_aiT16[k][3]*EO[3] + add)>>shift; 608 } 609 610 for (k=1;k<16;k+=2) 611 { 612 dst[ k*line ] = (g_aiT16[k][0]*O[0] + g_aiT16[k][1]*O[1] + g_aiT16[k][2]*O[2] + g_aiT16[k][3]*O[3] + 613 g_aiT16[k][4]*O[4] + g_aiT16[k][5]*O[5] + g_aiT16[k][6]*O[6] + g_aiT16[k][7]*O[7] + add)>>shift; 614 } 615 616 src += 16; 617 dst ++; 618 619 } 620 } 621 622 623 void partialButterflyInverse16(short *src,short *dst,int shift, int line) 624 { 625 int j,k; 626 int E[8],O[8]; 627 int EE[4],EO[4]; 628 int EEE[2],EEO[2]; 629 int add = 1<<(shift-1); 630 631 for (j=0; j<line; j++) 632 { 633 /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */ 634 for (k=0;k<8;k++) 635 { 636 O[k] = g_aiT16[ 1][k]*src[ line] + g_aiT16[ 3][k]*src[ 3*line] + g_aiT16[ 5][k]*src[ 5*line] + g_aiT16[ 7][k]*src[ 7*line] + 637 g_aiT16[ 9][k]*src[ 9*line] + g_aiT16[11][k]*src[11*line] + g_aiT16[13][k]*src[13*line] + g_aiT16[15][k]*src[15*line]; 638 } 639 for (k=0;k<4;k++) 640 { 641 EO[k] = g_aiT16[ 2][k]*src[ 2*line] + g_aiT16[ 6][k]*src[ 6*line] + g_aiT16[10][k]*src[10*line] + g_aiT16[14][k]*src[14*line]; 642 } 643 EEO[0] = g_aiT16[4][0]*src[ 4*line ] + g_aiT16[12][0]*src[ 12*line ]; 644 EEE[0] = g_aiT16[0][0]*src[ 0 ] + g_aiT16[ 8][0]*src[ 8*line ]; 645 EEO[1] = g_aiT16[4][1]*src[ 4*line ] + g_aiT16[12][1]*src[ 12*line ]; 646 EEE[1] = g_aiT16[0][1]*src[ 0 ] + g_aiT16[ 8][1]*src[ 8*line ]; 647 648 /* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */ 649 for (k=0;k<2;k++) 650 { 651 EE[k] = EEE[k] + EEO[k]; 652 EE[k+2] = EEE[1-k] - EEO[1-k]; 653 } 654 for (k=0;k<4;k++) 655 { 656 E[k] = EE[k] + EO[k]; 657 E[k+4] = EE[3-k] - EO[3-k]; 658 } 659 for (k=0;k<8;k++) 660 { 661 dst[k] = Clip3( -32768, 32767, (E[k] + O[k] + add)>>shift ); 662 dst[k+8] = Clip3( -32768, 32767, (E[7-k] - O[7-k] + add)>>shift ); 663 } 664 src ++; 665 dst += 16; 666 } 667 } 668 669 670 void partialButterfly32(short *src,short *dst,int shift, int line) 671 { 672 int j,k; 673 int E[16],O[16]; 674 int EE[8],EO[8]; 675 int EEE[4],EEO[4]; 676 int EEEE[2],EEEO[2]; 677 int add = 1<<(shift-1); 678 679 for (j=0; j<line; j++) 680 { 681 /* E and O*/ 682 for (k=0;k<16;k++) 683 { 684 E[k] = src[k] + src[31-k]; 685 O[k] = src[k] - src[31-k]; 686 } 687 /* EE and EO */ 688 for (k=0;k<8;k++) 689 { 690 EE[k] = E[k] + E[15-k]; 691 EO[k] = E[k] - E[15-k]; 692 } 693 /* EEE and EEO */ 694 for (k=0;k<4;k++) 695 { 696 EEE[k] = EE[k] + EE[7-k]; 697 EEO[k] = EE[k] - EE[7-k]; 698 } 699 /* EEEE and EEEO */ 700 EEEE[0] = EEE[0] + EEE[3]; 701 EEEO[0] = EEE[0] - EEE[3]; 702 EEEE[1] = EEE[1] + EEE[2]; 703 EEEO[1] = EEE[1] - EEE[2]; 704 705 dst[ 0 ] = (g_aiT32[ 0][0]*EEEE[0] + g_aiT32[ 0][1]*EEEE[1] + add)>>shift; 706 dst[ 16*line ] = (g_aiT32[16][0]*EEEE[0] + g_aiT32[16][1]*EEEE[1] + add)>>shift; 707 dst[ 8*line ] = (g_aiT32[ 8][0]*EEEO[0] + g_aiT32[ 8][1]*EEEO[1] + add)>>shift; 708 dst[ 24*line ] = (g_aiT32[24][0]*EEEO[0] + g_aiT32[24][1]*EEEO[1] + add)>>shift; 709 for (k=4;k<32;k+=8) 710 { 711 dst[ k*line ] = (g_aiT32[k][0]*EEO[0] + g_aiT32[k][1]*EEO[1] + g_aiT32[k][2]*EEO[2] + g_aiT32[k][3]*EEO[3] + add)>>shift; 712 } 713 for (k=2;k<32;k+=4) 714 { 715 dst[ k*line ] = (g_aiT32[k][0]*EO[0] + g_aiT32[k][1]*EO[1] + g_aiT32[k][2]*EO[2] + g_aiT32[k][3]*EO[3] + 716 g_aiT32[k][4]*EO[4] + g_aiT32[k][5]*EO[5] + g_aiT32[k][6]*EO[6] + g_aiT32[k][7]*EO[7] + add)>>shift; 717 } 718 for (k=1;k<32;k+=2) 719 { 720 dst[ k*line ] = (g_aiT32[k][ 0]*O[ 0] + g_aiT32[k][ 1]*O[ 1] + g_aiT32[k][ 2]*O[ 2] + g_aiT32[k][ 3]*O[ 3] + 721 g_aiT32[k][ 4]*O[ 4] + g_aiT32[k][ 5]*O[ 5] + g_aiT32[k][ 6]*O[ 6] + g_aiT32[k][ 7]*O[ 7] + 722 g_aiT32[k][ 8]*O[ 8] + g_aiT32[k][ 9]*O[ 9] + g_aiT32[k][10]*O[10] + g_aiT32[k][11]*O[11] + 723 g_aiT32[k][12]*O[12] + g_aiT32[k][13]*O[13] + g_aiT32[k][14]*O[14] + g_aiT32[k][15]*O[15] + add)>>shift; 724 } 725 src += 32; 726 dst ++; 727 } 728 } 729 730 731 void partialButterflyInverse32(short *src,short *dst,int shift, int line) 732 { 733 int j,k; 734 int E[16],O[16]; 735 int EE[8],EO[8]; 736 int EEE[4],EEO[4]; 737 int EEEE[2],EEEO[2]; 738 int add = 1<<(shift-1); 739 740 for (j=0; j<line; j++) 741 { 742 /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */ 743 for (k=0;k<16;k++) 744 { 745 O[k] = g_aiT32[ 1][k]*src[ line ] + g_aiT32[ 3][k]*src[ 3*line ] + g_aiT32[ 5][k]*src[ 5*line ] + g_aiT32[ 7][k]*src[ 7*line ] + 746 g_aiT32[ 9][k]*src[ 9*line ] + g_aiT32[11][k]*src[ 11*line ] + g_aiT32[13][k]*src[ 13*line ] + g_aiT32[15][k]*src[ 15*line ] + 747 g_aiT32[17][k]*src[ 17*line ] + g_aiT32[19][k]*src[ 19*line ] + g_aiT32[21][k]*src[ 21*line ] + g_aiT32[23][k]*src[ 23*line ] + 748 g_aiT32[25][k]*src[ 25*line ] + g_aiT32[27][k]*src[ 27*line ] + g_aiT32[29][k]*src[ 29*line ] + g_aiT32[31][k]*src[ 31*line ]; 749 } 750 for (k=0;k<8;k++) 751 { 752 EO[k] = g_aiT32[ 2][k]*src[ 2*line ] + g_aiT32[ 6][k]*src[ 6*line ] + g_aiT32[10][k]*src[ 10*line ] + g_aiT32[14][k]*src[ 14*line ] + 753 g_aiT32[18][k]*src[ 18*line ] + g_aiT32[22][k]*src[ 22*line ] + g_aiT32[26][k]*src[ 26*line ] + g_aiT32[30][k]*src[ 30*line ]; 754 } 755 for (k=0;k<4;k++) 756 { 757 EEO[k] = g_aiT32[4][k]*src[ 4*line ] + g_aiT32[12][k]*src[ 12*line ] + g_aiT32[20][k]*src[ 20*line ] + g_aiT32[28][k]*src[ 28*line ]; 758 } 759 EEEO[0] = g_aiT32[8][0]*src[ 8*line ] + g_aiT32[24][0]*src[ 24*line ]; 760 EEEO[1] = g_aiT32[8][1]*src[ 8*line ] + g_aiT32[24][1]*src[ 24*line ]; 761 EEEE[0] = g_aiT32[0][0]*src[ 0 ] + g_aiT32[16][0]*src[ 16*line ]; 762 EEEE[1] = g_aiT32[0][1]*src[ 0 ] + g_aiT32[16][1]*src[ 16*line ]; 763 764 /* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */ 765 EEE[0] = EEEE[0] + EEEO[0]; 766 EEE[3] = EEEE[0] - EEEO[0]; 767 EEE[1] = EEEE[1] + EEEO[1]; 768 EEE[2] = EEEE[1] - EEEO[1]; 769 for (k=0;k<4;k++) 770 { 771 EE[k] = EEE[k] + EEO[k]; 772 EE[k+4] = EEE[3-k] - EEO[3-k]; 773 } 774 for (k=0;k<8;k++) 775 { 776 E[k] = EE[k] + EO[k]; 777 E[k+8] = EE[7-k] - EO[7-k]; 778 } 779 for (k=0;k<16;k++) 780 { 781 dst[k] = Clip3( -32768, 32767, (E[k] + O[k] + add)>>shift ); 782 dst[k+16] = Clip3( -32768, 32767, (E[15-k] - O[15-k] + add)>>shift ); 783 } 784 src ++; 785 dst += 32; 786 } 787 } 788 789 790 /** MxN forward transform (2D) 791 * \param block input data (residual) 792 * \param coeff output data (transform coefficients) 793 * \param iWidth input data (width of transform) 794 * \param iHeight input data (height of transform) 795 */ 796 void xTrMxN(short *block,short *coeff, int iWidth, int iHeight, UInt uiMode) 797 { 798 #if FULL_NBIT 799 int shift_1st = g_aucConvertToBit[iWidth] + 1 + g_uiBitDepth - 8; // log2(iWidth) - 1 + g_uiBitDepth - 8 800 #else 801 int shift_1st = g_aucConvertToBit[iWidth] + 1 + g_uiBitIncrement; // log2(iWidth) - 1 + g_uiBitIncrement 802 #endif 803 int shift_2nd = g_aucConvertToBit[iHeight] + 8; // log2(iHeight) + 6 804 805 short tmp[ 64 * 64 ]; 806 807 if( iWidth == 16 && iHeight == 4) 808 { 809 partialButterfly16( block, tmp, shift_1st, iHeight ); 810 partialButterfly4( tmp, coeff, shift_2nd, iWidth ); 811 } 812 else if( iWidth == 32 && iHeight == 8 ) 813 { 814 partialButterfly32( block, tmp, shift_1st, iHeight ); 815 partialButterfly8( tmp, coeff, shift_2nd, iWidth ); 816 } 817 else if( iWidth == 4 && iHeight == 16) 818 { 819 partialButterfly4( block, tmp, shift_1st, iHeight ); 820 partialButterfly16( tmp, coeff, shift_2nd, iWidth ); 821 } 822 else if( iWidth == 8 && iHeight == 32 ) 823 { 824 partialButterfly8( block, tmp, shift_1st, iHeight ); 825 partialButterfly32( tmp, coeff, shift_2nd, iWidth ); 826 } 827 else if( iWidth == 4 && iHeight == 4) 828 { 829 if (uiMode != REG_DCT && (!uiMode || (uiMode>=2 && uiMode <= 25))) // Check for DCT or DST 830 { 831 fastForwardDst(block,tmp,shift_1st); // Forward DST BY FAST ALGORITHM, block input, tmp output 832 } 833 else 834 { 835 partialButterfly4(block, tmp, shift_1st, iHeight); 836 } 837 if (uiMode != REG_DCT && (!uiMode || (uiMode>=11 && uiMode <= 34))) // Check for DCT or DST 838 { 839 fastForwardDst(tmp,coeff,shift_2nd); // Forward DST BY FAST ALGORITHM, tmp input, coeff output 840 } 841 else 842 { 843 partialButterfly4(tmp, coeff, shift_2nd, iWidth); 844 } 845 } 846 else if( iWidth == 8 && iHeight == 8) 847 { 848 partialButterfly8( block, tmp, shift_1st, iHeight ); 849 partialButterfly8( tmp, coeff, shift_2nd, iWidth ); 850 } 851 else if( iWidth == 16 && iHeight == 16) 852 { 853 partialButterfly16( block, tmp, shift_1st, iHeight ); 854 partialButterfly16( tmp, coeff, shift_2nd, iWidth ); 855 } 856 else if( iWidth == 32 && iHeight == 32) 857 { 858 partialButterfly32( block, tmp, shift_1st, iHeight ); 859 partialButterfly32( tmp, coeff, shift_2nd, iWidth ); 860 } 861 } 862 /** MxN inverse transform (2D) 863 * \param coeff input data (transform coefficients) 864 * \param block output data (residual) 865 * \param iWidth input data (width of transform) 866 * \param iHeight input data (height of transform) 867 */ 868 void xITrMxN(short *coeff,short *block, int iWidth, int iHeight, UInt uiMode) 852 869 { 853 870 int shift_1st = SHIFT_INV_1ST; … … 857 874 int shift_2nd = SHIFT_INV_2ND - g_uiBitIncrement; 858 875 #endif 859 short tmp[8][8];860 861 partialButterflyInverse8(coeff,tmp,shift_1st);862 partialButterflyInverse8(tmp,block,shift_2nd);863 }864 865 /** 16x16 forward transform implemented using partial butterfly structure (1D)866 * \param src input data (residual)867 * \param dst output data (transform coefficients)868 * \param shift specifies right shift after 1D transform869 */870 void partialButterfly16(short src[16][16],short dst[16][16],int shift)871 {872 int j,k;873 int E[8],O[8];874 int EE[4],EO[4];875 int EEE[2],EEO[2];876 int add = 1<<(shift-1);877 878 for (j=0; j<16; j++)879 {880 /* E and O*/881 for (k=0;k<8;k++)882 {883 E[k] = src[j][k] + src[j][15-k];884 O[k] = src[j][k] - src[j][15-k];885 }886 /* EE and EO */887 for (k=0;k<4;k++)888 {889 EE[k] = E[k] + E[7-k];890 EO[k] = E[k] - E[7-k];891 }892 /* EEE and EEO */893 EEE[0] = EE[0] + EE[3];894 EEO[0] = EE[0] - EE[3];895 EEE[1] = EE[1] + EE[2];896 EEO[1] = EE[1] - EE[2];897 898 dst[ 0][j] = (g_aiT16[ 0][0]*EEE[0] + g_aiT16[ 0][1]*EEE[1] + add)>>shift;899 dst[ 8][j] = (g_aiT16[ 8][0]*EEE[0] + g_aiT16[ 8][1]*EEE[1] + add)>>shift;900 dst[ 4][j] = (g_aiT16[ 4][0]*EEO[0] + g_aiT16[ 4][1]*EEO[1] + add)>>shift;901 dst[12][j] = (g_aiT16[12][0]*EEO[0] + g_aiT16[12][1]*EEO[1] + add)>>shift;902 903 for (k=2;k<16;k+=4)904 {905 dst[k][j] = (g_aiT16[k][0]*EO[0] + g_aiT16[k][1]*EO[1] + g_aiT16[k][2]*EO[2] + g_aiT16[k][3]*EO[3] + add)>>shift;906 }907 908 for (k=1;k<16;k+=2)909 {910 dst[k][j] = (g_aiT16[k][0]*O[0] + g_aiT16[k][1]*O[1] + g_aiT16[k][2]*O[2] + g_aiT16[k][3]*O[3] +911 g_aiT16[k][4]*O[4] + g_aiT16[k][5]*O[5] + g_aiT16[k][6]*O[6] + g_aiT16[k][7]*O[7] + add)>>shift;912 }913 914 }915 }916 #endif917 918 void partialButterfly16(short *src,short *dst,int shift, int line)919 {920 int j,k;921 int E[8],O[8];922 int EE[4],EO[4];923 int EEE[2],EEO[2];924 int add = 1<<(shift-1);925 926 for (j=0; j<line; j++)927 {928 /* E and O*/929 for (k=0;k<8;k++)930 {931 E[k] = src[k] + src[15-k];932 O[k] = src[k] - src[15-k];933 }934 /* EE and EO */935 for (k=0;k<4;k++)936 {937 EE[k] = E[k] + E[7-k];938 EO[k] = E[k] - E[7-k];939 }940 /* EEE and EEO */941 EEE[0] = EE[0] + EE[3];942 EEO[0] = EE[0] - EE[3];943 EEE[1] = EE[1] + EE[2];944 EEO[1] = EE[1] - EE[2];945 946 dst[ 0 ] = (g_aiT16[ 0][0]*EEE[0] + g_aiT16[ 0][1]*EEE[1] + add)>>shift;947 dst[ 8*line ] = (g_aiT16[ 8][0]*EEE[0] + g_aiT16[ 8][1]*EEE[1] + add)>>shift;948 dst[ 4*line ] = (g_aiT16[ 4][0]*EEO[0] + g_aiT16[ 4][1]*EEO[1] + add)>>shift;949 dst[ 12*line] = (g_aiT16[12][0]*EEO[0] + g_aiT16[12][1]*EEO[1] + add)>>shift;950 951 for (k=2;k<16;k+=4)952 {953 dst[ k*line ] = (g_aiT16[k][0]*EO[0] + g_aiT16[k][1]*EO[1] + g_aiT16[k][2]*EO[2] + g_aiT16[k][3]*EO[3] + add)>>shift;954 }955 956 for (k=1;k<16;k+=2)957 {958 dst[ k*line ] = (g_aiT16[k][0]*O[0] + g_aiT16[k][1]*O[1] + g_aiT16[k][2]*O[2] + g_aiT16[k][3]*O[3] +959 g_aiT16[k][4]*O[4] + g_aiT16[k][5]*O[5] + g_aiT16[k][6]*O[6] + g_aiT16[k][7]*O[7] + add)>>shift;960 }961 962 src += 16;963 dst ++;964 965 }966 }967 968 #if !UNIFIED_TRANSFORM969 /** 16x16 forward transform (2D)970 * \param block input data (residual)971 * \param coeff output data (transform coefficients)972 */973 void xTr16(short block[16][16],short coeff[16][16])974 {975 #if FULL_NBIT976 int shift_1st = 3 + g_uiBitDepth - 8; // log2(16) - 1 + g_uiBitDepth - 8977 #else978 int shift_1st = 3 + g_uiBitIncrement; // log2(16) - 1 + g_uiBitIncrement979 #endif980 int shift_2nd = 10; // log2(16) + 6981 short tmp[16][16];982 983 partialButterfly16(block,tmp,shift_1st);984 partialButterfly16(tmp,coeff,shift_2nd);985 }986 987 /** 16x16 inverse transform implemented using partial butterfly structure (1D)988 * \param src input data (transform coefficients)989 * \param dst output data (residual)990 * \param shift specifies right shift after 1D transform991 */992 void partialButterflyInverse16(short src[16][16],short dst[16][16],int shift)993 {994 int j,k;995 int E[8],O[8];996 int EE[4],EO[4];997 int EEE[2],EEO[2];998 int add = 1<<(shift-1);999 1000 for (j=0; j<16; j++)1001 {1002 /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */1003 for (k=0;k<8;k++)1004 {1005 O[k] = g_aiT16[ 1][k]*src[ 1][j] + g_aiT16[ 3][k]*src[ 3][j] + g_aiT16[ 5][k]*src[ 5][j] + g_aiT16[ 7][k]*src[ 7][j] +1006 g_aiT16[ 9][k]*src[ 9][j] + g_aiT16[11][k]*src[11][j] + g_aiT16[13][k]*src[13][j] + g_aiT16[15][k]*src[15][j];1007 }1008 for (k=0;k<4;k++)1009 {1010 EO[k] = g_aiT16[ 2][k]*src[ 2][j] + g_aiT16[ 6][k]*src[ 6][j] + g_aiT16[10][k]*src[10][j] + g_aiT16[14][k]*src[14][j];1011 }1012 EEO[0] = g_aiT16[4][0]*src[4][j] + g_aiT16[12][0]*src[12][j];1013 EEE[0] = g_aiT16[0][0]*src[0][j] + g_aiT16[ 8][0]*src[ 8][j];1014 EEO[1] = g_aiT16[4][1]*src[4][j] + g_aiT16[12][1]*src[12][j];1015 EEE[1] = g_aiT16[0][1]*src[0][j] + g_aiT16[ 8][1]*src[ 8][j];1016 1017 /* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */1018 for (k=0;k<2;k++)1019 {1020 EE[k] = EEE[k] + EEO[k];1021 EE[k+2] = EEE[1-k] - EEO[1-k];1022 }1023 for (k=0;k<4;k++)1024 {1025 E[k] = EE[k] + EO[k];1026 E[k+4] = EE[3-k] - EO[3-k];1027 }1028 for (k=0;k<8;k++)1029 {1030 dst[j][k] = Clip3( -32768, 32767, (E[k] + O[k] + add)>>shift );1031 dst[j][k+8] = Clip3( -32768, 32767, (E[7-k] - O[7-k] + add)>>shift );1032 }1033 }1034 }1035 #endif1036 1037 void partialButterflyInverse16(short *src,short *dst,int shift, int line)1038 {1039 int j,k;1040 int E[8],O[8];1041 int EE[4],EO[4];1042 int EEE[2],EEO[2];1043 int add = 1<<(shift-1);1044 1045 for (j=0; j<line; j++)1046 {1047 /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */1048 for (k=0;k<8;k++)1049 {1050 O[k] = g_aiT16[ 1][k]*src[ line] + g_aiT16[ 3][k]*src[ 3*line] + g_aiT16[ 5][k]*src[ 5*line] + g_aiT16[ 7][k]*src[ 7*line] +1051 g_aiT16[ 9][k]*src[ 9*line] + g_aiT16[11][k]*src[11*line] + g_aiT16[13][k]*src[13*line] + g_aiT16[15][k]*src[15*line];1052 }1053 for (k=0;k<4;k++)1054 {1055 EO[k] = g_aiT16[ 2][k]*src[ 2*line] + g_aiT16[ 6][k]*src[ 6*line] + g_aiT16[10][k]*src[10*line] + g_aiT16[14][k]*src[14*line];1056 }1057 EEO[0] = g_aiT16[4][0]*src[ 4*line ] + g_aiT16[12][0]*src[ 12*line ];1058 EEE[0] = g_aiT16[0][0]*src[ 0 ] + g_aiT16[ 8][0]*src[ 8*line ];1059 EEO[1] = g_aiT16[4][1]*src[ 4*line ] + g_aiT16[12][1]*src[ 12*line ];1060 EEE[1] = g_aiT16[0][1]*src[ 0 ] + g_aiT16[ 8][1]*src[ 8*line ];1061 1062 /* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */1063 for (k=0;k<2;k++)1064 {1065 EE[k] = EEE[k] + EEO[k];1066 EE[k+2] = EEE[1-k] - EEO[1-k];1067 }1068 for (k=0;k<4;k++)1069 {1070 E[k] = EE[k] + EO[k];1071 E[k+4] = EE[3-k] - EO[3-k];1072 }1073 for (k=0;k<8;k++)1074 {1075 dst[k] = Clip3( -32768, 32767, (E[k] + O[k] + add)>>shift );1076 dst[k+8] = Clip3( -32768, 32767, (E[7-k] - O[7-k] + add)>>shift );1077 }1078 src ++;1079 dst += 16;1080 }1081 }1082 1083 #if !UNIFIED_TRANSFORM1084 /** 16x16 inverse transform (2D)1085 * \param coeff input data (transform coefficients)1086 * \param block output data (residual)1087 */1088 void xITr16(short coeff[16][16],short block[16][16])1089 {1090 int shift_1st = SHIFT_INV_1ST;1091 #if FULL_NBIT1092 int shift_2nd = SHIFT_INV_2ND - ((short)g_uiBitDepth - 8);1093 #else1094 int shift_2nd = SHIFT_INV_2ND - g_uiBitIncrement;1095 #endif1096 short tmp[16][16];1097 1098 partialButterflyInverse16(coeff,tmp,shift_1st);1099 partialButterflyInverse16(tmp,block,shift_2nd);1100 }1101 1102 /** 32x32 forward transform implemented using partial butterfly structure (1D)1103 * \param src input data (residual)1104 * \param dst output data (transform coefficients)1105 * \param shift specifies right shift after 1D transform1106 */1107 void partialButterfly32(short src[32][32],short dst[32][32],int shift)1108 {1109 int j,k;1110 int E[16],O[16];1111 int EE[8],EO[8];1112 int EEE[4],EEO[4];1113 int EEEE[2],EEEO[2];1114 int add = 1<<(shift-1);1115 1116 for (j=0; j<32; j++)1117 {1118 /* E and O*/1119 for (k=0;k<16;k++)1120 {1121 E[k] = src[j][k] + src[j][31-k];1122 O[k] = src[j][k] - src[j][31-k];1123 }1124 /* EE and EO */1125 for (k=0;k<8;k++)1126 {1127 EE[k] = E[k] + E[15-k];1128 EO[k] = E[k] - E[15-k];1129 }1130 /* EEE and EEO */1131 for (k=0;k<4;k++)1132 {1133 EEE[k] = EE[k] + EE[7-k];1134 EEO[k] = EE[k] - EE[7-k];1135 }1136 /* EEEE and EEEO */1137 EEEE[0] = EEE[0] + EEE[3];1138 EEEO[0] = EEE[0] - EEE[3];1139 EEEE[1] = EEE[1] + EEE[2];1140 EEEO[1] = EEE[1] - EEE[2];1141 1142 dst[ 0][j] = (g_aiT32[ 0][0]*EEEE[0] + g_aiT32[ 0][1]*EEEE[1] + add)>>shift;1143 dst[16][j] = (g_aiT32[16][0]*EEEE[0] + g_aiT32[16][1]*EEEE[1] + add)>>shift;1144 dst[ 8][j] = (g_aiT32[ 8][0]*EEEO[0] + g_aiT32[ 8][1]*EEEO[1] + add)>>shift;1145 dst[24][j] = (g_aiT32[24][0]*EEEO[0] + g_aiT32[24][1]*EEEO[1] + add)>>shift;1146 for (k=4;k<32;k+=8)1147 {1148 dst[k][j] = (g_aiT32[k][0]*EEO[0] + g_aiT32[k][1]*EEO[1] + g_aiT32[k][2]*EEO[2] + g_aiT32[k][3]*EEO[3] + add)>>shift;1149 }1150 for (k=2;k<32;k+=4)1151 {1152 dst[k][j] = (g_aiT32[k][0]*EO[0] + g_aiT32[k][1]*EO[1] + g_aiT32[k][2]*EO[2] + g_aiT32[k][3]*EO[3] +1153 g_aiT32[k][4]*EO[4] + g_aiT32[k][5]*EO[5] + g_aiT32[k][6]*EO[6] + g_aiT32[k][7]*EO[7] + add)>>shift;1154 }1155 for (k=1;k<32;k+=2)1156 {1157 dst[k][j] = (g_aiT32[k][ 0]*O[ 0] + g_aiT32[k][ 1]*O[ 1] + g_aiT32[k][ 2]*O[ 2] + g_aiT32[k][ 3]*O[ 3] +1158 g_aiT32[k][ 4]*O[ 4] + g_aiT32[k][ 5]*O[ 5] + g_aiT32[k][ 6]*O[ 6] + g_aiT32[k][ 7]*O[ 7] +1159 g_aiT32[k][ 8]*O[ 8] + g_aiT32[k][ 9]*O[ 9] + g_aiT32[k][10]*O[10] + g_aiT32[k][11]*O[11] +1160 g_aiT32[k][12]*O[12] + g_aiT32[k][13]*O[13] + g_aiT32[k][14]*O[14] + g_aiT32[k][15]*O[15] + add)>>shift;1161 }1162 }1163 }1164 #endif1165 1166 void partialButterfly32(short *src,short *dst,int shift, int line)1167 {1168 int j,k;1169 int E[16],O[16];1170 int EE[8],EO[8];1171 int EEE[4],EEO[4];1172 int EEEE[2],EEEO[2];1173 int add = 1<<(shift-1);1174 1175 for (j=0; j<line; j++)1176 {1177 /* E and O*/1178 for (k=0;k<16;k++)1179 {1180 E[k] = src[k] + src[31-k];1181 O[k] = src[k] - src[31-k];1182 }1183 /* EE and EO */1184 for (k=0;k<8;k++)1185 {1186 EE[k] = E[k] + E[15-k];1187 EO[k] = E[k] - E[15-k];1188 }1189 /* EEE and EEO */1190 for (k=0;k<4;k++)1191 {1192 EEE[k] = EE[k] + EE[7-k];1193 EEO[k] = EE[k] - EE[7-k];1194 }1195 /* EEEE and EEEO */1196 EEEE[0] = EEE[0] + EEE[3];1197 EEEO[0] = EEE[0] - EEE[3];1198 EEEE[1] = EEE[1] + EEE[2];1199 EEEO[1] = EEE[1] - EEE[2];1200 1201 dst[ 0 ] = (g_aiT32[ 0][0]*EEEE[0] + g_aiT32[ 0][1]*EEEE[1] + add)>>shift;1202 dst[ 16*line ] = (g_aiT32[16][0]*EEEE[0] + g_aiT32[16][1]*EEEE[1] + add)>>shift;1203 dst[ 8*line ] = (g_aiT32[ 8][0]*EEEO[0] + g_aiT32[ 8][1]*EEEO[1] + add)>>shift;1204 dst[ 24*line ] = (g_aiT32[24][0]*EEEO[0] + g_aiT32[24][1]*EEEO[1] + add)>>shift;1205 for (k=4;k<32;k+=8)1206 {1207 dst[ k*line ] = (g_aiT32[k][0]*EEO[0] + g_aiT32[k][1]*EEO[1] + g_aiT32[k][2]*EEO[2] + g_aiT32[k][3]*EEO[3] + add)>>shift;1208 }1209 for (k=2;k<32;k+=4)1210 {1211 dst[ k*line ] = (g_aiT32[k][0]*EO[0] + g_aiT32[k][1]*EO[1] + g_aiT32[k][2]*EO[2] + g_aiT32[k][3]*EO[3] +1212 g_aiT32[k][4]*EO[4] + g_aiT32[k][5]*EO[5] + g_aiT32[k][6]*EO[6] + g_aiT32[k][7]*EO[7] + add)>>shift;1213 }1214 for (k=1;k<32;k+=2)1215 {1216 dst[ k*line ] = (g_aiT32[k][ 0]*O[ 0] + g_aiT32[k][ 1]*O[ 1] + g_aiT32[k][ 2]*O[ 2] + g_aiT32[k][ 3]*O[ 3] +1217 g_aiT32[k][ 4]*O[ 4] + g_aiT32[k][ 5]*O[ 5] + g_aiT32[k][ 6]*O[ 6] + g_aiT32[k][ 7]*O[ 7] +1218 g_aiT32[k][ 8]*O[ 8] + g_aiT32[k][ 9]*O[ 9] + g_aiT32[k][10]*O[10] + g_aiT32[k][11]*O[11] +1219 g_aiT32[k][12]*O[12] + g_aiT32[k][13]*O[13] + g_aiT32[k][14]*O[14] + g_aiT32[k][15]*O[15] + add)>>shift;1220 }1221 src += 32;1222 dst ++;1223 }1224 }1225 1226 #if !UNIFIED_TRANSFORM1227 /** 32x32 forward transform (2D)1228 * \param block input data (residual)1229 * \param coeff output data (transform coefficients)1230 */1231 void xTr32(short block[32][32],short coeff[32][32])1232 {1233 #if FULL_NBIT1234 int shift_1st = 4 + g_uiBitDepth - 8; // log2(32) - 1 + g_uiBitDepth - 81235 #else1236 int shift_1st = 4 + g_uiBitIncrement; // log2(32) - 1 + g_uiBitIncrement1237 #endif1238 int shift_2nd = 11; // log2(32) + 61239 short tmp[32][32];1240 1241 partialButterfly32(block,tmp,shift_1st);1242 partialButterfly32(tmp,coeff,shift_2nd);1243 }1244 1245 /** 32x32 inverse transform implemented using partial butterfly structure (1D)1246 * \param src input data (transform coefficients)1247 * \param dst output data (residual)1248 * \param shift specifies right shift after 1D transform1249 */1250 void partialButterflyInverse32(short src[32][32],short dst[32][32],int shift)1251 {1252 int j,k;1253 int E[16],O[16];1254 int EE[8],EO[8];1255 int EEE[4],EEO[4];1256 int EEEE[2],EEEO[2];1257 int add = 1<<(shift-1);1258 1259 for (j=0; j<32; j++)1260 {1261 /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */1262 for (k=0;k<16;k++)1263 {1264 O[k] = g_aiT32[ 1][k]*src[ 1][j] + g_aiT32[ 3][k]*src[ 3][j] + g_aiT32[ 5][k]*src[ 5][j] + g_aiT32[ 7][k]*src[ 7][j] +1265 g_aiT32[ 9][k]*src[ 9][j] + g_aiT32[11][k]*src[11][j] + g_aiT32[13][k]*src[13][j] + g_aiT32[15][k]*src[15][j] +1266 g_aiT32[17][k]*src[17][j] + g_aiT32[19][k]*src[19][j] + g_aiT32[21][k]*src[21][j] + g_aiT32[23][k]*src[23][j] +1267 g_aiT32[25][k]*src[25][j] + g_aiT32[27][k]*src[27][j] + g_aiT32[29][k]*src[29][j] + g_aiT32[31][k]*src[31][j];1268 }1269 for (k=0;k<8;k++)1270 {1271 EO[k] = g_aiT32[ 2][k]*src[ 2][j] + g_aiT32[ 6][k]*src[ 6][j] + g_aiT32[10][k]*src[10][j] + g_aiT32[14][k]*src[14][j] +1272 g_aiT32[18][k]*src[18][j] + g_aiT32[22][k]*src[22][j] + g_aiT32[26][k]*src[26][j] + g_aiT32[30][k]*src[30][j];1273 }1274 for (k=0;k<4;k++)1275 {1276 EEO[k] = g_aiT32[4][k]*src[4][j] + g_aiT32[12][k]*src[12][j] + g_aiT32[20][k]*src[20][j] + g_aiT32[28][k]*src[28][j];1277 }1278 EEEO[0] = g_aiT32[8][0]*src[8][j] + g_aiT32[24][0]*src[24][j];1279 EEEO[1] = g_aiT32[8][1]*src[8][j] + g_aiT32[24][1]*src[24][j];1280 EEEE[0] = g_aiT32[0][0]*src[0][j] + g_aiT32[16][0]*src[16][j];1281 EEEE[1] = g_aiT32[0][1]*src[0][j] + g_aiT32[16][1]*src[16][j];1282 1283 /* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */1284 EEE[0] = EEEE[0] + EEEO[0];1285 EEE[3] = EEEE[0] - EEEO[0];1286 EEE[1] = EEEE[1] + EEEO[1];1287 EEE[2] = EEEE[1] - EEEO[1];1288 for (k=0;k<4;k++)1289 {1290 EE[k] = EEE[k] + EEO[k];1291 EE[k+4] = EEE[3-k] - EEO[3-k];1292 }1293 for (k=0;k<8;k++)1294 {1295 E[k] = EE[k] + EO[k];1296 E[k+8] = EE[7-k] - EO[7-k];1297 }1298 for (k=0;k<16;k++)1299 {1300 dst[j][k] = Clip3( -32768, 32767, (E[k] + O[k] + add)>>shift );1301 dst[j][k+16] = Clip3( -32768, 32767, (E[15-k] - O[15-k] + add)>>shift );1302 }1303 }1304 }1305 #endif1306 1307 void partialButterflyInverse32(short *src,short *dst,int shift, int line)1308 {1309 int j,k;1310 int E[16],O[16];1311 int EE[8],EO[8];1312 int EEE[4],EEO[4];1313 int EEEE[2],EEEO[2];1314 int add = 1<<(shift-1);1315 1316 for (j=0; j<line; j++)1317 {1318 /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */1319 for (k=0;k<16;k++)1320 {1321 O[k] = g_aiT32[ 1][k]*src[ line ] + g_aiT32[ 3][k]*src[ 3*line ] + g_aiT32[ 5][k]*src[ 5*line ] + g_aiT32[ 7][k]*src[ 7*line ] +1322 g_aiT32[ 9][k]*src[ 9*line ] + g_aiT32[11][k]*src[ 11*line ] + g_aiT32[13][k]*src[ 13*line ] + g_aiT32[15][k]*src[ 15*line ] +1323 g_aiT32[17][k]*src[ 17*line ] + g_aiT32[19][k]*src[ 19*line ] + g_aiT32[21][k]*src[ 21*line ] + g_aiT32[23][k]*src[ 23*line ] +1324 g_aiT32[25][k]*src[ 25*line ] + g_aiT32[27][k]*src[ 27*line ] + g_aiT32[29][k]*src[ 29*line ] + g_aiT32[31][k]*src[ 31*line ];1325 }1326 for (k=0;k<8;k++)1327 {1328 EO[k] = g_aiT32[ 2][k]*src[ 2*line ] + g_aiT32[ 6][k]*src[ 6*line ] + g_aiT32[10][k]*src[ 10*line ] + g_aiT32[14][k]*src[ 14*line ] +1329 g_aiT32[18][k]*src[ 18*line ] + g_aiT32[22][k]*src[ 22*line ] + g_aiT32[26][k]*src[ 26*line ] + g_aiT32[30][k]*src[ 30*line ];1330 }1331 for (k=0;k<4;k++)1332 {1333 EEO[k] = g_aiT32[4][k]*src[ 4*line ] + g_aiT32[12][k]*src[ 12*line ] + g_aiT32[20][k]*src[ 20*line ] + g_aiT32[28][k]*src[ 28*line ];1334 }1335 EEEO[0] = g_aiT32[8][0]*src[ 8*line ] + g_aiT32[24][0]*src[ 24*line ];1336 EEEO[1] = g_aiT32[8][1]*src[ 8*line ] + g_aiT32[24][1]*src[ 24*line ];1337 EEEE[0] = g_aiT32[0][0]*src[ 0 ] + g_aiT32[16][0]*src[ 16*line ];1338 EEEE[1] = g_aiT32[0][1]*src[ 0 ] + g_aiT32[16][1]*src[ 16*line ];1339 1340 /* Combining even and odd terms at each hierarchy levels to calculate the final spatial domain vector */1341 EEE[0] = EEEE[0] + EEEO[0];1342 EEE[3] = EEEE[0] - EEEO[0];1343 EEE[1] = EEEE[1] + EEEO[1];1344 EEE[2] = EEEE[1] - EEEO[1];1345 for (k=0;k<4;k++)1346 {1347 EE[k] = EEE[k] + EEO[k];1348 EE[k+4] = EEE[3-k] - EEO[3-k];1349 }1350 for (k=0;k<8;k++)1351 {1352 E[k] = EE[k] + EO[k];1353 E[k+8] = EE[7-k] - EO[7-k];1354 }1355 for (k=0;k<16;k++)1356 {1357 dst[k] = Clip3( -32768, 32767, (E[k] + O[k] + add)>>shift );1358 dst[k+16] = Clip3( -32768, 32767, (E[15-k] - O[15-k] + add)>>shift );1359 }1360 src ++;1361 dst += 32;1362 }1363 }1364 1365 #if !UNIFIED_TRANSFORM1366 /** 32x32 inverse transform (2D)1367 * \param coeff input data (transform coefficients)1368 * \param block output data (residual)1369 */1370 void xITr32(short coeff[32][32],short block[32][32])1371 {1372 int shift_1st = SHIFT_INV_1ST;1373 #if FULL_NBIT1374 int shift_2nd = SHIFT_INV_2ND - ((short)g_uiBitDepth - 8);1375 #else1376 int shift_2nd = SHIFT_INV_2ND - g_uiBitIncrement;1377 #endif1378 short tmp[32][32];1379 1380 partialButterflyInverse32(coeff,tmp,shift_1st);1381 partialButterflyInverse32(tmp,block,shift_2nd);1382 }1383 #endif1384 1385 /** MxN forward transform (2D)1386 * \param block input data (residual)1387 * \param coeff output data (transform coefficients)1388 * \param iWidth input data (width of transform)1389 * \param iHeight input data (height of transform)1390 */1391 #if UNIFIED_TRANSFORM1392 void xTrMxN(short *block,short *coeff, int iWidth, int iHeight, UInt uiMode)1393 #else1394 void xTrMxN(short *block,short *coeff, int iWidth, int iHeight)1395 #endif1396 {1397 #if FULL_NBIT1398 int shift_1st = g_aucConvertToBit[iWidth] + 1 + g_uiBitDepth - 8; // log2(iWidth) - 1 + g_uiBitDepth - 81399 #else1400 int shift_1st = g_aucConvertToBit[iWidth] + 1 + g_uiBitIncrement; // log2(iWidth) - 1 + g_uiBitIncrement1401 #endif1402 int shift_2nd = g_aucConvertToBit[iHeight] + 8; // log2(iHeight) + 61403 1404 short tmp[ 64 * 64 ];1405 1406 if( iWidth == 16 && iHeight == 4)1407 {1408 partialButterfly16( block, tmp, shift_1st, iHeight );1409 partialButterfly4( tmp, coeff, shift_2nd, iWidth );1410 }1411 else if( iWidth == 32 && iHeight == 8 )1412 {1413 partialButterfly32( block, tmp, shift_1st, iHeight );1414 partialButterfly8( tmp, coeff, shift_2nd, iWidth );1415 }1416 else if( iWidth == 4 && iHeight == 16)1417 {1418 partialButterfly4( block, tmp, shift_1st, iHeight );1419 partialButterfly16( tmp, coeff, shift_2nd, iWidth );1420 }1421 else if( iWidth == 8 && iHeight == 32 )1422 {1423 partialButterfly8( block, tmp, shift_1st, iHeight );1424 partialButterfly32( tmp, coeff, shift_2nd, iWidth );1425 }1426 #if UNIFIED_TRANSFORM1427 else if( iWidth == 4 && iHeight == 4)1428 {1429 #if LOGI_INTRA_NAME_3MPM1430 if (uiMode != REG_DCT && (!uiMode || (uiMode>=2 && uiMode <= 25))) // Check for DCT or DST1431 #else1432 if (uiMode != REG_DCT && g_aucDCTDSTMode_Hor[uiMode])// Check for DCT or DST1433 #endif1434 {1435 fastForwardDst(block,tmp,shift_1st); // Forward DST BY FAST ALGORITHM, block input, tmp output1436 }1437 else1438 {1439 partialButterfly4(block, tmp, shift_1st, iHeight);1440 }1441 #if LOGI_INTRA_NAME_3MPM1442 if (uiMode != REG_DCT && (!uiMode || (uiMode>=11 && uiMode <= 34))) // Check for DCT or DST1443 #else1444 if (uiMode != REG_DCT && g_aucDCTDSTMode_Vert[uiMode] ) // Check for DCT or DST1445 #endif1446 {1447 fastForwardDst(tmp,coeff,shift_2nd); // Forward DST BY FAST ALGORITHM, tmp input, coeff output1448 }1449 else1450 {1451 partialButterfly4(tmp, coeff, shift_2nd, iWidth);1452 }1453 }1454 else if( iWidth == 8 && iHeight == 8)1455 {1456 partialButterfly8( block, tmp, shift_1st, iHeight );1457 partialButterfly8( tmp, coeff, shift_2nd, iWidth );1458 }1459 else if( iWidth == 16 && iHeight == 16)1460 {1461 partialButterfly16( block, tmp, shift_1st, iHeight );1462 partialButterfly16( tmp, coeff, shift_2nd, iWidth );1463 }1464 else if( iWidth == 32 && iHeight == 32)1465 {1466 partialButterfly32( block, tmp, shift_1st, iHeight );1467 partialButterfly32( tmp, coeff, shift_2nd, iWidth );1468 }1469 #endif1470 }1471 /** MxN inverse transform (2D)1472 * \param coeff input data (transform coefficients)1473 * \param block output data (residual)1474 * \param iWidth input data (width of transform)1475 * \param iHeight input data (height of transform)1476 */1477 #if UNIFIED_TRANSFORM1478 void xITrMxN(short *coeff,short *block, int iWidth, int iHeight, UInt uiMode)1479 #else1480 void xITrMxN(short *coeff,short *block, int iWidth, int iHeight)1481 #endif1482 {1483 int shift_1st = SHIFT_INV_1ST;1484 #if FULL_NBIT1485 int shift_2nd = SHIFT_INV_2ND - ((short)g_uiBitDepth - 8);1486 #else1487 int shift_2nd = SHIFT_INV_2ND - g_uiBitIncrement;1488 #endif1489 876 1490 877 short tmp[ 64*64]; … … 1509 896 partialButterflyInverse8(tmp,block,shift_2nd,iHeight); 1510 897 } 1511 #if UNIFIED_TRANSFORM1512 898 else if( iWidth == 4 && iHeight == 4) 1513 899 { 1514 #if LOGI_INTRA_NAME_3MPM1515 900 if (uiMode != REG_DCT && (!uiMode || (uiMode>=11 && uiMode <= 34))) // Check for DCT or DST 1516 #else1517 if (uiMode != REG_DCT && g_aucDCTDSTMode_Vert[uiMode] ) // Check for DCT or DST1518 #endif1519 901 { 1520 902 fastInverseDst(coeff,tmp,shift_1st); // Inverse DST by FAST Algorithm, coeff input, tmp output … … 1524 906 partialButterflyInverse4(coeff,tmp,shift_1st,iWidth); 1525 907 } 1526 #if LOGI_INTRA_NAME_3MPM1527 908 if (uiMode != REG_DCT && (!uiMode || (uiMode>=2 && uiMode <= 25))) // Check for DCT or DST 1528 #else1529 if (uiMode != REG_DCT && g_aucDCTDSTMode_Hor[uiMode] ) // Check for DCT or DST1530 #endif1531 909 { 1532 910 fastInverseDst(tmp,block,shift_2nd); // Inverse DST by FAST Algorithm, tmp input, coeff output … … 1552 930 partialButterflyInverse32(tmp,block,shift_2nd,iHeight); 1553 931 } 1554 #endif1555 932 } 1556 933 1557 934 #endif //MATRIX_MULT 1558 935 1559 #if MULTIBITS_DATA_HIDING1560 936 // To minimize the distortion only. No rate is considered. 1561 937 Void TComTrQuant::signBitHidingHDQ( TComDataCU* pcCU, TCoeff* pQCoef, TCoeff* pCoef, UInt const *scan, Int* deltaU, Int width, Int height ) … … 1684 1060 return; 1685 1061 } 1686 #endif1687 1062 1688 1063 Void TComTrQuant::xQuant( TComDataCU* pcCU, … … 1715 1090 else 1716 1091 { 1717 #if MULTIBITS_DATA_HIDING1718 1092 const UInt log2BlockSize = g_aucConvertToBit[ iWidth ] + 2; 1719 1093 … … 1740 1114 1741 1115 Int deltaU[32*32] ; 1742 #endif1743 1116 1744 1117 #if ADAPTIVE_QP_SELECTION … … 1746 1119 Int iQpBase = pcCU->getSlice()->getSliceQpBase(); 1747 1120 1748 #if H0736_AVC_STYLE_QP_RANGE1749 1121 Int qpScaled; 1750 1122 Int qpBDOffset = (eTType == TEXT_LUMA)? pcCU->getSlice()->getSPS()->getQpBDOffsetY() : pcCU->getSlice()->getSPS()->getQpBDOffsetC(); … … 1768 1140 } 1769 1141 cQpBase.setQpParam(qpScaled, false, pcCU->getSlice()->getSliceType()); 1770 #else1771 if(eTType != TEXT_LUMA)1772 {1773 iQpBase = g_aucChromaScale[iQpBase];1774 }1775 cQpBase.setQpParam(iQpBase, false, pcCU->getSlice()->getSliceType());1776 #endif1777 1142 #endif 1778 1143 … … 1811 1176 #endif 1812 1177 1813 #if MULTIBITS_DATA_HIDING1814 1178 Int qBits8 = iQBits-8; 1815 #endif1816 1179 for( Int n = 0; n < iWidth*iHeight; n++ ) 1817 1180 { … … 1829 1192 } 1830 1193 iLevel = (Int)((tmpLevel + iAdd ) >> iQBits); 1831 #if MULTIBITS_DATA_HIDING1832 1194 deltaU[uiBlockPos] = (Int)((tmpLevel - (iLevel<<iQBits) )>> qBits8); 1833 #endif1834 1195 #else 1835 1196 iLevel = ((Int64)abs(iLevel) * piQuantCoeff[uiBlockPos] + iAdd ) >> iQBits; 1836 #if MULTIBITS_DATA_HIDING1837 1197 deltaU[uiBlockPos] = (Int)( ((Int64)abs(iLevel) * piQuantCoeff[uiBlockPos] - (iLevel<<iQBits) )>> qBits8 ); 1838 #endif1839 1198 #endif 1840 1199 uiAcSum += iLevel; … … 1842 1201 piQCoef[uiBlockPos] = Clip3( -32768, 32767, iLevel ); 1843 1202 } // for n 1844 #if MULTIBITS_DATA_HIDING1845 1203 if( pcCU->getSlice()->getPPS()->getSignHideFlag() ) 1846 1204 { … … 1850 1208 } 1851 1209 } 1852 #endif1853 1210 } //if RDOQ 1854 1211 //return; … … 1888 1245 iShift = QUANT_IQUANT_SHIFT - QUANT_SHIFT - iTransformShift; 1889 1246 1890 #if DEQUANT_CLIPPING1891 1247 TCoeff clipQCoef; 1892 1248 const Int bitRange = min( 15, ( Int )( 12 + uiLog2TrSize + uiBitDepth - m_cQP.m_iPer) ); 1893 1249 const Int levelLimit = 1 << bitRange; 1894 #endif1895 1250 1896 1251 if(getUseScalingList()) … … 1911 1266 for( Int n = 0; n < iWidth*iHeight; n++ ) 1912 1267 { 1913 #if DEQUANT_CLIPPING1914 1268 clipQCoef = Clip3( -32768, 32767, piQCoef[n] ); 1915 1269 iCoeffQ = ((clipQCoef * piDequantCoef[n]) + iAdd ) >> (iShift - m_cQP.m_iPer); 1916 #else1917 iCoeffQ = ((piQCoef[n] * piDequantCoef[n]) + iAdd ) >> (iShift - m_cQP.m_iPer);1918 #endif1919 1270 piCoef[n] = Clip3(-32768,32767,iCoeffQ); 1920 1271 } … … 1924 1275 for( Int n = 0; n < iWidth*iHeight; n++ ) 1925 1276 { 1926 #if DEQUANT_CLIPPING1927 1277 clipQCoef = Clip3( -levelLimit, levelLimit - 1, piQCoef[n] ); 1928 1278 iCoeffQ = (clipQCoef * piDequantCoef[n]) << (m_cQP.m_iPer - iShift); 1929 #else1930 iCoeffQ = (piQCoef[n] * piDequantCoef[n]) << (m_cQP.m_iPer - iShift);1931 #endif1932 1279 piCoef[n] = Clip3(-32768,32767,iCoeffQ); 1933 1280 } … … 1941 1288 for( Int n = 0; n < iWidth*iHeight; n++ ) 1942 1289 { 1943 #if DEQUANT_CLIPPING1944 1290 clipQCoef = Clip3( -32768, 32767, piQCoef[n] ); 1945 1291 iCoeffQ = ( clipQCoef * scale + iAdd ) >> iShift; 1946 #else1947 iCoeffQ = ( piQCoef[n] * scale + iAdd ) >> iShift;1948 #endif1949 1292 piCoef[n] = Clip3(-32768,32767,iCoeffQ); 1950 1293 } … … 2134 1477 xTr(piBlkResi,psCoeff,uiStride,(UInt)iSize,uiMode); 2135 1478 #else 2136 #if UNIFIED_TRANSFORM2137 1479 Int j; 2138 #else2139 Int iSize = iWidth;2140 if( iWidth != iHeight)2141 #endif2142 1480 { 2143 1481 short block[ 64 * 64 ]; … … 2149 1487 } 2150 1488 } 2151 #if UNIFIED_TRANSFORM2152 1489 xTrMxN( block, coeff, iWidth, iHeight, uiMode ); 2153 #else2154 xTrMxN( block, coeff, iWidth, iHeight );2155 #endif2156 1490 for ( j = 0; j < iHeight * iWidth; j++ ) 2157 1491 { … … 2160 1494 return ; 2161 1495 } 2162 #if !UNIFIED_TRANSFORM2163 if (iSize==4)2164 {2165 short block[4][4];2166 short coeff[4][4];2167 for (j=0; j<4; j++)2168 {2169 memcpy(block[j],piBlkResi+j*uiStride,4*sizeof(short));2170 }2171 xTr4(block,coeff,uiMode);2172 for (j=0; j<4; j++)2173 {2174 for (k=0; k<4; k++)2175 {2176 psCoeff[j*4+k] = coeff[j][k];2177 }2178 }2179 }2180 else if (iSize==8)2181 {2182 short block[8][8];2183 short coeff[8][8];2184 2185 for (j=0; j<8; j++)2186 {2187 memcpy(block[j],piBlkResi+j*uiStride,8*sizeof(short));2188 }2189 2190 xTr8(block,coeff);2191 for (j=0; j<8; j++)2192 {2193 for (k=0; k<8; k++)2194 {2195 psCoeff[j*8+k] = coeff[j][k];2196 }2197 }2198 }2199 else if (iSize==16)2200 {2201 short block[16][16];2202 short coeff[16][16];2203 2204 for (j=0; j<16; j++)2205 {2206 memcpy(block[j],piBlkResi+j*uiStride,16*sizeof(short));2207 }2208 xTr16(block,coeff);2209 for (j=0; j<16; j++)2210 {2211 for (k=0; k<16; k++)2212 {2213 psCoeff[j*16+k] = coeff[j][k];2214 }2215 }2216 }2217 else if (iSize==32)2218 {2219 short block[32][32];2220 short coeff[32][32];2221 2222 for (j=0; j<32; j++)2223 {2224 memcpy(block[j],piBlkResi+j*uiStride,32*sizeof(short));2225 }2226 xTr32(block,coeff);2227 for (j=0; j<32; j++)2228 {2229 for (k=0; k<32; k++)2230 {2231 psCoeff[j*32+k] = coeff[j][k];2232 }2233 }2234 }2235 #endif2236 1496 #endif 2237 1497 } … … 2255 1515 xITr(plCoef,pResidual,uiStride,(UInt)iSize,uiMode); 2256 1516 #else 2257 #if UNIFIED_TRANSFORM2258 1517 Int j; 2259 #else2260 Int j,k;2261 Int iSize = iWidth;2262 if( iWidth != iHeight )2263 #endif2264 1518 { 2265 1519 short block[ 64 * 64 ]; … … 2269 1523 coeff[j] = (short)plCoef[j]; 2270 1524 } 2271 #if UNIFIED_TRANSFORM2272 1525 xITrMxN( coeff, block, iWidth, iHeight, uiMode ); 2273 #else2274 xITrMxN( coeff, block, iWidth, iHeight );2275 #endif2276 1526 { 2277 1527 for ( j = 0; j < iHeight; j++ ) … … 2282 1532 return ; 2283 1533 } 2284 #if !UNIFIED_TRANSFORM2285 if (iSize==4)2286 {2287 short block[4][4];2288 short coeff[4][4];2289 2290 for (j=0; j<4; j++)2291 {2292 for (k=0; k<4; k++)2293 {2294 coeff[j][k] = (short)plCoef[j*4+k];2295 }2296 }2297 xITr4(coeff,block,uiMode);2298 for (j=0; j<4; j++)2299 {2300 memcpy(pResidual+j*uiStride,block[j],4*sizeof(short));2301 }2302 }2303 else if (iSize==8)2304 {2305 short block[8][8];2306 short coeff[8][8];2307 2308 for (j=0; j<8; j++)2309 {2310 for (k=0; k<8; k++)2311 {2312 coeff[j][k] = (short)plCoef[j*8+k];2313 }2314 }2315 xITr8(coeff,block);2316 for (j=0; j<8; j++)2317 {2318 memcpy(pResidual+j*uiStride,block[j],8*sizeof(short));2319 }2320 }2321 else if (iSize==16)2322 {2323 short block[16][16];2324 short coeff[16][16];2325 2326 for (j=0; j<16; j++)2327 {2328 for (k=0; k<16; k++)2329 {2330 coeff[j][k] = (short)plCoef[j*16+k];2331 }2332 }2333 xITr16(coeff,block);2334 for (j=0; j<16; j++)2335 {2336 memcpy(pResidual+j*uiStride,block[j],16*sizeof(short));2337 }2338 }2339 2340 else if (iSize==32)2341 {2342 short block[32][32];2343 short coeff[32][32];2344 2345 for (j=0; j<32; j++)2346 {2347 for (k=0; k<32; k++)2348 {2349 coeff[j][k] = (short)plCoef[j*32+k];2350 }2351 }2352 xITr32(coeff,block);2353 for (j=0; j<32; j++)2354 {2355 memcpy(pResidual+j*uiStride,block[j],32*sizeof(short));2356 }2357 }2358 #endif2359 1534 #endif 2360 1535 } … … 2442 1617 ::memset( pdCostCoeff, 0, sizeof(Double) * uiMaxNumCoeff ); 2443 1618 ::memset( pdCostSig, 0, sizeof(Double) * uiMaxNumCoeff ); 2444 #if MULTIBITS_DATA_HIDING2445 1619 Int rateIncUp [ 32 * 32 ]; 2446 1620 Int rateIncDown [ 32 * 32 ]; … … 2451 1625 ::memset( sigRateDelta, 0, sizeof(Int) * uiMaxNumCoeff ); 2452 1626 ::memset( deltaU, 0, sizeof(Int) * uiMaxNumCoeff ); 2453 #endif2454 1627 2455 1628 const UInt * scanCG; … … 2457 1630 { 2458 1631 scanCG = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlkSize > 3 ? uiLog2BlkSize-2-1 : 0 ]; 2459 #if MULTILEVEL_SIGMAP_EXT2460 1632 if( uiLog2BlkSize == 3 ) 2461 1633 { … … 2466 1638 scanCG = g_sigLastScanCG32x32; 2467 1639 } 2468 #endif2469 1640 } 2470 1641 else … … 2486 1657 dTemp = dErrScale; 2487 1658 2488 #if RESTRICT_GR1GR2FLAG_NUMBER2489 1659 UInt c1Idx = 0; 2490 1660 UInt c2Idx = 0; 2491 1661 Int baseLevel; 2492 #endif2493 1662 2494 1663 const UInt * scan; … … 2502 1671 } 2503 1672 2504 #if !MULTILEVEL_SIGMAP_EXT2505 if (blockType < 4)2506 {2507 for( Int iScanPos = (Int) uiMaxNumCoeff-1; iScanPos >= 0; iScanPos-- )2508 {2509 //===== quantization =====2510 UInt uiBlkPos = scan[iScanPos];2511 // set coeff2512 uiQ = piQCoef[uiBlkPos];2513 dTemp = pdErrScale[uiBlkPos];2514 Int lLevelDouble = plSrcCoeff[ uiBlkPos ];2515 lLevelDouble = (Int)min<Int64>(((Int64)abs(lLevelDouble) * uiQ), MAX_INT-(1 << (iQBits - 1)));2516 #if ADAPTIVE_QP_SELECTION2517 if( m_bUseAdaptQpSelect )2518 {2519 piArlDstCoeff[uiBlkPos] = (Int)(( lLevelDouble + iAddC) >> iQBitsC );2520 }2521 #endif2522 UInt uiMaxAbsLevel = (lLevelDouble + (1 << (iQBits - 1))) >> iQBits;2523 uiMaxAbsLevel=plSrcCoeff[ uiBlkPos ]>=0 ? min<UInt>(uiMaxAbsLevel,32767): min<UInt>(uiMaxAbsLevel,32768);2524 Double dErr = Double( lLevelDouble );2525 pdCostCoeff0[ iScanPos ] = dErr * dErr * dTemp;2526 d64BlockUncodedCost += pdCostCoeff0[ iScanPos ];2527 piDstCoeff[ uiBlkPos ] = uiMaxAbsLevel;2528 2529 if ( uiMaxAbsLevel > 0 && iLastScanPos < 0 )2530 {2531 iLastScanPos = iScanPos;2532 #if LEVEL_CTX_LUMA_RED2533 uiCtxSet = (iScanPos < SCAN_SET_SIZE || eTType!=TEXT_LUMA) ? 0 : 2;2534 #else2535 uiCtxSet = iScanPos < SCAN_SET_SIZE ? 0 : 3;2536 uiCtxSet = (iScanPos < SCAN_SET_SIZE || eTType!=TEXT_LUMA) ? 0 : 3;2537 #endif2538 }2539 2540 if ( iLastScanPos >= 0 )2541 {2542 //===== coefficient level estimation =====2543 UInt uiLevel;2544 UInt uiOneCtx = 4 * uiCtxSet + c1;2545 #if RESTRICT_GR1GR2FLAG_NUMBER2546 UInt uiAbsCtx = uiCtxSet + c2;2547 #else2548 UInt uiAbsCtx = 3 * uiCtxSet + c2;2549 #endif2550 2551 if( iScanPos == iLastScanPos )2552 {2553 #if RESTRICT_GR1GR2FLAG_NUMBER2554 uiLevel = xGetCodedLevel( pdCostCoeff[ iScanPos ], pdCostCoeff0[ iScanPos ], pdCostSig[ iScanPos ], lLevelDouble, uiMaxAbsLevel, 0, uiOneCtx, uiAbsCtx, uiGoRiceParam, c1Idx, c2Idx, iQBits, dTemp, 1 );2555 #else2556 uiLevel = xGetCodedLevel( pdCostCoeff[ iScanPos ], pdCostCoeff0[ iScanPos ], pdCostSig[ iScanPos ], lLevelDouble, uiMaxAbsLevel, 0, uiOneCtx, uiAbsCtx, uiGoRiceParam, iQBits, dTemp, 1 );2557 #endif2558 }2559 else2560 {2561 UInt uiPosY = uiBlkPos >> uiLog2BlkSize;2562 UInt uiPosX = uiBlkPos - ( uiPosY << uiLog2BlkSize );2563 UShort uiCtxSig = getSigCtxInc( piDstCoeff, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType );2564 #if RESTRICT_GR1GR2FLAG_NUMBER2565 uiLevel = xGetCodedLevel( pdCostCoeff[ iScanPos ], pdCostCoeff0[ iScanPos ], pdCostSig[ iScanPos ], lLevelDouble, uiMaxAbsLevel, uiCtxSig, uiOneCtx, uiAbsCtx, uiGoRiceParam, c1Idx, c2Idx, iQBits, dTemp, 0 );2566 #else2567 uiLevel = xGetCodedLevel( pdCostCoeff[ iScanPos ], pdCostCoeff0[ iScanPos ], pdCostSig[ iScanPos ], lLevelDouble, uiMaxAbsLevel, uiCtxSig, uiOneCtx, uiAbsCtx, uiGoRiceParam, iQBits, dTemp, 0 );2568 #endif2569 #if MULTIBITS_DATA_HIDING2570 sigRateDelta[ uiBlkPos ] = m_pcEstBitsSbac->significantBits[ uiCtxSig ][ 1 ] - m_pcEstBitsSbac->significantBits[ uiCtxSig ][ 0 ];2571 #endif2572 }2573 #if MULTIBITS_DATA_HIDING2574 deltaU[ uiBlkPos ] = (lLevelDouble - ((Int)uiLevel << iQBits)) >> (iQBits-8);2575 if( uiLevel > 0 )2576 {2577 #if RESTRICT_GR1GR2FLAG_NUMBER2578 Int rateNow = xGetICRate( uiLevel, uiOneCtx, uiAbsCtx, uiGoRiceParam, c1Idx, c2Idx );2579 rateIncUp [ uiBlkPos ] = xGetICRate( uiLevel+1, uiOneCtx, uiAbsCtx, uiGoRiceParam, c1Idx, c2Idx ) - rateNow;2580 rateIncDown [ uiBlkPos ] = xGetICRate( uiLevel-1, uiOneCtx, uiAbsCtx, uiGoRiceParam, c1Idx, c2Idx ) - rateNow;2581 #else2582 Int rateNow = xGetICRate( uiLevel, uiOneCtx, uiAbsCtx, uiGoRiceParam );2583 rateIncUp [ uiBlkPos ] = xGetICRate( uiLevel+1, uiOneCtx, uiAbsCtx, uiGoRiceParam ) - rateNow;2584 rateIncDown [ uiBlkPos ] = xGetICRate( uiLevel-1, uiOneCtx, uiAbsCtx, uiGoRiceParam ) - rateNow;2585 #endif2586 }2587 else // uiLevel == 02588 {2589 rateIncUp [ uiBlkPos ] = m_pcEstBitsSbac->m_greaterOneBits[ uiOneCtx ][ 0 ];2590 }2591 #endif2592 piDstCoeff[ uiBlkPos ] = uiLevel;2593 d64BaseCost += pdCostCoeff [ iScanPos ];2594 2595 #if RESTRICT_GR1GR2FLAG_NUMBER2596 baseLevel = (c1Idx < C1FLAG_NUMBER) ? (2 + (c2Idx < C2FLAG_NUMBER)) : 1;2597 if( uiLevel >= baseLevel )2598 {2599 #if EIGHT_BITS_RICE_CODE2600 uiGoRiceParam = g_aauiGoRiceUpdate[ uiGoRiceParam ][ min<UInt>( uiLevel - baseLevel, 23 ) ];2601 #else2602 uiGoRiceParam = g_aauiGoRiceUpdate[ uiGoRiceParam ][ min<UInt>( uiLevel - baseLevel, 15 ) ];2603 #endif2604 }2605 if ( uiLevel >= 1)2606 {2607 c1Idx ++;2608 }2609 #endif2610 2611 //===== update bin model =====2612 if( uiLevel > 1 )2613 {2614 c1 = 0;2615 c2 += (c2 < 2);2616 uiNumOne++;2617 #if RESTRICT_GR1GR2FLAG_NUMBER2618 c2Idx ++;2619 #else2620 if( uiLevel > 2 )2621 {2622 #if EIGHT_BITS_RICE_CODE2623 uiGoRiceParam = g_aauiGoRiceUpdate[ uiGoRiceParam ][ min<UInt>( uiLevel - 3, 23 ) ];2624 #else2625 uiGoRiceParam = g_aauiGoRiceUpdate[ uiGoRiceParam ][ min<UInt>( uiLevel - 3, 15 ) ];2626 #endif2627 }2628 #endif2629 }2630 else if( (c1 < 3) && (c1 > 0) && uiLevel)2631 {2632 c1++;2633 }2634 2635 //===== context set update =====2636 if( ( iScanPos % SCAN_SET_SIZE == 0 ) && ( iScanPos > 0 ) )2637 {2638 c1 = 1;2639 c2 = 0;2640 uiGoRiceParam = 0;2641 2642 #if RESTRICT_GR1GR2FLAG_NUMBER2643 c1Idx = 0;2644 c2Idx = 0;2645 #endif2646 #if LEVEL_CTX_LUMA_RED2647 uiCtxSet = (iScanPos == SCAN_SET_SIZE || eTType!=TEXT_LUMA) ? 0 : 2;2648 #else2649 uiCtxSet = (iScanPos == SCAN_SET_SIZE || eTType!=TEXT_LUMA) ? 0 : 3;2650 #endif2651 if( uiNumOne > 0 )2652 {2653 uiCtxSet++;2654 #if !LEVEL_CTX_LUMA_RED2655 if(uiNumOne > 3 && eTType==TEXT_LUMA)2656 {2657 uiCtxSet++;2658 }2659 #endif2660 }2661 uiNumOne >>= 1;2662 }2663 }2664 else2665 {2666 d64BaseCost += pdCostCoeff0[ iScanPos ];2667 }2668 }2669 }2670 else //(uiLog2BlkSize > 3), for 16x16 and 32x32 TU2671 {2672 #endif2673 1673 ::memset( pdCostCoeffGroupSig, 0, sizeof(Double) * MLS_GRP_NUM ); 2674 1674 ::memset( uiSigCoeffGroupFlag, 0, sizeof(UInt) * MLS_GRP_NUM ); … … 2683 1683 UInt uiCGPosY = uiCGBlkPos / uiNumBlkSide; 2684 1684 UInt uiCGPosX = uiCGBlkPos - (uiCGPosY * uiNumBlkSide); 2685 #if MULTILEVEL_SIGMAP_EXT2686 1685 if( uiWidth == 8 && uiHeight == 8 && (uiScanIdx == SCAN_HOR || uiScanIdx == SCAN_VER) ) 2687 1686 { … … 2689 1688 uiCGPosX = (uiScanIdx == SCAN_VER ? uiCGBlkPos : 0); 2690 1689 } 2691 #endif2692 1690 ::memset( &rdStats, 0, sizeof (coeffGroupRDStats)); 2693 1691 … … 2718 1716 { 2719 1717 iLastScanPos = iScanPos; 2720 #if LEVEL_CTX_LUMA_RED2721 1718 uiCtxSet = (iScanPos < SCAN_SET_SIZE || eTType!=TEXT_LUMA) ? 0 : 2; 2722 #else2723 uiCtxSet = (iScanPos < SCAN_SET_SIZE || eTType!=TEXT_LUMA) ? 0 : 3;2724 #endif2725 1719 iCGLastScanPos = iCGScanPos; 2726 1720 } … … 2731 1725 UInt uiLevel; 2732 1726 UInt uiOneCtx = 4 * uiCtxSet + c1; 2733 #if RESTRICT_GR1GR2FLAG_NUMBER2734 1727 UInt uiAbsCtx = uiCtxSet + c2; 2735 #else2736 UInt uiAbsCtx = 3 * uiCtxSet + c2;2737 #endif2738 1728 2739 1729 if( iScanPos == iLastScanPos ) 2740 1730 { 2741 #if RESTRICT_GR1GR2FLAG_NUMBER2742 1731 uiLevel = xGetCodedLevel( pdCostCoeff[ iScanPos ], pdCostCoeff0[ iScanPos ], pdCostSig[ iScanPos ], 2743 1732 lLevelDouble, uiMaxAbsLevel, 0, uiOneCtx, uiAbsCtx, uiGoRiceParam, 2744 1733 c1Idx, c2Idx, iQBits, dTemp, 1 ); 2745 #else2746 uiLevel = xGetCodedLevel( pdCostCoeff[ iScanPos ], pdCostCoeff0[ iScanPos ], pdCostSig[ iScanPos ],2747 lLevelDouble, uiMaxAbsLevel, 0, uiOneCtx, uiAbsCtx, uiGoRiceParam,2748 iQBits, dTemp, 1 );2749 #endif2750 1734 } 2751 1735 else … … 2754 1738 UInt uiPosX = uiBlkPos - ( uiPosY << uiLog2BlkSize ); 2755 1739 UShort uiCtxSig = getSigCtxInc( piDstCoeff, uiPosX, uiPosY, blockType, uiWidth, uiHeight, eTType ); 2756 #if RESTRICT_GR1GR2FLAG_NUMBER2757 1740 uiLevel = xGetCodedLevel( pdCostCoeff[ iScanPos ], pdCostCoeff0[ iScanPos ], pdCostSig[ iScanPos ], 2758 1741 lLevelDouble, uiMaxAbsLevel, uiCtxSig, uiOneCtx, uiAbsCtx, uiGoRiceParam, 2759 1742 c1Idx, c2Idx, iQBits, dTemp, 0 ); 2760 #else2761 uiLevel = xGetCodedLevel( pdCostCoeff[ iScanPos ], pdCostCoeff0[ iScanPos ], pdCostSig[ iScanPos ],2762 lLevelDouble, uiMaxAbsLevel, uiCtxSig, uiOneCtx, uiAbsCtx, uiGoRiceParam,2763 iQBits, dTemp, 0 );2764 #endif2765 #if MULTIBITS_DATA_HIDING2766 1743 sigRateDelta[ uiBlkPos ] = m_pcEstBitsSbac->significantBits[ uiCtxSig ][ 1 ] - m_pcEstBitsSbac->significantBits[ uiCtxSig ][ 0 ]; 2767 #endif2768 1744 } 2769 #if MULTIBITS_DATA_HIDING2770 1745 deltaU[ uiBlkPos ] = (lLevelDouble - ((Int)uiLevel << iQBits)) >> (iQBits-8); 2771 1746 if( uiLevel > 0 ) 2772 1747 { 2773 #if RESTRICT_GR1GR2FLAG_NUMBER2774 1748 Int rateNow = xGetICRate( uiLevel, uiOneCtx, uiAbsCtx, uiGoRiceParam, c1Idx, c2Idx ); 2775 1749 rateIncUp [ uiBlkPos ] = xGetICRate( uiLevel+1, uiOneCtx, uiAbsCtx, uiGoRiceParam, c1Idx, c2Idx ) - rateNow; 2776 1750 rateIncDown [ uiBlkPos ] = xGetICRate( uiLevel-1, uiOneCtx, uiAbsCtx, uiGoRiceParam, c1Idx, c2Idx ) - rateNow; 2777 #else2778 Int rateNow = xGetICRate( uiLevel, uiOneCtx, uiAbsCtx, uiGoRiceParam );2779 rateIncUp [ uiBlkPos ] = xGetICRate( uiLevel+1, uiOneCtx, uiAbsCtx, uiGoRiceParam ) - rateNow;2780 rateIncDown [ uiBlkPos ] = xGetICRate( uiLevel-1, uiOneCtx, uiAbsCtx, uiGoRiceParam ) - rateNow;2781 #endif2782 1751 } 2783 1752 else // uiLevel == 0 … … 2785 1754 rateIncUp [ uiBlkPos ] = m_pcEstBitsSbac->m_greaterOneBits[ uiOneCtx ][ 0 ]; 2786 1755 } 2787 #endif2788 1756 piDstCoeff[ uiBlkPos ] = uiLevel; 2789 1757 d64BaseCost += pdCostCoeff [ iScanPos ]; 2790 1758 2791 1759 2792 #if RESTRICT_GR1GR2FLAG_NUMBER2793 1760 baseLevel = (c1Idx < C1FLAG_NUMBER) ? (2 + (c2Idx < C2FLAG_NUMBER)) : 1; 2794 1761 if( uiLevel >= baseLevel ) 2795 1762 { 2796 #if EIGHT_BITS_RICE_CODE2797 1763 uiGoRiceParam = g_aauiGoRiceUpdate[ uiGoRiceParam ][ min<UInt>( uiLevel - baseLevel , 23 ) ]; 2798 #else2799 uiGoRiceParam = g_aauiGoRiceUpdate[ uiGoRiceParam ][ min<UInt>( uiLevel - baseLevel, 15 ) ];2800 #endif2801 1764 } 2802 1765 if ( uiLevel >= 1) … … 2804 1767 c1Idx ++; 2805 1768 } 2806 #endif2807 1769 2808 1770 //===== update bin model ===== … … 2812 1774 c2 += (c2 < 2); 2813 1775 uiNumOne++; 2814 #if RESTRICT_GR1GR2FLAG_NUMBER2815 1776 c2Idx ++; 2816 #else2817 if( uiLevel > 2 )2818 {2819 #if EIGHT_BITS_RICE_CODE2820 uiGoRiceParam = g_aauiGoRiceUpdate[ uiGoRiceParam ][ min<UInt>( uiLevel - 3, 23 ) ];2821 #else2822 uiGoRiceParam = g_aauiGoRiceUpdate[ uiGoRiceParam ][ min<UInt>( uiLevel - 3, 15 ) ];2823 #endif2824 }2825 #endif2826 1777 } 2827 1778 else if( (c1 < 3) && (c1 > 0) && uiLevel) … … 2837 1788 uiGoRiceParam = 0; 2838 1789 2839 #if RESTRICT_GR1GR2FLAG_NUMBER2840 1790 c1Idx = 0; 2841 1791 c2Idx = 0; 2842 #endif2843 #if LEVEL_CTX_LUMA_RED2844 1792 uiCtxSet = (iScanPos == SCAN_SET_SIZE || eTType!=TEXT_LUMA) ? 0 : 2; 2845 #else2846 uiCtxSet = (iScanPos == SCAN_SET_SIZE || eTType!=TEXT_LUMA) ? 0 : 3;2847 #endif2848 1793 if( uiNumOne > 0 ) 2849 1794 { 2850 1795 uiCtxSet++; 2851 #if !LEVEL_CTX_LUMA_RED2852 if( uiNumOne > 3 && eTType==TEXT_LUMA)2853 {2854 uiCtxSet++;2855 }2856 #endif2857 1796 } 2858 1797 uiNumOne >>= 1; … … 2882 1821 if (iCGLastScanPos >= 0) 2883 1822 { 2884 #if REMOVE_INFER_SIGGRP2885 1823 if( iCGScanPos ) 2886 #else2887 #if MULTILEVEL_SIGMAP_EXT2888 if ( !bothCGNeighboursOne( uiSigCoeffGroupFlag, uiCGPosX, uiCGPosY, uiScanIdx, uiWidth, uiHeight ) && (iCGScanPos != 0) )2889 #else2890 if ( !bothCGNeighboursOne( uiSigCoeffGroupFlag, uiCGPosX, uiCGPosY, uiWidth, uiHeight ) && (iCGScanPos != 0) )2891 #endif2892 #endif2893 1824 { 2894 1825 if (uiSigCoeffGroupFlag[ uiCGBlkPos ] == 0) 2895 1826 { 2896 #if MULTILEVEL_SIGMAP_EXT2897 1827 UInt uiCtxSig = getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, uiCGPosX, uiCGPosY, uiScanIdx, uiWidth, uiHeight); 2898 #else2899 UInt uiCtxSig = getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, uiCGPosX, uiCGPosY, uiWidth, uiHeight);2900 #endif2901 1828 d64BaseCost += xGetRateSigCoeffGroup(0, uiCtxSig) - rdStats.d64SigCost;; 2902 1829 pdCostCoeffGroupSig[ iCGScanPos ] = xGetRateSigCoeffGroup(0, uiCtxSig); … … 2915 1842 2916 1843 // add SigCoeffGroupFlag cost to total cost 2917 #if MULTILEVEL_SIGMAP_EXT2918 1844 UInt uiCtxSig = getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, uiCGPosX, uiCGPosY, uiScanIdx, uiWidth, uiHeight); 2919 #else2920 UInt uiCtxSig = getSigCoeffGroupCtxInc( uiSigCoeffGroupFlag, uiCGPosX, uiCGPosY, uiWidth, uiHeight);2921 #endif2922 1845 if (iCGScanPos < iCGLastScanPos) 2923 1846 { … … 2958 1881 } // end if if (uiSigCoeffGroupFlag[ uiCGBlkPos ] == 0) 2959 1882 } 2960 #if REMOVE_INFER_SIGGRP2961 1883 else 2962 1884 { 2963 1885 uiSigCoeffGroupFlag[ uiCGBlkPos ] = 1; 2964 1886 } 2965 #else2966 else // if ( !bothCGNeighboursOne( uiSigCoeffGroupFlag, uiCGPosX, uiCGPosY ) && (uiCGScanPos != 0) && (uiSigCoeffGroupFlag[ uiCGBlkPos ] != 0) )2967 {2968 uiSigCoeffGroupFlag[ uiCGBlkPos ] = 1;2969 } // end if ( !bothCGNeighboursOne( uiSigCoeffGroupFlag, uiCGPosX, uiCGPosY ) && (uiCGScanPos != 0) && (uiSigCoeffGroupFlag[ uiCGBlkPos ] != 0) )2970 #endif2971 1887 } 2972 1888 } //end for (iCGScanPos) 2973 #if !MULTILEVEL_SIGMAP_EXT2974 }2975 #endif2976 1889 2977 1890 //===== estimate last position ===== … … 2998 1911 } 2999 1912 3000 #if !MULTILEVEL_SIGMAP_EXT3001 if (blockType < 4)3002 {3003 for( Int iScanPos = iLastScanPos; iScanPos >= 0; iScanPos-- )3004 {3005 UInt uiBlkPos = scan[iScanPos];3006 if( piDstCoeff[ uiBlkPos ] )3007 {3008 UInt uiPosY = uiBlkPos >> uiLog2BlkSize;3009 UInt uiPosX = uiBlkPos - ( uiPosY << uiLog2BlkSize );3010 Double d64CostLast= uiScanIdx == SCAN_VER ? xGetRateLast( uiPosY, uiPosX, uiWidth ) : xGetRateLast( uiPosX, uiPosY, uiWidth );3011 Double totalCost = d64BaseCost + d64CostLast - pdCostSig[ iScanPos ];3012 if( totalCost < d64BestCost )3013 {3014 iBestLastIdxP1 = iScanPos + 1;3015 d64BestCost = totalCost;3016 }3017 if( piDstCoeff[ uiBlkPos ] > 1 )3018 {3019 break;3020 }3021 d64BaseCost -= pdCostCoeff[ iScanPos ];3022 d64BaseCost += pdCostCoeff0[ iScanPos ];3023 }3024 else3025 {3026 d64BaseCost -= pdCostSig[ iScanPos ];3027 }3028 }3029 }3030 else //if (uiLog2BlkSize < 4)3031 {3032 #endif3033 1913 Bool bFoundLast = false; 3034 1914 for (Int iCGScanPos = iCGLastScanPos; iCGScanPos >= 0; iCGScanPos--) … … 3041 1921 for (Int iScanPosinCG = uiCGSize-1; iScanPosinCG >= 0; iScanPosinCG--) 3042 1922 { 3043 #if MULTILEVEL_SIGMAP_EXT3044 1923 iScanPos = iCGScanPos*uiCGSize + iScanPosinCG; 3045 #else3046 Int iScanPos = iCGScanPos*uiCGSize + iScanPosinCG;3047 #endif3048 1924 if (iScanPos > iLastScanPos) continue; 3049 1925 UInt uiBlkPos = scan[iScanPos]; … … 3081 1957 } // end if (uiSigCoeffGroupFlag[ uiCGBlkPos ]) 3082 1958 } // end for 3083 #if !MULTILEVEL_SIGMAP_EXT3084 } //if (uiLog2BlkSize < 4)3085 #endif3086 1959 3087 1960 for ( Int scanPos = 0; scanPos < iBestLastIdxP1; scanPos++ ) … … 3099 1972 } 3100 1973 3101 #if MULTIBITS_DATA_HIDING3102 1974 if( pcCU->getSlice()->getPPS()->getSignHideFlag() && uiAbsSum>=2) 3103 1975 { … … 3226 2098 } 3227 2099 } 3228 #endif3229 2100 } 3230 2101 … … 3311 2182 const TCoeff *pData = pcCoeff + posX + posY * width; 3312 2183 3313 #if !SIGMAP_CTX_SUBBLOCK3314 Int thred = std::max(height, width) >> 2;3315 #endif3316 2184 3317 2185 Int cnt = 0; … … 3341 2209 3342 2210 cnt = ( cnt + 1 ) >> 1; 3343 #if SIGMAP_CTX_SUBBLOCK3344 2211 return (( textureType == TEXT_LUMA && ((posX>>2) + (posY>>2)) > 0 ) ? 4 : 1) + offset + cnt; 3345 #else3346 return (( textureType == TEXT_LUMA && posX + posY >= thred ) ? 4 : 1) + offset + cnt;3347 #endif3348 2212 } 3349 2213 … … 3373 2237 UShort ui16CtxNumAbs, 3374 2238 UShort ui16AbsGoRice, 3375 #if RESTRICT_GR1GR2FLAG_NUMBER3376 2239 UInt c1Idx, 3377 2240 UInt c2Idx, 3378 #endif3379 2241 Int iQBits, 3380 2242 Double dTemp, … … 3407 2269 { 3408 2270 Double dErr = Double( lLevelDouble - ( uiAbsLevel << iQBits ) ); 3409 #if RESTRICT_GR1GR2FLAG_NUMBER3410 2271 Double dCurrCost = dErr * dErr * dTemp + xGetICRateCost( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, c1Idx, c2Idx ); 3411 #else3412 Double dCurrCost = dErr * dErr * dTemp + xGetICRateCost( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice );3413 #endif3414 2272 dCurrCost += dCurrCostSig; 3415 2273 … … 3436 2294 UShort ui16CtxNumAbs, 3437 2295 UShort ui16AbsGoRice 3438 #if RESTRICT_GR1GR2FLAG_NUMBER3439 2296 , UInt c1Idx, 3440 2297 UInt c2Idx 3441 #endif3442 2298 ) const 3443 2299 { 3444 2300 Double iRate = xGetIEPRate(); 3445 #if RESTRICT_GR1GR2FLAG_NUMBER3446 2301 UInt baseLevel = (c1Idx < C1FLAG_NUMBER)? (2 + (c2Idx < C2FLAG_NUMBER)) : 1; 3447 2302 … … 3476 2331 } 3477 2332 else 3478 #endif3479 2333 if( uiAbsLevel == 1 ) 3480 2334 { … … 3488 2342 else 3489 2343 { 3490 #if RESTRICT_GR1GR2FLAG_NUMBER3491 2344 assert (0); 3492 #else 3493 UInt uiSymbol = uiAbsLevel - 3; 2345 } 2346 return xGetICost( iRate ); 2347 } 2348 2349 __inline Int TComTrQuant::xGetICRate ( UInt uiAbsLevel, 2350 UShort ui16CtxNumOne, 2351 UShort ui16CtxNumAbs, 2352 UShort ui16AbsGoRice 2353 , UInt c1Idx, 2354 UInt c2Idx 2355 ) const 2356 { 2357 Int iRate = 0; 2358 UInt baseLevel = (c1Idx < C1FLAG_NUMBER)? (2 + (c2Idx < C2FLAG_NUMBER)) : 1; 2359 2360 if ( uiAbsLevel >= baseLevel ) 2361 { 2362 UInt uiSymbol = uiAbsLevel - baseLevel; 3494 2363 UInt uiMaxVlc = g_auiGoRiceRange[ ui16AbsGoRice ]; 3495 2364 Bool bExpGolomb = ( uiSymbol > uiMaxVlc ); … … 3507 2376 3508 2377 iRate += ui16NumBins << 15; 3509 iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 1 ];3510 iRate += m_pcEstBitsSbac->m_levelAbsBits[ ui16CtxNumAbs ][ 1 ];3511 #endif3512 }3513 return xGetICost( iRate );3514 }3515 3516 #if MULTIBITS_DATA_HIDING3517 __inline Int TComTrQuant::xGetICRate ( UInt uiAbsLevel,3518 UShort ui16CtxNumOne,3519 UShort ui16CtxNumAbs,3520 UShort ui16AbsGoRice3521 #if RESTRICT_GR1GR2FLAG_NUMBER3522 , UInt c1Idx,3523 UInt c2Idx3524 #endif3525 ) const3526 {3527 Int iRate = 0;3528 #if RESTRICT_GR1GR2FLAG_NUMBER3529 UInt baseLevel = (c1Idx < C1FLAG_NUMBER)? (2 + (c2Idx < C2FLAG_NUMBER)) : 1;3530 3531 if ( uiAbsLevel >= baseLevel )3532 {3533 UInt uiSymbol = uiAbsLevel - baseLevel;3534 UInt uiMaxVlc = g_auiGoRiceRange[ ui16AbsGoRice ];3535 Bool bExpGolomb = ( uiSymbol > uiMaxVlc );3536 3537 if( bExpGolomb )3538 {3539 uiAbsLevel = uiSymbol - uiMaxVlc;3540 int iEGS = 1; for( UInt uiMax = 2; uiAbsLevel >= uiMax; uiMax <<= 1, iEGS += 2 );3541 iRate += iEGS << 15;3542 uiSymbol = min<UInt>( uiSymbol, ( uiMaxVlc + 1 ) );3543 }3544 3545 UShort ui16PrefLen = UShort( uiSymbol >> ui16AbsGoRice ) + 1;3546 UShort ui16NumBins = min<UInt>( ui16PrefLen, g_auiGoRicePrefixLen[ ui16AbsGoRice ] ) + ui16AbsGoRice;3547 3548 iRate += ui16NumBins << 15;3549 2378 3550 2379 if (c1Idx < C1FLAG_NUMBER) … … 3559 2388 } 3560 2389 else 3561 #endif3562 2390 if( uiAbsLevel == 0 ) 3563 2391 { … … 3575 2403 else 3576 2404 { 3577 #if RESTRICT_GR1GR2FLAG_NUMBER3578 2405 assert(0); 3579 #else3580 UInt uiSymbol = uiAbsLevel - 3;3581 UInt uiMaxVlc = g_auiGoRiceRange[ ui16AbsGoRice ];3582 Bool bExpGolomb = ( uiSymbol > uiMaxVlc );3583 3584 if( bExpGolomb )3585 {3586 uiAbsLevel = uiSymbol - uiMaxVlc;3587 int iEGS = 1; for( UInt uiMax = 2; uiAbsLevel >= uiMax; uiMax <<= 1, iEGS += 2 );3588 iRate += iEGS << 15;3589 uiSymbol = min<UInt>( uiSymbol, ( uiMaxVlc + 1 ) );3590 }3591 3592 UShort ui16PrefLen = UShort( uiSymbol >> ui16AbsGoRice ) + 1;3593 UShort ui16NumBins = min<UInt>( ui16PrefLen, g_auiGoRicePrefixLen[ ui16AbsGoRice ] ) + ui16AbsGoRice;3594 3595 iRate += ui16NumBins << 15;3596 iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 1 ];3597 iRate += m_pcEstBitsSbac->m_levelAbsBits[ ui16CtxNumAbs ][ 1 ];3598 #endif3599 2406 } 3600 2407 return iRate; 3601 2408 } 3602 #endif3603 2409 3604 2410 __inline Double TComTrQuant::xGetRateSigCoeffGroup ( UShort uiSignificanceCoeffGroup, … … 3674 2480 const UInt uiCGPosX, 3675 2481 const UInt uiCGPosY, 3676 #if MULTILEVEL_SIGMAP_EXT3677 2482 const UInt scanIdx, 3678 #endif3679 2483 Int width, Int height) 3680 2484 { … … 3684 2488 width >>= 2; 3685 2489 height >>= 2; 3686 #if MULTILEVEL_SIGMAP_EXT3687 2490 if( width == 2 && height == 2 ) // 8x8 3688 2491 { … … 3698 2501 } 3699 2502 } 3700 #endif3701 2503 if( uiCGPosX < width - 1 ) 3702 2504 { … … 3707 2509 uiLower = (uiSigCoeffGroupFlag[ (uiCGPosY + 1 ) * width + uiCGPosX ] != 0); 3708 2510 } 3709 #if REMOVE_INFER_SIGGRP3710 2511 return (uiRight || uiLower); 3711 #else 3712 return uiRight + uiLower; 3713 #endif 3714 3715 } 3716 #if !REMOVE_INFER_SIGGRP 3717 // return 1 if both right neighbour and lower neighour are 1's 3718 Bool TComTrQuant::bothCGNeighboursOne ( const UInt* uiSigCoeffGroupFlag, 3719 const UInt uiCGPosX, 3720 const UInt uiCGPosY, 3721 #if MULTILEVEL_SIGMAP_EXT 3722 const UInt scanIdx, 3723 #endif 3724 Int width, Int height) 3725 { 3726 UInt uiRight = 0; 3727 UInt uiLower = 0; 3728 3729 width >>= 2; 3730 height >>= 2; 3731 #if MULTILEVEL_SIGMAP_EXT 3732 if( width == 2 && height == 2 ) // 8x8 3733 { 3734 if( scanIdx == SCAN_HOR ) 3735 { 3736 width = 1; 3737 height = 4; 3738 } 3739 else if( scanIdx == SCAN_VER ) 3740 { 3741 width = 4; 3742 height = 1; 3743 } 3744 } 3745 #endif 3746 if( uiCGPosX < width - 1 ) 3747 { 3748 uiRight = (uiSigCoeffGroupFlag[ uiCGPosY * width + uiCGPosX + 1 ] != 0); 3749 } 3750 if (uiCGPosY < height - 1 ) 3751 { 3752 uiLower = (uiSigCoeffGroupFlag[ (uiCGPosY + 1 ) * width + uiCGPosX ] != 0); 3753 } 3754 3755 return (uiRight & uiLower); 3756 } 3757 #endif 2512 2513 } 3758 2514 /** set quantized matrix coefficient for encode 3759 2515 * \param scalingList quantaized matrix address … … 3842 2598 UInt width = g_scalingListSizeX[sizeId]; 3843 2599 UInt height = g_scalingListSizeX[sizeId]; 3844 #if SCALING_LIST3845 2600 UInt ratio = g_scalingListSizeX[sizeId]/min(MAX_MATRIX_SIZE_NUM,(Int)g_scalingListSizeX[sizeId]); 3846 #endif3847 2601 Int *quantcoeff; 3848 2602 Int *coeff = scalingList->getScalingListAddress(sizeId,listId); 3849 2603 quantcoeff = getQuantCoeff(listId, qp, sizeId, SCALING_LIST_SQT); 3850 2604 3851 #if SCALING_LIST3852 2605 processScalingListEnc(coeff,quantcoeff,g_quantScales[qp]<<4,height,width,ratio,min(MAX_MATRIX_SIZE_NUM,(Int)g_scalingListSizeX[sizeId]),scalingList->getScalingListDC(sizeId,listId)); 3853 #else3854 processScalingListEnc(coeff,quantcoeff,g_quantScales[qp]<<4,height,width,1,(Int)g_scalingListSizeX[sizeId],0);3855 #endif3856 2606 3857 2607 if(sizeId == SCALING_LIST_32x32 || sizeId == SCALING_LIST_16x16) //for NSQT 3858 2608 { 3859 2609 quantcoeff = getQuantCoeff(listId, qp, sizeId-1,SCALING_LIST_VER); 3860 #if SCALING_LIST3861 2610 processScalingListEnc(coeff,quantcoeff,g_quantScales[qp]<<4,height,width>>2,ratio,min(MAX_MATRIX_SIZE_NUM,(Int)g_scalingListSizeX[sizeId]),scalingList->getScalingListDC(sizeId,listId)); 3862 #else3863 processScalingListEnc(coeff,quantcoeff,g_quantScales[qp]<<4,height,width>>2,1,(Int)g_scalingListSizeX[sizeId],0);3864 #endif3865 2611 3866 2612 quantcoeff = getQuantCoeff(listId, qp, sizeId-1,SCALING_LIST_HOR); 3867 #if SCALING_LIST3868 2613 processScalingListEnc(coeff,quantcoeff,g_quantScales[qp]<<4,height>>2,width,ratio,min(MAX_MATRIX_SIZE_NUM,(Int)g_scalingListSizeX[sizeId]),scalingList->getScalingListDC(sizeId,listId)); 3869 #else3870 processScalingListEnc(coeff,quantcoeff,g_quantScales[qp]<<4,height>>2,width,1,(Int)g_scalingListSizeX[sizeId],0);3871 #endif3872 2614 } 3873 2615 } … … 3882 2624 UInt width = g_scalingListSizeX[sizeId]; 3883 2625 UInt height = g_scalingListSizeX[sizeId]; 3884 #if SCALING_LIST3885 2626 UInt ratio = g_scalingListSizeX[sizeId]/min(MAX_MATRIX_SIZE_NUM,(Int)g_scalingListSizeX[sizeId]); 3886 #endif3887 2627 Int *dequantcoeff; 3888 2628 Int *coeff = scalingList->getScalingListAddress(sizeId,listId); 3889 2629 3890 2630 dequantcoeff = getDequantCoeff(listId, qp, sizeId,SCALING_LIST_SQT); 3891 #if SCALING_LIST3892 2631 processScalingListDec(coeff,dequantcoeff,g_invQuantScales[qp],height,width,ratio,min(MAX_MATRIX_SIZE_NUM,(Int)g_scalingListSizeX[sizeId]),scalingList->getScalingListDC(sizeId,listId)); 3893 #else3894 processScalingListDec(coeff,dequantcoeff,g_invQuantScales[qp],height,width,1,(Int)g_scalingListSizeX[sizeId],0);3895 #endif3896 2632 3897 2633 if(sizeId == SCALING_LIST_32x32 || sizeId == SCALING_LIST_16x16) 3898 2634 { 3899 2635 dequantcoeff = getDequantCoeff(listId, qp, sizeId-1,SCALING_LIST_VER); 3900 #if SCALING_LIST3901 2636 processScalingListDec(coeff,dequantcoeff,g_invQuantScales[qp],height,width>>2,ratio,min(MAX_MATRIX_SIZE_NUM,(Int)g_scalingListSizeX[sizeId]),scalingList->getScalingListDC(sizeId,listId)); 3902 #else3903 processScalingListDec(coeff,dequantcoeff,g_invQuantScales[qp],height,width>>2,1,(Int)g_scalingListSizeX[sizeId],0);3904 #endif3905 2637 3906 2638 dequantcoeff = getDequantCoeff(listId, qp, sizeId-1,SCALING_LIST_HOR); 3907 2639 3908 #if SCALING_LIST3909 2640 processScalingListDec(coeff,dequantcoeff,g_invQuantScales[qp],height>>2,width,ratio,min(MAX_MATRIX_SIZE_NUM,(Int)g_scalingListSizeX[sizeId]),scalingList->getScalingListDC(sizeId,listId)); 3910 #else3911 processScalingListDec(coeff,dequantcoeff,g_invQuantScales[qp],height>>2,width,1,min(MAX_MATRIX_SIZE_NUM,(Int)g_scalingListSizeX[sizeId]),0);3912 #endif3913 2641 } 3914 2642 } … … 4004 2732 } 4005 2733 } 4006 #if SCALING_LIST4007 2734 if(ratio > 1) 4008 2735 { 4009 2736 quantcoeff[0] = quantScales / dc; 4010 2737 } 4011 #endif4012 2738 } 4013 2739 /** set quantized matrix coefficient for decode … … 4032 2758 } 4033 2759 } 4034 #if SCALING_LIST4035 2760 if(ratio > 1) 4036 2761 { 4037 2762 dequantcoeff[0] = invQuantScales * dc; 4038 2763 } 4039 #endif4040 2764 } 4041 2765
Note: See TracChangeset for help on using the changeset viewer.