shithub: openh264

Download patch

ref: 664127f39f17c9e935d19a221fdeb6da8053bd72
parent: 12e5f1b673d3a05c06ba3f2e0a4d35d58a08d8ce
parent: b160c198d7b298fb012774dea582cd3ad5edb6e4
author: ruil2 <[email protected]>
date: Wed May 3 09:16:12 EDT 2017

Merge pull request #2740 from huili2/hdt_qmatrix_bugfix

fix bug with ihadamard to correct place with qmatrix on

--- a/codec/decoder/core/src/decode_slice.cpp
+++ b/codec/decoder/core/src/decode_slice.cpp
@@ -155,9 +155,6 @@
   int32_t iMbXy = pCurLayer->iMbXyIndex;
   int32_t i, iIndex, iOffset;
 
-  WelsChromaDcIdct (pCurLayer->pScaledTCoeff[iMbXy] + 256);     // 256 = 16*16
-  WelsChromaDcIdct (pCurLayer->pScaledTCoeff[iMbXy] + 320);     // 320 = 16*16 + 16*4
-
   if (pCurLayer->pTransformSize8x8Flag[iMbXy]) {
     for (i = 0; i < 4; i++) {
       iIndex = g_kuiMbCountScan4Idx[i << 2];
@@ -207,7 +204,7 @@
 }
 
 void WelsLumaDcDequantIdct (int16_t* pBlock, int32_t iQp, PWelsDecoderContext pCtx) {
-  const int32_t kiQMul = pCtx->bUseScalingList ? pCtx->pDequant_coeff4x4[0][iQp][0] >> 4 : g_kuiDequantCoeff[iQp][0];
+  const int32_t kiQMul = pCtx->bUseScalingList ? pCtx->pDequant_coeff4x4[0][iQp][0] : (g_kuiDequantCoeff[iQp][0] << 4);
 #define STRIDE 16
   int32_t i;
   int32_t iTemp[16]; //FIXME check if this is a good idea
@@ -240,10 +237,10 @@
     const int32_t kiZ2 = iTemp[kiI4] - iTemp[8 + kiI4];
     const int32_t kiZ3 = iTemp[kiI4] + iTemp[8 + kiI4];
 
-    pBlk[kiOffset] = ((kiZ0 + kiZ3) * kiQMul + 2) >> 2; //FIXME think about merging this into decode_resdual
-    pBlk[kiYOffset[1] + kiOffset] = ((kiZ1 + kiZ2) * kiQMul + 2) >> 2;
-    pBlk[kiYOffset[2] + kiOffset] = ((kiZ1 - kiZ2) * kiQMul + 2) >> 2;
-    pBlk[kiYOffset[3] + kiOffset] = ((kiZ0 - kiZ3) * kiQMul + 2) >> 2;
+    pBlk[kiOffset] = ((kiZ0 + kiZ3) * kiQMul + (1 << 5)) >> 6; //FIXME think about merging this into decode_resdual
+    pBlk[kiYOffset[1] + kiOffset] = ((kiZ1 + kiZ2) * kiQMul + (1 << 5)) >> 6;
+    pBlk[kiYOffset[2] + kiOffset] = ((kiZ1 - kiZ2) * kiQMul + (1 << 5)) >> 6;
+    pBlk[kiYOffset[3] + kiOffset] = ((kiZ0 - kiZ3) * kiQMul + (1 << 5)) >> 6;
   }
 #undef STRIDE
 }
@@ -255,19 +252,12 @@
   WelsFillRecNeededMbInfo (pCtx, bOutput, pCurLayer);
 
   if (IS_INTRA16x16 (pCurLayer->pMbType[iMbXy])) {
-    WelsLumaDcDequantIdct (pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx);
     RecI16x16Mb (iMbXy, pCtx, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer);
-
-    return ERR_NONE;
-  }
-
-  if (IS_INTRA8x8 (pCurLayer->pMbType[iMbXy])) {
+  } else if (IS_INTRA8x8 (pCurLayer->pMbType[iMbXy])) {
     RecI8x8Mb (iMbXy, pCtx, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer);
-  }
-
-  if (IS_INTRA4x4 (pCurLayer->pMbType[iMbXy]))
+  } else if (IS_INTRA4x4 (pCurLayer->pMbType[iMbXy])) {
     RecI4x4Mb (iMbXy, pCtx, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer);
-
+  }
   return ERR_NONE;
 }
 
@@ -327,10 +317,10 @@
   iB = iC - iD;
   iC += iD;
 
-  pBlk[0] = (iA + iC) >> 1;
-  pBlk[iXStride] = (iE + iB) >> 1;
-  pBlk[iStride] = (iA - iC) >> 1;
-  pBlk[iStride1] = (iE - iB) >> 1;
+  pBlk[0] = (iA + iC);
+  pBlk[iXStride] = (iE + iB);
+  pBlk[iStride] = (iA - iC);
+  pBlk[iStride1] = (iE - iB);
 }
 
 void WelsMapNxNNeighToSampleNormal (PWelsNeighAvail pNeighAvail, int32_t* pSampleAvail) {
--- a/codec/decoder/core/src/parse_mb_syn_cabac.cpp
+++ b/codec/decoder/core/src/parse_mb_syn_cabac.cpp
@@ -31,6 +31,7 @@
  *      parse_mb_syn_cabac.cpp: cabac parse for syntax elements
  */
 #include "parse_mb_syn_cabac.h"
+#include "decode_slice.h"
 #include "mv_pred.h"
 #include "error_code.h"
 namespace WelsDec {
@@ -927,24 +928,36 @@
   int32_t j = 0;
   if (iResProperty == I16_LUMA_DC) {
     do {
-      if (pSignificantMap[j] != 0)
-        sTCoeff[pScanTable[j]] = pSignificantMap[j];
+      sTCoeff[pScanTable[j]] = pSignificantMap[j];
       ++j;
     } while (j < 16);
+    WelsLumaDcDequantIdct (sTCoeff, uiQp, pCtx);
   } else if (iResProperty == CHROMA_DC_U || iResProperty == CHROMA_DC_V) {
     do {
-      if (pSignificantMap[j] != 0)
-        sTCoeff[pScanTable[j]] = pCtx->bUseScalingList ? (int16_t) ((int64_t)pSignificantMap[j] *
-                                 (int64_t)pDeQuantMul[0] >> 4) :
-                                 (pSignificantMap[j] * pDeQuantMul[0]);
+      sTCoeff[pScanTable[j]] = pSignificantMap[j];
       ++j;
-    } while (j < 16);
+    } while (j < 4);
+    //iHadamard2x2
+    WelsChromaDcIdct (sTCoeff);
+    //scaling
+    if (!pCtx->bUseScalingList) {
+      for (j = 0; j < 4; ++j) {
+        sTCoeff[pScanTable[j]] = (int16_t) ((int64_t)sTCoeff[pScanTable[j]] * (int64_t)pDeQuantMul[0] >> 1);
+      }
+    } else { //with scaling list
+      for (j = 0; j < 4; ++j) {
+        sTCoeff[pScanTable[j]] = (int16_t) ((int64_t)sTCoeff[pScanTable[j]] * (int64_t)pDeQuantMul[0] >> 5);
+      }
+    }
   } else { //luma ac, chroma ac
     do {
-      if (pSignificantMap[j] != 0)
-        sTCoeff[pScanTable[j]] = pCtx->bUseScalingList ? (int16_t) ((int64_t)pSignificantMap[j] *
-                                 (int64_t)pDeQuantMul[pScanTable[j]] >> 4) :
-                                 pSignificantMap[j] * pDeQuantMul[pScanTable[j] & 0x07];
+      if (pSignificantMap[j] != 0) {
+        if (!pCtx->bUseScalingList) {
+          sTCoeff[pScanTable[j]] = pSignificantMap[j] * pDeQuantMul[pScanTable[j] & 0x07];
+        } else {
+          sTCoeff[pScanTable[j]] = (int16_t) (((int64_t)pSignificantMap[j] * (int64_t)pDeQuantMul[pScanTable[j]] + 8) >> 4);
+        }
+      }
       ++j;
     } while (j < 16);
   }
--- a/codec/decoder/core/src/parse_mb_syn_cavlc.cpp
+++ b/codec/decoder/core/src/parse_mb_syn_cavlc.cpp
@@ -40,6 +40,7 @@
 
 
 #include "parse_mb_syn_cavlc.h"
+#include "decode_slice.h"
 #include "error_code.h"
 #include "mv_pred.h"
 
@@ -880,8 +881,19 @@
       int32_t j;
       iCoeffNum += iRun[i] + 1; //FIXME add 1 earlier ?
       j          = kpZigzagTable[ iCoeffNum ];
-      pTCoeff[j] = pCtx->bUseScalingList ? (iLevel[i] * kpDequantCoeff[0]) >> 4 : (iLevel[i] * kpDequantCoeff[0]);
+      pTCoeff[j] = iLevel[i];
     }
+    WelsChromaDcIdct (pTCoeff);
+    //scaling
+    if (!pCtx->bUseScalingList) {
+      for (int j = 0; j < 4; ++j) {
+        pTCoeff[kpZigzagTable[j]] = (pTCoeff[kpZigzagTable[j]] * kpDequantCoeff[0]) >> 1;
+      }
+    } else {
+      for (int j = 0; j < 4; ++j) {
+        pTCoeff[kpZigzagTable[j]] = ((int64_t) pTCoeff[kpZigzagTable[j]] * (int64_t) kpDequantCoeff[0]) >> 5;
+      }
+    }
   } else if (iResidualProperty == I16_LUMA_DC) { //DC coefficent, only call in Intra_16x16, base_mode_flag = 0
     for (i = uiTotalCoeff - 1; i >= 0; --i) { //FIXME merge into rundecode?
       int32_t j;
@@ -889,12 +901,17 @@
       j          = kpZigzagTable[ iCoeffNum ];
       pTCoeff[j] = iLevel[i];
     }
+    WelsLumaDcDequantIdct (pTCoeff, uiQp, pCtx);
   } else {
     for (i = uiTotalCoeff - 1; i >= 0; --i) { //FIXME merge into  rundecode?
       int32_t j;
       iCoeffNum += iRun[i] + 1; //FIXME add 1 earlier ?
       j          = kpZigzagTable[ iCoeffNum ];
-      pTCoeff[j] = pCtx->bUseScalingList ? (iLevel[i] * kpDequantCoeff[j]) >> 4 : (iLevel[i] * kpDequantCoeff[j & 0x07]);
+      if (!pCtx->bUseScalingList) {
+        pTCoeff[j] = (iLevel[i] * kpDequantCoeff[j & 0x07]);
+      } else {
+        pTCoeff[j] = (iLevel[i] * kpDequantCoeff[j] + 8) >> 4;
+      }
     }
   }
 
--- a/codec/decoder/core/src/rec_mb.cpp
+++ b/codec/decoder/core/src/rec_mb.cpp
@@ -237,8 +237,10 @@
              int32_t iBlkWidth, int32_t iBlkHeight, int16_t iMVs[2]) {
   int32_t iFullMVx = (iXOffset << 2) + iMVs[0]; //quarter pixel
   int32_t iFullMVy = (iYOffset << 2) + iMVs[1];
-  iFullMVx = WELS_CLIP3 (iFullMVx, ((-PADDING_LENGTH + 2) * (1 << 2)), ((pMCRefMem->iPicWidth + PADDING_LENGTH - 19) * (1 << 2)));
-  iFullMVy = WELS_CLIP3 (iFullMVy, ((-PADDING_LENGTH + 2) * (1 << 2)), ((pMCRefMem->iPicHeight + PADDING_LENGTH - 19) * (1 << 2)));
+  iFullMVx = WELS_CLIP3 (iFullMVx, ((-PADDING_LENGTH + 2) * (1 << 2)),
+                         ((pMCRefMem->iPicWidth + PADDING_LENGTH - 19) * (1 << 2)));
+  iFullMVy = WELS_CLIP3 (iFullMVy, ((-PADDING_LENGTH + 2) * (1 << 2)),
+                         ((pMCRefMem->iPicHeight + PADDING_LENGTH - 19) * (1 << 2)));
 
   int32_t iSrcPixOffsetLuma = (iFullMVx >> 2) + (iFullMVy >> 2) * pMCRefMem->iSrcLineLuma;
   int32_t iSrcPixOffsetChroma = (iFullMVx >> 3) + (iFullMVy >> 3) * pMCRefMem->iSrcLineChroma;
@@ -541,8 +543,6 @@
   uint8_t uiCbpC = pDqLayer->pCbp[iMBXY] >> 4;
 
   if (1 == uiCbpC || 2 == uiCbpC) {
-    WelsChromaDcIdct (pScoeffLevel + 256);      // 256 = 16*16
-    WelsChromaDcIdct (pScoeffLevel + 320);      // 256 = 16*16
     for (i = 0; i < 2; i++) {
       int16_t* pRS = pScoeffLevel + 256 + (i << 6);
       uint8_t* pPred = pDqLayer->pPred[i + 1];