[313] | 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 | * |
---|
[595] | 6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
[313] | 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 TComPic.cpp |
---|
| 35 | \brief picture class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "TComPic.h" |
---|
| 39 | #include "SEI.h" |
---|
| 40 | |
---|
| 41 | //! \ingroup TLibCommon |
---|
| 42 | //! \{ |
---|
| 43 | |
---|
| 44 | // ==================================================================================================================== |
---|
| 45 | // Constructor / destructor / create / destroy |
---|
| 46 | // ==================================================================================================================== |
---|
| 47 | |
---|
| 48 | TComPic::TComPic() |
---|
| 49 | : m_uiTLayer (0) |
---|
| 50 | , m_bUsedByCurr (false) |
---|
| 51 | , m_bIsLongTerm (false) |
---|
| 52 | , m_apcPicSym (NULL) |
---|
| 53 | , m_pcPicYuvPred (NULL) |
---|
| 54 | , m_pcPicYuvResi (NULL) |
---|
| 55 | , m_bReconstructed (false) |
---|
| 56 | , m_bNeededForOutput (false) |
---|
| 57 | , m_uiCurrSliceIdx (0) |
---|
[595] | 58 | , m_bCheckLTMSB (false) |
---|
| 59 | #if SVC_EXTENSION |
---|
| 60 | , m_layerId( 0 ) |
---|
[540] | 61 | #endif |
---|
[313] | 62 | { |
---|
| 63 | #if SVC_EXTENSION |
---|
| 64 | memset( m_pcFullPelBaseRec, 0, sizeof( m_pcFullPelBaseRec ) ); |
---|
| 65 | memset( m_bSpatialEnhLayer, false, sizeof( m_bSpatialEnhLayer ) ); |
---|
| 66 | #endif |
---|
| 67 | m_apcPicYuv[0] = NULL; |
---|
| 68 | m_apcPicYuv[1] = NULL; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | TComPic::~TComPic() |
---|
| 72 | { |
---|
| 73 | } |
---|
[754] | 74 | #if SVC_EXTENSION |
---|
[494] | 75 | #if AUXILIARY_PICTURES |
---|
| 76 | Void TComPic::create( Int iWidth, Int iHeight, ChromaFormat chromaFormatIDC, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, |
---|
| 77 | Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual) |
---|
| 78 | #else |
---|
[313] | 79 | Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, |
---|
| 80 | Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual) |
---|
[494] | 81 | #endif |
---|
[313] | 82 | { |
---|
| 83 | m_apcPicSym = new TComPicSym; m_apcPicSym ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth ); |
---|
| 84 | if (!bIsVirtual) |
---|
| 85 | { |
---|
[494] | 86 | #if AUXILIARY_PICTURES |
---|
| 87 | m_apcPicYuv[0] = new TComPicYuv; m_apcPicYuv[0]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps ); |
---|
| 88 | #else |
---|
[313] | 89 | m_apcPicYuv[0] = new TComPicYuv; m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps ); |
---|
[494] | 90 | #endif |
---|
[313] | 91 | } |
---|
[494] | 92 | #if AUXILIARY_PICTURES |
---|
| 93 | m_apcPicYuv[1] = new TComPicYuv; m_apcPicYuv[1]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps ); |
---|
| 94 | #else |
---|
[313] | 95 | m_apcPicYuv[1] = new TComPicYuv; m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps ); |
---|
[494] | 96 | #endif |
---|
[313] | 97 | |
---|
| 98 | for( Int i = 0; i < MAX_LAYERS; i++ ) |
---|
| 99 | { |
---|
| 100 | if( m_bSpatialEnhLayer[i] ) |
---|
| 101 | { |
---|
[494] | 102 | #if AUXILIARY_PICTURES |
---|
| 103 | m_pcFullPelBaseRec[i] = new TComPicYuv; m_pcFullPelBaseRec[i]->create( iWidth, iHeight, chromaFormatIDC, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps ); |
---|
| 104 | #else |
---|
[313] | 105 | m_pcFullPelBaseRec[i] = new TComPicYuv; m_pcFullPelBaseRec[i]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps ); |
---|
[494] | 106 | #endif |
---|
[313] | 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | m_layerId = pcSps ? pcSps->getLayerId() : 0; |
---|
| 111 | |
---|
| 112 | // there are no SEI messages associated with this picture initially |
---|
| 113 | if (m_SEIs.size() > 0) |
---|
| 114 | { |
---|
| 115 | deleteSEIs (m_SEIs); |
---|
| 116 | } |
---|
| 117 | m_bUsedByCurr = false; |
---|
| 118 | |
---|
| 119 | /* store conformance window parameters with picture */ |
---|
| 120 | m_conformanceWindow = conformanceWindow; |
---|
| 121 | |
---|
| 122 | /* store display window parameters with picture */ |
---|
| 123 | m_defaultDisplayWindow = defaultDisplayWindow; |
---|
| 124 | |
---|
| 125 | /* store number of reorder pics with picture */ |
---|
| 126 | memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int)); |
---|
| 127 | |
---|
| 128 | return; |
---|
| 129 | } |
---|
| 130 | #else |
---|
| 131 | Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, |
---|
| 132 | Int *numReorderPics, Bool bIsVirtual) |
---|
| 133 | |
---|
| 134 | { |
---|
| 135 | m_apcPicSym = new TComPicSym; m_apcPicSym ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth ); |
---|
| 136 | if (!bIsVirtual) |
---|
| 137 | { |
---|
| 138 | m_apcPicYuv[0] = new TComPicYuv; m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth ); |
---|
| 139 | } |
---|
| 140 | m_apcPicYuv[1] = new TComPicYuv; m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth ); |
---|
| 141 | |
---|
| 142 | // there are no SEI messages associated with this picture initially |
---|
| 143 | if (m_SEIs.size() > 0) |
---|
| 144 | { |
---|
| 145 | deleteSEIs (m_SEIs); |
---|
| 146 | } |
---|
| 147 | m_bUsedByCurr = false; |
---|
| 148 | |
---|
| 149 | /* store conformance window parameters with picture */ |
---|
| 150 | m_conformanceWindow = conformanceWindow; |
---|
| 151 | |
---|
| 152 | /* store display window parameters with picture */ |
---|
| 153 | m_defaultDisplayWindow = defaultDisplayWindow; |
---|
| 154 | |
---|
| 155 | /* store number of reorder pics with picture */ |
---|
| 156 | memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int)); |
---|
| 157 | |
---|
| 158 | return; |
---|
| 159 | } |
---|
| 160 | #endif |
---|
| 161 | |
---|
| 162 | Void TComPic::destroy() |
---|
| 163 | { |
---|
| 164 | if (m_apcPicSym) |
---|
| 165 | { |
---|
| 166 | m_apcPicSym->destroy(); |
---|
| 167 | delete m_apcPicSym; |
---|
| 168 | m_apcPicSym = NULL; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | if (m_apcPicYuv[0]) |
---|
| 172 | { |
---|
| 173 | m_apcPicYuv[0]->destroy(); |
---|
| 174 | delete m_apcPicYuv[0]; |
---|
| 175 | m_apcPicYuv[0] = NULL; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | if (m_apcPicYuv[1]) |
---|
| 179 | { |
---|
| 180 | m_apcPicYuv[1]->destroy(); |
---|
| 181 | delete m_apcPicYuv[1]; |
---|
| 182 | m_apcPicYuv[1] = NULL; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | deleteSEIs(m_SEIs); |
---|
[754] | 186 | #if SVC_EXTENSION |
---|
[313] | 187 | for( Int i = 0; i < MAX_LAYERS; i++ ) |
---|
| 188 | { |
---|
| 189 | if( m_bSpatialEnhLayer[i] ) |
---|
| 190 | { |
---|
| 191 | m_pcFullPelBaseRec[i]->destroy(); |
---|
| 192 | delete m_pcFullPelBaseRec[i]; |
---|
| 193 | m_pcFullPelBaseRec[i] = NULL; |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | #endif |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | Void TComPic::compressMotion() |
---|
| 200 | { |
---|
| 201 | TComPicSym* pPicSym = getPicSym(); |
---|
| 202 | for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getFrameHeightInCU()*pPicSym->getFrameWidthInCU(); uiCUAddr++ ) |
---|
| 203 | { |
---|
| 204 | TComDataCU* pcCU = pPicSym->getCU(uiCUAddr); |
---|
| 205 | pcCU->compressMV(); |
---|
| 206 | } |
---|
| 207 | } |
---|
[595] | 208 | |
---|
[540] | 209 | Bool TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr) |
---|
| 210 | { |
---|
| 211 | Bool mergeCtbInSliceSeg = (mergeAddr >= getPicSym()->getCUOrderMap(getCU(currAddr)->getSlice()->getSliceCurStartCUAddr()/getNumPartInCU())); |
---|
| 212 | Bool mergeCtbInTile = (getPicSym()->getTileIdxMap(mergeAddr) == getPicSym()->getTileIdxMap(currAddr)); |
---|
| 213 | return (mergeCtbInSliceSeg && mergeCtbInTile); |
---|
| 214 | } |
---|
[313] | 215 | |
---|
[442] | 216 | #if SVC_EXTENSION |
---|
[313] | 217 | Void copyOnetoOnePicture( // SVC_NONCOLL |
---|
| 218 | Pel *in, |
---|
| 219 | Pel *out, |
---|
| 220 | Int nCols, |
---|
| 221 | Int nRows, |
---|
| 222 | Int fullRowWidth) |
---|
| 223 | { |
---|
| 224 | Int rX; |
---|
| 225 | |
---|
| 226 | for (rX = 0; rX < nRows; rX++) |
---|
| 227 | { |
---|
| 228 | memcpy( out, in, sizeof(Pel) * nCols ); |
---|
| 229 | in = in + fullRowWidth; |
---|
| 230 | out = out + fullRowWidth; |
---|
| 231 | } |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | Void TComPic::copyUpsampledPictureYuv(TComPicYuv* pcPicYuvIn, TComPicYuv* pcPicYuvOut) |
---|
| 235 | { |
---|
| 236 | Int upsampledRowWidthLuma = pcPicYuvOut->getStride(); // 2 * pcPicYuvOut->getLumaMargin() + pcPicYuvOut->getWidth(); |
---|
| 237 | Int upsampledRowWidthCroma = pcPicYuvOut->getCStride(); //2 * pcPicYuvOut->getChromaMargin() + (pcPicYuvOut->getWidth()>>1); |
---|
| 238 | |
---|
| 239 | copyOnetoOnePicture( |
---|
| 240 | pcPicYuvIn->getLumaAddr(), |
---|
| 241 | pcPicYuvOut->getLumaAddr(), |
---|
| 242 | pcPicYuvOut->getWidth(), |
---|
| 243 | pcPicYuvOut->getHeight(), |
---|
| 244 | upsampledRowWidthLuma); |
---|
| 245 | copyOnetoOnePicture( |
---|
| 246 | pcPicYuvIn->getCrAddr(), |
---|
| 247 | pcPicYuvOut->getCrAddr(), |
---|
| 248 | pcPicYuvOut->getWidth()>>1, |
---|
| 249 | pcPicYuvOut->getHeight()>>1, |
---|
| 250 | upsampledRowWidthCroma); |
---|
| 251 | copyOnetoOnePicture( |
---|
| 252 | pcPicYuvIn->getCbAddr(), |
---|
| 253 | pcPicYuvOut->getCbAddr(), |
---|
| 254 | pcPicYuvOut->getWidth()>>1, |
---|
| 255 | pcPicYuvOut->getHeight()>>1, |
---|
| 256 | upsampledRowWidthCroma); |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | #if REF_IDX_MFM |
---|
| 260 | Void TComPic::copyUpsampledMvField(UInt refLayerIdc, TComPic* pcPicBase) |
---|
| 261 | { |
---|
| 262 | UInt numPartitions = 1<<(g_uiMaxCUDepth<<1); |
---|
| 263 | UInt widthMinPU = g_uiMaxCUWidth/(1<<g_uiMaxCUDepth); |
---|
| 264 | UInt heightMinPU = g_uiMaxCUHeight/(1<<g_uiMaxCUDepth); |
---|
| 265 | Int unitNum = max (1, (Int)((16/widthMinPU)*(16/heightMinPU)) ); |
---|
| 266 | |
---|
| 267 | for(UInt cuIdx = 0; cuIdx < getPicSym()->getNumberOfCUsInFrame(); cuIdx++) //each LCU |
---|
| 268 | { |
---|
| 269 | TComDataCU* pcCUDes = getCU(cuIdx); |
---|
| 270 | |
---|
| 271 | for(UInt absPartIdx = 0; absPartIdx < numPartitions; absPartIdx+=unitNum ) //each 16x16 unit |
---|
| 272 | { |
---|
| 273 | //pixel position of each unit in up-sampled layer |
---|
| 274 | UInt pelX = pcCUDes->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[absPartIdx] ]; |
---|
| 275 | UInt pelY = pcCUDes->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[absPartIdx] ]; |
---|
| 276 | UInt baseCUAddr, baseAbsPartIdx; |
---|
| 277 | |
---|
| 278 | TComDataCU *pcColCU = 0; |
---|
[442] | 279 | pcColCU = pcCUDes->getBaseColCU(refLayerIdc, pelX + 8, pelY + 8, baseCUAddr, baseAbsPartIdx, 1); |
---|
[313] | 280 | |
---|
| 281 | if( pcColCU && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_NONE) && (pcColCU->getPredictionMode(baseAbsPartIdx) != MODE_INTRA) ) //base layer unit not skip and invalid mode |
---|
| 282 | { |
---|
| 283 | for(UInt refPicList = 0; refPicList < 2; refPicList++) //for each reference list |
---|
| 284 | { |
---|
| 285 | TComMvField sMvFieldBase, sMvField; |
---|
| 286 | pcColCU->getMvField( pcColCU, baseAbsPartIdx, (RefPicList)refPicList, sMvFieldBase); |
---|
| 287 | pcCUDes->scaleBaseMV( refLayerIdc, sMvField, sMvFieldBase ); |
---|
| 288 | |
---|
| 289 | pcCUDes->getCUMvField((RefPicList)refPicList)->setMvField(sMvField, absPartIdx); |
---|
| 290 | pcCUDes->setPredictionMode(absPartIdx, MODE_INTER); |
---|
| 291 | } |
---|
| 292 | } |
---|
| 293 | else |
---|
| 294 | { |
---|
| 295 | TComMvField zeroMvField; //zero MV and invalid reference index |
---|
| 296 | pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(zeroMvField, absPartIdx); |
---|
| 297 | pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(zeroMvField, absPartIdx); |
---|
| 298 | pcCUDes->setPredictionMode(absPartIdx, MODE_INTRA); |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | for(UInt i = 1; i < unitNum; i++ ) |
---|
| 302 | { |
---|
| 303 | pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_0)->getMv(absPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_0)->getRefIdx(absPartIdx), absPartIdx + i); |
---|
| 304 | pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_1)->getMv(absPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_1)->getRefIdx(absPartIdx), absPartIdx + i); |
---|
| 305 | pcCUDes->setPredictionMode(absPartIdx+i, pcCUDes->getPredictionMode(absPartIdx)); |
---|
| 306 | } |
---|
| 307 | } |
---|
| 308 | memset( pcCUDes->getPartitionSize(), SIZE_2Nx2N, sizeof(Char)*numPartitions); |
---|
| 309 | } |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | Void TComPic::initUpsampledMvField() |
---|
| 313 | { |
---|
| 314 | UInt uiNumPartitions = 1<<(g_uiMaxCUDepth<<1); |
---|
| 315 | |
---|
| 316 | for(UInt cuIdx = 0; cuIdx < getPicSym()->getNumberOfCUsInFrame(); cuIdx++) //each LCU |
---|
| 317 | { |
---|
| 318 | TComDataCU* pcCUDes = getCU(cuIdx); |
---|
| 319 | TComMvField zeroMvField; |
---|
| 320 | for(UInt list = 0; list < 2; list++) //each reference list |
---|
| 321 | { |
---|
| 322 | for(UInt i = 0; i < uiNumPartitions; i++ ) |
---|
| 323 | { |
---|
| 324 | pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(zeroMvField, i); |
---|
| 325 | pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(zeroMvField, i); |
---|
| 326 | pcCUDes->setPredictionMode(i, MODE_INTRA); |
---|
| 327 | pcCUDes->setPartitionSize(i, SIZE_2Nx2N); |
---|
| 328 | } |
---|
| 329 | } |
---|
| 330 | } |
---|
| 331 | return; |
---|
| 332 | } |
---|
| 333 | #endif |
---|
| 334 | #endif |
---|
| 335 | |
---|
| 336 | #if AVC_SYNTAX |
---|
| 337 | Void TComPic::readBLSyntax( fstream* filestream, UInt numBytes ) |
---|
| 338 | { |
---|
| 339 | if( !filestream->good() ) |
---|
| 340 | { |
---|
| 341 | return; |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | UInt width = this->getPicYuvRec()->getWidth(); |
---|
| 345 | UInt height = this->getPicYuvRec()->getHeight(); |
---|
[442] | 346 | |
---|
[313] | 347 | UInt64 poc = (UInt64)this->getPOC(); |
---|
| 348 | UInt partWidth = width / 4; |
---|
| 349 | UInt partHeight = height / 4; |
---|
| 350 | |
---|
| 351 | UInt numPartInWidth = this->getNumPartInWidth(); |
---|
| 352 | UInt numPartInHeight = this->getNumPartInHeight(); |
---|
| 353 | UInt numPartLCUInWidth = this->getFrameWidthInCU(); |
---|
| 354 | |
---|
| 355 | UInt64 uiPos = (UInt64)poc * width * height * numBytes / 16; |
---|
| 356 | |
---|
| 357 | filestream->seekg( uiPos, ios_base::beg ); |
---|
| 358 | |
---|
| 359 | for( Int i = 0; i < partHeight; i++ ) |
---|
| 360 | { |
---|
| 361 | for( Int j = 0; j < partWidth; j++ ) |
---|
| 362 | { |
---|
| 363 | UInt x = ( j / numPartInWidth ); |
---|
| 364 | UInt y = ( i / numPartInHeight ); |
---|
| 365 | |
---|
| 366 | UInt addrLCU = y * numPartLCUInWidth + x; |
---|
| 367 | UInt partAddr = ( i - y * numPartInHeight ) * numPartInWidth + ( j - x * numPartInWidth ); |
---|
| 368 | partAddr = g_auiRasterToZscan[partAddr]; |
---|
| 369 | |
---|
| 370 | TComDataCU* pcCU = this->getCU( addrLCU ); |
---|
| 371 | |
---|
| 372 | TComMv mv; |
---|
| 373 | Short temp; |
---|
| 374 | |
---|
| 375 | // RefIdxL0 |
---|
| 376 | Char refIdxL0 = -1; |
---|
| 377 | filestream->read( &refIdxL0, 1 ); |
---|
| 378 | assert( refIdxL0 >= -1 ); |
---|
| 379 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setRefIdx( (Int)refIdxL0, partAddr ); |
---|
| 380 | |
---|
| 381 | // RefIdxL1 |
---|
| 382 | Char refIdxL1 = -1; |
---|
| 383 | filestream->read( &refIdxL1, 1 ); |
---|
| 384 | assert( refIdxL1 >= -1 ); |
---|
| 385 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setRefIdx( (Int)refIdxL1, partAddr ); |
---|
| 386 | |
---|
| 387 | // MV L0 |
---|
| 388 | temp = 0; |
---|
| 389 | filestream->read( reinterpret_cast<char*>(&temp), 2 ); |
---|
| 390 | mv.setHor( (Short)temp ); |
---|
| 391 | temp = 0; |
---|
| 392 | filestream->read( reinterpret_cast<char*>(&temp), 2 ); |
---|
| 393 | mv.setVer( (Short)temp ); |
---|
| 394 | pcCU->getCUMvField( REF_PIC_LIST_0 )->setMv( mv, partAddr ); |
---|
| 395 | |
---|
| 396 | // MV L1 |
---|
| 397 | temp = 0; |
---|
| 398 | filestream->read( reinterpret_cast<char*>(&temp), 2 ); |
---|
| 399 | mv.setHor( (Short)temp ); |
---|
| 400 | temp = 0; |
---|
| 401 | filestream->read( reinterpret_cast<char*>(&temp), 2 ); |
---|
| 402 | mv.setVer( (Short)temp ); |
---|
| 403 | pcCU->getCUMvField( REF_PIC_LIST_1 )->setMv( mv, partAddr ); |
---|
| 404 | |
---|
| 405 | // set dependent information |
---|
| 406 | pcCU->setPredictionMode( partAddr, ( refIdxL0 == NOT_VALID && refIdxL1 == NOT_VALID ) ? MODE_INTRA : MODE_INTER ); |
---|
| 407 | UInt interDir = ( refIdxL0 != NOT_VALID ) + ( refIdxL1 != NOT_VALID && this->getSlice(0)->isInterB() ) * 2; |
---|
| 408 | assert( interDir <= 3 ); |
---|
| 409 | pcCU->setInterDir( partAddr, interDir ); |
---|
| 410 | } |
---|
| 411 | } |
---|
| 412 | } |
---|
| 413 | #endif |
---|
| 414 | |
---|
| 415 | #if SYNTAX_OUTPUT |
---|
| 416 | Void TComPic::wrireBLSyntax( fstream* filestream, UInt numBytes ) |
---|
| 417 | { |
---|
| 418 | if( !filestream->good() ) |
---|
| 419 | { |
---|
| 420 | return; |
---|
| 421 | } |
---|
| 422 | |
---|
| 423 | UInt width = this->getPicYuvRec()->getWidth(); |
---|
| 424 | UInt height = this->getPicYuvRec()->getHeight(); |
---|
| 425 | |
---|
| 426 | UInt64 poc = (UInt64)this->getPOC(); |
---|
| 427 | UInt partWidth = width / 4; |
---|
| 428 | UInt partHeight = height / 4; |
---|
| 429 | |
---|
| 430 | UInt numPartInWidth = this->getNumPartInWidth(); |
---|
| 431 | UInt numPartInHeight = this->getNumPartInHeight(); |
---|
| 432 | UInt numPartLCUInWidth = this->getFrameWidthInCU(); |
---|
| 433 | |
---|
| 434 | filestream->seekg( poc * width * height * numBytes / 16 ); |
---|
| 435 | |
---|
| 436 | for( Int i = 0; i < partHeight; i++ ) |
---|
| 437 | { |
---|
| 438 | for( Int j = 0; j < partWidth; j++ ) |
---|
| 439 | { |
---|
| 440 | UInt x = ( j / numPartInWidth ); |
---|
| 441 | UInt y = ( i / numPartInHeight ); |
---|
| 442 | |
---|
| 443 | UInt addrLCU = y * numPartLCUInWidth + x; |
---|
| 444 | UInt partAddr = ( i - y * numPartInHeight ) * numPartInWidth + ( j - x * numPartInWidth ); |
---|
| 445 | partAddr = g_auiRasterToZscan[partAddr]; |
---|
| 446 | |
---|
| 447 | TComDataCU* pcCU = this->getCU( addrLCU ); |
---|
| 448 | |
---|
| 449 | TComMv mv; |
---|
| 450 | Short temp; |
---|
| 451 | Char refIdxL0 = NOT_VALID, refIdxL1 = NOT_VALID; |
---|
| 452 | |
---|
| 453 | // RefIdx |
---|
| 454 | if( !pcCU->isIntra( partAddr ) ) |
---|
| 455 | { |
---|
| 456 | refIdxL0 = (Char)pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( partAddr ); |
---|
| 457 | refIdxL1 = (Char)pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( partAddr ); |
---|
| 458 | } |
---|
| 459 | assert( refIdxL0 >= - 1 && refIdxL1 >= - 1 ); |
---|
| 460 | filestream->put( refIdxL0 ); |
---|
| 461 | filestream->put( refIdxL1 ); |
---|
| 462 | |
---|
| 463 | // MV L0 |
---|
| 464 | mv.setZero(); |
---|
| 465 | if( refIdxL0 >= 0 ) |
---|
| 466 | { |
---|
| 467 | mv = pcCU->getCUMvField( REF_PIC_LIST_0 )->getMv( partAddr ); |
---|
| 468 | } |
---|
| 469 | temp = (Short)mv.getHor(); |
---|
| 470 | filestream->write( reinterpret_cast<char*>(&temp), 2 ); |
---|
| 471 | temp = (Short)mv.getVer(); |
---|
| 472 | filestream->write( reinterpret_cast<char*>(&temp), 2 ); |
---|
| 473 | |
---|
| 474 | // MV L1 |
---|
| 475 | mv.setZero(); |
---|
| 476 | if( refIdxL1 >= 0 ) |
---|
| 477 | { |
---|
| 478 | mv = pcCU->getCUMvField( REF_PIC_LIST_1 )->getMv( partAddr ); |
---|
| 479 | } |
---|
| 480 | temp = (Short)mv.getHor(); |
---|
| 481 | filestream->write( reinterpret_cast<char*>(&temp), 2 ); |
---|
| 482 | temp = (Short)mv.getVer(); |
---|
| 483 | filestream->write( reinterpret_cast<char*>(&temp), 2 ); |
---|
| 484 | } |
---|
| 485 | } |
---|
| 486 | } |
---|
| 487 | #endif |
---|
| 488 | |
---|
[494] | 489 | #if MFM_ENCCONSTRAINT |
---|
| 490 | Bool TComPic::checkSameRefInfo() |
---|
| 491 | { |
---|
| 492 | Bool bSameRefInfo = true; |
---|
| 493 | TComSlice * pSlice0 = getSlice( 0 ); |
---|
| 494 | for( UInt uSliceID = getNumAllocatedSlice() - 1 ; bSameRefInfo && uSliceID > 0 ; uSliceID-- ) |
---|
| 495 | { |
---|
| 496 | TComSlice * pSliceN = getSlice( uSliceID ); |
---|
| 497 | if( pSlice0->getSliceType() != pSliceN->getSliceType() ) |
---|
| 498 | { |
---|
| 499 | bSameRefInfo = false; |
---|
| 500 | } |
---|
| 501 | else if( pSlice0->getSliceType() != I_SLICE ) |
---|
| 502 | { |
---|
| 503 | Int nListNum = pSlice0->getSliceType() == B_SLICE ? 2 : 1; |
---|
| 504 | for( Int nList = 0 ; nList < nListNum ; nList++ ) |
---|
| 505 | { |
---|
| 506 | RefPicList eRefList = ( RefPicList )nList; |
---|
| 507 | if( pSlice0->getNumRefIdx( eRefList ) == pSliceN->getNumRefIdx( eRefList ) ) |
---|
| 508 | { |
---|
| 509 | for( Int refIdx = pSlice0->getNumRefIdx( eRefList ) - 1 ; refIdx >= 0 ; refIdx-- ) |
---|
| 510 | { |
---|
| 511 | if( pSlice0->getRefPic( eRefList , refIdx ) != pSliceN->getRefPic( eRefList , refIdx ) ) |
---|
| 512 | { |
---|
| 513 | bSameRefInfo = false; |
---|
| 514 | break; |
---|
| 515 | } |
---|
| 516 | } |
---|
| 517 | } |
---|
| 518 | else |
---|
| 519 | { |
---|
| 520 | bSameRefInfo = false; |
---|
| 521 | break; |
---|
| 522 | } |
---|
| 523 | } |
---|
| 524 | } |
---|
| 525 | } |
---|
[313] | 526 | |
---|
[494] | 527 | return( bSameRefInfo ); |
---|
| 528 | } |
---|
| 529 | #endif |
---|
| 530 | |
---|
[313] | 531 | //! \} |
---|