source: SHVCSoftware/branches/SHM-temp/source/Lib/TLibCommon/TComTU.cpp @ 1041

Last change on this file since 1041 was 1029, checked in by seregin, 10 years ago

merge with SHM-upgrade branch

File size: 9.0 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-2014, 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  : 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  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;
69    const UInt csx=getComponentScaleX(ComponentID(i), mChromaFormat);
70    const UInt csy=getComponentScaleY(ComponentID(i), mChromaFormat);
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
82TComTURecurse::TComTURecurse(      TComDataCU *pcCU,
83                             const UInt        absPartIdxCU)
84  : TComTU(pcCU, absPartIdxCU, pcCU->getDepth(absPartIdxCU), 0)
85{ }
86
87
88
89TComTU::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      {
154        mRect[i].width=MIN_TU_SIZE;
155        mRect[i].height=numPels/MIN_TU_SIZE;
156        mCodeAll[i]=true;
157      }
158      else
159      {
160        mRect[i].height=MIN_TU_SIZE;
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) mRect[i].width=0;
172  }
173}
174
175Bool TComTURecurse::nextSection(const TComTU &parent)
176{
177  if (mSplitMode==DONT_SPLIT)
178  {
179    mSection++;
180    return false;
181  }
182  else
183  {
184    for(UInt i=0; i<MAX_NUM_COMPONENT; i++)
185    {
186      mOffsets[i]+=mRect[i].width*mRect[i].height;
187      if (mbProcessLastOfLevel) mRect[i].width=mOrigWidth[i];
188      mRect[i].x0+=mRect[i].width;
189      const TComRectangle &parentRect=parent.getRect(ComponentID(i));
190      if (mRect[i].x0 >= parentRect.x0+parentRect.width)
191      {
192        mRect[i].x0=parentRect.x0;
193        mRect[i].y0+=mRect[i].height;
194      }
195      if (!mCodeAll[i])
196      {
197        if (!mbProcessLastOfLevel || mSection!=2) mRect[i].width=0;
198      }
199    }
200    assert(mRect[COMPONENT_Cb].x0==mRect[COMPONENT_Cr].x0);
201    assert(mRect[COMPONENT_Cb].y0==mRect[COMPONENT_Cr].y0);
202    assert(mRect[COMPONENT_Cb].width==mRect[COMPONENT_Cr].width);
203    assert(mRect[COMPONENT_Cb].height==mRect[COMPONENT_Cr].height);
204
205    mAbsPartIdxTURelCU+=mAbsPartIdxStep;
206    mSection++;
207    return mSection< (1<<mSplitMode);
208  }
209}
210
211
212UInt TComTU::GetEquivalentLog2TrSize(const ComponentID compID)     const
213{
214  return g_aucConvertToBit[ getRect(compID).height ] + 2;
215}
216
217
218Bool TComTU::useDST(const ComponentID compID)
219{
220        TComDataCU *const pcCU       = getCU();
221  const UInt              absPartIdx = GetAbsPartIdxTU(compID);
222
223  return isLuma(compID) && pcCU->isIntra(absPartIdx);
224}
225
226
227Bool TComTU::isNonTransformedResidualRotated(const ComponentID compID)
228{
229  // rotation only for 4x4 intra, and is only used for non-transformed blocks (the latter is not checked here)
230  return    getCU()->getSlice()->getSPS()->getUseResidualRotation()
231         && mRect[compID].width == 4
232         && getCU()->isIntra(GetAbsPartIdxTU());
233}
234
235
236UInt TComTU::getGolombRiceStatisticsIndex(const ComponentID compID)
237{
238        TComDataCU *const pcCU             = getCU();
239  const UInt              absPartIdx       = GetAbsPartIdxTU(compID);
240  const Bool              transformSkip    = pcCU->getTransformSkip(absPartIdx, compID);
241  const Bool              transquantBypass = pcCU->getCUTransquantBypass(absPartIdx);
242
243  //--------
244
245  const UInt channelTypeOffset    =  isChroma(compID)                   ? 2 : 0;
246  const UInt nonTransformedOffset = (transformSkip || transquantBypass) ? 1 : 0;
247
248  //--------
249
250  const UInt selectedIndex = channelTypeOffset + nonTransformedOffset;
251  assert(selectedIndex < RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS);
252
253  return selectedIndex;
254}
Note: See TracBrowser for help on using the repository browser.