Coverage Report

Created: 2026-12-01 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/vvenc/source/Lib/CommonLib/UnitPartitioner.cpp
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
The copyright in this software is being made available under the Clear BSD
3
License, included below. No patent rights, trademark rights and/or 
4
other Intellectual Property Rights other than the copyrights concerning 
5
the Software are granted under this license.
6
7
The Clear BSD License
8
9
Copyright (c) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors.
10
All rights reserved.
11
12
Redistribution and use in source and binary forms, with or without modification,
13
are permitted (subject to the limitations in the disclaimer below) provided that
14
the following conditions are met:
15
16
     * Redistributions of source code must retain the above copyright notice,
17
     this list of conditions and the following disclaimer.
18
19
     * Redistributions in binary form must reproduce the above copyright
20
     notice, this list of conditions and the following disclaimer in the
21
     documentation and/or other materials provided with the distribution.
22
23
     * Neither the name of the copyright holder nor the names of its
24
     contributors may be used to endorse or promote products derived from this
25
     software without specific prior written permission.
26
27
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
28
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
29
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
36
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
POSSIBILITY OF SUCH DAMAGE.
39
40
41
------------------------------------------------------------------------------------------- */
42
43
44
/** \file     UnitPartitioner.h
45
 *  \brief    Provides a class for partitioning management
46
 */
47
48
#include "UnitPartitioner.h"
49
#include "CodingStructure.h"
50
#include "Unit.h"
51
#include "Slice.h"
52
#include "UnitTools.h"
53
#include "Picture.h"
54
55
//! \ingroup CommonLib
56
//! \{
57
58
namespace vvenc {
59
60
PartLevel::PartLevel()
61
2.37M
: split               ( CU_DONT_SPLIT )
62
, parts               (               )
63
2.37M
, idx                 ( 0u            )
64
2.37M
, checkdIfImplicit    ( false         )
65
2.37M
, isImplicit          ( false         )
66
2.37M
, implicitSplit       ( CU_DONT_SPLIT )
67
2.37M
, firstSubPartSplit   ( CU_DONT_SPLIT )
68
2.37M
, canQtSplit          ( true          )
69
2.37M
, qgEnable            ( true          )
70
2.37M
, qgChromaEnable      ( true          )
71
2.37M
, modeType            ( MODE_TYPE_ALL )
72
2.37M
{
73
2.37M
}
74
75
void PartLevel::init()
76
245k
{
77
245k
  split               = CU_DONT_SPLIT;
78
245k
  idx                 = 0u;
79
245k
  checkdIfImplicit    = false;
80
245k
  isImplicit          = false;
81
245k
  implicitSplit       = CU_DONT_SPLIT;
82
245k
  firstSubPartSplit   = CU_DONT_SPLIT;
83
245k
  canQtSplit          = true;
84
245k
  qgEnable            = true;
85
245k
  qgChromaEnable      = true;
86
245k
  modeType            = MODE_TYPE_ALL;
87
245k
  numParts            = 0;
88
245k
}
89
90
//////////////////////////////////////////////////////////////////////////
91
// Partitioner class
92
//////////////////////////////////////////////////////////////////////////
93
94
SplitSeries Partitioner::getSplitSeries() const
95
158k
{
96
158k
  SplitSeries splitSeries = 0;
97
158k
  SplitSeries depth = 0;
98
99
158k
  for( const auto &level : m_partStack )
100
634k
  {
101
634k
    if( level.split == CTU_LEVEL ) continue;
102
476k
    else splitSeries += static_cast< SplitSeries >( level.split ) << ( depth * SPLIT_DMULT );
103
104
476k
    depth++;
105
476k
  }
106
107
158k
  return splitSeries;
108
158k
}
109
110
ModeTypeSeries Partitioner::getModeTypeSeries() const
111
158k
{
112
158k
  ModeTypeSeries modeTypeSeries = 0;
113
158k
  int depth = 0;
114
115
158k
  for( const auto &level : m_partStack )
116
634k
  {
117
634k
    if( level.split == CTU_LEVEL ) continue;
118
476k
    else modeTypeSeries += static_cast<int>(level.modeType) << (depth * 3);
119
120
476k
    depth++;
121
476k
  }
122
123
158k
  return modeTypeSeries;
124
158k
}
125
126
bool Partitioner::isSepTree( const CodingStructure &cs )
127
874k
{
128
874k
  return treeType != TREE_D || CS::isDualITree( cs );
129
874k
}
130
131
void Partitioner::setCUData( CodingUnit& cu )
132
158k
{
133
158k
  cu.depth       = currDepth;
134
158k
  cu.btDepth     = currBtDepth;
135
158k
  cu.mtDepth     = currMtDepth;
136
158k
  cu.qtDepth     = currQtDepth;
137
158k
  cu.splitSeries = getSplitSeries();
138
158k
  cu.modeTypeSeries = getModeTypeSeries();
139
158k
  cu.treeType    = treeType; 
140
158k
  cu.modeType    = modeType; 
141
142
158k
}
143
144
void Partitioner::copyState( const Partitioner& other )
145
0
{
146
0
  m_partStack = other.m_partStack;
147
0
  currBtDepth = other.currBtDepth;
148
0
  currQtDepth = other.currQtDepth;
149
0
  currDepth   = other.currDepth;
150
0
  currMtDepth = other.currMtDepth;
151
0
  currTrDepth = other.currTrDepth;
152
0
  currSubdiv  = other.currSubdiv;
153
0
  currQgPos   = other.currQgPos;
154
0
  currQgChromaPos = other.currQgChromaPos;
155
0
  currImplicitBtDepth
156
0
              = other.currImplicitBtDepth;
157
0
  chType      = other.chType;
158
0
#ifdef _DEBUG
159
0
  m_currArea  = other.m_currArea;
160
0
#endif
161
0
}
162
163
void Partitioner::setMaxMinDepth( unsigned& minDepth, unsigned& maxDepth, const CodingStructure& cs, int QtbttSpeedUp, bool MergeFlag,
164
                                  const CodingUnit* cuLeft, const CodingUnit* cuAbove ) const
165
156k
{
166
156k
  unsigned          stdMinDepth = 0;
167
156k
  unsigned          stdMaxDepth = cs.pcv->getMaxDepth( cs.slice->sliceType, chType );
168
156k
  const Position    pos         = currArea().blocks[chType].pos();
169
156k
  const unsigned    curSliceIdx = cs.slice->independentSliceIdx;
170
156k
  const unsigned    curTileIdx  = cs.pps->getTileIdx( currArea().lumaPos() );
171
172
156k
  const CodingUnit* cuBelowLeft   = cs.getCURestricted( pos.offset( -1, currArea().blocks[chType].height), pos, curSliceIdx, curTileIdx, chType, treeType );
173
156k
  const CodingUnit* cuAboveRight  = cs.getCURestricted( pos.offset( currArea().blocks[chType].width, -1 ), pos, curSliceIdx, curTileIdx, chType, treeType );
174
175
156k
  minDepth = stdMaxDepth;
176
156k
  maxDepth = stdMinDepth;
177
178
156k
  if( cuLeft )
179
92.9k
  {
180
92.9k
    minDepth = std::min<unsigned>( minDepth, cuLeft->qtDepth );
181
92.9k
    maxDepth = std::max<unsigned>( maxDepth, cuLeft->qtDepth );
182
92.9k
  }
183
63.3k
  else
184
63.3k
  {
185
63.3k
    minDepth = stdMinDepth;
186
63.3k
    maxDepth = stdMaxDepth;
187
63.3k
  }
188
189
156k
  if( cuBelowLeft )
190
14.2k
  {
191
14.2k
    minDepth = std::min<unsigned>( minDepth, cuBelowLeft->qtDepth );
192
14.2k
    maxDepth = std::max<unsigned>( maxDepth, cuBelowLeft->qtDepth );
193
14.2k
  }
194
142k
  else
195
142k
  {
196
142k
    minDepth = stdMinDepth;
197
142k
    maxDepth = stdMaxDepth;
198
142k
  }
199
200
156k
  if( cuAbove )
201
96.0k
  {
202
96.0k
    minDepth = std::min<unsigned>( minDepth, cuAbove->qtDepth );
203
96.0k
    maxDepth = std::max<unsigned>( maxDepth, cuAbove->qtDepth );
204
96.0k
  }
205
60.3k
  else
206
60.3k
  {
207
60.3k
    minDepth = stdMinDepth;
208
60.3k
    maxDepth = stdMaxDepth;
209
60.3k
  }
210
211
156k
  if( cuAboveRight )
212
34.2k
  {
213
34.2k
    minDepth = std::min<unsigned>( minDepth, cuAboveRight->qtDepth );
214
34.2k
    maxDepth = std::max<unsigned>( maxDepth, cuAboveRight->qtDepth );
215
34.2k
  }
216
122k
  else
217
122k
  {
218
122k
    minDepth = stdMinDepth;
219
122k
    maxDepth = stdMaxDepth;
220
122k
  }
221
222
156k
  minDepth = ( minDepth >= 1 ? minDepth - 1 : 0 );
223
156k
  maxDepth = std::min<unsigned>( stdMaxDepth, maxDepth + 1 );
224
156k
  if((QtbttSpeedUp >> 2) && (cs.slice->TLayer > 0) && ((cs.area.Y().width >= 8) || (cs.area.Y().height >= 8)))
225
0
  {
226
0
    int minDepthCur = stdMaxDepth;
227
0
    int maxDepthCur = stdMinDepth;
228
0
    int amountN = 0;
229
0
    for (int n = 0; n < 3; n++)
230
0
    {
231
0
      const CodingUnit* cuNeigh = (n==0)?cs.getCURestricted(pos.offset(-1, -1), pos, curSliceIdx, curTileIdx, chType, treeType): (n==1)? cuAbove : cuLeft;
232
0
      if (cuNeigh)
233
0
      {
234
0
        amountN++;
235
0
        minDepthCur = std::min<unsigned>(minDepthCur, cuNeigh->qtDepth);
236
0
        maxDepthCur = std::max<unsigned>(maxDepthCur, cuNeigh->qtDepth);
237
0
      }
238
0
    }
239
0
    if (amountN)
240
0
    {
241
0
      minDepthCur = (minDepthCur >= 1 ? minDepthCur - 1 : 0);
242
0
      maxDepthCur = std::min<unsigned>(stdMaxDepth, maxDepthCur + 1);
243
0
      maxDepth = std::min<unsigned>(maxDepthCur, maxDepth);
244
0
      minDepth = std::max<unsigned>(minDepthCur, minDepth);
245
0
    }
246
0
  }
247
248
156k
  if (!cs.slice->isIntra() && (QtbttSpeedUp & 3))
249
0
  {
250
0
    bool doMin_SCC = !(((QtbttSpeedUp & 3) == 2) && (cs.area.Y().width < cs.pcv->maxCUSize));
251
0
    bool LimitDepths = (QtbttSpeedUp & 2) ? (MergeFlag == 0) : (cs.area.Y().width >= cs.pcv->maxCUSize);
252
0
    if (LimitDepths && cuAbove && cuLeft && (cuLeft->qtDepth == cuAbove->qtDepth))
253
0
    {
254
0
      int minDepthCur = cuAbove->qtDepth;
255
0
      int maxDepthCur = cuAbove->qtDepth;
256
0
      minDepthCur = (minDepthCur > 0) ? (minDepthCur - 1) : 0;
257
0
      maxDepthCur = (maxDepthCur < stdMaxDepth) ? (maxDepthCur + 1) : maxDepthCur;
258
0
      maxDepth = std::min<unsigned>(maxDepthCur, maxDepth);
259
0
      minDepth = std::max<unsigned>(minDepthCur, minDepth);
260
0
    }
261
0
    else if (doMin_SCC && LimitDepths && cuAbove && cuLeft)
262
0
    {
263
0
      int minDepthCur = cuAbove->qtDepth;
264
0
      int maxDepthCur = cuAbove->qtDepth;
265
0
      minDepthCur = (minDepthCur > 0) ? (minDepthCur - 1) : 0;
266
0
      maxDepthCur = (maxDepthCur < stdMaxDepth) ? (maxDepthCur + 1) : maxDepthCur;
267
0
      if ((cuLeft->qtDepth > maxDepthCur) && ((cuLeft->qtDepth - 1) >= maxDepthCur))
268
0
      {
269
0
        minDepthCur += 1;
270
0
        maxDepthCur += 1;
271
0
      }
272
0
      else if ((cuLeft->qtDepth < minDepthCur) && ((cuLeft->qtDepth + 1) <= minDepthCur))
273
0
      {
274
0
        maxDepthCur -= 1;
275
0
        minDepthCur -= 1;
276
0
      }
277
0
      maxDepth = std::min<unsigned>(maxDepthCur, maxDepth);
278
0
      minDepth = std::max<unsigned>(minDepthCur, minDepth);
279
0
    }
280
0
    if ((QtbttSpeedUp & 2) && MergeFlag && (maxDepth == 4) && (cs.area.Y().width <= 16))
281
0
    {
282
0
      maxDepth = 3;
283
0
      minDepth = (minDepth == 3)? 2: minDepth;
284
0
    }
285
0
  }
286
156k
}
287
288
void Partitioner::initCtu( const UnitArea& ctuArea, const ChannelType _chType, const Slice& slice )
289
27.9k
{
290
27.9k
#if _DEBUG
291
27.9k
  m_currArea = ctuArea;
292
27.9k
#endif
293
27.9k
  currDepth   = 0;
294
27.9k
  currTrDepth = 0;
295
27.9k
  currBtDepth = 0;
296
27.9k
  currMtDepth = 0;
297
27.9k
  currQtDepth = 0;
298
27.9k
  currSubdiv  = 0;
299
27.9k
  currQgPos   = ctuArea.lumaPos();
300
27.9k
  currQgChromaPos = ctuArea.chromaFormat != CHROMA_400 ? ctuArea.chromaPos() : Position();
301
27.9k
  currImplicitBtDepth = 0;
302
27.9k
  chType      = _chType;
303
304
27.9k
  const PreCalcValues& pcv = *slice.pps->pcv;
305
  
306
27.9k
  maxBTD      = pcv.getMaxMTTDepth( slice, chType );
307
27.9k
  maxBtSize   = pcv.getMaxBtSize  ( slice, chType );
308
27.9k
  minTSize    = pcv.getMinTSize   ( slice, chType );
309
27.9k
  maxTtSize   = pcv.getMaxTtSize  ( slice, chType );
310
27.9k
  minQtSize   = pcv.getMinQtSize  ( slice, chType );
311
  
312
27.9k
  m_partBufIdx = 1;
313
27.9k
  m_partStack.resize_noinit( 1 );
314
27.9k
  m_partStack.back().init();
315
27.9k
  m_partStack.back().split = CTU_LEVEL;
316
27.9k
  m_partStack.back().parts = m_partBuf;
317
27.9k
  m_partStack.back().parts[0] = ctuArea;
318
27.9k
  m_partStack.back().numParts = 1;
319
320
27.9k
  treeType = TREE_D;
321
27.9k
  modeType = MODE_TYPE_ALL;
322
27.9k
}
323
324
void Partitioner::splitCurrArea( const PartSplit split, const CodingStructure& cs )
325
217k
{
326
217k
  if ((split != TU_1D_HORZ_SPLIT) && (split != TU_1D_VERT_SPLIT))
327
192k
  {
328
192k
    CHECKD(!canSplit(split, cs), "Trying to apply a prohibited split!");
329
192k
  }
330
331
  // only a BT or TT split keeps these
332
217k
  const bool isMtSplit = split == CU_HORZ_SPLIT || split == CU_VERT_SPLIT || split == CU_TRIH_SPLIT || split == CU_TRIV_SPLIT;
333
217k
  bool isImplicit = isMtSplit && isSplitImplicit( split, cs );
334
217k
  bool canQtSplit = isMtSplit && canSplit( CU_QUAD_SPLIT, cs );
335
217k
  bool qgEnable = currQgEnable();
336
217k
  bool qgChromaEnable = currQgChromaEnable();
337
338
217k
  const UnitArea& area = currArea();
339
217k
  m_partStack.resize_noinit( m_partStack.size() + 1 );
340
217k
  PartLevel& back = m_partStack.back();
341
217k
  back.init();
342
217k
  back.split = split;
343
217k
  back.parts = &m_partBuf[m_partBufIdx];
344
217k
  int numParts;
345
346
217k
  CHECK( m_partBufIdx > partBufSize, "Partition buffer overflow" );
347
348
217k
  switch( split )
349
217k
  {
350
63.6k
  case CU_QUAD_SPLIT:
351
63.6k
    numParts = PartitionerImpl::getCUSubPartitions( back.parts, area, cs, split );
352
63.6k
    back.modeType = modeType;
353
63.6k
    break;
354
63.7k
  case CU_HORZ_SPLIT:
355
128k
  case CU_VERT_SPLIT:
356
128k
    numParts = PartitionerImpl::getCUSubPartitions( back.parts, area, cs, split );
357
128k
    back.modeType = modeType;
358
128k
    break;
359
351
  case CU_TRIH_SPLIT:
360
402
  case CU_TRIV_SPLIT:
361
402
    numParts = PartitionerImpl::getCUSubPartitions( back.parts, area, cs, split );
362
402
    back.modeType = modeType;
363
402
    break;
364
0
  case TU_MAX_TR_SPLIT:
365
0
    numParts = PartitionerImpl::getMaxTuTiling( back.parts, area, cs );
366
0
    break;
367
0
  case SBT_VER_HALF_POS0_SPLIT:
368
0
  case SBT_VER_HALF_POS1_SPLIT:
369
0
  case SBT_HOR_HALF_POS0_SPLIT:
370
0
  case SBT_HOR_HALF_POS1_SPLIT:
371
0
  case SBT_VER_QUAD_POS0_SPLIT:
372
0
  case SBT_VER_QUAD_POS1_SPLIT:
373
0
  case SBT_HOR_QUAD_POS0_SPLIT:
374
0
  case SBT_HOR_QUAD_POS1_SPLIT:
375
0
    numParts = PartitionerImpl::getSbtTuTiling( back.parts, area, cs, split );
376
0
    break;
377
11.5k
  case TU_1D_HORZ_SPLIT:
378
24.3k
  case TU_1D_VERT_SPLIT:
379
24.3k
  {
380
24.3k
    numParts = PartitionerImpl::getTUIntraSubPartitions(back.parts, area, cs, split, TREE_D);
381
24.3k
    break;
382
11.5k
  }
383
0
  default:
384
0
    THROW( "Unknown split mode" );
385
0
    break;
386
217k
  }
387
388
217k
  back.numParts = numParts;
389
217k
  m_partBufIdx += numParts;
390
391
217k
  CHECK( m_partBufIdx > partBufSize, "Partition buffer overflow" );
392
393
217k
  currDepth++;
394
217k
  currSubdiv++;
395
217k
#if _DEBUG
396
217k
  m_currArea = m_partStack.back().parts[0];
397
217k
#endif
398
399
217k
  if ((split == TU_MAX_TR_SPLIT) || (split == TU_1D_HORZ_SPLIT) || (split == TU_1D_VERT_SPLIT))
400
24.3k
  {
401
24.3k
    currTrDepth++;
402
24.3k
  }
403
192k
  else if( split >= SBT_VER_HALF_POS0_SPLIT && split <= SBT_HOR_QUAD_POS1_SPLIT )
404
0
  {
405
0
    currTrDepth++;
406
0
  }
407
192k
  else
408
192k
  {
409
192k
    currTrDepth = 0;
410
192k
  }
411
412
217k
  if( split == CU_HORZ_SPLIT || split == CU_VERT_SPLIT || split == CU_TRIH_SPLIT || split == CU_TRIV_SPLIT )
413
129k
  {
414
129k
    currBtDepth++;
415
129k
    if( isImplicit ) currImplicitBtDepth++;
416
129k
    currMtDepth++;
417
418
129k
    if( split == CU_TRIH_SPLIT || split == CU_TRIV_SPLIT )
419
402
    {
420
      // first and last part of triple split are equivalent to double bt split
421
402
      currBtDepth++;
422
402
      currSubdiv++;
423
402
    }
424
129k
    m_partStack.back().canQtSplit = canQtSplit;
425
129k
  }
426
87.9k
  else if( split == CU_QUAD_SPLIT )
427
63.6k
  {
428
63.6k
    CHECK( currBtDepth > 0, "Cannot split a non-square area other than with a binary split" );
429
63.6k
    CHECK( currMtDepth > 0, "Cannot split a non-square area other than with a binary split" );
430
63.6k
    currMtDepth = 0;
431
63.6k
    currBtDepth = 0;
432
63.6k
    currQtDepth++;
433
63.6k
    currSubdiv++;
434
63.6k
  }
435
436
217k
  qgEnable       &= (currSubdiv <= (cs.slice->isIntra() ? cs.slice->picHeader->cuQpDeltaSubdivIntra : cs.slice->picHeader->cuQpDeltaSubdivInter ));
437
217k
  qgChromaEnable &= (currSubdiv <= (cs.slice->isIntra() ? cs.slice->picHeader->cuChromaQpOffsetSubdivIntra : cs.slice->picHeader->cuChromaQpOffsetSubdivInter ));
438
217k
  m_partStack.back().qgEnable       = qgEnable;
439
217k
  m_partStack.back().qgChromaEnable = qgChromaEnable;
440
217k
  if (qgEnable)
441
9.40k
    currQgPos = currArea().lumaPos();
442
217k
  if (qgChromaEnable)
443
0
    currQgChromaPos = currArea().chromaPos();
444
217k
}
445
446
void Partitioner::canSplit( const CodingStructure &cs, bool& canNo, bool& canQt, bool& canBh, bool& canBv, bool& canTh, bool& canTv )
447
2.33M
{
448
2.33M
  const PartSplit implicitSplit = m_partStack.back().checkdIfImplicit ? m_partStack.back().implicitSplit : getImplicitSplit( cs );
449
450
2.33M
  canNo = canQt = canBh = canTh = canBv = canTv = true;
451
2.33M
  bool canBtt = currMtDepth < (maxBTD + currImplicitBtDepth);
452
453
  // the minimal and maximal sizes are given in luma samples
454
2.33M
  const CompArea&  area  = currArea().Y();
455
2.33M
  const CompArea  *areaC = (chType == CH_C) ? &(currArea().Cb()) : nullptr;
456
2.33M
        PartLevel& level = m_partStack.back();
457
458
2.33M
  const PartSplit lastSplit = level.split;
459
2.33M
  const PartSplit parlSplit = lastSplit == CU_TRIH_SPLIT ? CU_HORZ_SPLIT : CU_VERT_SPLIT;
460
461
  // don't allow QT-splitting below a BT split
462
2.33M
  if( lastSplit != CTU_LEVEL && lastSplit != CU_QUAD_SPLIT ) canQt = false;
463
  // minQtSize is in luma samples unit
464
2.33M
  const unsigned minQTThreshold = minQtSize >> ((area.chromaFormat == CHROMA_400) ? 0 : ((int) getChannelTypeScaleX(CH_C, area.chromaFormat) - (int) getChannelTypeScaleY(CH_C, area.chromaFormat)));
465
2.33M
  if( area.width <= minQTThreshold )                         canQt = false;
466
2.33M
  if( areaC && areaC->width <= MIN_DUALTREE_CHROMA_WIDTH ) canQt = false;
467
2.33M
  if( treeType == TREE_C )
468
0
  {
469
0
    canQt = canBh = canTh = canBv = canTv = false;
470
0
    return;
471
0
  }
472
2.33M
  if( implicitSplit != CU_DONT_SPLIT )
473
968k
  {
474
968k
    canNo = canTh = canTv = false;
475
476
968k
    canBh = implicitSplit == CU_HORZ_SPLIT;
477
968k
    canBv = implicitSplit == CU_VERT_SPLIT;
478
968k
    if (areaC && areaC->width == 4) canBv = false;
479
968k
    if( !canBh && !canBv && !canQt ) canQt = true;
480
968k
    return;
481
968k
  }
482
483
1.36M
  if( ( lastSplit == CU_TRIH_SPLIT || lastSplit == CU_TRIV_SPLIT ) && currPartIdx() == 1 )
484
3.70k
  {
485
3.70k
    canBh = parlSplit != CU_HORZ_SPLIT;
486
3.70k
    canBv = parlSplit != CU_VERT_SPLIT;
487
3.70k
  }
488
489
1.36M
  if( canBtt && ( area.width <= minTSize && area.height <= minTSize ) )
490
0
  {
491
0
    canBtt = false;
492
0
  }
493
1.36M
  if( canBtt && ( area.width > maxBtSize || area.height > maxBtSize )
494
83.5k
      && ( ( area.width > maxTtSize || area.height > maxTtSize ) ) )
495
83.5k
  {
496
83.5k
    canBtt = false;
497
83.5k
  }
498
499
1.36M
  if( !canBtt )
500
298k
  {
501
298k
    canBh = canTh = canBv = canTv = false;
502
503
298k
    return;
504
298k
  }
505
506
1.06M
  if( area.width > maxBtSize || area.height > maxBtSize )
507
0
  {
508
0
    canBh = canBv = false;
509
0
  }
510
511
  // specific check for BT splits
512
1.06M
  if( area.height <= minTSize )                            canBh = false;
513
1.06M
  if( area.width > MAX_TB_SIZEY && area.height <= MAX_TB_SIZEY ) canBh = false;
514
1.06M
  if( areaC && areaC->width * areaC->height <= MIN_DUALTREE_CHROMA_SIZE )     canBh = false;
515
1.06M
  if( area.width <= minTSize )                              canBv = false;
516
1.06M
  if( area.width <= MAX_TB_SIZEY && area.height > MAX_TB_SIZEY ) canBv = false;
517
1.06M
  if (areaC && (areaC->width * areaC->height <= MIN_DUALTREE_CHROMA_SIZE || areaC->width == 4))     canBv = false;
518
1.06M
  if( modeType == MODE_TYPE_INTER && area.width * area.height == 32 )  canBv = canBh = false;
519
1.06M
  if( area.height <= 2 * minTSize || area.height > maxTtSize || area.width > maxTtSize )
520
450k
                                                                                       canTh = false;
521
1.06M
  if( area.width > MAX_TB_SIZEY || area.height > MAX_TB_SIZEY )  canTh = false;
522
1.06M
  if( areaC && areaC->width * areaC->height <= MIN_DUALTREE_CHROMA_SIZE*2 )     canTh = false;
523
1.06M
  if( area.width <= 2 * minTSize || area.width > maxTtSize || area.height > maxTtSize )
524
442k
                                                                                       canTv = false;
525
1.06M
  if( area.width > MAX_TB_SIZEY || area.height > MAX_TB_SIZEY )  canTv = false;
526
1.06M
  if (areaC && (areaC->width * areaC->height <= MIN_DUALTREE_CHROMA_SIZE * 2 || areaC->width == 8))     canTv = false;
527
1.06M
  if( modeType == MODE_TYPE_INTER && area.width * area.height == 64 )  canTv = canTh = false;
528
1.06M
}
529
530
bool Partitioner::canSplit( const PartSplit split, const CodingStructure &cs )
531
2.11M
{
532
  // the TU splits read none of the CU splits' flags
533
2.11M
  if( split == TU_MAX_TR_SPLIT )
534
315k
  {
535
315k
    const CompArea& area      = currArea().Y();
536
315k
    const unsigned  maxTrSize = cs.sps->getMaxTbSize();
537
315k
    return area.width > maxTrSize || area.height > maxTrSize;
538
315k
  }
539
1.79M
  if( split >= SBT_VER_HALF_POS0_SPLIT && split <= SBT_HOR_QUAD_POS1_SPLIT )
540
0
  {
541
0
    return currTrDepth == 0;
542
0
  }
543
544
1.79M
  bool canNo, canQt, canBh, canTh, canBv, canTv;
545
546
1.79M
  canSplit( cs, canNo, canQt, canBh, canBv, canTh, canTv );
547
548
1.79M
  switch( split )
549
1.79M
  {
550
0
  case CTU_LEVEL:
551
0
    THROW( "Checking if top level split is possible" );
552
0
    return true;
553
0
    break;
554
379k
  case CU_QUAD_SPLIT:
555
379k
    return canQt;
556
95.2k
  case CU_DONT_SPLIT:
557
95.2k
    return canNo;
558
475k
  case CU_HORZ_SPLIT:
559
475k
    return canBh;
560
473k
  case CU_VERT_SPLIT:
561
473k
    return canBv;
562
190k
  case CU_TRIH_SPLIT:
563
190k
    return canTh;
564
183k
  case CU_TRIV_SPLIT:
565
183k
    return canTv;
566
0
  case CU_MT_SPLIT:
567
0
    return ( canBh || canTh || canBv || canTv );
568
0
  case CU_BT_SPLIT:
569
0
    return ( canBh || canBv );
570
0
  break;
571
0
  default:
572
0
    THROW( "Unknown split mode" );
573
0
    return false;
574
0
    break;
575
1.79M
  }
576
577
0
  return true;
578
1.79M
}
579
580
bool Partitioner::canSplitISP(const PartSplit split, const CodingStructure& cs, CodingUnit& cu)
581
0
{
582
  // const PartSplit implicitSplit = getImplicitSplit(cs);
583
0
  const UnitArea& area = currArea();
584
585
0
  switch (split)
586
0
  {
587
0
  case TU_1D_HORZ_SPLIT:
588
0
  {
589
0
    return area.lheight() == cu.lheight();
590
0
  }
591
0
  case TU_1D_VERT_SPLIT:
592
0
  {
593
0
    return area.lwidth() == cu.lwidth();
594
0
  }
595
0
  case TU_MAX_TR_SPLIT:
596
0
  {
597
    // this split is performed implicitly with the other splits
598
0
    return false;
599
0
  }
600
0
  default: THROW("Unknown 1-D split mode"); break;
601
0
  }
602
0
}
603
604
bool Partitioner::isSplitImplicit( const PartSplit split, const CodingStructure &cs )
605
129k
{
606
129k
  return split == getImplicitSplit( cs );
607
129k
}
608
609
PartSplit Partitioner::getImplicitSplit( const CodingStructure &cs )
610
1.02M
{
611
1.02M
  if( m_partStack.back().checkdIfImplicit )
612
664k
  {
613
664k
    return m_partStack.back().implicitSplit;
614
664k
  }
615
616
363k
  PartSplit split = CU_DONT_SPLIT;
617
618
363k
  if( split == CU_DONT_SPLIT )
619
363k
  {
620
363k
    const bool isBlInPic = cs.picture->Y().contains( currArea().Y().bottomLeft() );
621
363k
    const bool isTrInPic = cs.picture->Y().contains( currArea().Y().topRight() );
622
623
363k
    const CompArea& area      = currArea().Y();
624
363k
    const bool isBtAllowed    = area.width <= maxBtSize && area.height <= maxBtSize && currMtDepth < (maxBTD + currImplicitBtDepth);
625
    // minQtSize is in luma samples unit
626
363k
    const unsigned minQTThreshold = minQtSize >> ((area.chromaFormat == CHROMA_400) ? 0 : ((int) getChannelTypeScaleX(CH_C, area.chromaFormat) - (int) getChannelTypeScaleY(CH_C, area.chromaFormat)));
627
363k
    const bool isQtAllowed    = area.width > minQTThreshold && currBtDepth == 0;
628
629
363k
    if( !isBlInPic && !isTrInPic && isQtAllowed )
630
24.8k
    {
631
24.8k
      split = CU_QUAD_SPLIT;
632
24.8k
    }
633
338k
    else if( !isBlInPic && isBtAllowed && area.width <= MAX_TB_SIZEY )
634
53.0k
    {
635
53.0k
      split = CU_HORZ_SPLIT;
636
53.0k
    }
637
285k
    else if( !isTrInPic && isBtAllowed && area.height <= MAX_TB_SIZEY )
638
55.7k
    {
639
55.7k
      split = CU_VERT_SPLIT;
640
55.7k
    }
641
229k
    else if( !isBlInPic || !isTrInPic )
642
29.2k
    {
643
29.2k
      split = CU_QUAD_SPLIT;
644
29.2k
    }
645
363k
    if (CS::isDualITree(cs) && (currArea().Y().width > 64 || currArea().Y().height > 64))
646
27.9k
    {
647
27.9k
      split = CU_QUAD_SPLIT;
648
27.9k
    }
649
363k
    if( (!isBlInPic || !isTrInPic) && split == CU_DONT_SPLIT )
650
0
    {
651
0
      split = CU_QUAD_SPLIT;
652
0
    }
653
363k
  }
654
655
363k
  m_partStack.back().checkdIfImplicit = true;
656
363k
  m_partStack.back().isImplicit = split != CU_DONT_SPLIT;
657
363k
  m_partStack.back().implicitSplit = split;
658
659
363k
  return split;
660
1.02M
}
661
662
void Partitioner::exitCurrSplit()
663
217k
{
664
217k
  const PartSplit currSplit = m_partStack.back().split;
665
217k
  const int       currIndex = m_partStack.back().idx;
666
217k
  const int       numParts  = m_partStack.back().numParts;
667
668
217k
  m_partStack.pop_back();
669
217k
  m_partBufIdx -= numParts;
670
671
217k
  CHECK( currDepth == 0, "depth is '0', although a split was performed" );
672
217k
  currDepth--;
673
217k
  currSubdiv--;
674
217k
  if( currQgEnable() )
675
45.2k
    currQgPos = currArea().lumaPos();
676
217k
  if( currArea().chromaFormat != CHROMA_400 && currQgChromaEnable() )
677
27.9k
    currQgChromaPos = currArea().chromaPos();
678
217k
#if _DEBUG
679
217k
  m_currArea = m_partStack.back().parts[m_partStack.back().idx];
680
217k
#endif
681
682
217k
  if( currSplit == CU_HORZ_SPLIT || currSplit == CU_VERT_SPLIT || currSplit == CU_TRIH_SPLIT || currSplit == CU_TRIV_SPLIT )
683
129k
  {
684
129k
    CHECK( !m_partStack.back().checkdIfImplicit, "Didn't check if the current split is implicit" );
685
129k
    CHECK( currBtDepth == 0, "BT depth is '0', athough a BT split was performed" );
686
129k
    CHECK( currMtDepth == 0, "MT depth is '0', athough a BT split was performed" );
687
129k
    currMtDepth--;
688
129k
    if( m_partStack.back().isImplicit ) currImplicitBtDepth--;
689
129k
    currBtDepth--;
690
129k
    if( ( currSplit == CU_TRIH_SPLIT || currSplit == CU_TRIV_SPLIT ) && currIndex != 1 )
691
402
    {
692
402
      CHECK( currBtDepth == 0, "BT depth is '0', athough a TT split was performed" );
693
402
      currBtDepth--;
694
402
      currSubdiv--;
695
402
    }
696
129k
  }
697
87.9k
  else if( currSplit == TU_MAX_TR_SPLIT )
698
0
  {
699
0
    CHECK( currTrDepth == 0, "TR depth is '0', although a TU split was performed" );
700
0
    currTrDepth--;
701
0
  }
702
87.9k
  else if( currSplit >= SBT_VER_HALF_POS0_SPLIT && currSplit <= SBT_HOR_QUAD_POS1_SPLIT )
703
0
  {
704
0
    CHECK( currTrDepth == 0, "TR depth is '0', although a TU split was performed" );
705
0
    currTrDepth--;
706
0
  }
707
87.9k
  else if ((currSplit == TU_1D_HORZ_SPLIT) || (currSplit == TU_1D_VERT_SPLIT))
708
24.3k
  {
709
24.3k
    CHECK(currTrDepth == 0, "TR depth is '0', although a TU split was performed");
710
24.3k
    currTrDepth--;
711
24.3k
  }
712
63.6k
  else
713
63.6k
  {
714
63.6k
    CHECK( currTrDepth > 0, "RQT found with QTBT partitioner" );
715
716
63.6k
    CHECK( currQtDepth == 0, "QT depth is '0', although a QT split was performed" );
717
63.6k
    currQtDepth--;
718
63.6k
    currSubdiv--;
719
63.6k
  }
720
217k
}
721
722
bool Partitioner::nextPart( const CodingStructure &cs, bool autoPop /*= false*/ )
723
543k
{
724
543k
  const Position& prevPos = currArea().blocks[chType].pos();
725
726
543k
  unsigned currIdx = ++m_partStack.back().idx;
727
728
543k
  m_partStack.back().checkdIfImplicit = false;
729
543k
  m_partStack.back().isImplicit = false;
730
731
543k
  if( currIdx == 1 )
732
200k
  {
733
200k
    const CodingUnit* prevCU = cs.getCU( prevPos, chType, treeType );
734
200k
    m_partStack.back().firstSubPartSplit = prevCU ? CU::getSplitAtDepth( *prevCU, currDepth ) : CU_DONT_SPLIT;
735
200k
  }
736
737
543k
  if( currIdx < m_partStack.back().numParts )
738
343k
  {
739
343k
    if( m_partStack.back().split == CU_TRIH_SPLIT || m_partStack.back().split == CU_TRIV_SPLIT )
740
804
    {
741
      // adapt the current bt depth
742
804
      if( currIdx == 1 ) currBtDepth--;
743
402
      else               currBtDepth++;
744
804
      if( currIdx == 1 ) currSubdiv--;
745
402
      else               currSubdiv++;
746
804
    }
747
343k
  if( currQgEnable() )
748
28.2k
    currQgPos = currArea().lumaPos();
749
343k
  if( currQgChromaEnable() )
750
0
    currQgChromaPos = currArea().chromaPos();
751
343k
#if _DEBUG
752
343k
    m_currArea = m_partStack.back().parts[currIdx];
753
343k
#endif
754
343k
    return true;
755
343k
  }
756
200k
  else
757
200k
  {
758
200k
    if( autoPop ) exitCurrSplit();
759
200k
    return false;
760
200k
  }
761
543k
}
762
763
bool Partitioner::hasNextPart()
764
147k
{
765
147k
  return ( ( m_partStack.back().idx + 1 ) < m_partStack.back().numParts );
766
147k
}
767
768
//////////////////////////////////////////////////////////////////////////
769
// Partitioner methods describing the actual partitioning logic
770
//////////////////////////////////////////////////////////////////////////
771
772
int PartitionerImpl::getCUSubPartitions( Partitioning& dst, const UnitArea &cuArea, const CodingStructure &cs, const PartSplit _splitType )
773
192k
{
774
192k
  const PartSplit splitType = _splitType;
775
776
192k
  if( splitType == CU_QUAD_SPLIT )
777
63.6k
  {
778
63.6k
    Partitioning& sub = dst;
779
780
318k
    for( uint32_t i = 0; i < 4; i++ )
781
254k
    {
782
254k
      sub[i] = cuArea;
783
784
254k
      for( auto &blk : sub[i].blocks )
785
764k
      {
786
764k
        blk.height >>= 1;
787
764k
        blk.width  >>= 1;
788
764k
        if( i >= 2 ) blk.y += blk.height;
789
764k
        if( i &  1 ) blk.x += blk.width;
790
764k
      }
791
254k
    }
792
793
63.6k
    return 4;
794
63.6k
  }
795
129k
  else if( splitType == CU_HORZ_SPLIT )
796
63.7k
  {
797
63.7k
    Partitioning& sub = dst;
798
799
191k
    for (uint32_t i = 0; i < 2; i++)
800
127k
    {
801
127k
      sub[i] = cuArea;
802
803
127k
      for (auto &blk : sub[i].blocks)
804
382k
      {
805
382k
        blk.height >>= 1;
806
382k
        if (i == 1) blk.y += blk.height;
807
382k
      }
808
127k
    }
809
810
63.7k
    return 2;
811
63.7k
  }
812
65.4k
  else if( splitType == CU_VERT_SPLIT )
813
65.0k
  {
814
65.0k
    Partitioning& sub = dst;
815
816
195k
    for( uint32_t i = 0; i < 2; i++ )
817
130k
    {
818
130k
      sub[i] = cuArea;
819
820
130k
      for( auto &blk : sub[i].blocks )
821
390k
      {
822
390k
        blk.width >>= 1;
823
390k
        if( i == 1 ) blk.x += blk.width;
824
390k
      }
825
130k
    }
826
827
65.0k
    return 2;
828
65.0k
  }
829
402
  else if( splitType == CU_TRIH_SPLIT )
830
351
  {
831
351
    Partitioning& sub = dst;
832
833
1.40k
    for( int i = 0; i < 3; i++ )
834
1.05k
    {
835
1.05k
      sub[i] = cuArea;
836
837
1.05k
      for( auto &blk : sub[i].blocks )
838
3.15k
      {
839
3.15k
        blk.height >>= 1;
840
3.15k
        if( ( i + 1 ) & 1 ) blk.height >>= 1;
841
3.15k
        if( i == 1 )        blk.y       +=     blk.height / 2;
842
3.15k
        if( i == 2 )        blk.y       += 3 * blk.height;
843
3.15k
      }
844
1.05k
    }
845
846
351
    return 3;
847
351
  }
848
51
  else if( splitType == CU_TRIV_SPLIT )
849
51
  {
850
51
    Partitioning& sub = dst;
851
852
204
    for( int i = 0; i < 3; i++ )
853
153
    {
854
153
      sub[i] = cuArea;
855
856
153
      for( auto &blk : sub[i].blocks )
857
459
      {
858
459
        blk.width >>= 1;
859
860
459
        if( ( i + 1 ) & 1 ) blk.width >>= 1;
861
459
        if( i == 1 )        blk.x      +=     blk.width / 2;
862
459
        if( i == 2 )        blk.x      += 3 * blk.width;
863
459
      }
864
153
    }
865
866
51
    return 3;
867
51
  }
868
0
  else
869
0
  {
870
0
    THROW( "Unknown CU sub-partitioning" );
871
0
  }
872
192k
}
873
874
int PartitionerImpl::getTUIntraSubPartitions( Partitioning& sub, const UnitArea &tuArea, const CodingStructure &cs, const PartSplit splitType, const TreeType treeType )
875
24.3k
{
876
24.3k
  uint32_t nPartitions;
877
24.3k
  uint32_t splitDimensionSize = CU::getISPSplitDim( tuArea.lumaSize().width, tuArea.lumaSize().height, splitType );
878
879
24.3k
  bool isDualTree = CS::isDualITree( cs ) || treeType != TREE_D;
880
881
24.3k
  if( splitType == TU_1D_HORZ_SPLIT )
882
11.5k
  {
883
11.5k
    nPartitions = tuArea.lumaSize().height >> Log2(splitDimensionSize);
884
885
57.9k
    for( uint32_t i = 0; i < nPartitions; i++ )
886
46.3k
    {
887
46.3k
      sub[i] = tuArea;
888
46.3k
      CompArea& blkY = sub[i].blocks[COMP_Y];
889
890
46.3k
      blkY.height = splitDimensionSize;
891
46.3k
      blkY.y = i > 0 ? sub[i - 1].blocks[COMP_Y].y + splitDimensionSize : blkY.y;
892
893
46.3k
      CHECK( sub[i].lumaSize().height < 1, "the cs split causes the block to be smaller than the minimal TU size" );
894
46.3k
    }
895
11.5k
  }
896
12.7k
  else if( splitType == TU_1D_VERT_SPLIT )
897
12.7k
  {
898
12.7k
    nPartitions = tuArea.lumaSize().width >> Log2(splitDimensionSize);
899
900
63.6k
    for( uint32_t i = 0; i < nPartitions; i++ )
901
50.8k
    {
902
50.8k
      sub[i] = tuArea;
903
50.8k
      CompArea& blkY = sub[i].blocks[COMP_Y];
904
905
50.8k
      blkY.width = splitDimensionSize;
906
50.8k
      blkY.x = i > 0 ? sub[i - 1].blocks[COMP_Y].x + splitDimensionSize : blkY.x;
907
50.8k
      CHECK( sub[i].lumaSize().width < 1, "the split causes the block to be smaller than the minimal TU size" );
908
50.8k
    }
909
12.7k
  }
910
0
  else
911
0
  {
912
0
    THROW( "Unknown TU sub-partitioning" );
913
0
  }
914
  //we only partition luma, so there is going to be only one chroma tu at the end (unless it is dual tree, in which case there won't be any chroma components)
915
24.3k
  uint32_t partitionsWithoutChroma = (cs.area.chromaFormat == CHROMA_400) ? 0 : (isDualTree ? nPartitions : nPartitions - 1);
916
121k
  for( uint32_t i = 0; i < partitionsWithoutChroma; i++ )
917
97.2k
  {
918
97.2k
    CompArea& blkCb = sub[i].blocks[COMP_Cb];
919
97.2k
    CompArea& blkCr = sub[i].blocks[COMP_Cr];
920
97.2k
    blkCb = CompArea();
921
97.2k
    blkCr = CompArea();
922
97.2k
  }
923
924
24.3k
  return nPartitions;
925
24.3k
}
926
927
928
static const int g_rsScanToZ_w4[16] =
929
{
930
   0,  1,  4,  5, // wouldn't work for 128x32 blocks, but those are forbidden bcs of VPDU constraints
931
   2,  3,  6,  7, // correct ordering for 128x64 (TU32)
932
   8,  9, 12, 13,
933
  10, 11, 14, 15, // correct ordering for 128x128 (TU32)
934
};
935
936
static const int g_rsScanToZ_w2[8] =
937
{
938
   0,  1, // correct ordering for 64x32 (TU32) and 128x64 (TU64)
939
   2,  3, // correct ordering for 64x64 (TU32) and 128x128 (TU64)
940
   4,  5,
941
   6,  7, // correct ordering for 32x64 (TU32) and 64x128 (TU64)
942
};
943
944
static const int g_rsScanToZ_w1[4] =
945
{
946
   0, // no tiling, never used
947
   1, // correct ordering for 64x32 (TU32) and 128x64 (TU64)
948
   2,
949
   3, // correct ordering for 128x32 (TU32)
950
};
951
952
static const int* g_rsScanToZ[3] = { g_rsScanToZ_w1, g_rsScanToZ_w2, g_rsScanToZ_w4 };
953
954
int PartitionerImpl::getMaxTuTiling( Partitioning& dst, const UnitArea& cuArea, const CodingStructure& cs )
955
0
{
956
0
  const Size area = cuArea.lumaSize();
957
0
  const int maxTrSize = cs.sps->getMaxTbSize();
958
0
  const int numTilesH = std::max<int>( 1, area.width / maxTrSize );
959
0
  const int numTilesV = std::max<int>( 1, area.height / maxTrSize );
960
0
  const int numTiles  = numTilesH * numTilesV;
961
0
  const int numLog2H  = Log2( numTilesH );
962
0
  const int* rsScanToZ = g_rsScanToZ[numLog2H];
963
964
0
  Partitioning& ret = dst;
965
966
0
  for( int i = 0; i < numTiles; i++ )
967
0
  {
968
0
    ret[i] = cuArea;
969
970
0
    const int zid = rsScanToZ[i];
971
972
0
    const int y = zid >> numLog2H;
973
0
    const int x = zid & ( ( 1 << numLog2H ) - 1 );
974
975
0
    UnitArea& tile = ret[i];
976
977
0
    for( CompArea& comp : tile.blocks )
978
0
    {
979
0
      if( !comp.valid() ) continue;
980
981
0
      comp.width  /= numTilesH;
982
0
      comp.height /= numTilesV;
983
984
0
      comp.x += comp.width  * x;
985
0
      comp.y += comp.height * y;
986
0
    }
987
0
  }
988
989
0
  return numTiles;
990
0
}
991
992
int PartitionerImpl::getSbtTuTiling( Partitioning& dst, const UnitArea& cuArea, const CodingStructure &cs, const PartSplit splitType )
993
0
{
994
0
  Partitioning& ret = dst;
995
0
  int numTiles      = 2;
996
0
  int widthFactor, heightFactor, xOffsetFactor, yOffsetFactor;
997
998
0
  CHECK( !(splitType >= SBT_VER_HALF_POS0_SPLIT && splitType <= SBT_HOR_QUAD_POS1_SPLIT), "wrong" );
999
1000
0
  for( int i = 0; i < numTiles; i++ )
1001
0
  {
1002
0
    ret[i] = cuArea;
1003
1004
0
    if( splitType >= SBT_VER_QUAD_POS0_SPLIT )
1005
0
    {
1006
0
      if( splitType == SBT_HOR_QUAD_POS0_SPLIT || splitType == SBT_HOR_QUAD_POS1_SPLIT )
1007
0
      {
1008
0
        widthFactor   = 4;
1009
0
        xOffsetFactor = 0;
1010
0
        heightFactor  = ( ( i == 0 &&        splitType == SBT_HOR_QUAD_POS0_SPLIT ) || ( i == 1 && splitType == SBT_HOR_QUAD_POS1_SPLIT ) ) ? 1 : 3;
1011
0
        yOffsetFactor =   ( i == 0 ) ? 0 : ( splitType == SBT_HOR_QUAD_POS0_SPLIT ? 1 : 3 );
1012
0
      }
1013
0
      else
1014
0
      {
1015
0
        widthFactor   = ( ( i == 0 &&        splitType == SBT_VER_QUAD_POS0_SPLIT ) || ( i == 1 && splitType == SBT_VER_QUAD_POS1_SPLIT ) ) ? 1 : 3;
1016
0
        xOffsetFactor =   ( i == 0 ) ? 0 : ( splitType == SBT_VER_QUAD_POS0_SPLIT ? 1 : 3 );
1017
0
        heightFactor  = 4;
1018
0
        yOffsetFactor = 0;
1019
0
      }
1020
0
    }
1021
0
    else
1022
0
    {
1023
0
      if( splitType == SBT_HOR_HALF_POS0_SPLIT || splitType == SBT_HOR_HALF_POS1_SPLIT )
1024
0
      {
1025
0
        widthFactor   = 4;
1026
0
        xOffsetFactor = 0;
1027
0
        heightFactor  = 2;
1028
0
        yOffsetFactor = ( i == 0 ) ? 0 : 2;
1029
0
      }
1030
0
      else
1031
0
      {
1032
0
        widthFactor   = 2;
1033
0
        xOffsetFactor = ( i == 0 ) ? 0 : 2;
1034
0
        heightFactor  = 4;
1035
0
        yOffsetFactor = 0;
1036
0
      }
1037
0
    }
1038
1039
0
    UnitArea& tile = ret[i];
1040
1041
0
    for( CompArea &comp : tile.blocks )
1042
0
    {
1043
0
      if( !comp.valid() ) continue;
1044
1045
0
      comp.x     += ( comp.width  * xOffsetFactor ) >> 2;
1046
0
      comp.y     += ( comp.height * yOffsetFactor ) >> 2;
1047
0
      comp.width  = ( comp.width  * widthFactor   ) >> 2;
1048
0
      comp.height = ( comp.height * heightFactor  ) >> 2;
1049
0
    }
1050
0
  }
1051
1052
0
  return numTiles;
1053
0
}
1054
1055
1056
} // namespace vvenc
1057
1058
//! \}
1059