Skip to content

Conversation

@Ethereal77
Copy link
Contributor

PR Details

Context: After the recent migration from System.Drawing.Common (using GDI+, Windows-specific) to FreeImage (cross-platform), the TestLoadAndSave of TestImage (in Stride.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(), in StandardImageHelper.Desktop.cs.

As an extra, I've reorganized StandardImageHelper to 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

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

* Save JPEGs with quality 90 and chroma subsampling 4:2:0 by default.
* Reorganize the class to better allow format-specific tweaks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant