Skip to content
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

Missing documentation / weird behaviour with PNG where size % 4 != 0 #32

Open
arthurlm opened this issue Sep 12, 2022 · 0 comments
Open

Comments

@arthurlm
Copy link
Contributor

Hi,

This question may have been ask earlier on GRRLIB forum, but I did not find any reference to this issue.

Problem description

There is weird / maybe undocumented behavior with PNG texture loading.
If texture width or height is not multiple of 4, then PNG data is zeroed.

This is due to the following check in GRRLIB_LoadTexturePNG:

if (imgProp.imgWidth != width || imgProp.imgHeight != height) {
// PNGU has resized the texture
memset(my_texture->data, 0, (my_texture->h * my_texture->w) << 2);
}

Width and height parameter are changed in libpngu in function PNGU_DecodeTo4x4RGBA8 here:

if(padWidth%4) padWidth += (4-padWidth%4);
if(padHeight%4) padHeight += (4-padHeight%4);

There are others conditions that may update witdh and height but this one is the most obvious and error prone to me.

Questions

What is the exact purpose of this check ?
Why cannot we load not multiple by 4 PNG data ?
When check is removed, all seems to work fine. Is this related to Wii hardware ?

Do we really need to recompute image size + decode PNG data if content is zeroed after ?
Does this check can be moved to libpngu ?
Looking at the code, most PNG loading tricks are not needed if we drop content.
Function can be simplified (see 2654a89).

This may be silly, but what is the exact purpose of libpngu ?
Is it here to make an abstraction layer between GRRLIB and libpng ?
Does it come from somewhere else ? Most of the code in it look unused / dead.

Should we add some documentation on GRRLIB_LoadTexturePNG on the image size multiple by 4 (instead of not correct) ?

Code to reproduce

I have made a branch on repository fork to store code and resources (see commit: 2b73935).

Bellow are some screenshot of running application.

  • with image of 352*89:
    image

  • with image of 352*82:
    image

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

No branches or pull requests

1 participant