[ImageResizer] Fix JPEG quality setting ignored after WinUI3 migration#47134
[ImageResizer] Fix JPEG quality setting ignored after WinUI3 migration#47134
Conversation
Regression from #45288 (WPF → WinUI3 migration): user-configured JPEG quality — whether set via the Settings UI slider, the CLI --quality flag, or the persisted imageresizer_jpegQualityLevel — had no effect on output. Any Q value from 1 to 100 produced byte-identical JPEGs at WIC's internal default (~Q90). Root cause: the transcode path calls BitmapEncoder.CreateForTranscodingAsync, which has no overload that accepts a BitmapPropertySet. The code tried to inject ImageQuality afterwards via encoder.BitmapProperties.SetPropertiesAsync — but that API writes image metadata (EXIF-style tags), not codec encoder options. So the encoder always ran with its built-in default quality. Fix: route JPEG output through FreshEncodeAsync whenever a real transform happens, so ImageQuality can be supplied at encoder-creation time via the correct BitmapEncoder.CreateAsync(id, stream, propertySet) overload. The noTransformNeeded shrink-only fast path stays on transcode (no re-encoding, quality is moot). AI super-resolution always takes the fresh path since SetSoftwareBitmap is incompatible with the transcode encoder anyway. Trade-off: JPEG transforms no longer get the transcode encoder's implicit metadata forwarding. FreshEncodeAsync is extended to copy KnownMetadataProperties (camera make/model, shoot time, orientation, color space, comment) from source to output so EXIF isn't silently wiped. Richer metadata (GPS, full capture settings) can be added in a follow-up — initial attempt to widen the copy list triggered atomic SetPropertiesAsync failures that regressed the conservative baseline. Verified: Q=5 → 13 KB, Q=50 → 38 KB, Q=95 → 103 KB (monotonic, was ~78 KB regardless). 9 of 42 source EXIF properties carry through on a real camera JPEG; --remove-metadata still strips as before. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@check-spelling-bot Report🔴 Please reviewSee the 📂 files view, the 📜action log, 👼 SARIF report, or 📝 job summary for details.Unrecognized words (1)DEFAULTTONEAREST These words are not needed and should be removeddefaulttonearest diu IPREVIEW ITHUMBNAIL LPCFHOOKPROC LUMA MAXDWORD MRT suntimes timespan traies udit VSyncTo accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands... in a clone of the git@github.com:microsoft/PowerToys.git repository curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/cfb6f7e75bbfc89c71eaa30366d0c166f1bd9c8c/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/24719121352/attempts/1' &&
git commit -m 'Update check-spelling metadata'OR To have the bot accept them for you, comment in the PR quoting the following line: If the flagged items are 🤯 false positivesIf items relate to a ...
|
There was a problem hiding this comment.
Pull request overview
Restores honoring of the user-configured JPEG quality setting in Image Resizer after the WinUI3 migration by changing how JPEG outputs are encoded (fresh-encode vs transcode) so codec options can take effect.
Changes:
- Introduces a
forceFreshflag to bypass WIC transcoding in cases where JPEG quality must apply. - Routes AI Super Resolution output through the fresh-encoder path (required for
SetSoftwareBitmap). - Adjusts fresh-encode metadata handling to explicitly carry over a selected set of properties.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Summary of the Pull Request
Restores honoring of the user-configured JPEG quality — via the Settings UI slider, the CLI
--qualityflag, or the persistedimageresizer_jpegQualityLevel— when resizing JPEG files. Since the WinUI3 migration (#45288) any Q value from 1 to 100 produced byte-identical output at WIC's internal default (~Q90) because the transcode encoder silently ignored the setting. Onlysrc/modules/imageresizer/ui/Models/ResizeOperation.csis changed.PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed
Built
ImageResizerCLI.csprojinRelease|x64with/p:RuntimeIdentifier=win-x64; no new warnings. Ran the resultingx64\Release\WinUI3Apps\PowerToys.ImageResizerCLI.exeagainst a synthetic test JPEG (a.jpg2373×905, ~240 KB) and both in-tree EXIF assets:src/modules/imageresizer/tests/TestMetadataIssue1928.jpg(42 EXIF properties)src/modules/imageresizer/tests/TestMetadataIssue2447.jpg(44 EXIF properties)