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 /** \file     TComDataCU.h
35     \brief    CU data structure (header)
36     \todo     not all entities are documented
37 */
38 
39 #ifndef __TCOMDATACU__
40 #define __TCOMDATACU__
41 
42 #include <assert.h>
43 
44 // Include files
45 #include "CommonDef.h"
46 #include "TComMotionInfo.h"
47 #include "TComSlice.h"
48 #include "TComRdCost.h"
49 #include "TComPattern.h"
50 
51 #include <algorithm>
52 #include <vector>
53 
54 //! \ingroup TLibCommon
55 //! \{
56 
57 class TComTU; // forward declaration
58 
59 static const UInt NUM_MOST_PROBABLE_MODES=3;
60 
61 // ====================================================================================================================
62 // Class definition
63 // ====================================================================================================================
64 
65 /// CU data structure class
66 class TComDataCU
67 {
68 private:
69 
70   // -------------------------------------------------------------------------------------------------------------------
71   // class pointers
72   // -------------------------------------------------------------------------------------------------------------------
73 
74   TComPic*      m_pcPic;              ///< picture class pointer
75   TComSlice*    m_pcSlice;            ///< slice header pointer
76 
77   // -------------------------------------------------------------------------------------------------------------------
78   // CU description
79   // -------------------------------------------------------------------------------------------------------------------
80 
81   UInt          m_ctuRsAddr;          ///< CTU (also known as LCU) address in a slice (Raster-scan address, as opposed to tile-scan/encoding order).
82   UInt          m_absZIdxInCtu;       ///< absolute address in a CTU. It's Z scan order
83   UInt          m_uiCUPelX;           ///< CU position in a pixel (X)
84   UInt          m_uiCUPelY;           ///< CU position in a pixel (Y)
85   UInt          m_uiNumPartition;     ///< total number of minimum partitions in a CU
86   UChar*        m_puhWidth;           ///< array of widths
87   UChar*        m_puhHeight;          ///< array of heights
88   UChar*        m_puhDepth;           ///< array of depths
89   Int           m_unitSize;           ///< size of a "minimum partition"
90 
91   // -------------------------------------------------------------------------------------------------------------------
92   // CU data
93   // -------------------------------------------------------------------------------------------------------------------
94 
95   Bool*          m_skipFlag;           ///< array of skip flags
96   Char*          m_pePartSize;         ///< array of partition sizes
97   Char*          m_pePredMode;         ///< array of prediction modes
98   Char*          m_crossComponentPredictionAlpha[MAX_NUM_COMPONENT]; ///< array of cross-component prediction alpha values
99   Bool*          m_CUTransquantBypass;   ///< array of cu_transquant_bypass flags
100   Char*          m_phQP;               ///< array of QP values
101   UChar*         m_ChromaQpAdj;        ///< array of chroma QP adjustments (indexed)
102   UInt           m_codedChromaQpAdj;
103   UChar*         m_puhTrIdx;           ///< array of transform indices
104   UChar*         m_puhTransformSkip[MAX_NUM_COMPONENT];///< array of transform skipping flags
105   UChar*         m_puhCbf[MAX_NUM_COMPONENT];          ///< array of coded block flags (CBF)
106   TComCUMvField  m_acCUMvField[NUM_REF_PIC_LIST_01];    ///< array of motion vectors.
107   TCoeff*        m_pcTrCoeff[MAX_NUM_COMPONENT];       ///< array of transform coefficient buffers (0->Y, 1->Cb, 2->Cr)
108 #if ADAPTIVE_QP_SELECTION
109   TCoeff*        m_pcArlCoeff[MAX_NUM_COMPONENT];  // ARL coefficient buffer (0->Y, 1->Cb, 2->Cr)
110   static TCoeff* m_pcGlbArlCoeff[MAX_NUM_COMPONENT]; // global ARL buffer
111   Bool           m_ArlCoeffIsAliasedAllocation;  ///< ARL coefficient buffer is an alias of the global buffer and must not be free()'d
112 #endif
113 
114   Pel*           m_pcIPCMSample[MAX_NUM_COMPONENT];    ///< PCM sample buffer (0->Y, 1->Cb, 2->Cr)
115 
116   // -------------------------------------------------------------------------------------------------------------------
117   // neighbour access variables
118   // -------------------------------------------------------------------------------------------------------------------
119 
120   TComDataCU*   m_pCtuAboveLeft;      ///< pointer of above-left CTU.
121   TComDataCU*   m_pCtuAboveRight;     ///< pointer of above-right CTU.
122   TComDataCU*   m_pCtuAbove;          ///< pointer of above CTU.
123   TComDataCU*   m_pCtuLeft;           ///< pointer of left CTU
124   TComDataCU*   m_apcCUColocated[NUM_REF_PIC_LIST_01];  ///< pointer of temporally colocated CU's for both directions
125   TComMvField   m_cMvFieldA;          ///< motion vector of position A
126   TComMvField   m_cMvFieldB;          ///< motion vector of position B
127   TComMvField   m_cMvFieldC;          ///< motion vector of position C
128   TComMv        m_cMvPred;            ///< motion vector predictor
129 
130   // -------------------------------------------------------------------------------------------------------------------
131   // coding tool information
132   // -------------------------------------------------------------------------------------------------------------------
133 
134   Bool*         m_pbMergeFlag;        ///< array of merge flags
135   UChar*        m_puhMergeIndex;      ///< array of merge candidate indices
136 #if AMP_MRG
137   Bool          m_bIsMergeAMP;
138 #endif
139   UChar*        m_puhIntraDir[MAX_NUM_CHANNEL_TYPE]; // 0-> Luma, 1-> Chroma
140   UChar*        m_puhInterDir;        ///< array of inter directions
141   Char*         m_apiMVPIdx[NUM_REF_PIC_LIST_01];       ///< array of motion vector predictor candidates
142   Char*         m_apiMVPNum[NUM_REF_PIC_LIST_01];       ///< array of number of possible motion vectors predictors
143   Bool*         m_pbIPCMFlag;         ///< array of intra_pcm flags
144 
145   // -------------------------------------------------------------------------------------------------------------------
146   // misc. variables
147   // -------------------------------------------------------------------------------------------------------------------
148 
149   Bool          m_bDecSubCu;          ///< indicates decoder-mode
150   Double        m_dTotalCost;         ///< sum of partition RD costs
151   Distortion    m_uiTotalDistortion;  ///< sum of partition distortion
152   UInt          m_uiTotalBits;        ///< sum of partition bits
153   UInt          m_uiTotalBins;        ///< sum of partition bins
154   Char          m_codedQP;
155   UChar*        m_explicitRdpcmMode[MAX_NUM_COMPONENT]; ///< Stores the explicit RDPCM mode for all TUs belonging to this CU
156 
157 protected:
158 
159   /// add possible motion vector predictor candidates
160   Bool          xAddMVPCand           ( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir );
161   Bool          xAddMVPCandOrder      ( AMVPInfo* pInfo, RefPicList eRefPicList, Int iRefIdx, UInt uiPartUnitIdx, MVP_DIR eDir );
162 
163   Void          deriveRightBottomIdx        ( UInt uiPartIdx, UInt& ruiPartIdxRB );
164   Bool          xGetColMVP( RefPicList eRefPicList, Int ctuRsAddr, Int uiPartUnitIdx, TComMv& rcMv, Int& riRefIdx );
165 
166   /// compute required bits to encode MVD (used in AMVP)
167   UInt          xGetMvdBits           ( TComMv cMvd );
168   UInt          xGetComponentBits     ( Int iVal );
169 
170   /// compute scaling factor from POC difference
171   Int           xGetDistScaleFactor   ( Int iCurrPOC, Int iCurrRefPOC, Int iColPOC, Int iColRefPOC );
172 
173   Void xDeriveCenterIdx( UInt uiPartIdx, UInt& ruiPartIdxCenter );
174 
175 public:
176   TComDataCU();
177   virtual ~TComDataCU();
178 
179   // -------------------------------------------------------------------------------------------------------------------
180   // create / destroy / initialize / copy
181   // -------------------------------------------------------------------------------------------------------------------
182 
183   Void          create                ( ChromaFormat chromaFormatIDC, UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize
184 #if ADAPTIVE_QP_SELECTION
185     , Bool bGlobalRMARLBuffer = false
186 #endif
187     );
188   Void          destroy               ();
189 
190   Void          initCtu               ( TComPic* pcPic, UInt ctuRsAddr );
191   Void          initEstData           ( const UInt uiDepth, const Int qp, const Bool bTransquantBypass );
192   Void          initSubCU             ( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp );
193   Void          setOutsideCUPart      ( UInt uiAbsPartIdx, UInt uiDepth );
194 
195   Void          copySubCU             ( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth );
196   Void          copyInterPredInfoFrom ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList );
197   Void          copyPartFrom          ( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth );
198 
199   Void          copyToPic             ( UChar uiDepth );
200   Void          copyToPic             ( UChar uiDepth, UInt uiPartIdx, UInt uiPartDepth );
201 
202   // -------------------------------------------------------------------------------------------------------------------
203   // member functions for CU description
204   // -------------------------------------------------------------------------------------------------------------------
205 
getPic()206   TComPic*        getPic              ()                        { return m_pcPic;           }
getPic()207   const TComPic*  getPic              () const                  { return m_pcPic;           }
getSlice()208   TComSlice*       getSlice           ()                        { return m_pcSlice;         }
getSlice()209   const TComSlice* getSlice           () const                  { return m_pcSlice;         }
getCtuRsAddr()210   UInt&         getCtuRsAddr          ()                        { return m_ctuRsAddr;       }
getCtuRsAddr()211   UInt          getCtuRsAddr          () const                  { return m_ctuRsAddr;       }
getZorderIdxInCtu()212   UInt          getZorderIdxInCtu     () const                  { return m_absZIdxInCtu;    }
getCUPelX()213   UInt          getCUPelX             () const                  { return m_uiCUPelX;        }
getCUPelY()214   UInt          getCUPelY             () const                  { return m_uiCUPelY;        }
215 
getDepth()216   UChar*        getDepth              ()                        { return m_puhDepth;        }
getDepth(UInt uiIdx)217   UChar         getDepth              ( UInt uiIdx ) const      { return m_puhDepth[uiIdx]; }
setDepth(UInt uiIdx,UChar uh)218   Void          setDepth              ( UInt uiIdx, UChar  uh ) { m_puhDepth[uiIdx] = uh;   }
219 
220   Void          setDepthSubParts      ( UInt uiDepth, UInt uiAbsPartIdx );
221 
222   // -------------------------------------------------------------------------------------------------------------------
223   // member functions for CU data
224   // -------------------------------------------------------------------------------------------------------------------
225 
getPartitionSize()226   Char*         getPartitionSize      ()                        { return m_pePartSize;        }
getPartitionSize(UInt uiIdx)227   PartSize      getPartitionSize      ( UInt uiIdx )            { return static_cast<PartSize>( m_pePartSize[uiIdx] ); }
setPartitionSize(UInt uiIdx,PartSize uh)228   Void          setPartitionSize      ( UInt uiIdx, PartSize uh){ m_pePartSize[uiIdx] = uh;   }
229   Void          setPartSizeSubParts   ( PartSize eMode, UInt uiAbsPartIdx, UInt uiDepth );
230   Void          setCUTransquantBypassSubParts( Bool flag, UInt uiAbsPartIdx, UInt uiDepth );
231 
getSkipFlag()232   Bool*         getSkipFlag            ()                        { return m_skipFlag;          }
getSkipFlag(UInt idx)233   Bool          getSkipFlag            (UInt idx)                { return m_skipFlag[idx];     }
setSkipFlag(UInt idx,Bool skip)234   Void          setSkipFlag           ( UInt idx, Bool skip)     { m_skipFlag[idx] = skip;   }
235   Void          setSkipFlagSubParts   ( Bool skip, UInt absPartIdx, UInt depth );
236 
getPredictionMode()237   Char*         getPredictionMode     ()                        { return m_pePredMode;        }
getPredictionMode(UInt uiIdx)238   PredMode      getPredictionMode     ( UInt uiIdx )            { return static_cast<PredMode>( m_pePredMode[uiIdx] ); }
setPredictionMode(UInt uiIdx,PredMode uh)239   Void          setPredictionMode     ( UInt uiIdx, PredMode uh){ m_pePredMode[uiIdx] = uh;   }
240   Void          setPredModeSubParts   ( PredMode eMode, UInt uiAbsPartIdx, UInt uiDepth );
241 
getCrossComponentPredictionAlpha(ComponentID compID)242   Char*         getCrossComponentPredictionAlpha( ComponentID compID )             { return m_crossComponentPredictionAlpha[compID];         }
getCrossComponentPredictionAlpha(UInt uiIdx,ComponentID compID)243   Char          getCrossComponentPredictionAlpha( UInt uiIdx, ComponentID compID ) { return m_crossComponentPredictionAlpha[compID][uiIdx];  }
244 
getCUTransquantBypass()245   Bool*         getCUTransquantBypass ()                        { return m_CUTransquantBypass;        }
getCUTransquantBypass(UInt uiIdx)246   Bool          getCUTransquantBypass( UInt uiIdx )             { return m_CUTransquantBypass[uiIdx]; }
247 
getWidth()248   UChar*        getWidth              ()                        { return m_puhWidth;          }
getWidth(UInt uiIdx)249   UChar         getWidth              ( UInt uiIdx )            { return m_puhWidth[uiIdx];   }
setWidth(UInt uiIdx,UChar uh)250   Void          setWidth              ( UInt uiIdx, UChar  uh ) { m_puhWidth[uiIdx] = uh;     }
251 
getHeight()252   UChar*        getHeight             ()                        { return m_puhHeight;         }
getHeight(UInt uiIdx)253   UChar         getHeight             ( UInt uiIdx )            { return m_puhHeight[uiIdx];  }
setHeight(UInt uiIdx,UChar uh)254   Void          setHeight             ( UInt uiIdx, UChar  uh ) { m_puhHeight[uiIdx] = uh;    }
255 
256   Void          setSizeSubParts       ( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, UInt uiDepth );
257 
getQP()258   Char*         getQP                 ()                        { return m_phQP;              }
getQP(UInt uiIdx)259   Char          getQP                 ( UInt uiIdx ) const      { return m_phQP[uiIdx];       }
setQP(UInt uiIdx,Char value)260   Void          setQP                 ( UInt uiIdx, Char value ){ m_phQP[uiIdx] =  value;     }
261   Void          setQPSubParts         ( Int qp,   UInt uiAbsPartIdx, UInt uiDepth );
262   Int           getLastValidPartIdx   ( Int iAbsPartIdx );
263   Char          getLastCodedQP        ( UInt uiAbsPartIdx );
264   Void          setQPSubCUs           ( Int qp, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf );
setCodedQP(Char qp)265   Void          setCodedQP            ( Char qp )               { m_codedQP = qp;             }
getCodedQP()266   Char          getCodedQP            ()                        { return m_codedQP;           }
267 
getChromaQpAdj()268   UChar*        getChromaQpAdj        ()                        { return m_ChromaQpAdj;       }
getChromaQpAdj(Int idx)269   UChar         getChromaQpAdj        (Int idx)           const { return m_ChromaQpAdj[idx];  }
setChromaQpAdj(Int idx,UChar val)270   Void          setChromaQpAdj        (Int idx, UChar val)      { m_ChromaQpAdj[idx] = val;   }
271   Void          setChromaQpAdjSubParts( UChar val, Int absPartIdx, Int depth );
setCodedChromaQpAdj(Char qp)272   Void          setCodedChromaQpAdj   ( Char qp )               { m_codedChromaQpAdj = qp;    }
getCodedChromaQpAdj()273   Char          getCodedChromaQpAdj   ()                        { return m_codedChromaQpAdj;  }
274 
275   Bool          isLosslessCoded       ( UInt absPartIdx );
276 
getTransformIdx()277   UChar*        getTransformIdx       ()                        { return m_puhTrIdx;          }
getTransformIdx(UInt uiIdx)278   UChar         getTransformIdx       ( UInt uiIdx )            { return m_puhTrIdx[uiIdx];   }
279   Void          setTrIdxSubParts      ( UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth );
280 
getTransformSkip(ComponentID compID)281   UChar*        getTransformSkip      ( ComponentID compID )    { return m_puhTransformSkip[compID];}
getTransformSkip(UInt uiIdx,ComponentID compID)282   UChar         getTransformSkip      ( UInt uiIdx, ComponentID compID)    { return m_puhTransformSkip[compID][uiIdx];}
283   Void          setTransformSkipSubParts  ( UInt useTransformSkip, ComponentID compID, UInt uiAbsPartIdx, UInt uiDepth);
284   Void          setTransformSkipSubParts  ( const UInt useTransformSkip[MAX_NUM_COMPONENT], UInt uiAbsPartIdx, UInt uiDepth );
285 
getExplicitRdpcmMode(ComponentID component)286   UChar*        getExplicitRdpcmMode      ( ComponentID component ) { return m_explicitRdpcmMode[component]; }
getExplicitRdpcmMode(ComponentID component,UInt partIdx)287   UChar         getExplicitRdpcmMode      ( ComponentID component, UInt partIdx ) {return m_explicitRdpcmMode[component][partIdx]; }
288   Void          setExplicitRdpcmModePartRange ( UInt rdpcmMode, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes );
289 
isRDPCMEnabled(UInt uiAbsPartIdx)290   Bool          isRDPCMEnabled         ( UInt uiAbsPartIdx )  { return getSlice()->getSPS()->getUseResidualDPCM(isIntra(uiAbsPartIdx) ? RDPCM_SIGNAL_IMPLICIT : RDPCM_SIGNAL_EXPLICIT); }
291 
292   Void          setCrossComponentPredictionAlphaPartRange    ( Char alphaValue, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes );
293   Void          setTransformSkipPartRange                    ( UInt useTransformSkip, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes );
294 
295   UInt          getQuadtreeTULog2MinSizeInCU( UInt uiIdx );
296 
getCUMvField(RefPicList e)297   TComCUMvField* getCUMvField         ( RefPicList e )          { return  &m_acCUMvField[e];  }
298 
getCoeff(ComponentID component)299   TCoeff*       getCoeff              (ComponentID component)   { return m_pcTrCoeff[component]; }
300 
301 #if ADAPTIVE_QP_SELECTION
getArlCoeff(ComponentID component)302   TCoeff*       getArlCoeff           ( ComponentID component ) { return m_pcArlCoeff[component]; }
303 #endif
getPCMSample(ComponentID component)304   Pel*          getPCMSample          ( ComponentID component ) { return m_pcIPCMSample[component]; }
305 
getCbf(UInt uiIdx,ComponentID eType)306   UChar         getCbf    ( UInt uiIdx, ComponentID eType )                  { return m_puhCbf[eType][uiIdx];  }
getCbf(ComponentID eType)307   UChar*        getCbf    ( ComponentID eType )                              { return m_puhCbf[eType];         }
getCbf(UInt uiIdx,ComponentID eType,UInt uiTrDepth)308   UChar         getCbf    ( UInt uiIdx, ComponentID eType, UInt uiTrDepth )  { return ( ( getCbf( uiIdx, eType ) >> uiTrDepth ) & 0x1 ); }
setCbf(UInt uiIdx,ComponentID eType,UChar uh)309   Void          setCbf    ( UInt uiIdx, ComponentID eType, UChar uh )        { m_puhCbf[eType][uiIdx] = uh;    }
310   Void          clearCbf  ( UInt uiIdx, ComponentID eType, UInt uiNumParts );
311   UChar         getQtRootCbf          ( UInt uiIdx );
312 
313   Void          setCbfSubParts        ( const UInt uiCbf[MAX_NUM_COMPONENT],  UInt uiAbsPartIdx, UInt uiDepth           );
314   Void          setCbfSubParts        ( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiDepth                    );
315   Void          setCbfSubParts        ( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth    );
316 
317   Void          setCbfPartRange       ( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes      );
318   Void          bitwiseOrCbfPartRange ( UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes      );
319 
320   // -------------------------------------------------------------------------------------------------------------------
321   // member functions for coding tool information
322   // -------------------------------------------------------------------------------------------------------------------
323 
getMergeFlag()324   Bool*         getMergeFlag          ()                        { return m_pbMergeFlag;               }
getMergeFlag(UInt uiIdx)325   Bool          getMergeFlag          ( UInt uiIdx )            { return m_pbMergeFlag[uiIdx];        }
setMergeFlag(UInt uiIdx,Bool b)326   Void          setMergeFlag          ( UInt uiIdx, Bool b )    { m_pbMergeFlag[uiIdx] = b;           }
327   Void          setMergeFlagSubParts  ( Bool bMergeFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
328 
getMergeIndex()329   UChar*        getMergeIndex         ()                        { return m_puhMergeIndex;                         }
getMergeIndex(UInt uiIdx)330   UChar         getMergeIndex         ( UInt uiIdx )            { return m_puhMergeIndex[uiIdx];                  }
setMergeIndex(UInt uiIdx,UInt uiMergeIndex)331   Void          setMergeIndex         ( UInt uiIdx, UInt uiMergeIndex ) { m_puhMergeIndex[uiIdx] = uiMergeIndex;  }
332   Void          setMergeIndexSubParts ( UInt uiMergeIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
333   template <typename T>
334   Void          setSubPart            ( T bParameter, T* pbBaseCtu, UInt uiCUAddr, UInt uiCUDepth, UInt uiPUIdx );
335 
336 #if AMP_MRG
setMergeAMP(Bool b)337   Void          setMergeAMP( Bool b )      { m_bIsMergeAMP = b; }
getMergeAMP()338   Bool          getMergeAMP( )             { return m_bIsMergeAMP; }
339 #endif
340 
getIntraDir(const ChannelType channelType)341   UChar*        getIntraDir         ( const ChannelType channelType )                   const { return m_puhIntraDir[channelType];         }
getIntraDir(const ChannelType channelType,const UInt uiIdx)342   UChar         getIntraDir         ( const ChannelType channelType, const UInt uiIdx ) const { return m_puhIntraDir[channelType][uiIdx];  }
343 
344   Void          setIntraDirSubParts ( const ChannelType channelType,
345                                       const UInt uiDir,
346                                       const UInt uiAbsPartIdx,
347                                       const UInt uiDepth );
348 
getInterDir()349   UChar*        getInterDir           ()                        { return m_puhInterDir;               }
getInterDir(UInt uiIdx)350   UChar         getInterDir           ( UInt uiIdx )            { return m_puhInterDir[uiIdx];        }
setInterDir(UInt uiIdx,UChar uh)351   Void          setInterDir           ( UInt uiIdx, UChar  uh ) { m_puhInterDir[uiIdx] = uh;          }
352   Void          setInterDirSubParts   ( UInt uiDir,  UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
getIPCMFlag()353   Bool*         getIPCMFlag           ()                        { return m_pbIPCMFlag;               }
getIPCMFlag(UInt uiIdx)354   Bool          getIPCMFlag           (UInt uiIdx )             { return m_pbIPCMFlag[uiIdx];        }
setIPCMFlag(UInt uiIdx,Bool b)355   Void          setIPCMFlag           (UInt uiIdx, Bool b )     { m_pbIPCMFlag[uiIdx] = b;           }
356   Void          setIPCMFlagSubParts   (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth);
357 
358   // -------------------------------------------------------------------------------------------------------------------
359   // member functions for accessing partition information
360   // -------------------------------------------------------------------------------------------------------------------
361 
362   Void          getPartIndexAndSize   ( UInt uiPartIdx, UInt& ruiPartAddr, Int& riWidth, Int& riHeight );
363   UChar         getNumPartitions      ( const UInt uiAbsPartIdx = 0 );
364   Bool          isFirstAbsZorderIdxInDepth (UInt uiAbsPartIdx, UInt uiDepth);
365 
366   // -------------------------------------------------------------------------------------------------------------------
367   // member functions for motion vector
368   // -------------------------------------------------------------------------------------------------------------------
369 
370   Void          getMvField            ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefPicList, TComMvField& rcMvField );
371 
372   Void          fillMvpCand           ( UInt uiPartIdx, UInt uiPartAddr, RefPicList eRefPicList, Int iRefIdx, AMVPInfo* pInfo );
373   Bool          isDiffMER             ( Int xN, Int yN, Int xP, Int yP);
374   Void          getPartPosition       ( UInt partIdx, Int& xP, Int& yP, Int& nPSW, Int& nPSH);
375 
setMVPIdx(RefPicList eRefPicList,UInt uiIdx,Int iMVPIdx)376   Void          setMVPIdx             ( RefPicList eRefPicList, UInt uiIdx, Int iMVPIdx)  { m_apiMVPIdx[eRefPicList][uiIdx] = iMVPIdx;  }
getMVPIdx(RefPicList eRefPicList,UInt uiIdx)377   Int           getMVPIdx             ( RefPicList eRefPicList, UInt uiIdx)               { return m_apiMVPIdx[eRefPicList][uiIdx];     }
getMVPIdx(RefPicList eRefPicList)378   Char*         getMVPIdx             ( RefPicList eRefPicList )                          { return m_apiMVPIdx[eRefPicList];            }
379 
setMVPNum(RefPicList eRefPicList,UInt uiIdx,Int iMVPNum)380   Void          setMVPNum             ( RefPicList eRefPicList, UInt uiIdx, Int iMVPNum ) { m_apiMVPNum[eRefPicList][uiIdx] = iMVPNum;  }
getMVPNum(RefPicList eRefPicList,UInt uiIdx)381   Int           getMVPNum             ( RefPicList eRefPicList, UInt uiIdx )              { return m_apiMVPNum[eRefPicList][uiIdx];     }
getMVPNum(RefPicList eRefPicList)382   Char*         getMVPNum             ( RefPicList eRefPicList )                          { return m_apiMVPNum[eRefPicList];            }
383 
384   Void          setMVPIdxSubParts     ( Int iMVPIdx, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
385   Void          setMVPNumSubParts     ( Int iMVPNum, RefPicList eRefPicList, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth );
386 
387   Void          clipMv                ( TComMv&     rcMv     );
getMvPredLeft(TComMv & rcMvPred)388   Void          getMvPredLeft         ( TComMv&     rcMvPred )   { rcMvPred = m_cMvFieldA.getMv(); }
getMvPredAbove(TComMv & rcMvPred)389   Void          getMvPredAbove        ( TComMv&     rcMvPred )   { rcMvPred = m_cMvFieldB.getMv(); }
getMvPredAboveRight(TComMv & rcMvPred)390   Void          getMvPredAboveRight   ( TComMv&     rcMvPred )   { rcMvPred = m_cMvFieldC.getMv(); }
391 
392   Void          compressMV            ();
393 
394   // -------------------------------------------------------------------------------------------------------------------
395   // utility functions for neighbouring information
396   // -------------------------------------------------------------------------------------------------------------------
397 
getCtuLeft()398   TComDataCU*   getCtuLeft                  () { return m_pCtuLeft;       }
getCtuAbove()399   TComDataCU*   getCtuAbove                 () { return m_pCtuAbove;      }
getCtuAboveLeft()400   TComDataCU*   getCtuAboveLeft             () { return m_pCtuAboveLeft;  }
getCtuAboveRight()401   TComDataCU*   getCtuAboveRight            () { return m_pCtuAboveRight; }
getCUColocated(RefPicList eRefPicList)402   TComDataCU*   getCUColocated              ( RefPicList eRefPicList ) { return m_apcCUColocated[eRefPicList]; }
CUIsFromSameSlice(const TComDataCU * pCU)403   Bool          CUIsFromSameSlice           ( const TComDataCU *pCU /* Can be NULL */) const { return ( pCU!=NULL && pCU->getSlice()->getSliceCurStartCtuTsAddr() == getSlice()->getSliceCurStartCtuTsAddr() ); }
404   Bool          CUIsFromSameTile            ( const TComDataCU *pCU /* Can be NULL */) const;
405   Bool          CUIsFromSameSliceAndTile    ( const TComDataCU *pCU /* Can be NULL */) const;
406   Bool          CUIsFromSameSliceTileAndWavefrontRow( const TComDataCU *pCU /* Can be NULL */) const;
407   Bool          isLastSubCUOfCtu(const UInt absPartIdx);
408 
409 
410   TComDataCU*   getPULeft                   ( UInt&  uiLPartUnitIdx,
411                                               UInt uiCurrPartUnitIdx,
412                                               Bool bEnforceSliceRestriction=true,
413                                               Bool bEnforceTileRestriction=true );
414   TComDataCU*   getPUAbove                  ( UInt&  uiAPartUnitIdx,
415                                               UInt uiCurrPartUnitIdx,
416                                               Bool bEnforceSliceRestriction=true,
417                                               Bool planarAtCTUBoundary = false,
418                                               Bool bEnforceTileRestriction=true );
419   TComDataCU*   getPUAboveLeft              ( UInt&  uiALPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction=true );
420   TComDataCU*   getPUAboveRight             ( UInt&  uiARPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction=true );
421   TComDataCU*   getPUBelowLeft              ( UInt&  uiBLPartUnitIdx, UInt uiCurrPartUnitIdx, Bool bEnforceSliceRestriction=true );
422 
423   TComDataCU*   getQpMinCuLeft              ( UInt&  uiLPartUnitIdx , UInt uiCurrAbsIdxInCtu );
424   TComDataCU*   getQpMinCuAbove             ( UInt&  uiAPartUnitIdx , UInt uiCurrAbsIdxInCtu );
425   Char          getRefQP                    ( UInt   uiCurrAbsIdxInCtu                       );
426 
427   TComDataCU*   getPUAboveRightAdi          ( UInt&  uiARPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset = 1, Bool bEnforceSliceRestriction=true );
428   TComDataCU*   getPUBelowLeftAdi           ( UInt&  uiBLPartUnitIdx, UInt uiCurrPartUnitIdx, UInt uiPartUnitOffset = 1, Bool bEnforceSliceRestriction=true );
429 
430   Void          deriveLeftRightTopIdx       ( UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT );
431   Void          deriveLeftBottomIdx         ( UInt uiPartIdx, UInt& ruiPartIdxLB );
432 
433   Void          deriveLeftRightTopIdxAdi    ( UInt& ruiPartIdxLT, UInt& ruiPartIdxRT, UInt uiPartOffset, UInt uiPartDepth );
434   Void          deriveLeftBottomIdxAdi      ( UInt& ruiPartIdxLB, UInt  uiPartOffset, UInt uiPartDepth ); // NOTE: Unused function.
435 
436   Bool          hasEqualMotion              ( UInt uiAbsPartIdx, TComDataCU* pcCandCU, UInt uiCandAbsPartIdx );
437   Void          getInterMergeCandidates       ( UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField* pcMFieldNeighbours, UChar* puhInterDirNeighbours, Int& numValidMergeCand, Int mrgCandIdx = -1 );
438 
439   Void          deriveLeftRightTopIdxGeneral  ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLT, UInt& ruiPartIdxRT );
440   Void          deriveLeftBottomIdxGeneral    ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLB );
441 
442   // -------------------------------------------------------------------------------------------------------------------
443   // member functions for modes
444   // -------------------------------------------------------------------------------------------------------------------
445 
isIntra(UInt uiPartIdx)446   Bool          isIntra            ( UInt uiPartIdx )  const { return m_pePredMode[ uiPartIdx ] == MODE_INTRA;                                              }
isInter(UInt uiPartIdx)447   Bool          isInter            ( UInt uiPartIdx )  const { return m_pePredMode[ uiPartIdx ] == MODE_INTER;                                              }
448   Bool          isSkipped          ( UInt uiPartIdx );                                                     ///< SKIP (no residual)
449   Bool          isBipredRestriction( UInt puIdx );
450 
451   // -------------------------------------------------------------------------------------------------------------------
452   // member functions for symbol prediction (most probable / mode conversion)
453   // -------------------------------------------------------------------------------------------------------------------
454 
455   UInt          getIntraSizeIdx                 ( UInt uiAbsPartIdx                                       );
456 
457   Void          getAllowedChromaDir             ( UInt uiAbsPartIdx, UInt* uiModeList );
458   Int           getIntraDirPredictor            ( UInt uiAbsPartIdx, Int uiIntraDirPred[NUM_MOST_PROBABLE_MODES], const ComponentID compID, Int* piMode = NULL );
459 
460   // -------------------------------------------------------------------------------------------------------------------
461   // member functions for SBAC context
462   // -------------------------------------------------------------------------------------------------------------------
463 
464   UInt          getCtxSplitFlag                 ( UInt   uiAbsPartIdx, UInt uiDepth                   );
465   UInt          getCtxQtCbf                     ( TComTU &rTu, const ChannelType chType );
466 
467   UInt          getCtxSkipFlag                  ( UInt   uiAbsPartIdx                                 );
468   UInt          getCtxInterDir                  ( UInt   uiAbsPartIdx                                 );
469 
getTotalBins()470   UInt&         getTotalBins            ()                            { return m_uiTotalBins;                              }
471   // -------------------------------------------------------------------------------------------------------------------
472   // member functions for RD cost storage
473   // -------------------------------------------------------------------------------------------------------------------
474 
getTotalCost()475   Double&       getTotalCost()                  { return m_dTotalCost;        }
getTotalDistortion()476   Distortion&   getTotalDistortion()            { return m_uiTotalDistortion; }
getTotalBits()477   UInt&         getTotalBits()                  { return m_uiTotalBits;       }
getTotalNumPart()478   UInt&         getTotalNumPart()               { return m_uiNumPartition;    }
479 
480   UInt          getCoefScanIdx(const UInt uiAbsPartIdx, const UInt uiWidth, const UInt uiHeight, const ComponentID compID) const ;
481 
482 };
483 
484 namespace RasterAddress
485 {
486   /** Check whether 2 addresses point to the same column
487    * \param addrA          First address in raster scan order
488    * \param addrB          Second address in raters scan order
489    * \param numUnitsPerRow Number of units in a row
490    * \return Result of test
491    */
isEqualCol(Int addrA,Int addrB,Int numUnitsPerRow)492   static inline Bool isEqualCol( Int addrA, Int addrB, Int numUnitsPerRow )
493   {
494     // addrA % numUnitsPerRow == addrB % numUnitsPerRow
495     return (( addrA ^ addrB ) &  ( numUnitsPerRow - 1 ) ) == 0;
496   }
497 
498   /** Check whether 2 addresses point to the same row
499    * \param addrA          First address in raster scan order
500    * \param addrB          Second address in raters scan order
501    * \param numUnitsPerRow Number of units in a row
502    * \return Result of test
503    */
isEqualRow(Int addrA,Int addrB,Int numUnitsPerRow)504   static inline Bool isEqualRow( Int addrA, Int addrB, Int numUnitsPerRow )
505   {
506     // addrA / numUnitsPerRow == addrB / numUnitsPerRow
507     return (( addrA ^ addrB ) &~ ( numUnitsPerRow - 1 ) ) == 0;
508   }
509 
510   /** Check whether 2 addresses point to the same row or column
511    * \param addrA          First address in raster scan order
512    * \param addrB          Second address in raters scan order
513    * \param numUnitsPerRow Number of units in a row
514    * \return Result of test
515    */
isEqualRowOrCol(Int addrA,Int addrB,Int numUnitsPerRow)516   static inline Bool isEqualRowOrCol( Int addrA, Int addrB, Int numUnitsPerRow )
517   {
518     return isEqualCol( addrA, addrB, numUnitsPerRow ) | isEqualRow( addrA, addrB, numUnitsPerRow );
519   }
520 
521   /** Check whether one address points to the first column
522    * \param addr           Address in raster scan order
523    * \param numUnitsPerRow Number of units in a row
524    * \return Result of test
525    */
isZeroCol(Int addr,Int numUnitsPerRow)526   static inline Bool isZeroCol( Int addr, Int numUnitsPerRow )
527   {
528     // addr % numUnitsPerRow == 0
529     return ( addr & ( numUnitsPerRow - 1 ) ) == 0;
530   }
531 
532   /** Check whether one address points to the first row
533    * \param addr           Address in raster scan order
534    * \param numUnitsPerRow Number of units in a row
535    * \return Result of test
536    */
isZeroRow(Int addr,Int numUnitsPerRow)537   static inline Bool isZeroRow( Int addr, Int numUnitsPerRow )
538   {
539     // addr / numUnitsPerRow == 0
540     return ( addr &~ ( numUnitsPerRow - 1 ) ) == 0;
541   }
542 
543   /** Check whether one address points to a column whose index is smaller than a given value
544    * \param addr           Address in raster scan order
545    * \param val            Given column index value
546    * \param numUnitsPerRow Number of units in a row
547    * \return Result of test
548    */
lessThanCol(Int addr,Int val,Int numUnitsPerRow)549   static inline Bool lessThanCol( Int addr, Int val, Int numUnitsPerRow )
550   {
551     // addr % numUnitsPerRow < val
552     return ( addr & ( numUnitsPerRow - 1 ) ) < val;
553   }
554 
555   /** Check whether one address points to a row whose index is smaller than a given value
556    * \param addr           Address in raster scan order
557    * \param val            Given row index value
558    * \param numUnitsPerRow Number of units in a row
559    * \return Result of test
560    */
lessThanRow(Int addr,Int val,Int numUnitsPerRow)561   static inline Bool lessThanRow( Int addr, Int val, Int numUnitsPerRow )
562   {
563     // addr / numUnitsPerRow < val
564     return addr < val * numUnitsPerRow;
565   }
566 }
567 
568 //! \}
569 
570 #endif
571