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 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 void writeIntraChromaPredMode(MEncoder encoder, int mbX, MBType left, MBType top, bool leftAvailable, bool topAvailable, int mode) { int ctx = 64; ctx += !leftAvailable || !left.isIntra() || chromaPredModeLeft == 0 ? 0 : 1; ctx += !topAvailable || !top.isIntra() || chromaPredModeTop[mbX] == 0 ? 0 : 1; encoder.encodeBin(ctx, mode-- == 0 ? 0 : 1); for (int i = 0; mode >= 0 && i < 2; i++) { encoder.encodeBin(67, mode-- == 0 ? 0 : 1); } chromaPredModeLeft = chromaPredModeTop[mbX] = mode; }
public int condTerm(MBType mbCur, bool nAvb, MBType mbN, bool nBlkAvb, int cbpN) { if (!nAvb) { return(mbCur.isIntra() ? 1 : 0); } if (mbN == MBType.I_PCM) { return(1); } if (!nBlkAvb) { return(0); } return(cbpN); }
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); }