public int readIntraChromaPredMode(MDecoder decoder, int mbX, MBType left, MBType top, bool leftAvailable, bool topAvailable) { int ctx = 64; ctx += !leftAvailable || left == null || !left.isIntra() || chromaPredModeLeft == 0 ? 0 : 1; ctx += !topAvailable || top == null || !top.isIntra() || chromaPredModeTop[mbX] == 0 ? 0 : 1; int mode; if (decoder.decodeBin(ctx) == 0) { mode = 0; } else if (decoder.decodeBin(67) == 0) { mode = 1; } else if (decoder.decodeBin(67) == 0) { mode = 2; } else { mode = 3; } chromaPredModeLeft = chromaPredModeTop[mbX] = mode; return(mode); }
public int readMBQpDelta(MDecoder decoder, MBType prevMbType) { int ctx = 60; ctx += prevMbType == null || prevMbType == MBType.I_PCM || (prevMbType != MBType.I_16x16 && prevCBP == 0) || prevMbQpDelta == 0 ? 0 : 1; int val = 0; if (decoder.decodeBin(ctx) == 1) { val++; if (decoder.decodeBin(62) == 1) { val++; while (decoder.decodeBin(63) == 1) { val++; } } } prevMbQpDelta = Utility.golomb2Signed(val); return(prevMbQpDelta); }
private int readCoeffAbsLevel(MDecoder decoder, BlockType blockType, int numDecodAbsLevelGt1, int numDecodAbsLevelEq1) { int incB0 = ((numDecodAbsLevelGt1 != 0) ? 0 : Math.Min(4, 1 + numDecodAbsLevelEq1)); int incBN = 5 + Math.Min(4 - blockType.coeffAbsLevelAdjust, numDecodAbsLevelGt1); int val, b = decoder.decodeBin(blockType.coeffAbsLevelCtxOff + incB0); for (val = 0; b != 0 && val < 13; val++) { b = decoder.decodeBin(blockType.coeffAbsLevelCtxOff + incBN); } val += b; if (val == 14) { int log = -2, add = 0, sum = 0; do { log++; b = decoder.decodeBinBypass(); } while (b != 0); for (; log >= 0; log--) { add |= decoder.decodeBinBypass() << log; sum += 1 << log; } val += add + sum; } return(val); }
public int readRefIdx(MDecoder mDecoder, bool leftAvailable, bool topAvailable, MBType leftType, MBType topType, H264Const.PartPred leftPred, H264Const.PartPred topPred, H264Const.PartPred curPred, int mbX, int partX, int partY, int partW, int partH, int list) { int partAbsX = (mbX << 2) + partX; bool predEqA = leftPred != null && leftPred != H264Const.PartPred.Direct && (leftPred == H264Const.PartPred.Bi || leftPred == curPred || (curPred == H264Const.PartPred.Bi && leftPred.usesList(list))); bool predEqB = topPred != null && topPred != H264Const.PartPred.Direct && (topPred == H264Const.PartPred.Bi || topPred == curPred || (curPred == H264Const.PartPred.Bi && topPred.usesList(list))); int ctA = !leftAvailable || leftType == null || leftType.isIntra() || !predEqA || refIdxLeft[list][partY] == 0 ? 0 : 1; int ctB = !topAvailable || topType == null || topType.isIntra() || !predEqB || refIdxTop[list][partAbsX] == 0 ? 0 : 1; int b0 = mDecoder.decodeBin(54 + ctA + 2 * ctB); int val; if (b0 == 0) { val = 0; } else { int b1 = mDecoder.decodeBin(58); if (b1 == 0) { val = 1; } else { for (val = 2; mDecoder.decodeBin(59) == 1; val++) { ; } } } for (int i = 0; i < partW; i++) { refIdxTop[list][partAbsX + i] = val; } for (int i = 0; i < partH; i++) { refIdxLeft[list][partY + i] = val; } return(val); }
public int readCodedBlockFlagChromaAC(MDecoder decoder, int blkX, int blkY, int comp, MBType left, MBType top, bool leftAvailable, bool topAvailable, int leftCBPChroma, int topCBPChroma, MBType cur) { int blkOffLeft = blkX & 1, blkOffTop = blkY & 1; int tLeft; if (blkOffLeft == 0) { tLeft = condTerm(cur, leftAvailable, left, left != null && left != MBType.I_PCM && (leftCBPChroma & 2) != 0, codedBlkLeft[comp][blkOffTop]); } else { tLeft = condTerm(cur, true, cur, true, codedBlkLeft[comp][blkOffTop]); } int tTop; if (blkOffTop == 0) { tTop = condTerm(cur, topAvailable, top, top != null && top != MBType.I_PCM && (topCBPChroma & 2) != 0, codedBlkTop[comp][blkX]); } else { tTop = condTerm(cur, true, cur, true, codedBlkTop[comp][blkX]); } int decoded = decoder.decodeBin(BlockType.CHROMA_AC.codedBlockCtxOff + tLeft + 2 * tTop); codedBlkLeft[comp][blkOffTop] = decoded; codedBlkTop[comp][blkX] = decoded; return(decoded); }
public bool readTransform8x8Flag(MDecoder mDecoder, bool leftAvailable, bool topAvailable, MBType leftType, MBType topType, bool is8x8Left, bool is8x8Top) { int ctx = 399 + (leftAvailable && leftType != null && is8x8Left ? 1 : 0) + (topAvailable && topType != null && is8x8Top ? 1 : 0); return(mDecoder.decodeBin(ctx) == 1); }
public int readMBTypeP(MDecoder decoder) { if (decoder.decodeBin(14) == 1) { return(5 + readIntraP(decoder, 17)); } else { if (decoder.decodeBin(15) == 0) { return(decoder.decodeBin(16) == 0 ? 0 : 3); } else { return(decoder.decodeBin(17) == 0 ? 2 : 1); } } }
public int readSubMbTypeP(MDecoder mDecoder) { if (mDecoder.decodeBin(21) == 1) { return(0); } else if (mDecoder.decodeBin(22) == 0) { return(1); } else if (mDecoder.decodeBin(23) == 1) { return(2); } else { return(3); } }
public int readCoeffs(MDecoder decoder, BlockType blockType, int[] outs, int first, int num, int[] reorder, int[] scMapping, int[] lscMapping) { bool [] sigCoeff = new bool[num]; int numCoeff; for (numCoeff = 0; numCoeff < num - 1; numCoeff++) { sigCoeff[numCoeff] = decoder.decodeBin(blockType.sigCoeffFlagCtxOff + scMapping[numCoeff]) == 1; if (sigCoeff[numCoeff] && decoder.decodeBin(blockType.lastSigCoeffCtxOff + lscMapping[numCoeff]) == 1) { break; } } sigCoeff[numCoeff++] = true; int numGt1 = 0, numEq1 = 0; for (int j = numCoeff - 1; j >= 0; j--) { if (!sigCoeff[j]) { continue; } int absLev = readCoeffAbsLevel(decoder, blockType, numGt1, numEq1); if (absLev == 0) { ++numEq1; } else { ++numGt1; } outs[reorder[j + first]] = toSigned(absLev + 1, -decoder.decodeBinBypass()); } // System.out.print("["); // for (int i = 0; i < out.length; i++) // System.out.print(out[i] + ","); // System.out.println("]"); return(numGt1 + numEq1); }
private int readIntraP(MDecoder decoder, int ctxOff) { if (decoder.decodeBin(ctxOff) == 0) { return(0); } else { return(decoder.decodeFinalBin() == 1 ? 25 : 1 + readMBType16x16P(decoder, ctxOff)); } }
public bool readMBSkipFlag(MDecoder mDecoder, SliceType slType, bool leftAvailable, bool topAvailable, int mbX) { int bbase = slType == SliceType.P ? 11 : 24; bool ret = mDecoder.decodeBin(bbase + (leftAvailable && !skipFlagLeft ? 1 : 0) + (topAvailable && !skipFlagsTop[mbX] ? 1 : 0)) == 1; skipFlagLeft = skipFlagsTop[mbX] = ret; return(ret); }
public int readCodedBlockFlagChromaDC(MDecoder decoder, int mbX, int comp, MBType left, MBType top, bool leftAvailable, bool topAvailable, int leftCBPChroma, int topCBPChroma, MBType cur) { int tLeft = condTerm(cur, leftAvailable, left, left != null && leftCBPChroma != 0, codedBlkDCLeft[comp]); int tTop = condTerm(cur, topAvailable, top, top != null && topCBPChroma != 0, codedBlkDCTop[comp][mbX]); int decoded = decoder.decodeBin(BlockType.CHROMA_DC.codedBlockCtxOff + tLeft + 2 * tTop); codedBlkDCLeft[comp] = decoded; codedBlkDCTop[comp][mbX] = decoded; return(decoded); }
public int readCodedBlockFlagLumaDC(MDecoder decoder, int mbX, MBType left, MBType top, bool leftAvailable, bool topAvailable, MBType cur) { int tLeft = condTerm(cur, leftAvailable, left, left == MBType.I_16x16, codedBlkDCLeft[0]); int tTop = condTerm(cur, topAvailable, top, top == MBType.I_16x16, codedBlkDCTop[0][mbX]); int decoded = decoder.decodeBin(BlockType.LUMA_16_DC.codedBlockCtxOff + tLeft + 2 * tTop); codedBlkDCLeft[0] = decoded; codedBlkDCTop[0][mbX] = decoded; return(decoded); }
public int readSubMbTypeB(MDecoder mDecoder) { if (mDecoder.decodeBin(36) == 0) { return(0); // direct } if (mDecoder.decodeBin(37) == 0) { return(1 + mDecoder.decodeBin(39)); } if (mDecoder.decodeBin(38) == 0) { return(3 + (mDecoder.decodeBin(39) << 1) + mDecoder.decodeBin(39)); } if (mDecoder.decodeBin(39) == 0) { return(7 + (mDecoder.decodeBin(39) << 1) + mDecoder.decodeBin(39)); } return(11 + mDecoder.decodeBin(39)); }
public int readMBTypeI(MDecoder decoder, MBType left, MBType top, bool leftAvailable, bool topAvailable) { int ctx = 3; ctx += !leftAvailable || left == MBType.I_NxN ? 0 : 1; ctx += !topAvailable || top == MBType.I_NxN ? 0 : 1; if (decoder.decodeBin(ctx) == 0) { return(0); } else { return(decoder.decodeFinalBin() == 1 ? 25 : 1 + readMBType16x16(decoder)); } }
private int readMBType16x16(MDecoder decoder) { int type = decoder.decodeBin(6) * 12; if (decoder.decodeBin(7) == 0) { return(type + (decoder.decodeBin(9) << 1) + decoder.decodeBin(10)); } else { return(type + (decoder.decodeBin(8) << 2) + (decoder.decodeBin(9) << 1) + decoder.decodeBin(10) + 4); } }
private int readMBType16x16P(MDecoder decoder, int ctxOff) { ctxOff++; int type = decoder.decodeBin(ctxOff) * 12; ctxOff++; if (decoder.decodeBin(ctxOff) == 0) { ctxOff++; return(type + (decoder.decodeBin(ctxOff) << 1) + decoder.decodeBin(ctxOff)); } else { return(type + (decoder.decodeBin(ctxOff) << 2) + (decoder.decodeBin(ctxOff + 1) << 1) + decoder.decodeBin(ctxOff + 1) + 4); } }
public int codedBlockPatternIntra(MDecoder mDecoder, bool leftAvailable, bool topAvailable, int cbpLeft, int cbpTop, MBType mbLeft, MBType mbTop) { int cbp0 = mDecoder.decodeBin(73 + condTerm(leftAvailable, mbLeft, (cbpLeft >> 1) & 1) + 2 * condTerm(topAvailable, mbTop, (cbpTop >> 2) & 1)); int cbp1 = mDecoder.decodeBin(73 + (1 - cbp0) + 2 * condTerm(topAvailable, mbTop, (cbpTop >> 3) & 1)); int cbp2 = mDecoder.decodeBin(73 + condTerm(leftAvailable, mbLeft, (cbpLeft >> 3) & 1) + 2 * (1 - cbp0)); int cbp3 = mDecoder.decodeBin(73 + (1 - cbp2) + 2 * (1 - cbp1)); int cr0 = mDecoder.decodeBin(77 + condTermCr0(leftAvailable, mbLeft, cbpLeft >> 4) + 2 * condTermCr0(topAvailable, mbTop, cbpTop >> 4)); int cr1 = cr0 != 0 ? mDecoder.decodeBin(81 + condTermCr1(leftAvailable, mbLeft, cbpLeft >> 4) + 2 * condTermCr1(topAvailable, mbTop, cbpTop >> 4)) : 0; return(cbp0 | (cbp1 << 1) | (cbp2 << 2) | (cbp3 << 3) | (cr0 << 4) | (cr1 << 5)); }
public int readCodedBlockFlagLuma64(MDecoder decoder, int blkX, int blkY, int comp, MBType left, MBType top, bool leftAvailable, bool topAvailable, int leftCBPLuma, int topCBPLuma, int curCBPLuma, MBType cur, bool is8x8Left, bool is8x8Top) { int blkOffLeft = blkX & 3, blkOffTop = blkY & 3; int tLeft; if (blkOffLeft == 0) { tLeft = condTerm(cur, leftAvailable, left, left != null && left != MBType.I_PCM && is8x8Left && cbp(leftCBPLuma, 3, blkOffTop), codedBlkLeft[comp][blkOffTop]); } else { tLeft = condTerm(cur, true, cur, cbp(curCBPLuma, blkOffLeft - 1, blkOffTop), codedBlkLeft[comp][blkOffTop]); } int tTop; if (blkOffTop == 0) { tTop = condTerm(cur, topAvailable, top, top != null && top != MBType.I_PCM && is8x8Top && cbp(topCBPLuma, blkOffLeft, 3), codedBlkTop[comp][blkX]); } else { tTop = condTerm(cur, true, cur, cbp(curCBPLuma, blkOffLeft, blkOffTop - 1), codedBlkTop[comp][blkX]); } int decoded = decoder.decodeBin(BlockType.LUMA_64.codedBlockCtxOff + tLeft + 2 * tTop); codedBlkLeft[comp][blkOffTop] = decoded; codedBlkTop[comp][blkX] = decoded; return(decoded); }
public int readMVD(MDecoder decoder, int comp, bool leftAvailable, bool topAvailable, MBType leftType, MBType topType, H264Const.PartPred leftPred, H264Const.PartPred topPred, H264Const.PartPred curPred, int mbX, int partX, int partY, int partW, int partH, int list) { int ctx = comp == 0 ? 40 : 47; int partAbsX = (mbX << 2) + partX; bool predEqA = leftPred != null && leftPred != H264Const.PartPred.Direct && (leftPred == H264Const.PartPred.Bi || leftPred == curPred || (curPred == H264Const.PartPred.Bi && leftPred.usesList(list))); bool predEqB = topPred != null && topPred != H264Const.PartPred.Direct && (topPred == H264Const.PartPred.Bi || topPred == curPred || (curPred == H264Const.PartPred.Bi && topPred.usesList(list))); // prefix and suffix as given by UEG3 with signedValFlag=1, uCoff=9 int absMvdComp = !leftAvailable || leftType == null || leftType.isIntra() || !predEqA ? 0 : Math .Abs(mvdLeft[list][comp][partY]); absMvdComp += !topAvailable || topType == null || topType.isIntra() || !predEqB ? 0 : Math .Abs(mvdTop[list][comp][partAbsX]); int val, b = decoder.decodeBin(ctx + (absMvdComp < 3 ? 0 : (absMvdComp > 32 ? 2 : 1))); for (val = 0; b != 0 && val < 8; val++) { b = decoder.decodeBin(Math.Min(ctx + val + 3, ctx + 6)); } val += b; if (val != 0) { if (val == 9) { int log = 2, add = 0, sum = 0, leftover = 0; do { sum += leftover; log++; b = decoder.decodeBinBypass(); leftover = 1 << log; } while (b != 0); --log; for (; log >= 0; log--) { add |= decoder.decodeBinBypass() << log; } val += add + sum; } val = toSigned(val, -decoder.decodeBinBypass()); } for (int i = 0; i < partW; i++) { mvdTop[list][comp][partAbsX + i] = val; } for (int i = 0; i < partH; i++) { mvdLeft[list][comp][partY + i] = val; } return(val); }
public bool prev4x4PredModeFlag(MDecoder decoder) { return(decoder.decodeBin(68) == 1); }
public int rem4x4PredMode(MDecoder decoder) { return(decoder.decodeBin(69) | (decoder.decodeBin(69) << 1) | (decoder.decodeBin(69) << 2)); }
public int readMBTypeB(MDecoder mDecoder, MBType left, MBType top, bool leftAvailable, bool topAvailable) { int ctx = 27; ctx += !leftAvailable || left == null || left == MBType.B_Direct_16x16 ? 0 : 1; ctx += !topAvailable || top == null || top == MBType.B_Direct_16x16 ? 0 : 1; if (mDecoder.decodeBin(ctx) == 0) { return(0); // B Direct } if (mDecoder.decodeBin(30) == 0) { return(1 + mDecoder.decodeBin(32)); } int b1 = mDecoder.decodeBin(31); if (b1 == 0) { return(3 + ((mDecoder.decodeBin(32) << 2) | (mDecoder.decodeBin(32) << 1) | mDecoder.decodeBin(32))); } else { if (mDecoder.decodeBin(32) == 0) { return(12 + ((mDecoder.decodeBin(32) << 2) | (mDecoder.decodeBin(32) << 1) | mDecoder.decodeBin(32))); } else { switch ((mDecoder.decodeBin(32) << 1) + mDecoder.decodeBin(32)) { case 0: return(20 + mDecoder.decodeBin(32)); case 1: return(23 + readIntraP(mDecoder, 32)); case 2: return(11); case 3: return(22); } } } return(0); }