Пример #1
0
        public int MbAnalyzeBestUvMode()
        {
            int bestAlpha     = DefaultAlpha;
            int smallestAlpha = 0;
            int bestMode      = 0;
            int maxMode       = MaxUvMode;
            int mode;

            this.MakeChroma8Preds();
            for (mode = 0; mode < maxMode; ++mode)
            {
                var histo = new Vp8Histogram();
                histo.CollectHistogram(this.YuvIn.AsSpan(UOffEnc), this.YuvP.AsSpan(Vp8Encoding.Vp8UvModeOffsets[mode]), 16, 16 + 4 + 4);
                int alpha = histo.GetAlpha();
                if (alpha > bestAlpha)
                {
                    bestAlpha = alpha;
                }

                // The best prediction mode tends to be the one with the smallest alpha.
                if (mode == 0 || alpha < smallestAlpha)
                {
                    smallestAlpha = alpha;
                    bestMode      = mode;
                }
            }

            this.SetIntraUvMode(bestMode);
            return(bestAlpha);
        }
Пример #2
0
        public int MbAnalyzeBestIntra4Mode(int bestAlpha)
        {
            byte[] modes      = new byte[16];
            int    maxMode    = MaxIntra4Mode;
            var    totalHisto = new Vp8Histogram();
            int    curHisto   = 0;

            this.StartI4();
            do
            {
                int         mode;
                int         bestModeAlpha = DefaultAlpha;
                var         histos        = new Vp8Histogram[2];
                Span <byte> src           = this.YuvIn.AsSpan(YOffEnc + WebpLookupTables.Vp8Scan[this.I4]);

                this.MakeIntra4Preds();
                for (mode = 0; mode < maxMode; ++mode)
                {
                    histos[curHisto] = new Vp8Histogram();
                    histos[curHisto].CollectHistogram(src, this.YuvP.AsSpan(Vp8Encoding.Vp8I4ModeOffsets[mode]), 0, 1);

                    int alpha = histos[curHisto].GetAlpha();
                    if (alpha > bestModeAlpha)
                    {
                        bestModeAlpha  = alpha;
                        modes[this.I4] = (byte)mode;

                        // Keep track of best histo so far.
                        curHisto ^= 1;
                    }
                }

                // Accumulate best histogram.
                histos[curHisto ^ 1].Merge(totalHisto);
            }while (this.RotateI4(this.YuvIn.AsSpan(YOffEnc))); // Note: we reuse the original samples for predictors.

            int i4Alpha = totalHisto.GetAlpha();

            if (i4Alpha > bestAlpha)
            {
                this.SetIntra4Mode(modes);
                bestAlpha = i4Alpha;
            }

            return(bestAlpha);
        }
Пример #3
0
        public int MbAnalyzeBestIntra16Mode()
        {
            int maxMode = MaxIntra16Mode;
            int mode;
            int bestAlpha = DefaultAlpha;
            int bestMode  = 0;

            this.MakeLuma16Preds();
            for (mode = 0; mode < maxMode; mode++)
            {
                var histo = new Vp8Histogram();
                histo.CollectHistogram(this.YuvIn.AsSpan(YOffEnc), this.YuvP.AsSpan(Vp8Encoding.Vp8I16ModeOffsets[mode]), 0, 16);
                int alpha = histo.GetAlpha();
                if (alpha > bestAlpha)
                {
                    bestAlpha = alpha;
                    bestMode  = mode;
                }
            }

            this.SetIntra16Mode(bestMode);
            return(bestAlpha);
        }