diff --git a/src/ImageSharp/Formats/Heif/Av1/Entropy/Av1RateDistortion.cs b/src/ImageSharp/Formats/Heif/Av1/Entropy/Av1RateDistortion.cs index c0edfb1ccd..d25f972d7c 100644 --- a/src/ImageSharp/Formats/Heif/Av1/Entropy/Av1RateDistortion.cs +++ b/src/ImageSharp/Formats/Heif/Av1/Entropy/Av1RateDistortion.cs @@ -19,6 +19,6 @@ internal static class Av1RateDistortion { long weightedRate = (long)rate * rateMultiplier; long roundedRate = (weightedRate + (1 << (Av1ProbabilityCost.CostShift - 1))) >> Av1ProbabilityCost.CostShift; - return roundedRate + distortion; + return roundedRate + (distortion << 7); } } diff --git a/tests/ImageSharp.Tests/Formats/Heif/Av1/Av1EntropyTests.cs b/tests/ImageSharp.Tests/Formats/Heif/Av1/Av1EntropyTests.cs index 966d78d8df..cbde2bf2d3 100644 --- a/tests/ImageSharp.Tests/Formats/Heif/Av1/Av1EntropyTests.cs +++ b/tests/ImageSharp.Tests/Formats/Heif/Av1/Av1EntropyTests.cs @@ -522,9 +522,9 @@ public class Av1EntropyTests [Theory] [InlineData(1, 255, 0L, 0L)] [InlineData(1, 256, 0L, 1L)] - [InlineData(128, 512, 1000L, 1128L)] - [InlineData(512, 512, 1000L, 1512L)] - [InlineData(64, 1024, 4_000_000_000L, 4_000_000_128L)] + [InlineData(128, 512, 1000L, 128_128L)] + [InlineData(512, 512, 1000L, 128_512L)] + [InlineData(64, 1024, 4_000_000_000L, 512_000_000_128L)] public void RateDistortionCostMatchesCurrentLibaom( int rateMultiplier, int rate,