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 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); }