OpenKh
OpenKh copied to clipboard
IMGD refactoring
I recently became aware that IMGD files are very close to TM2 files. Therefore I updated the code to make them more similar.
Does this also handle RAWBMP images (Headerless, preset sized TM2s)?
Does this also handle RAWBMP images (Headerless, preset sized TM2s)?
No, that part will remain untouched. For now. This PR deals only with IMD.
I used OpenKh.command.ImgTool to create five test IMGD files to see if they continue to work with other programs as of this refactor. One thing I noticed is swizzled images tend to get their second half cut off. The attached zip includes the original PNG I used as well as five IMGDs I have generated. 2x 4bpp ones, one swizzled (tagged with "s"), 2x 8bpp ones, and one 32bpp one. The unswizzled images all load fine in the Image Viewer, for example, but swizzled ones are cut off. images.zip
up
I used OpenKh.command.ImgTool to create five test IMGD files to see if they continue to work with other programs as of this refactor. One thing I noticed is swizzled images tend to get their second half cut off. The attached zip includes the original PNG I used as well as five IMGDs I have generated. 2x 4bpp ones, one swizzled (tagged with "s"), 2x 8bpp ones, and one 32bpp one. The unswizzled images all load fine in the Image Viewer, for example, but swizzled ones are cut off.
I understood why this occurred just now.
Swizzling process is performed per Page size (8KB).
4bpp (PSMT4)
- Block width is fixed 128px
- Block height is: 8192 ÷ 128 × 2 → 128px
In the 4bpp mode, image width will be choice of them: 128, 256, 512, 1024 image height will be choice of them: 128, 256, 512, 1024
e.g. 128 x 128 is valid. 128 x 256 is valid too.
However 384 x 128 is invalid, because GS won't accept such a value.
Instead region clamp / region repeat can be usable in pixel unit. This technique resembles how we build CSS image sprite in big single image. This emits one texture image with 2 or more GS infos. The color palette (clut) is brought by GS info too.
8bpp (PSMT8)
- Block width is fixed 128px
- Block height is: 8192 ÷ 128 → 64px
In the 8bpp mode, image width will be choice of them: 128, 256, 512, 1024 image height will be choice of them: 64, 128, 256, 512, 1024
The source png image is 500x500. The swizzling will work if png image size is stretched to 512x512.
I'll fix merge conflict in near future...
This will be ready
Is this still necessary with the recent changes to image handling? @kenjiuno If not, I will close the pull request.
Is this still necessary with the recent changes to image handling? @kenjiuno If not, I will close the pull request.
The changes in this pull request don't affect image handling at all.
But changes are useful. The ps2 texture format is resolved like: Format4bpp → GsPSM.GS_PSMT4 And IMGD documentation is more rich.