Ticket #171: shift_fix.patch

File shift_fix.patch, 7.1 KB (added by ksuehring, 5 years ago)

proposed fix

  • source/Lib/CommonLib/TrQuant.cpp

    diff --git a/source/Lib/CommonLib/TrQuant.cpp b/source/Lib/CommonLib/TrQuant.cpp
    index 2327718..69451f7 100644
    a b void TrQuant::xT( const TransformUnit &tu, const ComponentID &compID, const CPel 
    396396  const unsigned maxLog2TrDynamicRange  = tu.cs->sps->getMaxLog2TrDynamicRange( toChannelType( compID ) );
    397397  const unsigned bitDepth               = tu.cs->sps->getBitDepth(              toChannelType( compID ) );
    398398  const int      TRANSFORM_MATRIX_SHIFT = g_transformMatrixShift[TRANSFORM_FORWARD];
     399#if !JVET_M0102_INTRA_SUBPARTITIONS
    399400  const int      shift_1st              = ((g_aucLog2[width ]) + bitDepth + TRANSFORM_MATRIX_SHIFT) - maxLog2TrDynamicRange + COM16_C806_TRANS_PREC;
    400401  const int      shift_2nd              =  (g_aucLog2[height])            + TRANSFORM_MATRIX_SHIFT                          + COM16_C806_TRANS_PREC;
     402#endif
    401403  const uint32_t transformWidthIndex    = g_aucLog2[width ] - 1;  // nLog2WidthMinus1, since transform start from 2-point
    402404  const uint32_t transformHeightIndex   = g_aucLog2[height] - 1;  // nLog2HeightMinus1, since transform start from 2-point
    403405#if !JVET_M0297_32PT_MTS_ZERO_OUT
    void TrQuant::xT( const TransformUnit &tu, const ComponentID &compID, const CPel 
    405407  const int      skipHeight             = height > JVET_C0024_ZERO_OUT_TH ? height - JVET_C0024_ZERO_OUT_TH : 0;
    406408#endif
    407409 
     410#if !JVET_M0102_INTRA_SUBPARTITIONS
    408411  CHECK( shift_1st < 0, "Negative shift" );
    409412  CHECK( shift_2nd < 0, "Negative shift" );
     413#endif
    410414 
    411415  int trTypeHor = DCT2;
    412416  int trTypeVer = DCT2;
    void TrQuant::xT( const TransformUnit &tu, const ComponentID &compID, const CPel 
    441445#if JVET_M0102_INTRA_SUBPARTITIONS
    442446  if( width > 1 && height > 1 ) // 2-D transform
    443447  {
     448    const int      shift_1st              = ((g_aucLog2[width ]) + bitDepth + TRANSFORM_MATRIX_SHIFT) - maxLog2TrDynamicRange + COM16_C806_TRANS_PREC;
     449    const int      shift_2nd              =  (g_aucLog2[height])            + TRANSFORM_MATRIX_SHIFT                          + COM16_C806_TRANS_PREC;
     450    CHECK( shift_1st < 0, "Negative shift" );
     451    CHECK( shift_2nd < 0, "Negative shift" );
    444452#endif
    445453  TCoeff *tmp = ( TCoeff * ) alloca( width * height * sizeof( TCoeff ) );
    446454 
    void TrQuant::xT( const TransformUnit &tu, const ComponentID &compID, const CPel 
    450458  }
    451459  else if( height == 1 ) //1-D horizontal transform
    452460  {
     461    const int      shift              = ((g_aucLog2[width ]) + bitDepth + TRANSFORM_MATRIX_SHIFT) - maxLog2TrDynamicRange + COM16_C806_TRANS_PREC;
     462    CHECK( shift < 0, "Negative shift" );
    453463    CHECKD( ( transformWidthIndex < 0 ), "There is a problem with the width." );
    454     fastFwdTrans[trTypeHor][transformWidthIndex]( block, dstCoeff.buf, shift_1st, 1, 0, skipWidth );
     464    fastFwdTrans[trTypeHor][transformWidthIndex]( block, dstCoeff.buf, shift, 1, 0, skipWidth );
    455465  }
    456466  else //if (iWidth == 1) //1-D vertical transform
    457467  {
     468    int shift = ( ( g_aucLog2[height] ) + bitDepth + TRANSFORM_MATRIX_SHIFT ) - maxLog2TrDynamicRange + COM16_C806_TRANS_PREC;
     469    CHECK( shift < 0, "Negative shift" );
    458470    CHECKD( ( transformHeightIndex < 0 ), "There is a problem with the height." );
    459     int newShift = ( ( g_aucLog2[height] ) + bitDepth + TRANSFORM_MATRIX_SHIFT ) - maxLog2TrDynamicRange + COM16_C806_TRANS_PREC;
    460     fastFwdTrans[trTypeVer][transformHeightIndex]( block, dstCoeff.buf, newShift, 1, 0, skipHeight );
     471    fastFwdTrans[trTypeVer][transformHeightIndex]( block, dstCoeff.buf, shift, 1, 0, skipHeight );
    461472  }
    462473#endif
    463474}
    void TrQuant::xIT( const TransformUnit &tu, const ComponentID &compID, const CCo 
    471482  const int      TRANSFORM_MATRIX_SHIFT = g_transformMatrixShift[TRANSFORM_INVERSE];
    472483  const TCoeff   clipMinimum            = -( 1 << maxLog2TrDynamicRange );
    473484  const TCoeff   clipMaximum            =  ( 1 << maxLog2TrDynamicRange ) - 1;
     485#if !JVET_M0102_INTRA_SUBPARTITIONS
    474486  const int      shift_1st              =   TRANSFORM_MATRIX_SHIFT + 1 + COM16_C806_TRANS_PREC; // 1 has been added to shift_1st at the expense of shift_2nd
    475487  const int      shift_2nd              = ( TRANSFORM_MATRIX_SHIFT + maxLog2TrDynamicRange - 1 ) - bitDepth + COM16_C806_TRANS_PREC;
     488#endif
    476489  const uint32_t transformWidthIndex    = g_aucLog2[width ] - 1;                                // nLog2WidthMinus1, since transform start from 2-point
    477490  const uint32_t transformHeightIndex   = g_aucLog2[height] - 1;                                // nLog2HeightMinus1, since transform start from 2-point
    478491#if !JVET_M0297_32PT_MTS_ZERO_OUT
    void TrQuant::xIT( const TransformUnit &tu, const ComponentID &compID, const CCo 
    480493  const int      skipHeight             = height > JVET_C0024_ZERO_OUT_TH ? height - JVET_C0024_ZERO_OUT_TH : 0;
    481494#endif
    482495 
     496#if !JVET_M0102_INTRA_SUBPARTITIONS
    483497  CHECK( shift_1st < 0, "Negative shift" );
    484498  CHECK( shift_2nd < 0, "Negative shift" );
    485  
     499#endif
     500
    486501  int trTypeHor = DCT2;
    487502  int trTypeVer = DCT2;
    488503 
    void TrQuant::xIT( const TransformUnit &tu, const ComponentID &compID, const CCo 
    501516#if JVET_M0102_INTRA_SUBPARTITIONS
    502517  if( width > 1 && height > 1 ) //2-D transform
    503518  {
     519    const int      shift_1st              =   TRANSFORM_MATRIX_SHIFT + 1 + COM16_C806_TRANS_PREC; // 1 has been added to shift_1st at the expense of shift_2nd
     520    const int      shift_2nd              = ( TRANSFORM_MATRIX_SHIFT + maxLog2TrDynamicRange - 1 ) - bitDepth + COM16_C806_TRANS_PREC;
     521    CHECK( shift_1st < 0, "Negative shift" );
     522    CHECK( shift_2nd < 0, "Negative shift" );
    504523    TCoeff *tmp = ( TCoeff * ) alloca( width * height * sizeof( TCoeff ) );
    505524#endif
    506525  fastInvTrans[trTypeVer][transformHeightIndex](pCoeff.buf, tmp, shift_1st, width, skipWidth, skipHeight, clipMinimum, clipMaximum);
    void TrQuant::xIT( const TransformUnit &tu, const ComponentID &compID, const CCo 
    509528  }
    510529  else if( width == 1 ) //1-D vertical transform
    511530  {
     531    int shift = ( TRANSFORM_MATRIX_SHIFT + maxLog2TrDynamicRange - 1 ) - bitDepth + COM16_C806_TRANS_PREC;
     532    CHECK( shift < 0, "Negative shift" );
    512533    CHECK( ( transformHeightIndex < 0 ), "There is a problem with the height." );
    513     int newShift = ( TRANSFORM_MATRIX_SHIFT + maxLog2TrDynamicRange - 1 ) - bitDepth + COM16_C806_TRANS_PREC;
    514     fastInvTrans[trTypeVer][transformHeightIndex]( pCoeff.buf, block, newShift + 1, 1, 0, skipHeight, clipMinimum, clipMaximum );
     534    fastInvTrans[trTypeVer][transformHeightIndex]( pCoeff.buf, block, shift + 1, 1, 0, skipHeight, clipMinimum, clipMaximum );
    515535  }
    516536  else //if(iHeight == 1) //1-D horizontal transform
    517537  {
     538    const int      shift              = ( TRANSFORM_MATRIX_SHIFT + maxLog2TrDynamicRange - 1 ) - bitDepth + COM16_C806_TRANS_PREC;
     539    CHECK( shift < 0, "Negative shift" );
    518540    CHECK( ( transformWidthIndex < 0 ), "There is a problem with the width." );
    519     fastInvTrans[trTypeHor][transformWidthIndex]( pCoeff.buf, block, shift_2nd + 1, 1, 0, skipWidth, clipMinimum, clipMaximum );
     541    fastInvTrans[trTypeHor][transformWidthIndex]( pCoeff.buf, block, shift + 1, 1, 0, skipWidth, clipMinimum, clipMaximum );
    520542  }
    521543#endif
    522544