/src/vvdec/source/Lib/CommonLib/UnitPartitioner.h
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) 2018-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVdeC 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 | | /** \file UnitPartitioner.h |
44 | | * \brief Provides a class for partitioning management |
45 | | */ |
46 | | |
47 | | #pragma once |
48 | | |
49 | | #include "Unit.h" |
50 | | |
51 | | #include "CommonDef.h" |
52 | | |
53 | | namespace vvdec |
54 | | { |
55 | | |
56 | | typedef UnitArea* Partitioning; |
57 | | |
58 | | ////////////////////////////////////////////////////////////////////////// |
59 | | // PartManager class - manages the partitioning tree |
60 | | // |
61 | | // contains the currently processed partitioning area (currArea) |
62 | | // as well as the all partitioning decisions that led to this area |
63 | | // being processed (in m_partStack). |
64 | | ////////////////////////////////////////////////////////////////////////// |
65 | | |
66 | | enum PartSplit |
67 | | { |
68 | | CTU_LEVEL = 0, |
69 | | CU_QUAD_SPLIT, |
70 | | CU_HORZ_SPLIT, |
71 | | CU_VERT_SPLIT, |
72 | | CU_TRIH_SPLIT, |
73 | | CU_TRIV_SPLIT, |
74 | | TU_MAX_TR_SPLIT, |
75 | | TU_NO_ISP, |
76 | | TU_1D_HORZ_SPLIT, |
77 | | TU_1D_VERT_SPLIT, |
78 | | SBT_VER_HALF_POS0_SPLIT, |
79 | | SBT_VER_HALF_POS1_SPLIT, |
80 | | SBT_HOR_HALF_POS0_SPLIT, |
81 | | SBT_HOR_HALF_POS1_SPLIT, |
82 | | SBT_VER_QUAD_POS0_SPLIT, |
83 | | SBT_VER_QUAD_POS1_SPLIT, |
84 | | SBT_HOR_QUAD_POS0_SPLIT, |
85 | | SBT_HOR_QUAD_POS1_SPLIT, |
86 | | NUM_PART_SPLIT, |
87 | | CU_DONT_SPLIT = 2000 ///< dummy element to indicate no splitting |
88 | | }; |
89 | | |
90 | | |
91 | | |
92 | | struct PartLevel |
93 | | { |
94 | | PartSplit split; |
95 | | Partitioning parts; |
96 | | unsigned numParts; |
97 | | unsigned idx; |
98 | | const CodingUnit *cuAbove; |
99 | | const CodingUnit *cuLeft; |
100 | | ModeType modeType; |
101 | | bool qgEnable; |
102 | | bool qgChromaEnable; |
103 | | |
104 | | PartLevel(); |
105 | | PartLevel( const PartSplit _split, const Partitioning _parts ); |
106 | | |
107 | | void init(); |
108 | | }; |
109 | | |
110 | | // set depending on max QT / BT possibilities |
111 | | typedef static_vector<PartLevel, 2 * MAX_CU_DEPTH + 1> PartitioningStack; |
112 | | |
113 | | class Partitioner |
114 | | { |
115 | | protected: |
116 | | PartitioningStack m_partStack; |
117 | | #if _DEBUG |
118 | | UnitArea m_currArea; |
119 | | #endif |
120 | | static const size_t partBufSize = 128; |
121 | | UnitArea m_partBuf[partBufSize]; |
122 | | ptrdiff_t m_partBufIdx; |
123 | | |
124 | | public: |
125 | | |
126 | | bool isDualITree; |
127 | | unsigned maxBTD; |
128 | | unsigned maxBtSize; |
129 | | unsigned minBtSize; |
130 | | unsigned maxTtSize; |
131 | | unsigned minTtSize; |
132 | | unsigned maxTrSize; |
133 | | unsigned minQtSize; |
134 | | |
135 | | unsigned currDepth; |
136 | | unsigned currQtDepth; |
137 | | unsigned currTrDepth; |
138 | | unsigned currSubdiv; |
139 | | unsigned currMtDepth; |
140 | | unsigned currSliceIdx; |
141 | | unsigned currTileIdx; |
142 | | Position currQgPos; |
143 | | Position currQgChromaPos; |
144 | | |
145 | | unsigned currImplicitBtDepth; |
146 | | ChannelType chType; |
147 | | TreeType treeType; |
148 | | ModeType modeType; |
149 | | |
150 | | const Slice* slice; |
151 | | |
152 | 0 | const PartLevel& currPartLevel () const { return m_partStack.back(); } |
153 | 0 | const UnitArea& currArea () const { return currPartLevel().parts[currPartIdx()]; } |
154 | 0 | unsigned currPartIdx () const { return currPartLevel().idx; } |
155 | 0 | const PartitioningStack& getPartStack () const { return m_partStack; } |
156 | 0 | const bool currQgEnable () const { return currPartLevel().qgEnable; } |
157 | 0 | const bool currQgChromaEnable () const { return currPartLevel().qgChromaEnable; } |
158 | | |
159 | | SplitSeries getSplitSeries () const; |
160 | | |
161 | | void initCtu ( const UnitArea& ctuArea, const ChannelType _chType, const CodingStructure& cs, const Slice& slice ); |
162 | | void splitCurrArea ( const PartSplit split, const CodingStructure &cs ); |
163 | | void exitCurrSplit ( const CodingStructure& cs ); |
164 | | bool nextPart ( const CodingStructure &cs, bool autoPop = false ); |
165 | | bool hasNextPart () const; |
166 | | void setCUData ( CodingUnit& cu ); |
167 | | void canSplit ( const CodingStructure &cs, bool& canNo, bool& canQt, bool& canBh, bool& canBv, bool& canTh, bool& canTv ) const; |
168 | | bool canSplit ( const PartSplit split, const CodingStructure &cs, bool isISP = false ) const; |
169 | | bool isSepTree ( const CodingStructure &cs ) const; |
170 | 0 | bool isConsInter () const { return modeType == MODE_TYPE_INTER; } |
171 | 0 | bool isConsIntra () const { return modeType == MODE_TYPE_INTRA; } |
172 | | void updateNeighbors ( const CodingStructure& cs ); |
173 | | }; |
174 | | |
175 | | ////////////////////////////////////////////////////////////////////////// |
176 | | // Partitioner namespace - contains methods calculating the actual splits |
177 | | ////////////////////////////////////////////////////////////////////////// |
178 | | |
179 | | namespace PartitionerImpl |
180 | | { |
181 | | int getCUSubPartitions ( const UnitArea &area, const CodingStructure &cs, const PartSplit splitType, Partitioning& dst ); |
182 | | int getMaxTuTiling ( const UnitArea &area, const CodingStructure &cs, Partitioning& dst ); |
183 | | int getTUIntraSubPartitions( const UnitArea &area, const CodingStructure &cs, const bool isDualITree, const PartSplit splitType, Partitioning &sub, const TreeType treeType ); |
184 | | int getSbtTuTiling ( const UnitArea &area, const CodingStructure &cs, const PartSplit splitType, Partitioning& dst ); |
185 | | } |
186 | | |
187 | | } |