Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allocate clean buffer in AnalyzeEntropy #1873

Merged
merged 2 commits into from
Dec 4, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ public void Encode_Lossless_WithDifferentMethodAndQuality_Works<TPixel>(TestImag
image.VerifyEncoder(provider, "webp", testOutputDetails, encoder);
}

[Theory]
[WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 15114)]
public void Encode_Lossless_WithBestQuality_HasExpectedSize<TPixel>(TestImageProvider<TPixel> provider, int expectedBytes)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
{
FileFormat = WebpFileFormatType.Lossless,
Method = WebpEncodingMethod.BestQuality
};

using Image<TPixel> image = provider.GetImage();
using var memoryStream = new MemoryStream();
image.Save(memoryStream, encoder);

Assert.Equal(memoryStream.Length, expectedBytes);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need strict equality? Doesn't the spec allow some space for the implementation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No the spec is not that strict. The analyses step could have choosen different transformation, e.g. here the analyses step has choosen to use the following features PREDICTION CROSS-COLOR-TRANSFORM SUBTRACT-GREEN. If one of those transformations would not been applied, the image would be still valid, but a bit larger.

Nonetheless i think we should try to aim to be as close to the reference implementation as possible and this is what libwebp would have encoded to.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok then, we can relax this restriction later if it will become necessary for some reason in the future.

}

[Theory]
[WithFile(RgbTestPattern100x100, PixelTypes.Rgba32, 85)]
[WithFile(RgbTestPattern100x100, PixelTypes.Rgba32, 60)]
Expand Down