[1313] | 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 | |
---|
| 44 | static const UInt partIdxStepShift [TComTU::NUMBER_OF_SPLIT_MODES] = { 0, 1, 2 }; |
---|
| 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; |
---|
| 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 | |
---|
| 82 | TComTURecurse::TComTURecurse( TComDataCU *pcCU, |
---|
| 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 | { |
---|
| 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) |
---|
| 172 | { |
---|
| 173 | mRect[i].width=0; |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | Bool TComTURecurse::nextSection(const TComTU &parent) |
---|
| 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; |
---|
| 190 | if (mbProcessLastOfLevel) |
---|
| 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 | |
---|
| 214 | mAbsPartIdxTURelCU+=mAbsPartIdxStep; |
---|
| 215 | mSection++; |
---|
| 216 | return mSection< (1<<mSplitMode); |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | UInt TComTU::GetEquivalentLog2TrSize(const ComponentID compID) const |
---|
| 222 | { |
---|
| 223 | return g_aucConvertToBit[ getRect(compID).height ] + 2; |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | |
---|
| 227 | Bool TComTU::useDST(const ComponentID compID) |
---|
| 228 | { |
---|
| 229 | TComDataCU *const pcCU = getCU(); |
---|
| 230 | const UInt absPartIdx = GetAbsPartIdxTU(compID); |
---|
| 231 | |
---|
| 232 | return isLuma(compID) && pcCU->isIntra(absPartIdx); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | |
---|
| 236 | Bool TComTU::isNonTransformedResidualRotated(const ComponentID compID) |
---|
| 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()->getSpsRangeExtension().getTransformSkipRotationEnabledFlag() |
---|
| 240 | && mRect[compID].width == 4 |
---|
| 241 | && getCU()->isIntra(GetAbsPartIdxTU()); |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | |
---|
| 245 | UInt TComTU::getGolombRiceStatisticsIndex(const ComponentID compID) |
---|
| 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 | } |
---|