[5] | 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 |
---|
[56] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[1412] | 6 | * Copyright (c) 2010-2017, ITU/ISO/IEC |
---|
[5] | 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. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 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 | */ |
---|
[2] | 33 | |
---|
| 34 | /** \file TComMotionInfo.h |
---|
| 35 | \brief motion information handling classes (header) |
---|
| 36 | \todo TComMvField seems to be better to be inherited from TComMv |
---|
| 37 | */ |
---|
| 38 | |
---|
| 39 | #ifndef __TCOMMOTIONINFO__ |
---|
| 40 | #define __TCOMMOTIONINFO__ |
---|
| 41 | |
---|
| 42 | #include <memory.h> |
---|
| 43 | #include "CommonDef.h" |
---|
| 44 | #include "TComMv.h" |
---|
[1321] | 45 | |
---|
[56] | 46 | //! \ingroup TLibCommon |
---|
| 47 | //! \{ |
---|
| 48 | |
---|
[2] | 49 | // ==================================================================================================================== |
---|
| 50 | // Type definition |
---|
| 51 | // ==================================================================================================================== |
---|
| 52 | |
---|
[1412] | 53 | #if NH_3D |
---|
[724] | 54 | class TComDataCU; |
---|
| 55 | #endif |
---|
[2] | 56 | /// parameters for AMVP |
---|
| 57 | typedef struct _AMVPInfo |
---|
| 58 | { |
---|
[1386] | 59 | TComMv m_acMvCand[ AMVP_MAX_NUM_CANDS ]; ///< array of motion vector predictor candidates |
---|
[2] | 60 | Int iN; ///< number of motion vector predictor candidates |
---|
[1412] | 61 | #if MCTS_ENC_CHECK |
---|
| 62 | UInt numSpatialMVPCandidates; |
---|
| 63 | #endif |
---|
[2] | 64 | } AMVPInfo; |
---|
| 65 | |
---|
[1412] | 66 | #if NH_3D |
---|
[608] | 67 | typedef struct _DisCand |
---|
[100] | 68 | { |
---|
[608] | 69 | TComMv m_acNBDV; // DV from NBDV |
---|
| 70 | TComMv m_acDoNBDV; // DV from DoNBDV |
---|
| 71 | Int m_aVIdxCan; // View order index (the same with the NBDV and the DoNBDV) |
---|
[100] | 72 | } DisInfo; |
---|
[332] | 73 | |
---|
[608] | 74 | typedef struct _IDVCand // IDV |
---|
[332] | 75 | { |
---|
[608] | 76 | TComMv m_acMvCand[2][ IDV_CANDS ]; |
---|
| 77 | Int m_aVIdxCan[2][ IDV_CANDS ]; |
---|
| 78 | Bool m_bAvailab[2][ IDV_CANDS ]; |
---|
| 79 | Bool m_bFound; |
---|
| 80 | } IDVInfo; |
---|
| 81 | #endif |
---|
[1084] | 82 | |
---|
[608] | 83 | // ==================================================================================================================== |
---|
[2] | 84 | // Class definition |
---|
| 85 | // ==================================================================================================================== |
---|
| 86 | |
---|
| 87 | /// class for motion vector with reference index |
---|
| 88 | class TComMvField |
---|
| 89 | { |
---|
| 90 | private: |
---|
| 91 | TComMv m_acMv; |
---|
| 92 | Int m_iRefIdx; |
---|
| 93 | |
---|
| 94 | public: |
---|
[56] | 95 | TComMvField() : m_iRefIdx( NOT_VALID ) {} |
---|
[2] | 96 | |
---|
[56] | 97 | Void setMvField( TComMv const & cMv, Int iRefIdx ) |
---|
[2] | 98 | { |
---|
| 99 | m_acMv = cMv; |
---|
| 100 | m_iRefIdx = iRefIdx; |
---|
| 101 | } |
---|
| 102 | |
---|
[56] | 103 | Void setRefIdx( Int refIdx ) { m_iRefIdx = refIdx; } |
---|
[2] | 104 | |
---|
[56] | 105 | TComMv const & getMv() const { return m_acMv; } |
---|
| 106 | TComMv & getMv() { return m_acMv; } |
---|
| 107 | |
---|
| 108 | Int getRefIdx() const { return m_iRefIdx; } |
---|
| 109 | Int getHor () const { return m_acMv.getHor(); } |
---|
| 110 | Int getVer () const { return m_acMv.getVer(); } |
---|
[1412] | 111 | #if NH_3D |
---|
[189] | 112 | Bool operator== ( const TComMvField& rcMv ) const |
---|
| 113 | { |
---|
| 114 | return (m_acMv.getHor()==rcMv.getHor() && m_acMv.getVer()==rcMv.getVer() && m_iRefIdx == rcMv.getRefIdx()); |
---|
| 115 | } |
---|
| 116 | #endif |
---|
[2] | 117 | }; |
---|
| 118 | |
---|
| 119 | /// class for motion information in one CU |
---|
| 120 | class TComCUMvField |
---|
| 121 | { |
---|
| 122 | private: |
---|
| 123 | TComMv* m_pcMv; |
---|
| 124 | TComMv* m_pcMvd; |
---|
[1386] | 125 | SChar* m_piRefIdx; |
---|
[2] | 126 | UInt m_uiNumPartition; |
---|
| 127 | AMVPInfo m_cAMVPInfo; |
---|
[56] | 128 | |
---|
| 129 | template <typename T> |
---|
| 130 | Void setAll( T *p, T const & val, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx ); |
---|
| 131 | |
---|
[2] | 132 | public: |
---|
[56] | 133 | TComCUMvField() : m_pcMv(NULL), m_pcMvd(NULL), m_piRefIdx(NULL), m_uiNumPartition(0) {} |
---|
| 134 | ~TComCUMvField() {} |
---|
| 135 | |
---|
[2] | 136 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 137 | // create / destroy |
---|
| 138 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 139 | |
---|
[56] | 140 | Void create( UInt uiNumPartition ); |
---|
| 141 | Void destroy(); |
---|
[2] | 142 | |
---|
| 143 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 144 | // clear / copy |
---|
| 145 | // ------------------------------------------------------------------------------------------------------------------ |
---|
[56] | 146 | |
---|
| 147 | Void clearMvField(); |
---|
[2] | 148 | |
---|
[56] | 149 | Void copyFrom( TComCUMvField const * pcCUMvFieldSrc, Int iNumPartSrc, Int iPartAddrDst ); |
---|
| 150 | Void copyTo ( TComCUMvField* pcCUMvFieldDst, Int iPartAddrDst ) const; |
---|
| 151 | Void copyTo ( TComCUMvField* pcCUMvFieldDst, Int iPartAddrDst, UInt uiOffset, UInt uiNumPart ) const; |
---|
[2] | 152 | |
---|
| 153 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 154 | // get |
---|
| 155 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 156 | |
---|
[56] | 157 | TComMv const & getMv ( Int iIdx ) const { return m_pcMv [iIdx]; } |
---|
| 158 | TComMv const & getMvd ( Int iIdx ) const { return m_pcMvd [iIdx]; } |
---|
| 159 | Int getRefIdx( Int iIdx ) const { return m_piRefIdx[iIdx]; } |
---|
[2] | 160 | |
---|
| 161 | AMVPInfo* getAMVPInfo () { return &m_cAMVPInfo; } |
---|
[56] | 162 | |
---|
[2] | 163 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 164 | // set |
---|
| 165 | // ------------------------------------------------------------------------------------------------------------------ |
---|
| 166 | |
---|
[56] | 167 | Void setAllMv ( TComMv const & rcMv, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 ); |
---|
| 168 | Void setAllMvd ( TComMv const & rcMvd, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 ); |
---|
| 169 | Void setAllRefIdx ( Int iRefIdx, PartSize eMbMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 ); |
---|
| 170 | Void setAllMvField( TComMvField const & mvField, PartSize eMbMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 ); |
---|
[1412] | 171 | #if NH_3D |
---|
[724] | 172 | Void setMvFieldSP ( TComDataCU* pcCU, UInt uiAbsPartIdx, TComMvField cMvField, Int iWidth, Int iHeight ); |
---|
[833] | 173 | Void setMv ( Int iIdx, TComMv const & rcMv ) { m_pcMv[iIdx] = rcMv; } |
---|
| 174 | Void setRefIdx ( Int iIdx, Int iRefIdx ) { m_piRefIdx[iIdx] = iRefIdx; } |
---|
| 175 | #endif |
---|
[56] | 176 | |
---|
| 177 | Void setNumPartition( Int iNumPart ) |
---|
| 178 | { |
---|
| 179 | m_uiNumPartition = iNumPart; |
---|
| 180 | } |
---|
[2] | 181 | |
---|
[56] | 182 | Void linkToWithOffset( TComCUMvField const * src, Int offset ) |
---|
| 183 | { |
---|
| 184 | m_pcMv = src->m_pcMv + offset; |
---|
| 185 | m_pcMvd = src->m_pcMvd + offset; |
---|
| 186 | m_piRefIdx = src->m_piRefIdx + offset; |
---|
| 187 | } |
---|
[2] | 188 | |
---|
[1412] | 189 | #if REDUCED_ENCODER_MEMORY |
---|
| 190 | Void compress(SChar *pePredMode, const SChar* pePredModeSource, const Int scale, const TComCUMvField &source); |
---|
| 191 | #else |
---|
[1386] | 192 | Void compress(SChar* pePredMode, Int scale); |
---|
[1412] | 193 | #endif |
---|
[1321] | 194 | #if NH_MV |
---|
[1386] | 195 | Void print (SChar* pePredMode); |
---|
[1321] | 196 | #endif |
---|
[2] | 197 | }; |
---|
| 198 | |
---|
[56] | 199 | //! \} |
---|
| 200 | |
---|
[1412] | 201 | #if NH_3D |
---|
[1313] | 202 | /// class for container of merge candidate |
---|
[950] | 203 | class TComMotionCand |
---|
| 204 | { |
---|
| 205 | public: |
---|
| 206 | Bool m_bAvailable; |
---|
| 207 | TComMvField m_cMvField[2]; |
---|
| 208 | UChar m_uDir; |
---|
| 209 | Int m_iVspFlag; |
---|
| 210 | Bool m_bSPIVMPFlag; |
---|
| 211 | |
---|
| 212 | public: |
---|
| 213 | TComMotionCand() |
---|
| 214 | { |
---|
| 215 | m_bAvailable = false; |
---|
| 216 | m_uDir = 0; |
---|
| 217 | m_iVspFlag = 0; |
---|
| 218 | m_bSPIVMPFlag = false; |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | ~TComMotionCand() |
---|
| 222 | { |
---|
| 223 | |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | Void init() |
---|
| 227 | { |
---|
| 228 | TComMv cZeroMv; |
---|
| 229 | |
---|
| 230 | m_bAvailable = false; |
---|
| 231 | m_uDir = 0; |
---|
| 232 | m_iVspFlag = 0; |
---|
| 233 | m_bSPIVMPFlag = false; |
---|
| 234 | m_cMvField[0].setMvField(cZeroMv, NOT_VALID); |
---|
| 235 | m_cMvField[1].setMvField(cZeroMv, NOT_VALID); |
---|
| 236 | } |
---|
| 237 | |
---|
[1412] | 238 | Void setCand(TComMvField* pcMvFieldNeighbours, UChar uhInterDirNeighbours, Int vspFlag, Bool bSPIVMPFlag ) |
---|
[950] | 239 | { |
---|
| 240 | m_bAvailable = true; |
---|
| 241 | m_cMvField[0] = pcMvFieldNeighbours[0]; |
---|
| 242 | m_cMvField[1] = pcMvFieldNeighbours[1]; |
---|
| 243 | m_uDir = uhInterDirNeighbours; |
---|
| 244 | m_iVspFlag = vspFlag; |
---|
| 245 | m_bSPIVMPFlag = bSPIVMPFlag; |
---|
| 246 | } |
---|
[1313] | 247 | |
---|
[1412] | 248 | Void getCand(Int iCount, TComMvField* pcMvFieldNeighbours, UChar* puhInterDirNeighbours, Int* vspFlag , Bool* pbSPIVMPFlag ) |
---|
[950] | 249 | { |
---|
| 250 | pcMvFieldNeighbours[iCount<<1] = m_cMvField[0]; |
---|
| 251 | pcMvFieldNeighbours[(iCount<<1) + 1] = m_cMvField[1]; |
---|
| 252 | puhInterDirNeighbours[iCount] = m_uDir; |
---|
| 253 | vspFlag[iCount] = m_iVspFlag; |
---|
| 254 | pbSPIVMPFlag[iCount] = m_bSPIVMPFlag; |
---|
| 255 | } |
---|
[1321] | 256 | Void print( Int i ); |
---|
[950] | 257 | }; |
---|
[1321] | 258 | |
---|
| 259 | |
---|
[950] | 260 | #endif |
---|
| 261 | |
---|
| 262 | |
---|
[2] | 263 | #endif // __TCOMMOTIONINFO__ |
---|