source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibCommon/TComTU.cpp @ 1499

Last change on this file since 1499 was 1499, checked in by seregin, 8 years ago

update get chroma format idc, patched-by Guillaume Barroux<guillaume.b@…>

File size: 9.2 KB
Line 
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
44static     const UInt         partIdxStepShift  [TComTU::NUMBER_OF_SPLIT_MODES] = { 0, 1, 2 };
45
46//----------------------------------------------------------------------------------------------------------------------
47
48TComTU::TComTU(TComDataCU *pcCU, const UInt absPartIdxCU, const UInt cuDepth, const UInt initTrDepthRelCU)
49#if SCALABLE_REXT
50  : mChromaFormat(pcCU->getSlice()->getChromaFormatIdc()),
51#else
52  : mChromaFormat(pcCU->getSlice()->getSPS()->getChromaFormatIdc()),
53#endif
54    mbProcessLastOfLevel(true), // does not matter. the top level is not 4 quadrants.
55    mCuDepth(cuDepth),
56    mSection(0),
57    mSplitMode(DONT_SPLIT),
58    mAbsPartIdxCU(absPartIdxCU),
59    mAbsPartIdxTURelCU(0),
60    mAbsPartIdxStep(pcCU->getPic()->getNumPartitionsInCtu() >> (pcCU->getDepth(absPartIdxCU)<<1)),
61    mpcCU(pcCU),
62    mLog2TrLumaSize(0),
63    mpParent(NULL)
64{
65  const TComSPS *pSPS=pcCU->getSlice()->getSPS();
66  mLog2TrLumaSize = g_aucConvertToBit[pSPS->getMaxCUWidth() >> (mCuDepth+initTrDepthRelCU)]+2;
67
68  const UInt baseOffset444=pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight()*absPartIdxCU;
69
70  for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
71  {
72    mTrDepthRelCU[i] = initTrDepthRelCU;
73    const UInt csx=getComponentScaleX(ComponentID(i), mChromaFormat);
74    const UInt csy=getComponentScaleY(ComponentID(i), mChromaFormat);
75    mOrigWidth[i]=mRect[i].width = (i < getNumberValidComponents(mChromaFormat)) ? (pcCU->getWidth( absPartIdxCU) >> csx) : 0;
76    mRect[i].height              = (i < getNumberValidComponents(mChromaFormat)) ? (pcCU->getHeight(absPartIdxCU) >> csy) : 0;
77    mRect[i].x0=0;
78    mRect[i].y0=0;
79    mCodeAll[i]=true;
80    mOffsets[i]=baseOffset444>>(csx+csy);
81  }
82}
83
84
85
86TComTURecurse::TComTURecurse(      TComDataCU *pcCU,
87                             const UInt        absPartIdxCU)
88  : TComTU(pcCU, absPartIdxCU, pcCU->getDepth(absPartIdxCU), 0)
89{ }
90
91
92
93TComTU::TComTU(TComTU &parent, const Bool bProcessLastOfLevel, const TU_SPLIT_MODE splitMode, const Bool splitAtCurrentDepth, const ComponentID absPartIdxSourceComponent)
94  : mChromaFormat(parent.mChromaFormat),
95    mbProcessLastOfLevel(bProcessLastOfLevel),
96    mCuDepth(parent.mCuDepth),
97    mSection(0),
98    mSplitMode(splitMode),
99    mAbsPartIdxCU(parent.mAbsPartIdxCU),
100    mAbsPartIdxTURelCU(parent.GetRelPartIdxTU(absPartIdxSourceComponent)),
101    mAbsPartIdxStep(std::max<UInt>(1, (parent.GetAbsPartIdxNumParts(absPartIdxSourceComponent) >> partIdxStepShift[splitMode]))),
102    mpcCU(parent.mpcCU),
103    mLog2TrLumaSize(parent.mLog2TrLumaSize - ((splitMode != QUAD_SPLIT) ? 0 : 1)), //no change in width for vertical split
104    mpParent(&parent)
105{
106  for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
107  {
108    mTrDepthRelCU[i] = parent.mTrDepthRelCU[i] + ((splitAtCurrentDepth || (splitMode == DONT_SPLIT)) ? 0 : 1);
109  }
110
111  if (mSplitMode==DONT_SPLIT)
112  {
113    for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
114    {
115      mRect[i] = (parent.mRect[i]);
116      mOffsets[i]=parent.mOffsets[i];
117      mCodeAll[i]=true; // The 1 TU at this level is coded.
118      mOrigWidth[i]=mRect[i].width;
119    }
120    return;
121  }
122  else if (mSplitMode==VERTICAL_SPLIT)
123  {
124    for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
125    {
126      mRect[i].x0 = (parent.mRect[i].x0);
127      mRect[i].y0 = (parent.mRect[i].y0);
128      mRect[i].width  = (parent.mRect[i].width);
129      mRect[i].height = (parent.mRect[i].height)>>1;
130      mOffsets[i]=parent.mOffsets[i];
131      mCodeAll[i]=true; // The 2 TUs at this level is coded.
132      mOrigWidth[i]=mRect[i].width;
133    }
134    return;
135  }
136
137  for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
138  {
139    mRect[i].width = (parent.mRect[i].width >> 1);
140    mRect[i].height= (parent.mRect[i].height>> 1);
141    mRect[i].x0=parent.mRect[i].x0;
142    mRect[i].y0=parent.mRect[i].y0;
143    mOffsets[i]=parent.mOffsets[i];
144
145    if ((mRect[i].width < MIN_TU_SIZE || mRect[i].height < MIN_TU_SIZE) && mRect[i].width!=0)
146    {
147      const UInt numPels=mRect[i].width * mRect[i].height;
148      if (numPels < (MIN_TU_SIZE*MIN_TU_SIZE))
149      {
150        // this level doesn't have enough pixels to have 4 blocks of any relative dimension
151        mRect[i].width = parent.mRect[i].width;
152        mRect[i].height= parent.mRect[i].height;
153        mCodeAll[i]=false; // go up a level, so only process one entry of a quadrant
154        mTrDepthRelCU[i]--;
155      }
156      else if (mRect[i].width < mRect[i].height)
157      {
158        mRect[i].width=MIN_TU_SIZE;
159        mRect[i].height=numPels/MIN_TU_SIZE;
160        mCodeAll[i]=true;
161      }
162      else
163      {
164        mRect[i].height=MIN_TU_SIZE;
165        mRect[i].width=numPels/MIN_TU_SIZE;
166        mCodeAll[i]=true;
167      }
168    }
169    else
170    {
171      mCodeAll[i]=true;
172    }
173
174    mOrigWidth[i]=mRect[i].width;
175    if (!mCodeAll[i] && mbProcessLastOfLevel)
176    {
177      mRect[i].width=0;
178    }
179  }
180}
181
182Bool TComTURecurse::nextSection(const TComTU &parent)
183{
184  if (mSplitMode==DONT_SPLIT)
185  {
186    mSection++;
187    return false;
188  }
189  else
190  {
191    for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
192    {
193      mOffsets[i]+=mRect[i].width*mRect[i].height;
194      if (mbProcessLastOfLevel)
195      {
196        mRect[i].width=mOrigWidth[i];
197      }
198      mRect[i].x0+=mRect[i].width;
199      const TComRectangle &parentRect=parent.getRect(ComponentID(i));
200      if (mRect[i].x0 >= parentRect.x0+parentRect.width)
201      {
202        mRect[i].x0=parentRect.x0;
203        mRect[i].y0+=mRect[i].height;
204      }
205      if (!mCodeAll[i])
206      {
207        if (!mbProcessLastOfLevel || mSection!=2)
208        {
209          mRect[i].width=0;
210        }
211      }
212    }
213    assert(mRect[COMPONENT_Cb].x0==mRect[COMPONENT_Cr].x0);
214    assert(mRect[COMPONENT_Cb].y0==mRect[COMPONENT_Cr].y0);
215    assert(mRect[COMPONENT_Cb].width==mRect[COMPONENT_Cr].width);
216    assert(mRect[COMPONENT_Cb].height==mRect[COMPONENT_Cr].height);
217
218    mAbsPartIdxTURelCU+=mAbsPartIdxStep;
219    mSection++;
220    return mSection< (1<<mSplitMode);
221  }
222}
223
224
225UInt TComTU::GetEquivalentLog2TrSize(const ComponentID compID)     const
226{
227  return g_aucConvertToBit[ getRect(compID).height ] + 2;
228}
229
230
231Bool TComTU::useDST(const ComponentID compID)
232{
233        TComDataCU *const pcCU       = getCU();
234  const UInt              absPartIdx = GetAbsPartIdxTU(compID);
235
236  return isLuma(compID) && pcCU->isIntra(absPartIdx);
237}
238
239
240Bool TComTU::isNonTransformedResidualRotated(const ComponentID compID)
241{
242  // rotation only for 4x4 intra, and is only used for non-transformed blocks (the latter is not checked here)
243  return    getCU()->getSlice()->getSPS()->getSpsRangeExtension().getTransformSkipRotationEnabledFlag()
244         && mRect[compID].width == 4
245         && getCU()->isIntra(GetAbsPartIdxTU());
246}
247
248
249UInt TComTU::getGolombRiceStatisticsIndex(const ComponentID compID)
250{
251        TComDataCU *const pcCU             = getCU();
252  const UInt              absPartIdx       = GetAbsPartIdxTU(compID);
253  const Bool              transformSkip    = pcCU->getTransformSkip(absPartIdx, compID);
254  const Bool              transquantBypass = pcCU->getCUTransquantBypass(absPartIdx);
255
256  //--------
257
258  const UInt channelTypeOffset    =  isChroma(compID)                   ? 2 : 0;
259  const UInt nonTransformedOffset = (transformSkip || transquantBypass) ? 1 : 0;
260
261  //--------
262
263  const UInt selectedIndex = channelTypeOffset + nonTransformedOffset;
264  assert(selectedIndex < RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS);
265
266  return selectedIndex;
267}
Note: See TracBrowser for help on using the repository browser.