示例#1
0
        public static Mv ClampMvToUmvBorderSb(ref MacroBlockD xd, ref Mv srcMv, int bw, int bh, int ssX, int ssY)
        {
            // If the MV points so far into the UMV border that no visible pixels
            // are used for reconstruction, the subpel part of the MV can be
            // discarded and the MV limited to 16 pixels with equivalent results.
            int spelLeft   = (Constants.Vp9InterpExtend + bw) << SubpelBits;
            int spelRight  = spelLeft - SubpelShifts;
            int spelTop    = (Constants.Vp9InterpExtend + bh) << SubpelBits;
            int spelBottom = spelTop - SubpelShifts;
            Mv  clampedMv  = new Mv()
            {
                Row = (short)(srcMv.Row * (1 << (1 - ssY))),
                Col = (short)(srcMv.Col * (1 << (1 - ssX)))
            };

            Debug.Assert(ssX <= 1);
            Debug.Assert(ssY <= 1);

            clampedMv.ClampMv(
                xd.MbToLeftEdge * (1 << (1 - ssX)) - spelLeft,
                xd.MbToRightEdge * (1 << (1 - ssX)) + spelRight,
                xd.MbToTopEdge * (1 << (1 - ssY)) - spelTop,
                xd.MbToBottomEdge * (1 << (1 - ssY)) + spelBottom);

            return(clampedMv);
        }
示例#2
0
 private static unsafe void BuildIntraPredictorsHigh(
     ref MacroBlockD xd,
     byte *ref8,
     int refStride,
     byte *dst8,
     int dstStride,
     PredictionMode mode,
     TxSize txSize,
     int upAvailable,
     int leftAvailable,
     int rightAvailable,
     int x,
     int y,
     int plane)
 {
     int     i;
     ushort *dst = (ushort *)dst8;
     ushort *refr = (ushort *)ref8;
     ushort *leftCol = stackalloc ushort[32];
     ushort *aboveData = stackalloc ushort[64 + 16];
     ushort *aboveRow = aboveData + 16;
     ushort *constAboveRow = aboveRow;
     int     bs = 4 << (int)txSize;
     int     frameWidth, frameHeight;
     int     x0, y0;
     ref MacroBlockDPlane pd = ref xd.Plane[plane];
示例#3
0
        private static PredictionMode ReadInterMode(ref Vp9Common cm, ref MacroBlockD xd, ref Reader r, int ctx)
        {
            int mode = r.ReadTree(Luts.Vp9InterModeTree, cm.Fc.Value.InterModeProb[ctx].ToSpan());

            if (!xd.Counts.IsNull)
            {
                ++xd.Counts.Value.InterMode[ctx][mode];
            }

            return(PredictionMode.NearestMv + mode);
        }
示例#4
0
        private static PredictionMode ReadIntraModeUv(ref Vp9Common cm, ref MacroBlockD xd, ref Reader r, byte yMode)
        {
            PredictionMode uvMode = ReadIntraMode(ref r, cm.Fc.Value.UvModeProb[yMode].ToSpan());

            if (!xd.Counts.IsNull)
            {
                ++xd.Counts.Value.UvMode[yMode][(int)uvMode];
            }

            return(uvMode);
        }
示例#5
0
        private static PredictionMode ReadIntraModeY(ref Vp9Common cm, ref MacroBlockD xd, ref Reader r, int sizeGroup)
        {
            PredictionMode yMode = ReadIntraMode(ref r, cm.Fc.Value.YModeProb[sizeGroup].ToSpan());

            if (!xd.Counts.IsNull)
            {
                ++xd.Counts.Value.YMode[sizeGroup][(int)yMode];
            }

            return(yMode);
        }
示例#6
0
 private static int DecodeCoefs(
     ref MacroBlockD xd,
     PlaneType type,
     Span <int> dqcoeff,
     TxSize txSize,
     ref Array2 <short> dq,
     int ctx,
     ReadOnlySpan <short> scan,
     ReadOnlySpan <short> nb,
     ref Reader r)
 {
     ref Vp9BackwardUpdates counts = ref xd.Counts.Value;
示例#7
0
        private static TxSize ReadTxSize(ref Vp9Common cm, ref MacroBlockD xd, bool allowSelect, ref Reader r)
        {
            TxMode    txMode    = cm.TxMode;
            BlockSize bsize     = xd.Mi[0].Value.SbType;
            TxSize    maxTxSize = Luts.MaxTxSizeLookup[(int)bsize];

            if (allowSelect && txMode == TxMode.TxModeSelect && bsize >= BlockSize.Block8x8)
            {
                return(ReadSelectedTxSize(ref cm, ref xd, maxTxSize, ref r));
            }
            else
            {
                return((TxSize)Math.Min((int)maxTxSize, (int)Luts.TxModeToBiggestTxSize[(int)txMode]));
            }
        }
示例#8
0
        public static int GetReferenceModeContext(ref Vp9Common cm, ref MacroBlockD xd)
        {
            int ctx;

            // Note:
            // The mode info data structure has a one element border above and to the
            // left of the entries corresponding to real macroblocks.
            // The prediction flags in these dummy entries are initialized to 0.
            if (!xd.AboveMi.IsNull && !xd.LeftMi.IsNull)
            {  // both edges available
                if (!xd.AboveMi.Value.HasSecondRef() && !xd.LeftMi.Value.HasSecondRef())
                {
                    // Neither edge uses comp pred (0/1)
                    ctx = (xd.AboveMi.Value.RefFrame[0] == cm.CompFixedRef ? 1 : 0) ^
                          (xd.LeftMi.Value.RefFrame[0] == cm.CompFixedRef ? 1 : 0);
                }
                else if (!xd.AboveMi.Value.HasSecondRef())
                {
                    // One of two edges uses comp pred (2/3)
                    ctx = 2 + (xd.AboveMi.Value.RefFrame[0] == cm.CompFixedRef || !xd.AboveMi.Value.IsInterBlock() ? 1 : 0);
                }
                else if (!xd.LeftMi.Value.HasSecondRef())
                {
                    // One of two edges uses comp pred (2/3)
                    ctx = 2 + (xd.LeftMi.Value.RefFrame[0] == cm.CompFixedRef || !xd.LeftMi.Value.IsInterBlock() ? 1 : 0);
                }
                else  // Both edges use comp pred (4)
                {
                    ctx = 4;
                }
            }
            else if (!xd.AboveMi.IsNull || !xd.LeftMi.IsNull)
            {  // One edge available
                ref ModeInfo edgeMi = ref !xd.AboveMi.IsNull ? ref xd.AboveMi.Value : ref xd.LeftMi.Value;

                if (!edgeMi.HasSecondRef())
                {
                    // Edge does not use comp pred (0/1)
                    ctx = edgeMi.RefFrame[0] == cm.CompFixedRef ? 1 : 0;
                }
                else
                {
                    // Edge uses comp pred (3)
                    ctx = 3;
                }
            }
示例#9
0
        private static TxSize ReadSelectedTxSize(ref Vp9Common cm, ref MacroBlockD xd, TxSize maxTxSize, ref Reader r)
        {
            int ctx = xd.GetTxSizeContext();
            ReadOnlySpan <byte> txProbs = GetTxProbs(ref cm.Fc.Value, maxTxSize, ctx);
            TxSize txSize = (TxSize)r.Read(txProbs[0]);

            if (txSize != TxSize.Tx4x4 && maxTxSize >= TxSize.Tx16x16)
            {
                txSize += r.Read(txProbs[1]);
                if (txSize != TxSize.Tx8x8 && maxTxSize >= TxSize.Tx32x32)
                {
                    txSize += r.Read(txProbs[2]);
                }
            }

            if (!xd.Counts.IsNull)
            {
                ++GetTxCounts(ref xd.Counts.Value, maxTxSize, ctx)[(int)txSize];
            }

            return(txSize);
        }
示例#10
0
 private static void InverseTransformBlockInter(ref MacroBlockD xd, int plane, TxSize txSize, Span <byte> dst, int stride, int eob)
 {
     ref MacroBlockDPlane pd      = ref xd.Plane[plane];