Skip to content
Snippets Groups Projects
UnitTools.cpp 128 KiB
Newer Older
  • Learn to ignore specific revisions
  • bool TU::getCbfAtDepth(const TransformUnit &tu, const ComponentID &compID, const unsigned &depth)
    {
    
      if( !tu.blocks[compID].valid() )
        CHECK( tu.cbf[compID] != 0, "cbf must be 0 if the component is not available" );
    
      return ((tu.cbf[compID] >> depth) & 1) == 1;
    }
    
    void TU::setCbfAtDepth(TransformUnit &tu, const ComponentID &compID, const unsigned &depth, const bool &cbf)
    {
      // first clear the CBF at the depth
      tu.cbf[compID] &= ~(1  << depth);
      // then set the CBF
      tu.cbf[compID] |= ((cbf ? 1 : 0) << depth);
    }
    
    
    Tung Nguyen's avatar
    Tung Nguyen committed
    bool TU::isTSAllowed(const TransformUnit &tu, const ComponentID compID)
    {
    
      const int maxSize = tu.cs->sps->getLog2MaxTransformSkipBlockSize();
    
    Tung Nguyen's avatar
    Tung Nguyen committed
    
    
      bool tsAllowed = tu.cs->sps->getTransformSkipEnabledFlag();
    
      tsAllowed &= ( !tu.cu->ispMode || !isLuma(compID) );
    
      SizeType transformSkipMaxSize = 1 << maxSize;
    
      tsAllowed &= !(tu.cu->bdpcmMode && isLuma(compID));
    
      tsAllowed &= !(tu.cu->bdpcmModeChroma && isChroma(compID));
    
      tsAllowed &= tu.blocks[compID].width <= transformSkipMaxSize && tu.blocks[compID].height <= transformSkipMaxSize;
    
      tsAllowed &= !tu.cu->sbtInfo;
    
    Tung Nguyen's avatar
    Tung Nguyen committed
    
      return tsAllowed;
    }
    
    
    int TU::getICTMode( const TransformUnit& tu, int jointCbCr )
    {
      if( jointCbCr < 0 )
      {
        jointCbCr = tu.jointCbCr;
      }
    
    Brian Heng's avatar
    Brian Heng committed
      return g_ictModes[ tu.cs->picHeader->getJointCbCrSignFlag() ][ jointCbCr ];
    
    bool TU::hasCrossCompPredInfo( const TransformUnit &tu, const ComponentID &compID )
    {
    
    Yu Han's avatar
    Yu Han committed
      return (isChroma(compID) && tu.cs->pps->getPpsRangeExtension().getCrossComponentPredictionEnabledFlag() && TU::getCbf(tu, COMPONENT_Y) &&
        (!CU::isIntra(*tu.cu) || PU::isChromaIntraModeCrossCheckMode(*tu.cs->getPU(tu.blocks[compID].pos(), toChannelType(compID)))));
    
    bool TU::needsSqrt2Scale( const TransformUnit &tu, const ComponentID &compID )
    {
      const Size &size=tu.blocks[compID];
    
      const bool isTransformSkip = (tu.mtsIdx[compID] == MTS_SKIP);
    
      return (!isTransformSkip) && (((floorLog2(size.width) + floorLog2(size.height)) & 1) == 1);
    
    bool TU::needsBlockSizeTrafoScale( const TransformUnit &tu, const ComponentID &compID )
    {
      return needsSqrt2Scale( tu, compID ) || isNonLog2BlockSize( tu.blocks[compID] );
    }
    
    TransformUnit* TU::getPrevTU( const TransformUnit &tu, const ComponentID compID )
    {
      TransformUnit* prevTU = tu.prev;
    
      if( prevTU != nullptr && ( prevTU->cu != tu.cu || !prevTU->blocks[compID].valid() ) )
      {
        prevTU = nullptr;
      }
    
      return prevTU;
    }
    
    bool TU::getPrevTuCbfAtDepth( const TransformUnit &currentTu, const ComponentID compID, const int trDepth )
    {
      const TransformUnit* prevTU = getPrevTU( currentTu, compID );
      return ( prevTU != nullptr ) ? TU::getCbfAtDepth( *prevTU, compID, trDepth ) : false;
    }
    
    
    // other tools
    
    uint32_t getCtuAddr( const Position& pos, const PreCalcValues& pcv )
    {
      return ( pos.x >> pcv.maxCUWidthLog2 ) + ( pos.y >> pcv.maxCUHeightLog2 ) * pcv.widthInCtus;
    }
    
    
    int getNumModesMip(const Size& block)
    {
    
      switch( getMipSizeId(block) )
      {
      case 0: return 16;
      case 1: return  8;
      case 2: return  6;
      default: THROW( "Invalid mipSizeId" );
      }
    
    int getMipSizeId(const Size& block)
    {
      if( block.width == 4 && block.height == 4 )
      {
        return 0;
      }
    
      else if( block.width == 4 || block.height == 4 || (block.width == 8 && block.height == 8) )
    
    bool allowLfnstWithMip(const Size& block)
    {
      if (block.width >= 16 && block.height >= 16)
      {
        return true;
      }
      return false;
    }