Skip to content

Fix Switch swizzle texture conversion and optimize Texture2DConverter #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from

Conversation

isHarryh
Copy link
Contributor

@isHarryh isHarryh commented May 26, 2025

Summary

This PR mainly fixes the issue of Switch texture decoding, including:

  • Fixes Alpha8 swizzle texture decoding and encoding.
  • Fixes RGB24 swizzle texture decoding and encoding.
  • Fixes DXT5 swizzle texture decoding and encoding.
  • Fixes incorrect swizzle detection (platform blob).

This PR also does some improvements and small fixes to the Texture2DConverter:

  • Removes the unnecessary copy procedure in parse_image_data, making it ~5% faster.
  • Removes the unnecessary paste procedure in pad_image, making it ~20% faster.
  • Fixes an error in swap_bytes_for_xbox that bytes object is not mutable.
  • Changes A mode to L mode in image_to_texture2d, because A is not a valid PIL image mode.
  • Refactors the CONV_TABLE.
    • Now TextureFormat -> (converter function, (additional args, ...)).
    • Typo of EAC_R_SIGNED has been fixed.
    • ETC series uses "ETC2_RGB"-like fmt instead of [2, "RGB"]-like.
  • Wraps the functions in the TextureSwizzler.

Related Issues

Fixes #317

Fixes #319

@isHarryh isHarryh force-pushed the patch-texture branch 2 times, most recently from 0fa3a2b to dbe9b2e Compare May 26, 2025 14:18
@isHarryh isHarryh changed the title Fix Alpha8 texture conversion and optimize Texture2DConverter Fix Switch swizzle texture conversion and optimize Texture2DConverter May 26, 2025
@isHarryh
Copy link
Contributor Author

Tests

Samples provided by #317 and #319 .

Format Decoding Encoding
Alpha8 swizzle
RGBA32 swizzle
BGRA32 swizzle ? ?
RGB24 swizzle
BGR24 swizzle ? ?
DXT1 swizzle ? ?
DXT5 swizzle

√ = tested, ? = not tested but theoretically okay

tests_result.zip

@isHarryh
Copy link
Contributor Author

Oh! It seems you forgot about my PR and independently resolved the swizzle texture issue in version 1.22.4.

However, there are still some issues with your implementation.

Due to commit conflicts, I’ll go ahead and close this PR and open new PRs to address these problems, while also including the other optimizations from this PR.

@K0lb3

@K0lb3
Copy link
Owner

K0lb3 commented May 28, 2025

I implemented a fixed version before I saw that you included it as well, otherwise I would have sticked and requested a fair amount of changes.
Imo PRs that fix things should more or less stay atomar and only implement the fix, and nothing else.
This makes it easier to review and therefore gets merged faster.

Regarding the changes I would have requested, it would have started with using the formatting defined by rust.toml.
I might be at fault for that not being correct, as I borked the inclusion pattern in ruff.toml, but in the end it could still be seen in the git difference.

Some asserts you included aren't really necessary, at least the type checker didn't complain to me about those points, and I don't really see how a type checker could get confused by some of them.

Anyway, in case I didn't annoy you too much with my behavior,
I would be happy to merge threeseparate PRs based on your changes.

  • the alpha fix
  • the changes to etc and eac
  • the removal of the unnecessary paste

@isHarryh
Copy link
Contributor Author

Sorry for changing too many things in one single PR. I am also happy to draft new separated PRs later to fix these remaining things.

@isHarryh
Copy link
Contributor Author

isHarryh commented Jun 1, 2025

Fine. Now all the changes this PR addressed has been implemented in 1.22.5.

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.

Export Texture2D swizzle problem for TokimekiGirlSide3 switch Export Texture2D wrong for game TokimekiMemorial1 switch
2 participants