Skip to content

[ImageResizer] Fix JPEG quality setting ignored after WinUI3 migration#47134

Merged
moooyo merged 1 commit intomainfrom
yuleng/ir/f/5
Apr 22, 2026
Merged

[ImageResizer] Fix JPEG quality setting ignored after WinUI3 migration#47134
moooyo merged 1 commit intomainfrom
yuleng/ir/f/5

Conversation

@moooyo
Copy link
Copy Markdown
Contributor

@moooyo moooyo commented Apr 21, 2026

Summary of the Pull Request

Restores honoring of the user-configured JPEG quality — via the Settings UI slider, the CLI --quality flag, or the persisted imageresizer_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. Only src/modules/imageresizer/ui/Models/ResizeOperation.cs is changed.

PR Checklist

  • Communication: I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end-user-facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Built ImageResizerCLI.csproj in Release|x64 with /p:RuntimeIdentifier=win-x64; no new warnings. Ran the resulting x64\Release\WinUI3Apps\PowerToys.ImageResizerCLI.exe against a synthetic test JPEG (a.jpg 2373×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)

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>
@github-actions
Copy link
Copy Markdown

@check-spelling-bot Report

🔴 Please review

See 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 removed defaulttonearest diu IPREVIEW ITHUMBNAIL LPCFHOOKPROC LUMA MAXDWORD MRT suntimes timespan traies udit VSync

To 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
on the yuleng/ir/f/5 branch (ℹ️ how do I use this?):

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:
@check-spelling-bot apply updates.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 forceFresh flag 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.

Comment thread src/modules/imageresizer/ui/Models/ResizeOperation.cs
Comment thread src/modules/imageresizer/ui/Models/ResizeOperation.cs
Comment thread src/modules/imageresizer/ui/Models/ResizeOperation.cs
@moooyo
Copy link
Copy Markdown
Contributor Author

moooyo commented Apr 21, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@moooyo moooyo merged commit c8ffcb7 into main Apr 22, 2026
19 checks passed
@moooyo moooyo deleted the yuleng/ir/f/5 branch April 22, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JPEG quality setting ignored after WinUI3 migration

3 participants