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