Skip to content

fix(dds): keep the colours of DDS pictures inside other files - #745

Merged
KnifeLemon merged 1 commit into
KnifeLemon:mainfrom
SeoJCalive:fix/741-dds-in-other-files
Oct 29, 2026
Merged

KnifeLemon merged 1 commit into
KnifeLemon:mainfrom
SeoJCalive:fix/741-dds-in-other-files

Conversation

@SeoJCalive

Copy link
Copy Markdown
Collaborator

What does this change?

Closes #741. Follow-up to #627, as asked there.

DDS pictures inside other files now keep their colours. Each of these places decodes an embedded DDS with ImageMagick and re-encodes it as PNG, but without the red/blue correction that standalone DDS conversion and the crop window have had since #627. They now call DdsChannelOrder.Correct right after reading the image:

Place Covers
EbookFiles.CommonImage Pictures and covers in EPUB, FB2, HTMLZ, TXTZ, HTML and Markdown output
DocxWriter.WritePackage DOCX output
HwpxWriter.WritePackage HWPX output
GltfFormat.TextureForGltf GLB/glTF textures

glTF textures come as bytes, not a file, so DdsChannelOrder gets a Correct(ReadOnlySpan<byte>, image) overload. It shares the header check and the existing probes with the file version. The shared LayoutOf now returns "not this layout" for anything shorter than the 128-byte header before it reads a field, so short or broken bytes are never corrected and never throw.

Not in this PR:

  • A DDS saved under a .svg name in HtmlReader
  • Comic-book pages, which already skip .dds
  • Mipmap and cube-map handling
  • Any new format classification or route change

Type of change

  • Bug fix
  • New feature or improvement
  • New format or engine
  • Translation
  • Documentation
  • Build, CI or dependencies

How was it tested?

  • dotnet format --verify-no-changes: no changes. Build warnings are the same as on main.
  • dotnet test: new tests for MD→EPUB, MD→DOCX, MD→HWPX and OBJ/MTL→GLB, each for both alpha flags, read the real output PNG and check that every RGB pixel matches the source red. Byte tests check that null, empty, 1 to 127 byte and malformed headers get no swap, and that the byte and file checks agree. Removing any one of the four new Correct calls fails its test with blue instead of red. Dropping the length guard or always swapping fails the byte tests.
  • Tried it with the CLI on Linux: every conversion that came out swapped before, plus embedded FBX textures and GLB/glTF output, now gives pure red (43 runs). Since a bundled Pandoc takes HTML→MD, I also checked that route without Pandoc.

Full Engines, Core and App tests on Linux (Release): the failures are the same by name as on main on this machine (rhwp needs a newer glibc, LibreOffice and FFmpeg codec setup, and one engines page check). Only the 11 new tests were added, and they pass.

Screenshots (UI changes)

No UI change.

Checklist

  • New UI strings are in all src/Filee.App/Assets/i18n/*.json files (none)
  • New third-party code or binaries are listed in THIRD-PARTY-NOTICES.md (none)
  • The PR does one thing (unrelated changes go in a separate PR)

E-book pictures, DOCX and HWPX output and glTF textures decode an
embedded DDS with ImageMagick and re-encode it as PNG, so they came
out with red and blue swapped. Call DdsChannelOrder.Correct there as
well, add a byte overload for textures, and reject headers shorter
than 128 bytes before reading them.

Closes KnifeLemon#741
@github-actions github-actions Bot added the bug Something isn't working label Oct 29, 2026

@KnifeLemon KnifeLemon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks, @SeoJCalive! All four places now go through DdsChannelOrder.Correct, the byte overload shares the header check, and the short-header guard keeps broken bytes from being read. The arm64 failure on the first run was StallWatchTests, a timing test unrelated to this change.

@KnifeLemon
KnifeLemon merged commit 241bf6c into KnifeLemon:main Oct 29, 2026
15 of 17 checks passed
@SeoJCalive
SeoJCalive deleted the fix/741-dds-in-other-files branch October 29, 2026 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DDS pictures inside other files still come out with red and blue swapped

2 participants