/src/vvenc/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) 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 | | /** \file UnitPartitioner.h |
43 | | * \brief Provides a class for partitioning management |
44 | | */ |
45 | | |
46 | | #pragma once |
47 | | |
48 | | #include "Unit.h" |
49 | | #include "CommonDef.h" |
50 | | |
51 | | //! \ingroup CommonLib |
52 | | //! \{ |
53 | | |
54 | | namespace vvenc { |
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 | | |
71 | | CU_HORZ_SPLIT, |
72 | | CU_VERT_SPLIT, |
73 | | CU_TRIH_SPLIT, |
74 | | CU_TRIV_SPLIT, |
75 | | TU_MAX_TR_SPLIT, |
76 | | TU_NO_ISP, |
77 | | TU_1D_HORZ_SPLIT, |
78 | | TU_1D_VERT_SPLIT, |
79 | | SBT_VER_HALF_POS0_SPLIT, |
80 | | SBT_VER_HALF_POS1_SPLIT, |
81 | | SBT_HOR_HALF_POS0_SPLIT, |
82 | | SBT_HOR_HALF_POS1_SPLIT, |
83 | | SBT_VER_QUAD_POS0_SPLIT, |
84 | | SBT_VER_QUAD_POS1_SPLIT, |
85 | | SBT_HOR_QUAD_POS0_SPLIT, |
86 | | SBT_HOR_QUAD_POS1_SPLIT, |
87 | | NUM_PART_SPLIT, |
88 | | CU_MT_SPLIT = 1000, ///< dummy element to indicate the MT (multi-type-tree) split |
89 | | CU_BT_SPLIT = 1001, ///< dummy element to indicate the BT split |
90 | | CU_DONT_SPLIT = 2000 ///< dummy element to indicate no splitting |
91 | | }; |
92 | | |
93 | | |
94 | | |
95 | | struct PartLevel |
96 | | { |
97 | | PartSplit split; |
98 | | Partitioning parts; |
99 | | unsigned numParts; |
100 | | unsigned idx; |
101 | | bool checkdIfImplicit; |
102 | | bool isImplicit; |
103 | | PartSplit implicitSplit; |
104 | | PartSplit firstSubPartSplit; |
105 | | bool canQtSplit; |
106 | | bool qgEnable; |
107 | | bool qgChromaEnable; |
108 | | int modeType; |
109 | | |
110 | | PartLevel(); |
111 | | PartLevel( const PartSplit _split, const Partitioning _parts ); |
112 | | void init(); |
113 | | }; |
114 | | |
115 | | // set depending on max QT / BT possibilities |
116 | | typedef static_vector<PartLevel, 2 * MAX_CU_DEPTH + 1> PartitioningStack; |
117 | | |
118 | | class Partitioner |
119 | | { |
120 | | protected: |
121 | | PartitioningStack m_partStack; |
122 | | #if _DEBUG |
123 | | UnitArea m_currArea; |
124 | | #endif |
125 | | static const size_t partBufSize = 128; |
126 | | UnitArea m_partBuf[partBufSize]; |
127 | | ptrdiff_t m_partBufIdx; |
128 | | |
129 | | public: |
130 | | unsigned currDepth; |
131 | | unsigned currQtDepth; |
132 | | unsigned currTrDepth; |
133 | | unsigned currBtDepth; |
134 | | unsigned currMtDepth; |
135 | | unsigned currSubdiv; |
136 | | Position currQgPos; |
137 | | Position currQgChromaPos; |
138 | | |
139 | | unsigned currImplicitBtDepth; |
140 | | ChannelType chType; |
141 | | TreeType treeType; |
142 | | ModeType modeType; |
143 | | |
144 | | unsigned maxBTD; |
145 | | unsigned maxBtSize; |
146 | | unsigned minTSize; |
147 | | unsigned maxTtSize; |
148 | | unsigned minQtSize; |
149 | | |
150 | 0 | const PartLevel& currPartLevel () const { return m_partStack.back(); } |
151 | 0 | const UnitArea& currArea () const { return currPartLevel().parts[currPartIdx()]; } |
152 | 0 | const unsigned currPartIdx () const { return currPartLevel().idx; } |
153 | 0 | const PartitioningStack& getPartStack () const { return m_partStack; } |
154 | 0 | const bool currQgEnable () const { return currPartLevel().qgEnable; } |
155 | 0 | const bool currQgChromaEnable () const { return currPartLevel().qgChromaEnable; } |
156 | | |
157 | | SplitSeries getSplitSeries () const; |
158 | | ModeTypeSeries getModeTypeSeries () const; |
159 | | |
160 | | void initCtu ( const UnitArea& ctuArea, const ChannelType _chType, const Slice& slice ); |
161 | | void splitCurrArea ( const PartSplit split, const CodingStructure &cs ); |
162 | | void exitCurrSplit (); |
163 | | bool nextPart ( const CodingStructure &cs, bool autoPop = false ); |
164 | | bool hasNextPart (); |
165 | | |
166 | | void setCUData ( CodingUnit& cu ); |
167 | | |
168 | | void copyState ( const Partitioner& other ); |
169 | | |
170 | | public: |
171 | | void canSplit ( const CodingStructure &cs, bool& canNo, bool& canQt, bool& canBh, bool& canBv, bool& canTh, bool& canTv ); |
172 | | bool canSplit ( const PartSplit split, const CodingStructure &cs ); |
173 | | bool canSplitISP ( const PartSplit split, const CodingStructure& cs, CodingUnit& cu ); |
174 | | bool isSplitImplicit ( const PartSplit split, const CodingStructure &cs ); |
175 | | PartSplit getImplicitSplit ( const CodingStructure &cs ); |
176 | | bool isSepTree ( const CodingStructure &cs ); |
177 | 0 | bool isConsInter () { return modeType == MODE_TYPE_INTER; } |
178 | 0 | bool isConsIntra () { return modeType == MODE_TYPE_INTRA; } |
179 | | |
180 | | void setMaxMinDepth ( unsigned& minDepth, unsigned& maxDepth, const CodingStructure& cs, int QtbttSpeedUp, bool MergeFlag ) const; |
181 | | }; |
182 | | |
183 | | ////////////////////////////////////////////////////////////////////////// |
184 | | // Partitioner namespace - contains methods calculating the actual splits |
185 | | ////////////////////////////////////////////////////////////////////////// |
186 | | |
187 | | namespace PartitionerImpl |
188 | | { |
189 | | int getCUSubPartitions ( Partitioning &sub, const UnitArea& cuArea, const CodingStructure &cs, const PartSplit splitType = CU_QUAD_SPLIT ); |
190 | | int getMaxTuTiling ( Partitioning &sub, const UnitArea& curArea, const CodingStructure &cs ); |
191 | | int getTUIntraSubPartitions( Partitioning &sub, const UnitArea& tuArea, const CodingStructure &cs, const PartSplit splitType, const TreeType treeType); |
192 | | int getSbtTuTiling ( Partitioning &sub, const UnitArea& curArea, const CodingStructure &cs, const PartSplit splitType ); |
193 | | }; |
194 | | |
195 | | } // namespace vvenc |
196 | | |
197 | | //! \} |
198 | | |