예제 #1
0
        public int GetCostLuma16(Vp8ModeScore rd, Vp8EncProba proba, Vp8Residual res)
        {
            int r = 0;

            // re-import the non-zero context.
            this.NzToBytes();

            // DC
            res.Init(0, 1, proba);
            res.SetCoeffs(rd.YDcLevels);
            r += res.GetResidualCost(this.TopNz[8] + this.LeftNz[8]);

            // AC
            res.Init(1, 0, proba);
            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 4; x++)
                {
                    int ctx = this.TopNz[x] + this.LeftNz[y];
                    res.SetCoeffs(rd.YAcLevels.AsSpan((x + (y * 4)) * 16, 16));
                    r            += res.GetResidualCost(ctx);
                    this.TopNz[x] = this.LeftNz[y] = res.Last >= 0 ? 1 : 0;
                }
            }

            return(r);
        }
예제 #2
0
        public int GetCostLuma4(Span <short> levels, Vp8EncProba proba, Vp8Residual res)
        {
            int x = this.I4 & 3;
            int y = this.I4 >> 2;
            int r = 0;

            res.Init(0, 3, proba);
            int ctx = this.TopNz[x] + this.LeftNz[y];

            res.SetCoeffs(levels);
            r += res.GetResidualCost(ctx);
            return(r);
        }
예제 #3
0
        public int GetCostUv(Vp8ModeScore rd, Vp8EncProba proba, Vp8Residual res)
        {
            int r = 0;

            // re-import the non-zero context.
            this.NzToBytes();

            res.Init(0, 2, proba);
            for (int ch = 0; ch <= 2; ch += 2)
            {
                for (int y = 0; y < 2; y++)
                {
                    for (int x = 0; x < 2; x++)
                    {
                        int ctx = this.TopNz[4 + ch + x] + this.LeftNz[4 + ch + y];
                        res.SetCoeffs(rd.UvLevels.AsSpan(((ch * 2) + x + (y * 2)) * 16, 16));
                        r += res.GetResidualCost(ctx);
                        this.TopNz[4 + ch + x] = this.LeftNz[4 + ch + y] = res.Last >= 0 ? 1 : 0;
                    }
                }
            }

            return(r);
        }