Skip to content
Snippets Groups Projects
Picture.cpp 60.2 KiB
Newer Older
  • Learn to ignore specific revisions
  •                               const CPelBuf& beforeScale, const int beforeScaleLeftOffset, const int beforeScaleTopOffset,
                                  const PelBuf& afterScale, const int afterScaleLeftOffset, const int afterScaleTopOffset,
                                  const int bitDepth, const bool useLumaFilter, const bool downsampling )
    #endif
    {
      const Pel* orgSrc = beforeScale.buf;
      const int orgWidth = beforeScale.width;
      const int orgHeight = beforeScale.height;
      const int orgStride = beforeScale.stride;
    
      Pel* scaledSrc = afterScale.buf;
      const int scaledWidth = afterScale.width;
      const int scaledHeight = afterScale.height;
      const int scaledStride = afterScale.stride;
    
      if( orgWidth == scaledWidth && orgHeight == scaledHeight && scalingRatio == SCALE_1X && !beforeScaleLeftOffset && !beforeScaleTopOffset && !afterScaleLeftOffset && !afterScaleTopOffset )
      {
        for( int j = 0; j < orgHeight; j++ )
        {
          memcpy( scaledSrc + j * scaledStride, orgSrc + j * orgStride, sizeof( Pel ) * orgWidth );
        }
    
        return;
      }
    
      const TFilterCoeff* filterHor = useLumaFilter ? &InterpolationFilter::m_lumaFilter[0][0] : &InterpolationFilter::m_chromaFilter[0][0];
      const TFilterCoeff* filterVer = useLumaFilter ? &InterpolationFilter::m_lumaFilter[0][0] : &InterpolationFilter::m_chromaFilter[0][0];
      const int numFracPositions = useLumaFilter ? 15 : 31;
      const int numFracShift = useLumaFilter ? 4 : 5;
    
      const int posShiftX = SCALE_RATIO_BITS - numFracShift + compScale.first;
      const int posShiftY = SCALE_RATIO_BITS - numFracShift + compScale.second;
    
      int addX = ( 1 << ( posShiftX - 1 ) ) + ( beforeScaleLeftOffset << SCALE_RATIO_BITS ) + ( ( int( 1 - horCollocatedPositionFlag ) * 8 * ( scalingRatio.first - SCALE_1X.first ) + ( 1 << ( 2 + compScale.first ) ) ) >> ( 3 + compScale.first ) );
      int addY = ( 1 << ( posShiftY - 1 ) ) + ( beforeScaleTopOffset << SCALE_RATIO_BITS ) + ( ( int( 1 - verCollocatedPositionFlag ) * 8 * ( scalingRatio.second - SCALE_1X.second ) + ( 1 << ( 2 + compScale.second ) ) ) >> ( 3 + compScale.second ) );
    
      int addX = ( 1 << ( posShiftX - 1 ) ) + ( beforeScaleLeftOffset << SCALE_RATIO_BITS );
      int addY = ( 1 << ( posShiftY - 1 ) ) + ( beforeScaleTopOffset << SCALE_RATIO_BITS );
    
    #endif
    
      if( downsampling )
      {
        int verFilter = 0;
        int horFilter = 0;
    
        if( scalingRatio.first > ( 15 << SCALE_RATIO_BITS ) / 4 )   horFilter = 7;
        else if( scalingRatio.first > ( 20 << SCALE_RATIO_BITS ) / 7 )   horFilter = 6;
        else if( scalingRatio.first > ( 5 << SCALE_RATIO_BITS ) / 2 )   horFilter = 5;
        else if( scalingRatio.first > ( 2 << SCALE_RATIO_BITS ) )   horFilter = 4;
        else if( scalingRatio.first > ( 5 << SCALE_RATIO_BITS ) / 3 )   horFilter = 3;
        else if( scalingRatio.first > ( 5 << SCALE_RATIO_BITS ) / 4 )   horFilter = 2;
        else if( scalingRatio.first > ( 20 << SCALE_RATIO_BITS ) / 19 )   horFilter = 1;
    
        if( scalingRatio.second > ( 15 << SCALE_RATIO_BITS ) / 4 )   verFilter = 7;
        else if( scalingRatio.second > ( 20 << SCALE_RATIO_BITS ) / 7 )   verFilter = 6;
        else if( scalingRatio.second > ( 5 << SCALE_RATIO_BITS ) / 2 )   verFilter = 5;
        else if( scalingRatio.second > ( 2 << SCALE_RATIO_BITS ) )   verFilter = 4;
        else if( scalingRatio.second > ( 5 << SCALE_RATIO_BITS ) / 3 )   verFilter = 3;
        else if( scalingRatio.second > ( 5 << SCALE_RATIO_BITS ) / 4 )   verFilter = 2;
        else if( scalingRatio.second > ( 20 << SCALE_RATIO_BITS ) / 19 )   verFilter = 1;
    
        filterHor = &DownsamplingFilterSRC[horFilter][0][0];
        filterVer = &DownsamplingFilterSRC[verFilter][0][0];
      }
    
      const int filterLength = downsampling ? 12 : ( useLumaFilter ? NTAPS_LUMA : NTAPS_CHROMA );
      const int log2Norm = downsampling ? 14 : 12;
    
      int *buf = new int[orgHeight * scaledWidth];
      int maxVal = ( 1 << bitDepth ) - 1;
    
      CHECK( bitDepth > 17, "Overflow may happen!" );
    
      for( int i = 0; i < scaledWidth; i++ )
      {
        const Pel* org = orgSrc;
    
        int refPos = ( ( ( i << compScale.first ) - afterScaleLeftOffset ) * scalingRatio.first + addX ) >> posShiftX;
    
        int integer = refPos >> numFracShift;
        int frac = refPos & numFracPositions;
        int* tmp = buf + i;
    
        for( int j = 0; j < orgHeight; j++ )
        {
          int sum = 0;
          const TFilterCoeff* f = filterHor + frac * filterLength;
    
          for( int k = 0; k < filterLength; k++ )
          {
            int xInt = std::min<int>( std::max( 0, integer + k - filterLength / 2 + 1 ), orgWidth - 1 );
            sum += f[k] * org[xInt]; // postpone horizontal filtering gain removal after vertical filtering
          }
    
          *tmp = sum;
    
          tmp += scaledWidth;
          org += orgStride;
        }
      }
    
      Pel* dst = scaledSrc;
    
      for( int j = 0; j < scaledHeight; j++ )
      {
    
        int refPos = ( ( ( j << compScale.second ) - afterScaleTopOffset ) * scalingRatio.second + addY ) >> posShiftY;
    
        int integer = refPos >> numFracShift;
        int frac = refPos & numFracPositions;
    
        for( int i = 0; i < scaledWidth; i++ )
        {
          int sum = 0;
          int* tmp = buf + i;
          const TFilterCoeff* f = filterVer + frac * filterLength;
    
          for( int k = 0; k < filterLength; k++ )
          {
            int yInt = std::min<int>( std::max( 0, integer + k - filterLength / 2 + 1 ), orgHeight - 1 );
            sum += f[k] * tmp[yInt*scaledWidth];
          }
    
          dst[i] = std::min<int>( std::max( 0, ( sum + ( 1 << ( log2Norm - 1 ) ) ) >> log2Norm ), maxVal );
        }
    
        dst += scaledStride;
      }
    
      delete[] buf;
    }
    #else
    #if JVET_P0592_CHROMA_PHASE
    void Picture::sampleRateConv( const std::pair<int, int> scalingRatio, const std::pair<int, int> compScale,
                                  const Pel* orgSrc, SizeType orgWidth, SizeType orgHeight, SizeType orgStride,
                                  Pel* scaledSrc, SizeType scaledWidth, SizeType scaledHeight,
                                  SizeType paddedWidth, SizeType paddedHeight, SizeType scaledStride,
                                  const int bitDepth, const bool useLumaFilter, const bool downsampling,
                                  const bool horCollocatedPositionFlag, const bool verCollocatedPositionFlag )
    #else
    
    void Picture::sampleRateConv( const Pel* orgSrc, SizeType orgWidth, SizeType orgHeight, SizeType orgStride, Pel* scaledSrc, SizeType scaledWidth, SizeType scaledHeight, SizeType paddedWidth, SizeType paddedHeight, SizeType scaledStride, const int bitDepth, const bool useLumaFilter, const bool downsampling )
    
    {
      if( orgWidth == scaledWidth && orgHeight == scaledHeight )
      {
        for( int j = 0; j < orgHeight; j++ )
        {
          memcpy( scaledSrc + j * scaledStride, orgSrc + j * orgStride, sizeof( Pel ) * orgWidth );
        }
    
        return;
      }
    
    
      const TFilterCoeff* filterHor = useLumaFilter ? &InterpolationFilter::m_lumaFilter[0][0] : &InterpolationFilter::m_chromaFilter[0][0];
      const TFilterCoeff* filterVer = useLumaFilter ? &InterpolationFilter::m_lumaFilter[0][0] : &InterpolationFilter::m_chromaFilter[0][0];
      const int numFracPositions = useLumaFilter ? 15 : 31;
    
      const int numFracShift = useLumaFilter ? 4 : 5;
    
    #if JVET_P0592_CHROMA_PHASE
      const int posShift = SCALE_RATIO_BITS - numFracShift;
      int addX = ( 1 << ( posShift - 1 ) ) + ( ( int( 1 - horCollocatedPositionFlag ) * 8 * ( scalingRatio.first - SCALE_1X.first ) + ( 1 << ( 3 + compScale.first ) ) ) >> ( 4 + compScale.first ) );
      int addY = ( 1 << ( posShift - 1 ) ) + ( ( int( 1 - verCollocatedPositionFlag ) * 8 * ( scalingRatio.second - SCALE_1X.second ) + ( 1 << ( 3 + compScale.second ) ) ) >> ( 4 + compScale.second ) );
    #endif
    
    
      if( downsampling )
      {
        int verFilter = 0;
        int horFilter = 0;
    
        if( 4 * orgHeight > 15 * scaledHeight )   verFilter = 7;
        else if( 7 * orgHeight > 20 * scaledHeight )   verFilter = 6;
        else if( 2 * orgHeight > 5 * scaledHeight )   verFilter = 5;
        else if( 1 * orgHeight > 2 * scaledHeight )   verFilter = 4;
        else if( 3 * orgHeight > 5 * scaledHeight )   verFilter = 3;
        else if( 4 * orgHeight > 5 * scaledHeight )   verFilter = 2;
        else if( 19 * orgHeight > 20 * scaledHeight )   verFilter = 1;
    
        if( 4 * orgWidth > 15 * scaledWidth )   horFilter = 7;
        else if( 7 * orgWidth > 20 * scaledWidth )   horFilter = 6;
        else if( 2 * orgWidth > 5 * scaledWidth )   horFilter = 5;
        else if( 1 * orgWidth > 2 * scaledWidth )   horFilter = 4;
        else if( 3 * orgWidth > 5 * scaledWidth )   horFilter = 3;
        else if( 4 * orgWidth > 5 * scaledWidth )   horFilter = 2;
        else if( 19 * orgWidth > 20 * scaledWidth )   horFilter = 1;
    
        filterHor = &DownsamplingFilterSRC[horFilter][0][0];
        filterVer = &DownsamplingFilterSRC[verFilter][0][0];
      }
    
    
      const int filerLength = downsampling ? 12 : ( useLumaFilter ? NTAPS_LUMA : NTAPS_CHROMA );
    
      const int log2Norm = downsampling ? 14 : 12;
    
    
      int *buf = new int[orgHeight * paddedWidth];
    
      int maxVal = ( 1 << bitDepth ) - 1;
    
      CHECK( bitDepth > 17, "Overflow may happen!" );
    
    
      for( int i = 0; i < paddedWidth; i++ )
    
    #if JVET_P0592_CHROMA_PHASE
        int refPos = ( i * scalingRatio.first + addX ) >> posShift;
        int integer = refPos >> numFracShift;
        int frac = refPos & numFracPositions;
    #else
    
        int integer = ( i * orgWidth ) / scaledWidth;
    
        int frac = ( ( i * orgWidth << numFracShift ) / scaledWidth ) & numFracPositions;
    
    
        int* tmp = buf + i;
    
        for( int j = 0; j < orgHeight; j++ )
        {
          int sum = 0;
    
          const TFilterCoeff* f = filterHor + frac * filerLength;
    
    
          for( int k = 0; k < filerLength; k++ )
          {
            int xInt = std::min<int>( std::max( 0, integer + k - filerLength / 2 + 1 ), orgWidth - 1 );
            sum += f[k] * org[xInt]; // postpone horizontal filtering gain removal after vertical filtering
          }
    
          *tmp = sum;
    
    
          tmp += paddedWidth;
    
      for( int j = 0; j < paddedHeight; j++ )
    
    #if JVET_P0592_CHROMA_PHASE
        int refPos = ( j * scalingRatio.second + addY ) >> posShift;
        int integer = refPos >> numFracShift;
        int frac = refPos & numFracPositions;
    #else
    
        int integer = ( j * orgHeight ) / scaledHeight;
    
        int frac = ( ( j * orgHeight << numFracShift ) / scaledHeight ) & numFracPositions;
    
        for( int i = 0; i < paddedWidth; i++ )
    
          const TFilterCoeff* f = filterVer + frac * filerLength;
    
    
          for( int k = 0; k < filerLength; k++ )
          {
            int yInt = std::min<int>( std::max( 0, integer + k - filerLength / 2 + 1 ), orgHeight - 1 );
    
            sum += f[k] * tmp[yInt*paddedWidth];
    
          }
    
          dst[i] = std::min<int>( std::max( 0, ( sum + ( 1 << ( log2Norm - 1 ) ) ) >> log2Norm ), maxVal );
        }
    
        dst += scaledStride;
      }
    
      delete[] buf;
    }
    
    #endif
    
    #if JVET_P0590_SCALING_WINDOW
    void Picture::rescalePicture( const std::pair<int, int> scalingRatio,
                                  const CPelUnitBuf& beforeScaling, const Window& scalingWindowBefore,
                                  const PelUnitBuf& afterScaling, const Window& scalingWindowAfter,
    #if JVET_P0592_CHROMA_PHASE
                                  const ChromaFormat chromaFormatIDC, const BitDepths& bitDepths, const bool useLumaFilter, const bool downsampling,
                                  const bool horCollocatedChromaFlag, const bool verCollocatedChromaFlag )
    #else
                                  const ChromaFormat chromaFormatIDC, const BitDepths& bitDepths, const bool useLumaFilter, const bool downsampling )
    #endif
    {
      for( int comp = 0; comp < ::getNumberValidComponents( chromaFormatIDC ); comp++ )
      {
        ComponentID compID = ComponentID( comp );
        const CPelBuf& beforeScale = beforeScaling.get( compID );
        const PelBuf& afterScale = afterScaling.get( compID );
    
    #if JVET_P0592_CHROMA_PHASE
        sampleRateConv( scalingRatio, std::pair<int, int>( ::getComponentScaleX( compID, chromaFormatIDC ), ::getComponentScaleY( compID, chromaFormatIDC ) ),
                        beforeScale, scalingWindowBefore.getWindowLeftOffset(), scalingWindowBefore.getWindowTopOffset(), 
                        afterScale, scalingWindowAfter.getWindowLeftOffset(), scalingWindowAfter.getWindowTopOffset(), 
                        bitDepths.recon[comp], downsampling || useLumaFilter ? true : isLuma( compID ), downsampling,
                        isLuma( compID ) ? 1 : horCollocatedChromaFlag, isLuma( compID ) ? 1 : verCollocatedChromaFlag );
    #else
        Picture::sampleRateConv( scalingRatio, 
                                 beforeScale, scalingWindowBefore.getWindowLeftOffset(), scalingWindowBefore.getWindowTopOffset(), 
                                 afterScale, scalingWindowAfter.getWindowLeftOffset(), scalingWindowAfter.getWindowTopOffset(), 
                                 bitDepths.recon[comp], downsampling || useLumaFilter ? true : isLuma( compID ), downsampling );
    #endif
      }
    }
    #elif JVET_P0592_CHROMA_PHASE
    void Picture::rescalePicture( const std::pair<int, int> scalingRatio,
                                  const CPelUnitBuf& beforeScaling, const Window& confBefore,
                                  const PelUnitBuf& afterScaling, const Window& confAfter,
                                  const ChromaFormat chromaFormatIDC, const BitDepths& bitDepths, const bool useLumaFilter, const bool downsampling,
                                  const bool horCollocatedChromaFlag, const bool verCollocatedChromaFlag )
    {
      for( int comp = 0; comp < ::getNumberValidComponents( chromaFormatIDC ); comp++ )
      {
        ComponentID compID = ComponentID( comp );
        const CPelBuf& beforeScale = beforeScaling.get( compID );
        const PelBuf& afterScale = afterScaling.get( compID );
        int widthBefore = beforeScale.width - ( ( ( confBefore.getWindowLeftOffset() + confBefore.getWindowRightOffset() ) * SPS::getWinUnitX( chromaFormatIDC ) ) >> getChannelTypeScaleX( (ChannelType)( comp > 0 ), chromaFormatIDC ) );
        int heightBefore = beforeScale.height - ( ( ( confBefore.getWindowTopOffset() + confBefore.getWindowBottomOffset() ) * SPS::getWinUnitY( chromaFormatIDC ) ) >> getChannelTypeScaleY( (ChannelType)( comp > 0 ), chromaFormatIDC ) );
        int widthAfter = afterScale.width - ( ( ( confAfter.getWindowLeftOffset() + confAfter.getWindowRightOffset() ) * SPS::getWinUnitX( chromaFormatIDC ) ) >> getChannelTypeScaleX( (ChannelType)( comp > 0 ), chromaFormatIDC ) );
        int heightAfter = afterScale.height - ( ( ( confAfter.getWindowTopOffset() + confAfter.getWindowBottomOffset() ) * SPS::getWinUnitY( chromaFormatIDC ) ) >> getChannelTypeScaleY( (ChannelType)( comp > 0 ), chromaFormatIDC ) );
    
        sampleRateConv( scalingRatio, std::pair<int, int>( ::getComponentScaleX( compID, chromaFormatIDC ), ::getComponentScaleY( compID, chromaFormatIDC ) ),
                        beforeScale.buf, widthBefore, heightBefore, beforeScale.stride,
                        afterScale.buf, widthAfter, heightAfter, afterScale.width, afterScale.height, afterScale.stride,
                        bitDepths.recon[comp], downsampling || useLumaFilter ? true : isLuma( compID ), downsampling,
                        isLuma( compID ) ? 1 : horCollocatedChromaFlag, isLuma( compID ) ? 1 : verCollocatedChromaFlag );
      }
    }
    #else
    
    void Picture::rescalePicture( const CPelUnitBuf& beforeScaling, const Window& confBefore, const PelUnitBuf& afterScaling, const Window& confAfter, const ChromaFormat chromaFormatIDC, const BitDepths& bitDepths, const bool useLumaFilter, const bool downsampling )
    
    {
      for( int comp = 0; comp < ::getNumberValidComponents( chromaFormatIDC ); comp++ )
      {
    
        ComponentID compID = ComponentID( comp );
        const CPelBuf& beforeScale = beforeScaling.get( compID );
        const PelBuf& afterScale = afterScaling.get( compID );
    
        int widthBefore = beforeScale.width - (((confBefore.getWindowLeftOffset() + confBefore.getWindowRightOffset()) * SPS::getWinUnitX(chromaFormatIDC)) >> getChannelTypeScaleX((ChannelType)(comp > 0), chromaFormatIDC));
        int heightBefore = beforeScale.height - (((confBefore.getWindowTopOffset() + confBefore.getWindowBottomOffset()) * SPS::getWinUnitY(chromaFormatIDC)) >> getChannelTypeScaleY((ChannelType)(comp > 0), chromaFormatIDC));
        int widthAfter = afterScale.width - (((confAfter.getWindowLeftOffset() + confAfter.getWindowRightOffset()) * SPS::getWinUnitX(chromaFormatIDC)) >> getChannelTypeScaleX((ChannelType)(comp > 0), chromaFormatIDC));
        int heightAfter = afterScale.height - (((confAfter.getWindowTopOffset() + confAfter.getWindowBottomOffset()) * SPS::getWinUnitY(chromaFormatIDC)) >> getChannelTypeScaleY((ChannelType)(comp > 0), chromaFormatIDC));
    
        Picture::sampleRateConv( beforeScale.buf,  widthBefore, heightBefore, beforeScale.stride, afterScale.buf, widthAfter, heightAfter, afterScale.width, afterScale.height, afterScale.stride, bitDepths.recon[comp], downsampling || useLumaFilter ? true : isLuma(compID), downsampling );
    
    void Picture::extendPicBorder()
    {
      if ( m_bIsBorderExtended )
      {
        return;
      }
    
      for(int comp=0; comp<getNumberValidComponents( cs->area.chromaFormat ); comp++)
      {
        ComponentID compID = ComponentID( comp );
        PelBuf p = M_BUFS( 0, PIC_RECONSTRUCTION ).get( compID );
        Pel *piTxt = p.bufAt(0,0);
        int xmargin = margin >> getComponentScaleX( compID, cs->area.chromaFormat );
        int ymargin = margin >> getComponentScaleY( compID, cs->area.chromaFormat );
    
        Pel*  pi = piTxt;
        // do left and right margins
    
    Philippe Hanhart's avatar
    Philippe Hanhart committed
          for (int y = 0; y < p.height; y++)
          {
            for (int x = 0; x < xmargin; x++ )
            {
              pi[ -xmargin + x ] = pi[0];
              pi[  p.width + x ] = pi[p.width-1];
            }
            pi += p.stride;
          }
    
    
        // pi is now the (0,height) (bottom left of image within bigger picture
        pi -= (p.stride + xmargin);
        // pi is now the (-marginX, height-1)
        for (int y = 0; y < ymargin; y++ )
        {
          ::memcpy( pi + (y+1)*p.stride, pi, sizeof(Pel)*(p.width + (xmargin << 1)));
        }
    
        // pi is still (-marginX, height-1)
        pi -= ((p.height-1) * p.stride);
        // pi is now (-marginX, 0)
        for (int y = 0; y < ymargin; y++ )
        {
          ::memcpy( pi - (y+1)*p.stride, pi, sizeof(Pel)*(p.width + (xmargin<<1)) );
        }
    
        // reference picture with horizontal wrapped boundary
        if (cs->sps->getWrapAroundEnabledFlag())
        {
          p = M_BUFS( 0, PIC_RECON_WRAP ).get( compID );
          p.copyFrom(M_BUFS( 0, PIC_RECONSTRUCTION ).get( compID ));
          piTxt = p.bufAt(0,0);
          pi = piTxt;
          int xoffset = cs->sps->getWrapAroundOffset() >> getComponentScaleX( compID, cs->area.chromaFormat );
          for (int y = 0; y < p.height; y++)
          {
            for (int x = 0; x < xmargin; x++ )
            {
    
              if( x < xoffset )
    
              {
                pi[ -x - 1 ] = pi[ -x - 1 + xoffset ];
                pi[  p.width + x ] = pi[ p.width + x - xoffset ];
              }
    
              {
                pi[ -x - 1 ] = pi[ 0 ];
                pi[  p.width + x ] = pi[ p.width - 1 ];
              }
            }
            pi += p.stride;
          }
          pi -= (p.stride + xmargin);
          for (int y = 0; y < ymargin; y++ )
          {
            ::memcpy( pi + (y+1)*p.stride, pi, sizeof(Pel)*(p.width + (xmargin << 1)));
          }
          pi -= ((p.height-1) * p.stride);
          for (int y = 0; y < ymargin; y++ )
          {
            ::memcpy( pi - (y+1)*p.stride, pi, sizeof(Pel)*(p.width + (xmargin<<1)) );
          }
        }
    
      }
    
      m_bIsBorderExtended = true;
    }
    
    PelBuf Picture::getBuf( const ComponentID compID, const PictureType &type )
    {
    
      return M_BUFS( ( type == PIC_ORIGINAL || type == PIC_TRUE_ORIGINAL || type == PIC_ORIGINAL_INPUT || type == PIC_TRUE_ORIGINAL_INPUT ) ? 0 : scheduler.getSplitPicId(), type ).getBuf( compID );
    
    }
    
    const CPelBuf Picture::getBuf( const ComponentID compID, const PictureType &type ) const
    {
    
      return M_BUFS( ( type == PIC_ORIGINAL || type == PIC_TRUE_ORIGINAL || type == PIC_ORIGINAL_INPUT || type == PIC_TRUE_ORIGINAL_INPUT ) ? 0 : scheduler.getSplitPicId(), type ).getBuf( compID );
    
    }
    
    PelBuf Picture::getBuf( const CompArea &blk, const PictureType &type )
    {
      if( !blk.valid() )
      {
        return PelBuf();
      }
    
    #if ENABLE_SPLIT_PARALLELISM
    
      const int jId = ( type == PIC_ORIGINAL || type == PIC_TRUE_ORIGINAL || type == PIC_ORIGINAL_INPUT || type == PIC_TRUE_ORIGINAL_INPUT ) ? 0 : scheduler.getSplitPicId();
    
    #endif
    #if !KEEP_PRED_AND_RESI_SIGNALS
      if( type == PIC_RESIDUAL || type == PIC_PREDICTION )
      {
        CompArea localBlk = blk;
        localBlk.x &= ( cs->pcv->maxCUWidthMask  >> getComponentScaleX( blk.compID, blk.chromaFormat ) );
        localBlk.y &= ( cs->pcv->maxCUHeightMask >> getComponentScaleY( blk.compID, blk.chromaFormat ) );
    
        return M_BUFS( jId, type ).getBuf( localBlk );
      }
    #endif
    
      return M_BUFS( jId, type ).getBuf( blk );
    }
    
    const CPelBuf Picture::getBuf( const CompArea &blk, const PictureType &type ) const
    {
      if( !blk.valid() )
      {
        return PelBuf();
      }
    
    #if ENABLE_SPLIT_PARALLELISM
    
      const int jId = ( type == PIC_ORIGINAL || type == PIC_TRUE_ORIGINAL ) ? 0 : scheduler.getSplitPicId();
    
    
    #endif
    #if !KEEP_PRED_AND_RESI_SIGNALS
      if( type == PIC_RESIDUAL || type == PIC_PREDICTION )
      {
        CompArea localBlk = blk;
        localBlk.x &= ( cs->pcv->maxCUWidthMask  >> getComponentScaleX( blk.compID, blk.chromaFormat ) );
        localBlk.y &= ( cs->pcv->maxCUHeightMask >> getComponentScaleY( blk.compID, blk.chromaFormat ) );
    
        return M_BUFS( jId, type ).getBuf( localBlk );
      }
    #endif
    
      return M_BUFS( jId, type ).getBuf( blk );
    }
    
    PelUnitBuf Picture::getBuf( const UnitArea &unit, const PictureType &type )
    {
      if( chromaFormat == CHROMA_400 )
      {
        return PelUnitBuf( chromaFormat, getBuf( unit.Y(), type ) );
      }
      else
      {
        return PelUnitBuf( chromaFormat, getBuf( unit.Y(), type ), getBuf( unit.Cb(), type ), getBuf( unit.Cr(), type ) );
      }
    }
    
    const CPelUnitBuf Picture::getBuf( const UnitArea &unit, const PictureType &type ) const
    {
      if( chromaFormat == CHROMA_400 )
      {
        return CPelUnitBuf( chromaFormat, getBuf( unit.Y(), type ) );
      }
      else
      {
        return CPelUnitBuf( chromaFormat, getBuf( unit.Y(), type ), getBuf( unit.Cb(), type ), getBuf( unit.Cr(), type ) );
      }
    }
    
    Pel* Picture::getOrigin( const PictureType &type, const ComponentID compID ) const
    {
    #if ENABLE_SPLIT_PARALLELISM
    
      const int jId = ( type == PIC_ORIGINAL || type == PIC_TRUE_ORIGINAL ) ? 0 : scheduler.getSplitPicId();
    
    
    void Picture::createSpliceIdx(int nums)
    {
      m_ctuNums = nums;
      m_spliceIdx = new int[m_ctuNums];
      memset(m_spliceIdx, 0, m_ctuNums * sizeof(int));
    }
    
    bool Picture::getSpliceFull()
    {
      int count = 0;
      for (int i = 0; i < m_ctuNums; i++)
      {
        if (m_spliceIdx[i] != 0)
          count++;
      }
      if (count < m_ctuNums * 0.25)
        return false;
      return true;
    }
    
    
    void Picture::addPictureToHashMapForInter()
    {
    
      int picWidth = slices[0]->getPPS()->getPicWidthInLumaSamples();
      int picHeight = slices[0]->getPPS()->getPicHeightInLumaSamples();
    
      uint32_t* blockHashValues[2][2];
    
      bool* bIsBlockSame[2][3];
    
      for (int i = 0; i < 2; i++)
      {
        for (int j = 0; j < 2; j++)
        {
    
          blockHashValues[i][j] = new uint32_t[picWidth*picHeight];
    
        }
    
        for (int j = 0; j < 3; j++)
        {
          bIsBlockSame[i][j] = new bool[picWidth*picHeight];
        }
      }
    
      m_hashMap.create(picWidth, picHeight);
    
      m_hashMap.generateBlock2x2HashValue(getOrigBuf(), picWidth, picHeight, slices[0]->getSPS()->getBitDepths(), blockHashValues[0], bIsBlockSame[0]);//2x2
      m_hashMap.generateBlockHashValue(picWidth, picHeight, 4, 4, blockHashValues[0], blockHashValues[1], bIsBlockSame[0], bIsBlockSame[1]);//4x4
      m_hashMap.addToHashMapByRowWithPrecalData(blockHashValues[1], bIsBlockSame[1][2], picWidth, picHeight, 4, 4);
    
      m_hashMap.generateBlockHashValue(picWidth, picHeight, 8, 8, blockHashValues[1], blockHashValues[0], bIsBlockSame[1], bIsBlockSame[0]);//8x8
      m_hashMap.addToHashMapByRowWithPrecalData(blockHashValues[0], bIsBlockSame[0][2], picWidth, picHeight, 8, 8);
    
      m_hashMap.generateBlockHashValue(picWidth, picHeight, 16, 16, blockHashValues[0], blockHashValues[1], bIsBlockSame[0], bIsBlockSame[1]);//16x16
      m_hashMap.addToHashMapByRowWithPrecalData(blockHashValues[1], bIsBlockSame[1][2], picWidth, picHeight, 16, 16);
    
      m_hashMap.generateBlockHashValue(picWidth, picHeight, 32, 32, blockHashValues[1], blockHashValues[0], bIsBlockSame[1], bIsBlockSame[0]);//32x32
      m_hashMap.addToHashMapByRowWithPrecalData(blockHashValues[0], bIsBlockSame[0][2], picWidth, picHeight, 32, 32);
    
      m_hashMap.generateBlockHashValue(picWidth, picHeight, 64, 64, blockHashValues[0], blockHashValues[1], bIsBlockSame[0], bIsBlockSame[1]);//64x64
      m_hashMap.addToHashMapByRowWithPrecalData(blockHashValues[1], bIsBlockSame[1][2], picWidth, picHeight, 64, 64);
    
      m_hashMap.setInitial();
    
      for (int i = 0; i < 2; i++)
      {
        for (int j = 0; j < 2; j++)
        {
          delete[] blockHashValues[i][j];
        }
    
        for (int j = 0; j < 3; j++)
        {
          delete[] bIsBlockSame[i][j];
        }
      }
    }