Browse Source

Correct AV1 distortion cost scaling

pull/2633/head
James Jackson-South 1 month ago
parent
commit
43035256d7
  1. 2
      src/ImageSharp/Formats/Heif/Av1/Entropy/Av1RateDistortion.cs
  2. 6
      tests/ImageSharp.Tests/Formats/Heif/Av1/Av1EntropyTests.cs

2
src/ImageSharp/Formats/Heif/Av1/Entropy/Av1RateDistortion.cs

@ -19,6 +19,6 @@ internal static class Av1RateDistortion
{ {
long weightedRate = (long)rate * rateMultiplier; long weightedRate = (long)rate * rateMultiplier;
long roundedRate = (weightedRate + (1 << (Av1ProbabilityCost.CostShift - 1))) >> Av1ProbabilityCost.CostShift; long roundedRate = (weightedRate + (1 << (Av1ProbabilityCost.CostShift - 1))) >> Av1ProbabilityCost.CostShift;
return roundedRate + distortion; return roundedRate + (distortion << 7);
} }
} }

6
tests/ImageSharp.Tests/Formats/Heif/Av1/Av1EntropyTests.cs

@ -522,9 +522,9 @@ public class Av1EntropyTests
[Theory] [Theory]
[InlineData(1, 255, 0L, 0L)] [InlineData(1, 255, 0L, 0L)]
[InlineData(1, 256, 0L, 1L)] [InlineData(1, 256, 0L, 1L)]
[InlineData(128, 512, 1000L, 1128L)] [InlineData(128, 512, 1000L, 128_128L)]
[InlineData(512, 512, 1000L, 1512L)] [InlineData(512, 512, 1000L, 128_512L)]
[InlineData(64, 1024, 4_000_000_000L, 4_000_000_128L)] [InlineData(64, 1024, 4_000_000_000L, 512_000_000_128L)]
public void RateDistortionCostMatchesCurrentLibaom( public void RateDistortionCostMatchesCurrentLibaom(
int rateMultiplier, int rateMultiplier,
int rate, int rate,

Loading…
Cancel
Save