Newer
Older

Karsten Suehring
committed
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
#if HEVC_TILES_WPP
const CodingUnit *cuAbove = cs.getCURestricted( pos.offset( 0, -1 ), cs.slice->getIndependentSliceIdx(), cs.picture->tileMap->getTileIdxMap( pos ), CH_L );
#else
const CodingUnit *cuAbove = cs.getCURestricted( pos.offset( 0, -1 ), cs.slice->getIndependentSliceIdx(), CH_L );
#endif
maxImvNumCand = std::max( maxImvNumCand, ( cuAbove ) ? cuAbove->imvNumCand : numDefault );
return maxImvNumCand;
}
#endif
// TU tools
#if HEVC_USE_4x4_DSTVII
bool TU::useDST(const TransformUnit &tu, const ComponentID &compID)
{
return isLuma(compID) && tu.cu->predMode == MODE_INTRA;
}
#endif
bool TU::isNonTransformedResidualRotated(const TransformUnit &tu, const ComponentID &compID)
{
return tu.cs->sps->getSpsRangeExtension().getTransformSkipRotationEnabledFlag() && tu.blocks[compID].width == 4 && tu.cu->predMode == MODE_INTRA;
}
bool TU::getCbf( const TransformUnit &tu, const ComponentID &compID )
{
#if ENABLE_BMS
return getCbfAtDepth( tu, compID, tu.depth );
#else
return tu.cbf[compID];
#endif
}
#if ENABLE_BMS
bool TU::getCbfAtDepth(const TransformUnit &tu, const ComponentID &compID, const unsigned &depth)
{
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);
}
#else
void TU::setCbf( TransformUnit &tu, const ComponentID &compID, const bool &cbf )
{
tu.cbf[compID] = cbf;
}
#endif
bool TU::hasTransformSkipFlag(const CodingStructure& cs, const CompArea& area)
{
uint32_t transformSkipLog2MaxSize = cs.pps->getPpsRangeExtension().getLog2MaxTransformSkipBlockSize();
if( cs.pcv->rectCUs )
{
return ( area.width * area.height <= (1 << ( transformSkipLog2MaxSize << 1 )) );
}
return ( area.width <= (1 << transformSkipLog2MaxSize) );
}
uint32_t TU::getGolombRiceStatisticsIndex(const TransformUnit &tu, const ComponentID &compID)
{
const bool transformSkip = tu.transformSkip[compID];
const bool transquantBypass = tu.cu->transQuantBypass;
//--------
const uint32_t channelTypeOffset = isChroma(compID) ? 2 : 0;
const uint32_t nonTransformedOffset = (transformSkip || transquantBypass) ? 1 : 0;
//--------
const uint32_t selectedIndex = channelTypeOffset + nonTransformedOffset;
CHECK( selectedIndex >= RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS, "Invalid golomb rice adaptation statistics set" );
return selectedIndex;
}
#if HEVC_USE_MDCS
uint32_t TU::getCoefScanIdx(const TransformUnit &tu, const ComponentID &compID)
{
//------------------------------------------------
//this mechanism is available for intra only
if( !CU::isIntra( *tu.cu ) )
{
return SCAN_DIAG;
}
//------------------------------------------------
//check that MDCS can be used for this TU
const CompArea &area = tu.blocks[compID];
const SPS &sps = *tu.cs->sps;
const ChromaFormat format = sps.getChromaFormatIdc();
const uint32_t maximumWidth = MDCS_MAXIMUM_WIDTH >> getComponentScaleX(compID, format);
const uint32_t maximumHeight = MDCS_MAXIMUM_HEIGHT >> getComponentScaleY(compID, format);
if ((area.width > maximumWidth) || (area.height > maximumHeight))
{
return SCAN_DIAG;
}
//------------------------------------------------
//otherwise, select the appropriate mode
const PredictionUnit &pu = *tu.cs->getPU( area.pos(), toChannelType( compID ) );
uint32_t uiDirMode = PU::getFinalIntraMode(pu, toChannelType(compID));
//------------------
if (abs((int) uiDirMode - VER_IDX) <= MDCS_ANGLE_LIMIT)
{
return SCAN_HOR;
}
else if (abs((int) uiDirMode - HOR_IDX) <= MDCS_ANGLE_LIMIT)
{
return SCAN_VER;
}
else
{
return SCAN_DIAG;
}
}
#endif
bool TU::hasCrossCompPredInfo( const TransformUnit &tu, const ComponentID &compID )
{
return ( isChroma(compID) && tu.cs->pps->getPpsRangeExtension().getCrossComponentPredictionEnabledFlag() && TU::getCbf( tu, COMPONENT_Y ) &&
( CU::isInter(*tu.cu) || PU::isChromaIntraModeCrossCheckMode( *tu.cs->getPU( tu.blocks[compID].pos(), toChannelType( compID ) ) ) ) );
}
uint32_t TU::getNumNonZeroCoeffsNonTS( const TransformUnit& tu, const bool bLuma, const bool bChroma )
{
uint32_t count = 0;
for( uint32_t i = 0; i < ::getNumberValidTBlocks( *tu.cs->pcv ); i++ )
{
if( tu.blocks[i].valid() && !tu.transformSkip[i] && TU::getCbf( tu, ComponentID( i ) ) )
{
if( isLuma ( tu.blocks[i].compID ) && !bLuma ) continue;
if( isChroma( tu.blocks[i].compID ) && !bChroma ) continue;
uint32_t area = tu.blocks[i].area();
const TCoeff* coeff = tu.getCoeffs( ComponentID( i ) ).buf;
for( uint32_t j = 0; j < area; j++ )
{
count += coeff[j] != 0;
}
}
}
return count;
}
bool TU::needsSqrt2Scale( const Size& size )
{
return (((g_aucLog2[size.width] + g_aucLog2[size.height]) & 1) == 1);
}
#if HM_QTBT_AS_IN_JEM_QUANT
bool TU::needsBlockSizeTrafoScale( const Size& size )
{
return needsSqrt2Scale( size ) || isNonLog2BlockSize( size );
}
#else
bool TU::needsQP3Offset(const TransformUnit &tu, const ComponentID &compID)
{
if( tu.cs->pcv->rectCUs && !tu.transformSkip[compID] )
{
return ( ( ( g_aucLog2[tu.blocks[compID].width] + g_aucLog2[tu.blocks[compID].height] ) & 1 ) == 1 );
}
return false;
}
#endif
// other tools
uint32_t getCtuAddr( const Position& pos, const PreCalcValues& pcv )
{
return ( pos.x >> pcv.maxCUWidthLog2 ) + ( pos.y >> pcv.maxCUHeightLog2 ) * pcv.widthInCtus;
}