private bool Decimate(Vp8EncIterator it, ref Vp8ModeScore rd, Vp8RdLevel rdOpt) { rd.InitScore(); // We can perform predictions for Luma16x16 and Chroma8x8 already. // Luma4x4 predictions needs to be done as-we-go. it.MakeLuma16Preds(); it.MakeChroma8Preds(); if (rdOpt > Vp8RdLevel.RdOptNone) { QuantEnc.PickBestIntra16(it, ref rd, this.SegmentInfos, this.Proba); if (this.method >= WebpEncodingMethod.Level2) { QuantEnc.PickBestIntra4(it, ref rd, this.SegmentInfos, this.Proba, this.maxI4HeaderBits); } QuantEnc.PickBestUv(it, ref rd, this.SegmentInfos, this.Proba); } else { // At this point we have heuristically decided intra16 / intra4. // For method >= 2, pick the best intra4/intra16 based on SSE (~tad slower). // For method <= 1, we don't re-examine the decision but just go ahead with // quantization/reconstruction. QuantEnc.RefineUsingDistortion(it, this.SegmentInfos, rd, this.method >= WebpEncodingMethod.Level2, this.method >= WebpEncodingMethod.Level1, this.MbHeaderLimit); } bool isSkipped = rd.Nz == 0; it.SetSkip(isSkipped); return(isSkipped); }
private int MbAnalyze(Vp8EncIterator it, int[] alphas, out int bestUvAlpha) { it.SetIntra16Mode(0); // default: Intra16, DC_PRED it.SetSkip(false); // not skipped. it.SetSegment(0); // default segment, spec-wise. int bestAlpha; if (this.method <= WebpEncodingMethod.Level1) { bestAlpha = it.FastMbAnalyze(this.quality); } else { bestAlpha = it.MbAnalyzeBestIntra16Mode(); if (this.method >= WebpEncodingMethod.Level5) { // We go and make a fast decision for intra4/intra16. // It's usually not a good and definitive pick, but helps seeding the stats about level bit-cost. bestAlpha = it.MbAnalyzeBestIntra4Mode(bestAlpha); } } bestUvAlpha = it.MbAnalyzeBestUvMode(); // Final susceptibility mix. bestAlpha = ((3 * bestAlpha) + bestUvAlpha + 2) >> 2; bestAlpha = FinalAlphaValue(bestAlpha); alphas[bestAlpha]++; it.CurrentMacroBlockInfo.Alpha = bestAlpha; // For later remapping. return(bestAlpha); // Mixed susceptibility (not just luma). }