[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 | * |
---|
[872] | 6 | * Copyright (c) 2010-2014, 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.cpp |
---|
| 35 | \brief motion information handling classes |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include <memory.h> |
---|
| 39 | #include "TComMotionInfo.h" |
---|
| 40 | #include "assert.h" |
---|
| 41 | #include <stdlib.h> |
---|
[773] | 42 | #if H_3D_SPIVMP |
---|
[724] | 43 | #include "TComDataCU.h" |
---|
| 44 | #include "TComPic.h" |
---|
| 45 | #endif |
---|
[2] | 46 | |
---|
[56] | 47 | //! \ingroup TLibCommon |
---|
| 48 | //! \{ |
---|
| 49 | |
---|
[2] | 50 | // ==================================================================================================================== |
---|
| 51 | // Public member functions |
---|
| 52 | // ==================================================================================================================== |
---|
| 53 | |
---|
| 54 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 55 | // Create / destroy |
---|
| 56 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 57 | |
---|
| 58 | Void TComCUMvField::create( UInt uiNumPartition ) |
---|
| 59 | { |
---|
[56] | 60 | assert(m_pcMv == NULL); |
---|
| 61 | assert(m_pcMvd == NULL); |
---|
| 62 | assert(m_piRefIdx == NULL); |
---|
[2] | 63 | |
---|
[56] | 64 | m_pcMv = new TComMv[ uiNumPartition ]; |
---|
| 65 | m_pcMvd = new TComMv[ uiNumPartition ]; |
---|
| 66 | m_piRefIdx = new Char [ uiNumPartition ]; |
---|
| 67 | |
---|
[2] | 68 | m_uiNumPartition = uiNumPartition; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | Void TComCUMvField::destroy() |
---|
| 72 | { |
---|
[56] | 73 | assert(m_pcMv != NULL); |
---|
| 74 | assert(m_pcMvd != NULL); |
---|
| 75 | assert(m_piRefIdx != NULL); |
---|
| 76 | |
---|
| 77 | delete[] m_pcMv; |
---|
| 78 | delete[] m_pcMvd; |
---|
| 79 | delete[] m_piRefIdx; |
---|
| 80 | |
---|
| 81 | m_pcMv = NULL; |
---|
| 82 | m_pcMvd = NULL; |
---|
| 83 | m_piRefIdx = NULL; |
---|
| 84 | |
---|
| 85 | m_uiNumPartition = 0; |
---|
[2] | 86 | } |
---|
| 87 | |
---|
| 88 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 89 | // Clear / copy |
---|
| 90 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 91 | |
---|
| 92 | Void TComCUMvField::clearMvField() |
---|
| 93 | { |
---|
[56] | 94 | for ( Int i = 0; i < m_uiNumPartition; i++ ) |
---|
[2] | 95 | { |
---|
[56] | 96 | m_pcMv [ i ].setZero(); |
---|
| 97 | m_pcMvd[ i ].setZero(); |
---|
[2] | 98 | } |
---|
[56] | 99 | assert( sizeof( *m_piRefIdx ) == 1 ); |
---|
| 100 | memset( m_piRefIdx, NOT_VALID, m_uiNumPartition * sizeof( *m_piRefIdx ) ); |
---|
[2] | 101 | } |
---|
| 102 | |
---|
[56] | 103 | Void TComCUMvField::copyFrom( TComCUMvField const * pcCUMvFieldSrc, Int iNumPartSrc, Int iPartAddrDst ) |
---|
[2] | 104 | { |
---|
| 105 | Int iSizeInTComMv = sizeof( TComMv ) * iNumPartSrc; |
---|
| 106 | |
---|
[56] | 107 | memcpy( m_pcMv + iPartAddrDst, pcCUMvFieldSrc->m_pcMv, iSizeInTComMv ); |
---|
| 108 | memcpy( m_pcMvd + iPartAddrDst, pcCUMvFieldSrc->m_pcMvd, iSizeInTComMv ); |
---|
| 109 | memcpy( m_piRefIdx + iPartAddrDst, pcCUMvFieldSrc->m_piRefIdx, sizeof( *m_piRefIdx ) * iNumPartSrc ); |
---|
[2] | 110 | } |
---|
| 111 | |
---|
[56] | 112 | Void TComCUMvField::copyTo( TComCUMvField* pcCUMvFieldDst, Int iPartAddrDst ) const |
---|
[2] | 113 | { |
---|
[56] | 114 | copyTo( pcCUMvFieldDst, iPartAddrDst, 0, m_uiNumPartition ); |
---|
[2] | 115 | } |
---|
| 116 | |
---|
[56] | 117 | Void TComCUMvField::copyTo( TComCUMvField* pcCUMvFieldDst, Int iPartAddrDst, UInt uiOffset, UInt uiNumPart ) const |
---|
[2] | 118 | { |
---|
| 119 | Int iSizeInTComMv = sizeof( TComMv ) * uiNumPart; |
---|
| 120 | Int iOffset = uiOffset + iPartAddrDst; |
---|
| 121 | |
---|
[56] | 122 | memcpy( pcCUMvFieldDst->m_pcMv + iOffset, m_pcMv + uiOffset, iSizeInTComMv ); |
---|
| 123 | memcpy( pcCUMvFieldDst->m_pcMvd + iOffset, m_pcMvd + uiOffset, iSizeInTComMv ); |
---|
| 124 | memcpy( pcCUMvFieldDst->m_piRefIdx + iOffset, m_piRefIdx + uiOffset, sizeof( *m_piRefIdx ) * uiNumPart ); |
---|
[2] | 125 | } |
---|
| 126 | |
---|
| 127 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 128 | // Set |
---|
| 129 | // -------------------------------------------------------------------------------------------------------------------- |
---|
| 130 | |
---|
[56] | 131 | template <typename T> |
---|
| 132 | Void TComCUMvField::setAll( T *p, T const & val, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx ) |
---|
[2] | 133 | { |
---|
| 134 | Int i; |
---|
[56] | 135 | p += iPartAddr; |
---|
| 136 | Int numElements = m_uiNumPartition >> ( 2 * uiDepth ); |
---|
[2] | 137 | |
---|
| 138 | switch( eCUMode ) |
---|
| 139 | { |
---|
| 140 | case SIZE_2Nx2N: |
---|
[56] | 141 | for ( i = 0; i < numElements; i++ ) |
---|
[2] | 142 | { |
---|
[56] | 143 | p[ i ] = val; |
---|
[2] | 144 | } |
---|
| 145 | break; |
---|
[56] | 146 | |
---|
[2] | 147 | case SIZE_2NxN: |
---|
[56] | 148 | numElements >>= 1; |
---|
| 149 | for ( i = 0; i < numElements; i++ ) |
---|
[2] | 150 | { |
---|
[56] | 151 | p[ i ] = val; |
---|
[2] | 152 | } |
---|
| 153 | break; |
---|
[56] | 154 | |
---|
[2] | 155 | case SIZE_Nx2N: |
---|
[56] | 156 | numElements >>= 2; |
---|
| 157 | for ( i = 0; i < numElements; i++ ) |
---|
[2] | 158 | { |
---|
[56] | 159 | p[ i ] = val; |
---|
| 160 | p[ i + 2 * numElements ] = val; |
---|
[2] | 161 | } |
---|
| 162 | break; |
---|
[56] | 163 | |
---|
[2] | 164 | case SIZE_NxN: |
---|
[56] | 165 | numElements >>= 2; |
---|
| 166 | for ( i = 0; i < numElements; i++) |
---|
[2] | 167 | { |
---|
[56] | 168 | p[ i ] = val; |
---|
[2] | 169 | } |
---|
| 170 | break; |
---|
[56] | 171 | case SIZE_2NxnU: |
---|
| 172 | { |
---|
| 173 | Int iCurrPartNumQ = numElements>>2; |
---|
| 174 | if( iPartIdx == 0 ) |
---|
[2] | 175 | { |
---|
[56] | 176 | T *pT = p; |
---|
| 177 | T *pT2 = p + iCurrPartNumQ; |
---|
| 178 | for (i = 0; i < (iCurrPartNumQ>>1); i++) |
---|
| 179 | { |
---|
| 180 | pT [i] = val; |
---|
| 181 | pT2[i] = val; |
---|
| 182 | } |
---|
[2] | 183 | } |
---|
[56] | 184 | else |
---|
[2] | 185 | { |
---|
[56] | 186 | T *pT = p; |
---|
| 187 | for (i = 0; i < (iCurrPartNumQ>>1); i++) |
---|
| 188 | { |
---|
| 189 | pT[i] = val; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | pT = p + iCurrPartNumQ; |
---|
| 193 | for (i = 0; i < ( (iCurrPartNumQ>>1) + (iCurrPartNumQ<<1) ); i++) |
---|
| 194 | { |
---|
| 195 | pT[i] = val; |
---|
| 196 | } |
---|
[2] | 197 | } |
---|
| 198 | break; |
---|
[56] | 199 | } |
---|
| 200 | case SIZE_2NxnD: |
---|
[2] | 201 | { |
---|
[56] | 202 | Int iCurrPartNumQ = numElements>>2; |
---|
| 203 | if( iPartIdx == 0 ) |
---|
[2] | 204 | { |
---|
[56] | 205 | T *pT = p; |
---|
| 206 | for (i = 0; i < ( (iCurrPartNumQ>>1) + (iCurrPartNumQ<<1) ); i++) |
---|
| 207 | { |
---|
| 208 | pT[i] = val; |
---|
| 209 | } |
---|
| 210 | pT = p + ( numElements - iCurrPartNumQ ); |
---|
| 211 | for (i = 0; i < (iCurrPartNumQ>>1); i++) |
---|
| 212 | { |
---|
| 213 | pT[i] = val; |
---|
| 214 | } |
---|
[2] | 215 | } |
---|
[56] | 216 | else |
---|
| 217 | { |
---|
| 218 | T *pT = p; |
---|
| 219 | T *pT2 = p + iCurrPartNumQ; |
---|
| 220 | for (i = 0; i < (iCurrPartNumQ>>1); i++) |
---|
| 221 | { |
---|
| 222 | pT [i] = val; |
---|
| 223 | pT2[i] = val; |
---|
| 224 | } |
---|
| 225 | } |
---|
[2] | 226 | break; |
---|
| 227 | } |
---|
[56] | 228 | case SIZE_nLx2N: |
---|
| 229 | { |
---|
| 230 | Int iCurrPartNumQ = numElements>>2; |
---|
| 231 | if( iPartIdx == 0 ) |
---|
[2] | 232 | { |
---|
[56] | 233 | T *pT = p; |
---|
| 234 | T *pT2 = p + (iCurrPartNumQ<<1); |
---|
| 235 | T *pT3 = p + (iCurrPartNumQ>>1); |
---|
| 236 | T *pT4 = p + (iCurrPartNumQ<<1) + (iCurrPartNumQ>>1); |
---|
[2] | 237 | |
---|
[56] | 238 | for (i = 0; i < (iCurrPartNumQ>>2); i++) |
---|
| 239 | { |
---|
| 240 | pT [i] = val; |
---|
| 241 | pT2[i] = val; |
---|
| 242 | pT3[i] = val; |
---|
| 243 | pT4[i] = val; |
---|
| 244 | } |
---|
[2] | 245 | } |
---|
[56] | 246 | else |
---|
[2] | 247 | { |
---|
[56] | 248 | T *pT = p; |
---|
| 249 | T *pT2 = p + (iCurrPartNumQ<<1); |
---|
| 250 | for (i = 0; i < (iCurrPartNumQ>>2); i++) |
---|
| 251 | { |
---|
| 252 | pT [i] = val; |
---|
| 253 | pT2[i] = val; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | pT = p + (iCurrPartNumQ>>1); |
---|
| 257 | pT2 = p + (iCurrPartNumQ<<1) + (iCurrPartNumQ>>1); |
---|
| 258 | for (i = 0; i < ( (iCurrPartNumQ>>2) + iCurrPartNumQ ); i++) |
---|
| 259 | { |
---|
| 260 | pT [i] = val; |
---|
| 261 | pT2[i] = val; |
---|
| 262 | } |
---|
[2] | 263 | } |
---|
| 264 | break; |
---|
[56] | 265 | } |
---|
| 266 | case SIZE_nRx2N: |
---|
[2] | 267 | { |
---|
[56] | 268 | Int iCurrPartNumQ = numElements>>2; |
---|
| 269 | if( iPartIdx == 0 ) |
---|
[2] | 270 | { |
---|
[56] | 271 | T *pT = p; |
---|
| 272 | T *pT2 = p + (iCurrPartNumQ<<1); |
---|
| 273 | for (i = 0; i < ( (iCurrPartNumQ>>2) + iCurrPartNumQ ); i++) |
---|
| 274 | { |
---|
| 275 | pT [i] = val; |
---|
| 276 | pT2[i] = val; |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | pT = p + iCurrPartNumQ + (iCurrPartNumQ>>1); |
---|
| 280 | pT2 = p + numElements - iCurrPartNumQ + (iCurrPartNumQ>>1); |
---|
| 281 | for (i = 0; i < (iCurrPartNumQ>>2); i++) |
---|
| 282 | { |
---|
| 283 | pT [i] = val; |
---|
| 284 | pT2[i] = val; |
---|
| 285 | } |
---|
[2] | 286 | } |
---|
[56] | 287 | else |
---|
[2] | 288 | { |
---|
[56] | 289 | T *pT = p; |
---|
| 290 | T *pT2 = p + (iCurrPartNumQ>>1); |
---|
| 291 | T *pT3 = p + (iCurrPartNumQ<<1); |
---|
| 292 | T *pT4 = p + (iCurrPartNumQ<<1) + (iCurrPartNumQ>>1); |
---|
| 293 | for (i = 0; i < (iCurrPartNumQ>>2); i++) |
---|
| 294 | { |
---|
| 295 | pT [i] = val; |
---|
| 296 | pT2[i] = val; |
---|
| 297 | pT3[i] = val; |
---|
| 298 | pT4[i] = val; |
---|
| 299 | } |
---|
[2] | 300 | } |
---|
| 301 | break; |
---|
[56] | 302 | } |
---|
[2] | 303 | default: |
---|
| 304 | assert(0); |
---|
| 305 | break; |
---|
| 306 | } |
---|
| 307 | } |
---|
| 308 | |
---|
[56] | 309 | Void TComCUMvField::setAllMv( TComMv const & mv, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx ) |
---|
[2] | 310 | { |
---|
[56] | 311 | setAll(m_pcMv, mv, eCUMode, iPartAddr, uiDepth, iPartIdx); |
---|
[2] | 312 | } |
---|
| 313 | |
---|
[56] | 314 | Void TComCUMvField::setAllMvd( TComMv const & mvd, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx ) |
---|
| 315 | { |
---|
| 316 | setAll(m_pcMvd, mvd, eCUMode, iPartAddr, uiDepth, iPartIdx); |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | Void TComCUMvField::setAllRefIdx ( Int iRefIdx, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx ) |
---|
| 320 | { |
---|
| 321 | setAll(m_piRefIdx, static_cast<Char>(iRefIdx), eCUMode, iPartAddr, uiDepth, iPartIdx); |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | Void TComCUMvField::setAllMvField( TComMvField const & mvField, PartSize eCUMode, Int iPartAddr, UInt uiDepth, Int iPartIdx ) |
---|
| 325 | { |
---|
| 326 | setAllMv ( mvField.getMv(), eCUMode, iPartAddr, uiDepth, iPartIdx ); |
---|
| 327 | setAllRefIdx( mvField.getRefIdx(), eCUMode, iPartAddr, uiDepth, iPartIdx ); |
---|
| 328 | } |
---|
| 329 | |
---|
[773] | 330 | #if H_3D_SPIVMP |
---|
[724] | 331 | Void TComCUMvField::setMvFieldSP( TComDataCU* pcCU, UInt uiAbsPartIdx, TComMvField cMvField, Int iWidth, Int iHeight ) |
---|
| 332 | { |
---|
| 333 | uiAbsPartIdx += pcCU->getZorderIdxInCU(); |
---|
| 334 | Int iStartPelX = g_auiRasterToPelX[g_auiZscanToRaster[uiAbsPartIdx]]; |
---|
| 335 | Int iStartPelY = g_auiRasterToPelY[g_auiZscanToRaster[uiAbsPartIdx]]; |
---|
| 336 | Int iEndPelX = iStartPelX + iWidth; |
---|
| 337 | Int iEndPelY = iStartPelY + iHeight; |
---|
| 338 | |
---|
| 339 | Int iCurrRaster, uiPartAddr; |
---|
| 340 | |
---|
| 341 | for (Int i=iStartPelY; i<iEndPelY; i+=pcCU->getPic()->getMinCUHeight()) |
---|
| 342 | { |
---|
| 343 | for (Int j=iStartPelX; j < iEndPelX; j += pcCU->getPic()->getMinCUWidth()) |
---|
| 344 | { |
---|
| 345 | iCurrRaster = i / pcCU->getPic()->getMinCUHeight() * pcCU->getPic()->getNumPartInWidth() + j/pcCU->getPic()->getMinCUWidth(); |
---|
| 346 | uiPartAddr = g_auiRasterToZscan[iCurrRaster]; |
---|
| 347 | uiPartAddr -= pcCU->getZorderIdxInCU(); |
---|
| 348 | |
---|
| 349 | m_pcMv[uiPartAddr] = cMvField.getMv(); |
---|
| 350 | m_piRefIdx[uiPartAddr] = cMvField.getRefIdx(); |
---|
| 351 | } |
---|
| 352 | } |
---|
| 353 | } |
---|
| 354 | #endif |
---|
| 355 | |
---|
[2] | 356 | /**Subsampling of the stored prediction mode, reference index and motion vector |
---|
[56] | 357 | * \param pePredMode Pointer to prediction modes |
---|
| 358 | * \param scale Factor by which to subsample motion information |
---|
[2] | 359 | */ |
---|
[56] | 360 | Void TComCUMvField::compress(Char* pePredMode, Int scale) |
---|
[2] | 361 | { |
---|
[56] | 362 | Int N = scale * scale; |
---|
| 363 | assert( N > 0 && N <= m_uiNumPartition); |
---|
| 364 | |
---|
| 365 | for ( Int uiPartIdx = 0; uiPartIdx < m_uiNumPartition; uiPartIdx += N ) |
---|
[2] | 366 | { |
---|
| 367 | TComMv cMv(0,0); |
---|
| 368 | PredMode predMode = MODE_INTRA; |
---|
| 369 | Int iRefIdx = 0; |
---|
| 370 | |
---|
| 371 | cMv = m_pcMv[ uiPartIdx ]; |
---|
[56] | 372 | predMode = static_cast<PredMode>( pePredMode[ uiPartIdx ] ); |
---|
[2] | 373 | iRefIdx = m_piRefIdx[ uiPartIdx ]; |
---|
[56] | 374 | for ( Int i = 0; i < N; i++ ) |
---|
[2] | 375 | { |
---|
[56] | 376 | m_pcMv[ uiPartIdx + i ] = cMv; |
---|
| 377 | pePredMode[ uiPartIdx + i ] = predMode; |
---|
| 378 | m_piRefIdx[ uiPartIdx + i ] = iRefIdx; |
---|
[2] | 379 | } |
---|
| 380 | } |
---|
| 381 | } |
---|
[56] | 382 | //! \} |
---|