HEVC Test Model (HM)  HM-16.3
TComTU.cpp
Go to the documentation of this file.
1 /* The copyright in this software is being made available under the BSD
2  * License, included below. This software may be subject to other third party
3  * and contributor rights, including patent rights, and no such rights are
4  * granted under this license.
5  *
6  * Copyright (c) 2010-2015, ITU/ISO/IEC
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18  * be used to endorse or promote products derived from this software without
19  * specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31  * THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 
35 #include "TComTU.h"
36 #include "TComRom.h"
37 #include "TComDataCU.h"
38 #include "TComPic.h"
39 
40 //----------------------------------------------------------------------------------------------------------------------
41 
42 /*static*/ const UInt TComTU::NUMBER_OF_SECTIONS[TComTU::NUMBER_OF_SPLIT_MODES] = { 1, 2, 4 };
43 
45 
46 //----------------------------------------------------------------------------------------------------------------------
47 
48 TComTU::TComTU(TComDataCU *pcCU, const UInt absPartIdxCU, const UInt cuDepth, const UInt initTrDepthRelCU)
49  : mChromaFormat(pcCU->getSlice()->getSPS()->getChromaFormatIdc()),
50  mbProcessLastOfLevel(true), // does not matter. the top level is not 4 quadrants.
51  mCuDepth(cuDepth),
52  mSection(0),
53  mSplitMode(DONT_SPLIT),
54  mAbsPartIdxCU(absPartIdxCU),
55  mAbsPartIdxTURelCU(0),
56  mAbsPartIdxStep(pcCU->getPic()->getNumPartitionsInCtu() >> (pcCU->getDepth(absPartIdxCU)<<1)),
57  mpcCU(pcCU),
58  mLog2TrLumaSize(0),
59  mpParent(NULL)
60 {
61  const TComSPS *pSPS=pcCU->getSlice()->getSPS();
62  mLog2TrLumaSize = g_aucConvertToBit[pSPS->getMaxCUWidth() >> (mCuDepth+initTrDepthRelCU)]+2;
63 
64  const UInt baseOffset444=pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight()*absPartIdxCU;
65 
66  for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
67  {
68  mTrDepthRelCU[i] = initTrDepthRelCU;
71  mOrigWidth[i]=mRect[i].width = (i < getNumberValidComponents(mChromaFormat)) ? (pcCU->getWidth( absPartIdxCU) >> csx) : 0;
72  mRect[i].height = (i < getNumberValidComponents(mChromaFormat)) ? (pcCU->getHeight(absPartIdxCU) >> csy) : 0;
73  mRect[i].x0=0;
74  mRect[i].y0=0;
75  mCodeAll[i]=true;
76  mOffsets[i]=baseOffset444>>(csx+csy);
77  }
78 }
79 
80 
81 
83  const UInt absPartIdxCU)
84  : TComTU(pcCU, absPartIdxCU, pcCU->getDepth(absPartIdxCU), 0)
85 { }
86 
87 
88 
89 TComTU::TComTU(TComTU &parent, const Bool bProcessLastOfLevel, const TU_SPLIT_MODE splitMode, const Bool splitAtCurrentDepth, const ComponentID absPartIdxSourceComponent)
90  : mChromaFormat(parent.mChromaFormat),
91  mbProcessLastOfLevel(bProcessLastOfLevel),
92  mCuDepth(parent.mCuDepth),
93  mSection(0),
94  mSplitMode(splitMode),
95  mAbsPartIdxCU(parent.mAbsPartIdxCU),
96  mAbsPartIdxTURelCU(parent.GetRelPartIdxTU(absPartIdxSourceComponent)),
97  mAbsPartIdxStep(std::max<UInt>(1, (parent.GetAbsPartIdxNumParts(absPartIdxSourceComponent) >> partIdxStepShift[splitMode]))),
98  mpcCU(parent.mpcCU),
99  mLog2TrLumaSize(parent.mLog2TrLumaSize - ((splitMode != QUAD_SPLIT) ? 0 : 1)), //no change in width for vertical split
100  mpParent(&parent)
101 {
102  for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
103  {
104  mTrDepthRelCU[i] = parent.mTrDepthRelCU[i] + ((splitAtCurrentDepth || (splitMode == DONT_SPLIT)) ? 0 : 1);
105  }
106 
107  if (mSplitMode==DONT_SPLIT)
108  {
109  for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
110  {
111  mRect[i] = (parent.mRect[i]);
112  mOffsets[i]=parent.mOffsets[i];
113  mCodeAll[i]=true; // The 1 TU at this level is coded.
114  mOrigWidth[i]=mRect[i].width;
115  }
116  return;
117  }
118  else if (mSplitMode==VERTICAL_SPLIT)
119  {
120  for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
121  {
122  mRect[i].x0 = (parent.mRect[i].x0);
123  mRect[i].y0 = (parent.mRect[i].y0);
124  mRect[i].width = (parent.mRect[i].width);
125  mRect[i].height = (parent.mRect[i].height)>>1;
126  mOffsets[i]=parent.mOffsets[i];
127  mCodeAll[i]=true; // The 2 TUs at this level is coded.
128  mOrigWidth[i]=mRect[i].width;
129  }
130  return;
131  }
132 
133  for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
134  {
135  mRect[i].width = (parent.mRect[i].width >> 1);
136  mRect[i].height= (parent.mRect[i].height>> 1);
137  mRect[i].x0=parent.mRect[i].x0;
138  mRect[i].y0=parent.mRect[i].y0;
139  mOffsets[i]=parent.mOffsets[i];
140 
141  if ((mRect[i].width < MIN_TU_SIZE || mRect[i].height < MIN_TU_SIZE) && mRect[i].width!=0)
142  {
143  const UInt numPels=mRect[i].width * mRect[i].height;
144  if (numPels < (MIN_TU_SIZE*MIN_TU_SIZE))
145  {
146  // this level doesn't have enough pixels to have 4 blocks of any relative dimension
147  mRect[i].width = parent.mRect[i].width;
148  mRect[i].height= parent.mRect[i].height;
149  mCodeAll[i]=false; // go up a level, so only process one entry of a quadrant
150  mTrDepthRelCU[i]--;
151  }
152  else if (mRect[i].width < mRect[i].height)
153  {
155  mRect[i].height=numPels/MIN_TU_SIZE;
156  mCodeAll[i]=true;
157  }
158  else
159  {
161  mRect[i].width=numPels/MIN_TU_SIZE;
162  mCodeAll[i]=true;
163  }
164  }
165  else
166  {
167  mCodeAll[i]=true;
168  }
169 
170  mOrigWidth[i]=mRect[i].width;
171  if (!mCodeAll[i] && mbProcessLastOfLevel)
172  {
173  mRect[i].width=0;
174  }
175  }
176 }
177 
179 {
180  if (mSplitMode==DONT_SPLIT)
181  {
182  mSection++;
183  return false;
184  }
185  else
186  {
187  for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
188  {
189  mOffsets[i]+=mRect[i].width*mRect[i].height;
191  {
192  mRect[i].width=mOrigWidth[i];
193  }
194  mRect[i].x0+=mRect[i].width;
195  const TComRectangle &parentRect=parent.getRect(ComponentID(i));
196  if (mRect[i].x0 >= parentRect.x0+parentRect.width)
197  {
198  mRect[i].x0=parentRect.x0;
199  mRect[i].y0+=mRect[i].height;
200  }
201  if (!mCodeAll[i])
202  {
203  if (!mbProcessLastOfLevel || mSection!=2)
204  {
205  mRect[i].width=0;
206  }
207  }
208  }
209  assert(mRect[COMPONENT_Cb].x0==mRect[COMPONENT_Cr].x0);
210  assert(mRect[COMPONENT_Cb].y0==mRect[COMPONENT_Cr].y0);
211  assert(mRect[COMPONENT_Cb].width==mRect[COMPONENT_Cr].width);
212  assert(mRect[COMPONENT_Cb].height==mRect[COMPONENT_Cr].height);
213 
215  mSection++;
216  return mSection< (1<<mSplitMode);
217  }
218 }
219 
220 
222 {
223  return g_aucConvertToBit[ getRect(compID).height ] + 2;
224 }
225 
226 
228 {
229  TComDataCU *const pcCU = getCU();
230  const UInt absPartIdx = GetAbsPartIdxTU(compID);
231 
232  return isLuma(compID) && pcCU->isIntra(absPartIdx);
233 }
234 
235 
237 {
238  // rotation only for 4x4 intra, and is only used for non-transformed blocks (the latter is not checked here)
239  return getCU()->getSlice()->getSPS()->getUseResidualRotation()
240  && mRect[compID].width == 4
241  && getCU()->isIntra(GetAbsPartIdxTU());
242 }
243 
244 
246 {
247  TComDataCU *const pcCU = getCU();
248  const UInt absPartIdx = GetAbsPartIdxTU(compID);
249  const Bool transformSkip = pcCU->getTransformSkip(absPartIdx, compID);
250  const Bool transquantBypass = pcCU->getCUTransquantBypass(absPartIdx);
251 
252  //--------
253 
254  const UInt channelTypeOffset = isChroma(compID) ? 2 : 0;
255  const UInt nonTransformedOffset = (transformSkip || transquantBypass) ? 1 : 0;
256 
257  //--------
258 
259  const UInt selectedIndex = channelTypeOffset + nonTransformedOffset;
260  assert(selectedIndex < RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS);
261 
262  return selectedIndex;
263 }
CU data structure class.
Definition: TComDataCU.h:64
Bool useDST(const ComponentID compID)
Definition: TComTU.cpp:227
ChromaFormat mChromaFormat
Definition: TComTU.h:56
global variables & functions (header)
#define NULL
Definition: CommonDef.h:100
static UInt getComponentScaleY(const ComponentID id, const ChromaFormat fmt)
Char g_aucConvertToBit[(1<<(6))+1]
Definition: TComRom.cpp:558
unsigned int UInt
Definition: TypeDef.h:297
static UInt getComponentScaleX(const ComponentID id, const ChromaFormat fmt)
STL namespace.
picture class (header)
Bool nextSection(const TComTU &parent)
Definition: TComTU.cpp:178
UInt getMinCUWidth() const
Definition: TComPic.h:122
Bool mCodeAll[MAX_NUM_COMPONENT]
Definition: TComTU.h:63
UInt GetAbsPartIdxTU() const
Definition: TComTU.h:119
static const UInt partIdxStepShift[TComTU::NUMBER_OF_SPLIT_MODES]
Definition: TComTU.cpp:44
UInt mOffsets[MAX_NUM_COMPONENT]
Definition: TComTU.h:65
UInt getGolombRiceStatisticsIndex(const ComponentID compID)
Definition: TComTU.cpp:245
UInt mAbsPartIdxTURelCU
Definition: TComTU.h:67
TU_SPLIT_MODE mSplitMode
Definition: TComTU.h:61
bool Bool
Definition: TypeDef.h:286
TComTU(const TComTU &)
Bool isIntra(UInt uiPartIdx) const
Definition: TComDataCU.h:443
UInt getMinCUHeight() const
Definition: TComPic.h:123
UInt GetEquivalentLog2TrSize(const ComponentID compID) const
Definition: TComTU.cpp:221
#define MIN_TU_SIZE
Definition: TComRom.h:56
static const UInt NUMBER_OF_SECTIONS[NUMBER_OF_SPLIT_MODES]
Definition: TComTU.h:53
const TComRectangle & getRect(const ComponentID compID) const
Definition: TComTU.h:96
Bool mbProcessLastOfLevel
Definition: TComTU.h:57
UChar * getTransformSkip(ComponentID compID)
Definition: TComDataCU.h:278
TComDataCU * getCU()
Definition: TComTU.h:126
UChar * getHeight()
Definition: TComDataCU.h:249
Bool * getCUTransquantBypass()
Definition: TComDataCU.h:242
UInt mCuDepth
Definition: TComTU.h:58
TComPic * getPic()
Definition: TComDataCU.h:203
Definition: TComTU.h:48
UInt mSection
Definition: TComTU.h:60
UChar * getWidth()
Definition: TComDataCU.h:245
static Bool isChroma(const ComponentID id)
ComponentID
Definition: TypeDef.h:368
Bool getUseResidualRotation() const
Definition: TComSlice.h:895
TU_SPLIT_MODE
Definition: TComTU.h:51
Bool isNonTransformedResidualRotated(const ComponentID compID)
Definition: TComTU.cpp:236
TComTURecurse(TComDataCU *pcCU, const UInt absPartIdxCU, const UInt forcedDepthOfCU)
Definition: TComTU.h:146
UInt mTrDepthRelCU[MAX_NUM_COMPONENT]
Definition: TComTU.h:59
CU data structure (header)
TComRectangle mRect[MAX_NUM_COMPONENT]
Definition: TComTU.h:62
static UInt getNumberValidComponents(const ChromaFormat fmt)
#define RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS
Definition: TypeDef.h:247
UInt mAbsPartIdxStep
Definition: TComTU.h:68
UInt mOrigWidth[MAX_NUM_COMPONENT]
Definition: TComTU.h:64
static Bool isLuma(const ComponentID id)
UInt getMaxCUWidth() const
Definition: TComSlice.h:845
UInt mLog2TrLumaSize
Definition: TComTU.h:70
TComSlice * getSlice()
Definition: TComDataCU.h:205
const TComSPS * getSPS() const
Definition: TComSlice.h:1306
SPS class.
Definition: TComSlice.h:722