| 395 | } |
| 396 | |
| 397 | void CreateImplicitWeightTable (PWelsDecoderContext pCtx) { |
| 398 | |
| 399 | PSlice pSlice = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer; |
| 400 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; |
| 401 | PDqLayer pCurDqLayer = pCtx->pCurDqLayer; |
| 402 | if (pCurDqLayer->bUseWeightedBiPredIdc && pSliceHeader->pPps->uiWeightedBipredIdc == 2) { |
| 403 | int32_t iPoc = pSliceHeader->iPicOrderCntLsb; |
| 404 | |
| 405 | //fix Bugzilla 1485229 check if pointers are NULL |
| 406 | if (pCtx->sRefPic.pRefList[LIST_0][0] && pCtx->sRefPic.pRefList[LIST_1][0]) { |
| 407 | if (pSliceHeader->uiRefCount[0] == 1 && pSliceHeader->uiRefCount[1] == 1 |
| 408 | && int64_t(pCtx->sRefPic.pRefList[LIST_0][0]->iFramePoc) + int64_t(pCtx->sRefPic.pRefList[LIST_1][0]->iFramePoc) == 2 * int64_t(iPoc)) { |
| 409 | pCurDqLayer->bUseWeightedBiPredIdc = false; |
| 410 | return; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | pCurDqLayer->pPredWeightTable->uiLumaLog2WeightDenom = 5; |
| 415 | pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom = 5; |
| 416 | for (int32_t iRef0 = 0; iRef0 < pSliceHeader->uiRefCount[0]; iRef0++) { |
| 417 | if (pCtx->sRefPic.pRefList[LIST_0][iRef0]) { |
| 418 | const int32_t iPoc0 = pCtx->sRefPic.pRefList[LIST_0][iRef0]->iFramePoc; |
| 419 | bool bIsLongRef0 = pCtx->sRefPic.pRefList[LIST_0][iRef0]->bIsLongRef; |
| 420 | for (int32_t iRef1 = 0; iRef1 < pSliceHeader->uiRefCount[1]; iRef1++) { |
| 421 | if (pCtx->sRefPic.pRefList[LIST_1][iRef1]) { |
| 422 | const int32_t iPoc1 = pCtx->sRefPic.pRefList[LIST_1][iRef1]->iFramePoc; |
| 423 | bool bIsLongRef1 = pCtx->sRefPic.pRefList[LIST_1][iRef1]->bIsLongRef; |
| 424 | pCurDqLayer->pPredWeightTable->iImplicitWeight[iRef0][iRef1] = 32; |
| 425 | if (!bIsLongRef0 && !bIsLongRef1) { |
| 426 | const int32_t iTd = WELS_CLIP3 (iPoc1 - iPoc0, -128, 127); |
| 427 | if (iTd) { |
| 428 | int32_t iTb = WELS_CLIP3 (iPoc - iPoc0, -128, 127); |
| 429 | int32_t iTx = (16384 + (WELS_ABS (iTd) >> 1)) / iTd; |
| 430 | int32_t iDistScaleFactor = (iTb * iTx + 32) >> 8; |
| 431 | if (iDistScaleFactor >= -64 && iDistScaleFactor <= 128) { |
| 432 | pCurDqLayer->pPredWeightTable->iImplicitWeight[iRef0][iRef1] = 64 - iDistScaleFactor; |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | return; |
| 442 | } |
| 443 | |
| 444 | /* |
| 445 | * Predeclared function routines .. |