| @@ -444,6 +444,10 @@ int32_t ParseIntra4x4Mode (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail · 443 unmodified lines |
| 444 | 444 | pCurDqLayer->pIntraPredMode[iMbXy][4] = pIntraPredMode[4 + 8 * 1]; |
| 445 | 445 | pCurDqLayer->pIntraPredMode[iMbXy][5] = pIntraPredMode[4 + 8 * 2]; |
| 446 | 446 | pCurDqLayer->pIntraPredMode[iMbXy][6] = pIntraPredMode[4 + 8 * 3]; |
| 447 | + |
| 448 | + if (pCtx->pSps->uiChromaFormatIdc == 0)//no need parse chroma |
| 449 | + return ERR_NONE; |
| 450 | + |
| 447 | 451 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { |
| 448 | 452 | WELS_READ_VERIFY (ParseIntraPredModeChromaCabac (pCtx, uiNeighAvail, iCode)); |
| 449 | 453 | if (iCode > MAX_PRED_MODE_ID_CHROMA) { |
| @@ -462,7 +466,6 @@ int32_t ParseIntra4x4Mode (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail · 12 unmodified lines |
| 462 | 466 | || CheckIntraChromaPredMode (uiNeighAvail, &pCurDqLayer->pChromaPredMode[iMbXy])) { |
| 463 | 467 | return ERR_INFO_INVALID_I_CHROMA_PRED_MODE; |
| 464 | 468 | } |
| 465 | | − |
| 466 | 469 | return ERR_NONE; |
| 467 | 470 | } |
| 468 | 471 | |
| @@ -478,6 +481,9 @@ int32_t ParseIntra16x16Mode (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAva · 9 unmodified lines |
| 478 | 481 | &pCurDqLayer->pIntraPredMode[iMbXy][7])) { //invalid iPredMode, must stop decoding |
| 479 | 482 | return ERR_INFO_INVALID_I16x16_PRED_MODE; |
| 480 | 483 | } |
| 484 | + if (pCtx->pSps->uiChromaFormatIdc == 0) |
| 485 | + return ERR_NONE; |
| 486 | + |
| 481 | 487 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { |
| 482 | 488 | WELS_READ_VERIFY (ParseIntraPredModeChromaCabac (pCtx, uiNeighAvail, iCode)); |
| 483 | 489 | if (iCode > MAX_PRED_MODE_ID_CHROMA) { |
| @@ -519,6 +525,9 @@ int32_t WelsDecodeMbCabacISliceBaseMode0 (PWelsDecoderContext pCtx, uint32_t& ui · 35 unmodified lines |
| 519 | 525 | WELS_READ_VERIFY (ParseMBTypeISliceCabac (pCtx, &sNeighAvail, uiMbType)); |
| 520 | 526 | if (uiMbType > 25) { |
| 521 | 527 | return ERR_INFO_INVALID_MB_TYPE; |
| 528 | + } else if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 |
| 529 | + && uiMbType <= 24))) { |
| 530 | + return ERR_INFO_INVALID_MB_TYPE; |
| 522 | 531 | } else if (25 == uiMbType) { //I_PCM |
| 523 | 532 | WELS_READ_VERIFY (ParseIPCMInfoCabac (pCtx)); |
| 524 | 533 | pSlice->iLastDeltaQp = 0; |
| @@ -536,19 +545,18 @@ int32_t WelsDecodeMbCabacISliceBaseMode0 (PWelsDecoderContext pCtx, uint32_t& ui · 11 unmodified lines |
| 536 | 545 | WELS_READ_VERIFY (ParseCbpInfoCabac (pCtx, &sNeighAvail, uiCbp)); |
| 537 | 546 | pCurLayer->pCbp[iMbXy] = uiCbp; |
| 538 | 547 | pSlice->iLastDeltaQp = uiCbp == 0 ? 0 : pSlice->iLastDeltaQp; |
| 539 | | − uiCbpChroma = uiCbp >> 4; |
| 548 | + uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? uiCbp >> 4 : 0; |
| 540 | 549 | uiCbpLuma = uiCbp & 15; |
| 541 | 550 | } else { //I16x16; |
| 542 | 551 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; |
| 543 | 552 | pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3; |
| 544 | 553 | pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2]; |
| 545 | | − uiCbpChroma = pCurLayer->pCbp[iMbXy] >> 4; |
| 554 | + uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0 ; |
| 546 | 555 | uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15; |
| 547 | 556 | WelsFillCacheNonZeroCount (&sNeighAvail, pNonZeroCount, pCurLayer); |
| 548 | 557 | WELS_READ_VERIFY (ParseIntra16x16Mode (pCtx, &sNeighAvail, pBsAux, pCurLayer)); |
| 549 | 558 | } |
| 550 | 559 | |
| 551 | | − |
| 552 | 560 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); |
| 553 | 561 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); |
| 554 | 562 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); |
| @@ -705,9 +713,10 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 150 unmodified lines |
| 705 | 713 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; |
| 706 | 714 | } else { //Intra mode |
| 707 | 715 | uiMbType -= 5; |
| 708 | | − if (uiMbType > 25) { |
| 716 | + if (uiMbType > 25) |
| 717 | + return ERR_INFO_INVALID_MB_TYPE; |
| 718 | + if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24))) |
| 709 | 719 | return ERR_INFO_INVALID_MB_TYPE; |
| 710 | | − } |
| 711 | 720 | |
| 712 | 721 | if (25 == uiMbType) { //I_PCM |
| 713 | 722 | WELS_READ_VERIFY (ParseIPCMInfoCabac (pCtx)); |
| @@ -727,7 +736,7 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 13 unmodified lines |
| 727 | 736 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; |
| 728 | 737 | pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3; |
| 729 | 738 | pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2]; |
| 730 | | − uiCbpChroma = pCurLayer->pCbp[iMbXy] >> 4; |
| 739 | + uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0; |
| 731 | 740 | uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15; |
| 732 | 741 | WelsFillCacheNonZeroCount (pNeighAvail, pNonZeroCount, pCurLayer); |
| 733 | 742 | WELS_READ_VERIFY (ParseIntra16x16Mode (pCtx, pNeighAvail, pBsAux, pCurLayer)); |
| @@ -735,21 +744,6 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 1 unmodified line |
| 735 | 744 | } |
| 736 | 745 | } |
| 737 | 746 | |
| 738 | | − |
| 739 | | − |
| 740 | | − |
| 741 | | − |
| 742 | | − |
| 743 | | − |
| 744 | | − |
| 745 | | − |
| 746 | | − |
| 747 | | − |
| 748 | | − |
| 749 | | − |
| 750 | | − |
| 751 | | − |
| 752 | | − |
| 753 | 747 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); |
| 754 | 748 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); |
| 755 | 749 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); |
| @@ -759,9 +753,10 @@ int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAv · 3 unmodified lines |
| 759 | 753 | |
| 760 | 754 | if (MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy]) { |
| 761 | 755 | WELS_READ_VERIFY (ParseCbpInfoCabac (pCtx, pNeighAvail, uiCbp)); |
| 756 | + |
| 762 | 757 | pCurLayer->pCbp[iMbXy] = uiCbp; |
| 763 | 758 | pSlice->iLastDeltaQp = uiCbp == 0 ? 0 : pSlice->iLastDeltaQp; |
| 764 | | − uiCbpChroma = pCurLayer->pCbp[iMbXy] >> 4; |
| 759 | + uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0 ; |
| 765 | 760 | uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15; |
| 766 | 761 | } |
| 767 | 762 | |
| @@ -1104,9 +1099,10 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 336 unmodified lines |
| 1104 | 1099 | |
| 1105 | 1100 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //uiMbType |
| 1106 | 1101 | uiMbType = uiCode; |
| 1107 | | − if (uiMbType > 25) { |
| 1102 | + if (uiMbType > 25) |
| 1103 | + return ERR_INFO_INVALID_MB_TYPE; |
| 1104 | + if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24))) |
| 1108 | 1105 | return ERR_INFO_INVALID_MB_TYPE; |
| 1109 | | − } |
| 1110 | 1106 | |
| 1111 | 1107 | if (25 == uiMbType) { |
| 1112 | 1108 | int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0]; |
| @@ -1169,11 +1165,15 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 56 unmodified lines |
| 1169 | 1165 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //coded_block_pattern |
| 1170 | 1166 | uiCbp = uiCode; |
| 1171 | 1167 | //G.9.1 Alternative parsing process for coded pBlock pattern |
| 1172 | | − if (uiCbp > 47) |
| 1168 | + if (pCtx->pSps->uiChromaFormatIdc && (uiCbp > 47)) |
| 1169 | + return ERR_INFO_INVALID_CBP; |
| 1170 | + if (!pCtx->pSps->uiChromaFormatIdc && (uiCbp > 15)) |
| 1173 | 1171 | return ERR_INFO_INVALID_CBP; |
| 1174 | 1172 | |
| 1175 | | − uiCbp = g_kuiIntra4x4CbpTable[uiCbp]; |
| 1176 | | − |
| 1173 | + if (pCtx->pSps->uiChromaFormatIdc) |
| 1174 | + uiCbp = g_kuiIntra4x4CbpTable[uiCbp]; |
| 1175 | + else |
| 1176 | + uiCbp = g_kuiIntra4x4CbpTable400[uiCbp]; |
| 1177 | 1177 | pCurLayer->pCbp[iMbXy] = uiCbp; |
| 1178 | 1178 | uiCbpC = uiCbp >> 4; |
| 1179 | 1179 | uiCbpL = uiCbp & 15; |
| @@ -1181,7 +1181,7 @@ int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { · 1 unmodified line |
| 1181 | 1181 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; |
| 1182 | 1182 | pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3; |
| 1183 | 1183 | pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2]; |
| 1184 | | − uiCbpC = pCurLayer->pCbp[iMbXy] >> 4; |
| 1184 | + uiCbpC = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0; |
| 1185 | 1185 | uiCbpL = pCurLayer->pCbp[iMbXy] & 15; |
| 1186 | 1186 | WelsFillCacheNonZeroCount (&sNeighAvail, pNonZeroCount, pCurLayer); |
| 1187 | 1187 | WELS_READ_VERIFY (ParseIntra16x16Mode (pCtx, &sNeighAvail, pBs, pCurLayer)); |
| @@ -1398,9 +1398,10 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 210 unmodified lines |
| 1398 | 1398 | } |
| 1399 | 1399 | } else { //intra MB type |
| 1400 | 1400 | uiMbType -= 5; |
| 1401 | | − if (uiMbType > 25) { |
| 1401 | + if (uiMbType > 25) |
| 1402 | + return ERR_INFO_INVALID_MB_TYPE; |
| 1403 | + if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24))) |
| 1402 | 1404 | return ERR_INFO_INVALID_MB_TYPE; |
| 1403 | | − } |
| 1404 | 1405 | |
| 1405 | 1406 | if (25 == uiMbType) { |
| 1406 | 1407 | int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0]; |
| @@ -1471,7 +1472,7 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 64 unmodified lines |
| 1471 | 1472 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; |
| 1472 | 1473 | pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3; |
| 1473 | 1474 | pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2]; |
| 1474 | | − uiCbpC = pCurLayer->pCbp[iMbXy] >> 4; |
| 1475 | + uiCbpC = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0; |
| 1475 | 1476 | uiCbpL = pCurLayer->pCbp[iMbXy] & 15; |
| 1476 | 1477 | WelsFillCacheNonZeroCount (&sNeighAvail, pNonZeroCount, pCurLayer); |
| 1477 | 1478 | if (ParseIntra16x16Mode (pCtx, &sNeighAvail, pBs, pCurLayer)) { |
| @@ -1485,13 +1486,15 @@ int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { · 7 unmodified lines |
| 1485 | 1486 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //coded_block_pattern |
| 1486 | 1487 | uiCbp = uiCode; |
| 1487 | 1488 | { |
| 1488 | | − if (uiCbp > 47) |
| 1489 | + if (pCtx->pSps->uiChromaFormatIdc && (uiCbp > 47)) |
| 1490 | + return ERR_INFO_INVALID_CBP; |
| 1491 | + if (!pCtx->pSps->uiChromaFormatIdc && (uiCbp > 15)) |
| 1489 | 1492 | return ERR_INFO_INVALID_CBP; |
| 1490 | | − |
| 1491 | 1493 | if (MB_TYPE_INTRA4x4 == pCurLayer->pMbType[iMbXy]) { |
| 1492 | | − uiCbp = g_kuiIntra4x4CbpTable[uiCbp]; |
| 1494 | + |
| 1495 | + uiCbp = pCtx->pSps->uiChromaFormatIdc ? g_kuiIntra4x4CbpTable[uiCbp] : g_kuiIntra4x4CbpTable400[uiCbp]; |
| 1493 | 1496 | } else //inter |
| 1494 | | − uiCbp = g_kuiInterCbpTable[uiCbp]; |
| 1497 | + uiCbp = pCtx->pSps->uiChromaFormatIdc ? g_kuiInterCbpTable[uiCbp] : g_kuiInterCbpTable400[uiCbp]; |
| 1495 | 1498 | } |
| 1496 | 1499 | |
| 1497 | 1500 | pCurLayer->pCbp[iMbXy] = uiCbp; |