OpenKh icon indicating copy to clipboard operation
OpenKh copied to clipboard

IMGD refactoring

Open Xeeynamo opened this issue 4 years ago • 4 comments

I recently became aware that IMGD files are very close to TM2 files. Therefore I updated the code to make them more similar.

Xeeynamo avatar Feb 15 '21 18:02 Xeeynamo

Does this also handle RAWBMP images (Headerless, preset sized TM2s)?

ghost avatar Feb 15 '21 20:02 ghost

Does this also handle RAWBMP images (Headerless, preset sized TM2s)?

No, that part will remain untouched. For now. This PR deals only with IMD.

Xeeynamo avatar Feb 15 '21 20:02 Xeeynamo

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

Vladabdf avatar Feb 16 '21 05:02 Vladabdf

up

Xeeynamo avatar Mar 28 '21 12:03 Xeeynamo

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.

2023-01-25_21h01_09

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.

2023-01-25_21h10_37

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.

kenjiuno avatar Jan 25 '23 12:01 kenjiuno

I'll fix merge conflict in near future...

kenjiuno avatar Jan 25 '23 12:01 kenjiuno

This will be ready

kenjiuno avatar Jan 26 '23 03:01 kenjiuno

Is this still necessary with the recent changes to image handling? @kenjiuno If not, I will close the pull request.

Vladabdf avatar Aug 03 '23 02:08 Vladabdf

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.

kenjiuno avatar Aug 03 '23 05:08 kenjiuno