[x265] [PATCH 1 of 3] improve codeCoeffNxN by inline getSigCtxInc()
Steve Borho
steve at borho.org
Wed Mar 25 18:51:46 CET 2015
On 03/24, Min Chen wrote:
> # HG changeset patch
> # User Min Chen <chenm003 at 163.com>
> # Date 1427247531 25200
> # Node ID 51f63f5968617c7854b30d4e339418802e383795
> # Parent e637273e2ae6391d43a037d9a4298a8be8e178ad
> improve codeCoeffNxN by inline getSigCtxInc()
queued the series for testing
> ---
> source/encoder/entropy.cpp | 102 +++++++++++++++++++++++++++++++++++++++-----
> 1 files changed, 91 insertions(+), 11 deletions(-)
>
> diff -r e637273e2ae6 -r 51f63f596861 source/encoder/entropy.cpp
> --- a/source/encoder/entropy.cpp Tue Mar 24 15:31:05 2015 -0500
> +++ b/source/encoder/entropy.cpp Tue Mar 24 18:38:51 2015 -0700
> @@ -1555,21 +1555,101 @@
> // encode significant_coeff_flag
> if (sigCoeffGroupFlag64 & cgBlkPosMask)
> {
> + X265_CHECK((log2TrSize != 2) || (log2TrSize == 2 && subSet == 0), "log2TrSize and subSet mistake!\n");
> const int patternSigCtx = Quant::calcPatternSigCtx(sigCoeffGroupFlag64, cgPosX, cgPosY, codingParameters.log2TrSizeCG);
> - uint32_t blkPos, sig, ctxSig;
> - for (; scanPosSigOff >= 0; scanPosSigOff--)
> +
> + if (log2TrSize == 2)
> {
> - blkPos = codingParameters.scan[subPosBase + scanPosSigOff];
> - sig = scanFlagMask & 1;
> - scanFlagMask >>= 1;
> - X265_CHECK((uint32_t)(coeff[blkPos] != 0) == sig, "sign bit mistake\n");
> - if (scanPosSigOff != 0 || subSet == 0 || numNonZero)
> + uint32_t blkPos, sig, ctxSig;
> + for (; scanPosSigOff >= 0; scanPosSigOff--)
> {
> - ctxSig = Quant::getSigCtxInc(patternSigCtx, log2TrSize, trSize, blkPos, bIsLuma, codingParameters.firstSignificanceMapContext);
> - encodeBin(sig, baseCtx[ctxSig]);
> + blkPos = codingParameters.scan[subPosBase + scanPosSigOff];
> + sig = scanFlagMask & 1;
> + scanFlagMask >>= 1;
> + X265_CHECK((uint32_t)(coeff[blkPos] != 0) == sig, "sign bit mistake\n");
> + {
> + static const uint8_t ctxIndMap[16] =
> + {
> + 0, 1, 4, 5,
> + 2, 3, 4, 5,
> + 6, 6, 8, 8,
> + 7, 7, 8, 8
> + };
> + ctxSig = ctxIndMap[blkPos];
> + X265_CHECK(ctxSig == Quant::getSigCtxInc(patternSigCtx, log2TrSize, trSize, blkPos, bIsLuma, codingParameters.firstSignificanceMapContext), "sigCtx mistake!\n");;
> + encodeBin(sig, baseCtx[ctxSig]);
> + }
> + absCoeff[numNonZero] = int(abs(coeff[blkPos]));
> + numNonZero += sig;
> }
> - absCoeff[numNonZero] = int(abs(coeff[blkPos]));
> - numNonZero += sig;
> + }
> + else
> + {
> + X265_CHECK((log2TrSize > 2), "log2TrSize must be more than 2 in this path!\n");
> +
> + // NOTE: [patternSigCtx][posXinSubset][posYinSubset]
> + static const uint8_t table_cnt[4][4][4] =
> + {
> + // patternSigCtx = 0
> + {
> + { 2, 1, 1, 0 },
> + { 1, 1, 0, 0 },
> + { 1, 0, 0, 0 },
> + { 0, 0, 0, 0 },
> + },
> + // patternSigCtx = 1
> + {
> + { 2, 1, 0, 0 },
> + { 2, 1, 0, 0 },
> + { 2, 1, 0, 0 },
> + { 2, 1, 0, 0 },
> + },
> + // patternSigCtx = 2
> + {
> + { 2, 2, 2, 2 },
> + { 1, 1, 1, 1 },
> + { 0, 0, 0, 0 },
> + { 0, 0, 0, 0 },
> + },
> + // patternSigCtx = 3
> + {
> + { 2, 2, 2, 2 },
> + { 2, 2, 2, 2 },
> + { 2, 2, 2, 2 },
> + { 2, 2, 2, 2 },
> + }
> + };
> + const uint8_t (*tabSigCtx)[4] = table_cnt[(uint32_t)patternSigCtx];
> + const int offset = codingParameters.firstSignificanceMapContext;
> + const uint32_t lumaMask = bIsLuma ? ~0 : 0;
> + static const uint32_t posXY4Mask[] = {0x024, 0x0CC, 0x39C};
> + const uint32_t posGT4Mask = posXY4Mask[log2TrSize - 3] & lumaMask;
> +
> + uint32_t blkPos, sig, ctxSig;
> + for (; scanPosSigOff >= 0; scanPosSigOff--)
> + {
> + blkPos = codingParameters.scan[subPosBase + scanPosSigOff];
> + X265_CHECK(blkPos || (subPosBase + scanPosSigOff == 0), "blkPos==0 must be at scan[0]\n");
> + const uint32_t posZeroMask = (subPosBase + scanPosSigOff) ? ~0 : 0;
> + sig = scanFlagMask & 1;
> + scanFlagMask >>= 1;
> + X265_CHECK((uint32_t)(coeff[blkPos] != 0) == sig, "sign bit mistake\n");
> + if (scanPosSigOff != 0 || subSet == 0 || numNonZero)
> + {
> + const uint32_t posY = blkPos >> log2TrSize;
> + const uint32_t posOffset = (blkPos & posGT4Mask) ? 3 : 0;
> +
> + const uint32_t posXinSubset = blkPos & 3;
> + const uint32_t posYinSubset = posY & 3;
> + const uint32_t cnt = tabSigCtx[posXinSubset][posYinSubset] + offset;
> + ctxSig = (cnt + posOffset) & posZeroMask;
> +
> + X265_CHECK(ctxSig == Quant::getSigCtxInc(patternSigCtx, log2TrSize, trSize, blkPos, bIsLuma, codingParameters.firstSignificanceMapContext), "sigCtx mistake!\n");;
> + encodeBin(sig, baseCtx[ctxSig]);
> + }
> + absCoeff[numNonZero] = int(abs(coeff[blkPos]));
> + numNonZero += sig;
> + }
> }
> }
> X265_CHECK(coeffNum[subSet] == numNonZero, "coefNum mistake\n");
>
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
--
Steve Borho
More information about the x265-devel
mailing list