Set default quality flags when saving in JPEG format #3034
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Details
Context: After the recent migration from
System.Drawing.Common(using GDI+, Windows-specific) to FreeImage (cross-platform), theTestLoadAndSaveofTestImage(inStride.Graphics.Tests) started failing for me. However, it only fails when the source (reference image to compare against) and the destination formats are both JPEG.The failure seems to be caused by differences in the way FreeImage encodes JPEGs, the quality, chroma subsampling, and possibly other things. This makes the resulting JPEG be more compressed and with worse quality, and the test image comparison fails because the differences are greater than the allowed difference of 30.
Solution: This PR sets quality and chroma subsampling flags so FreeImage can save an image more in line with the default configuration GDI+ was producing before the migration, making the test pass again. The key part is in
SaveJpegFromMemory(), inStandardImageHelper.Desktop.cs.As an extra, I've reorganized
StandardImageHelperto be more readable and to be able to set custom format-specific flags easier in the future. Currently the files are being saved using FreeImage defaults, and custom flags are hardcoded. I've also improved the documentation and comments.Related Issue
No issue. Discussed briefly on Discord.
Types of changes
Checklist