Newer
Older

Karsten Suehring
committed
/* The copyright in this software is being made available under the BSD
* License, included below. This software may be subject to other third party
* and contributor rights, including patent rights, and no such rights are
* granted under this license.
*
* Copyright (c) 2010-2019, ITU/ISO/IEC

Karsten Suehring
committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/** \file UnitPartitioner.h
* \brief Provides a class for partitioning management
*/
#include "UnitPartitioner.h"
#include "CodingStructure.h"
#include "Unit.h"
#include "Slice.h"
#include "UnitTools.h"
#include "Picture.h"
PartLevel::PartLevel()
: split ( CU_DONT_SPLIT )
, parts ( )
, idx ( 0u )
, checkdIfImplicit ( false )
, isImplicit ( false )
, implicitSplit ( CU_DONT_SPLIT )
, firstSubPartSplit ( CU_DONT_SPLIT )
, canQtSplit ( true )
, qgEnable ( true )
, qgChromaEnable ( true )

Karsten Suehring
committed
{
}
PartLevel::PartLevel( const PartSplit _split, const Partitioning& _parts )
: split ( _split )
, parts ( _parts )
, idx ( 0u )
, checkdIfImplicit ( false )
, isImplicit ( false )
, implicitSplit ( CU_DONT_SPLIT )
, firstSubPartSplit ( CU_DONT_SPLIT )
, canQtSplit ( true )
, qgEnable ( true )
, qgChromaEnable ( true )

Karsten Suehring
committed
{
}
PartLevel::PartLevel( const PartSplit _split, Partitioning&& _parts )
: split ( _split )
, parts ( std::forward<Partitioning>( _parts ) )
, idx ( 0u )
, checkdIfImplicit ( false )
, isImplicit ( false )
, implicitSplit ( CU_DONT_SPLIT )
, firstSubPartSplit ( CU_DONT_SPLIT )
, canQtSplit ( true )
, qgEnable ( true )
, qgChromaEnable ( true )

Karsten Suehring
committed
{
}
//////////////////////////////////////////////////////////////////////////
// Partitioner class
//////////////////////////////////////////////////////////////////////////
SplitSeries Partitioner::getSplitSeries() const
{
SplitSeries splitSeries = 0;
SplitSeries depth = 0;
for( const auto &level : m_partStack )
{
if( level.split == CTU_LEVEL ) continue;
else splitSeries += static_cast< SplitSeries >( level.split ) << ( depth * SPLIT_DMULT );
depth++;
}
return splitSeries;
}
ModeTypeSeries Partitioner::getModeTypeSeries() const
{
ModeTypeSeries modeTypeSeries = 0;
int depth = 0;
for( const auto &level : m_partStack )
{
if( level.split == CTU_LEVEL ) continue;
else modeTypeSeries += static_cast<int>(level.modeType) << (depth * 3);
depth++;
}
return modeTypeSeries;
}
bool Partitioner::isSepTree( const CodingStructure &cs )
{
return treeType != TREE_D || CS::isDualITree( cs );
}

Karsten Suehring
committed
void Partitioner::setCUData( CodingUnit& cu )
{
cu.depth = currDepth;
cu.btDepth = currBtDepth;
cu.mtDepth = currMtDepth;
cu.qtDepth = currQtDepth;
cu.splitSeries = getSplitSeries();
cu.modeTypeSeries = getModeTypeSeries();

Karsten Suehring
committed
}
void Partitioner::copyState( const Partitioner& other )
{
m_partStack = other.m_partStack;
currBtDepth = other.currBtDepth;
currQtDepth = other.currQtDepth;
currDepth = other.currDepth;
currMtDepth = other.currMtDepth;
currTrDepth = other.currTrDepth;
currSubdiv = other.currSubdiv;
currQgPos = other.currQgPos;
currQgChromaPos = other.currQgChromaPos;

Karsten Suehring
committed
currImplicitBtDepth
= other.currImplicitBtDepth;
chType = other.chType;
#ifdef _DEBUG
m_currArea = other.m_currArea;
#endif
}
//////////////////////////////////////////////////////////////////////////
// AdaptiveDepthPartitioner class
//////////////////////////////////////////////////////////////////////////
void AdaptiveDepthPartitioner::setMaxMinDepth( unsigned& minDepth, unsigned& maxDepth, const CodingStructure& cs ) const
{
unsigned stdMinDepth = 0;
unsigned stdMaxDepth = ( floorLog2(cs.sps->getCTUSize()) - floorLog2(cs.sps->getMinQTSize( cs.slice->getSliceType(), chType )));

Karsten Suehring
committed
const Position pos = currArea().blocks[chType].pos();
const unsigned curSliceIdx = cs.slice->getIndependentSliceIdx();
const unsigned curTileIdx = cs.picture->brickMap->getBrickIdxRsMap( currArea().lumaPos() );

Karsten Suehring
committed
const CodingUnit* cuLeft = cs.getCURestricted( pos.offset( -1, 0 ), pos, curSliceIdx, curTileIdx, chType );
const CodingUnit* cuBelowLeft = cs.getCURestricted( pos.offset( -1, currArea().blocks[chType].height), pos, curSliceIdx, curTileIdx, chType );
const CodingUnit* cuAbove = cs.getCURestricted( pos.offset( 0, -1 ), pos, curSliceIdx, curTileIdx, chType );
const CodingUnit* cuAboveRight = cs.getCURestricted( pos.offset( currArea().blocks[chType].width, -1 ), pos, curSliceIdx, curTileIdx, chType );

Karsten Suehring
committed
minDepth = stdMaxDepth;
maxDepth = stdMinDepth;
if( cuLeft )
{
minDepth = std::min<unsigned>( minDepth, cuLeft->qtDepth );
maxDepth = std::max<unsigned>( maxDepth, cuLeft->qtDepth );
}
else
{
minDepth = stdMinDepth;
maxDepth = stdMaxDepth;
}
if( cuBelowLeft )
{
minDepth = std::min<unsigned>( minDepth, cuBelowLeft->qtDepth );
maxDepth = std::max<unsigned>( maxDepth, cuBelowLeft->qtDepth );
}
else
{
minDepth = stdMinDepth;
Loading
Loading full blame...