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

minor graphical issue when extract assets. #304

Open
iseeaitch opened this issue Jun 4, 2022 · 3 comments
Open

minor graphical issue when extract assets. #304

iseeaitch opened this issue Jun 4, 2022 · 3 comments

Comments

@iseeaitch
Copy link

When extracting assets with modlunky, there seems to be a problem with the sprites being slightly deformed.
Translucent parts(especially glowing effect) on a extracted image turns black.
This can be clearly seen at Arrow of light, jellyfish, orb, etc.

0
1
2

@gmjosack
Copy link
Member

gmjosack commented Jun 4, 2022

Interesting. Is this observed in the png itself or after loading extracted assets back into the game? Would be good to isolate if this is from the DDS to png conversion or if it's happen on Playlunky when being converted back for loading into the game.

@iseeaitch
Copy link
Author

iseeaitch commented Jun 4, 2022

It is observed in the png itself but also seems to be appeared in Playlunky.
3

@Dregu
Copy link
Contributor

Dregu commented Oct 23, 2022

Thoughts from Discord:

  1. DDS files in the game are premultiplied alpha, but extraction does not un-premultiply when making PNGs (premultiplied PNG is not even a thing but whatever)
  2. Multiplying/Dividing the alpha is lossy and we can't really get an original PNG back that could be both loaded in PL and look right in an editor
  3. Playlunky is premultiplying all images from mods, cause they are likely PNG and not premultiplied
  4. Playlunky is also premultiplying the cached vanilla files it extracted when stitching entity sheets or sprite maps, which is bad and any unmodified parts get premultiplied twice in the end
  5. Using any mods that custom sprite map to items.png will break all the other items because of 4
  6. There might even be a feedback loop so files in the cache get premultiplied again and again

Solutions:

  • Modlunky could predivide alphas when extracting, but it's not going to look the same when premultiplying again
    • We could just say the extracted PNG files are premultiplied and anyone who uses very transparent parts as base for their mods is stupid
  • Playlunky definitely shouldn't divide or premultiply cached (vanilla) files ever, only premultiply user-provided files once before caching or stitching
    • Disabling premultiplication in PL will load extracted vanilla PNG files correctly, but this is obviously a useless feature

I tried to undo the premultiplication and then load the textures again in PL https://imgur.com/a/Z4ToeAS
I extracted the divided textures with this modification but nothing looks quite right either way...

def dds_to_png(data):
    """Takes a .DDS `Image` and returns .png data."""
    img = Image.open(io.BytesIO(data))
    px = img.load()
    width, height = img.size
    for i in range(width):
        for j in range(height):
            if px[i, j][3] != 0:
                R = int(255.0 * px[i, j][0] / px[i, j][3] + 0.5)
                G = int(255.0 * px[i, j][1] / px[i, j][3] + 0.5)
                B = int(255.0 * px[i, j][2] / px[i, j][3] + 0.5)
                a = px[i, j][3]
                px[i, j] = (R, G, B, a)
    new_data = io.BytesIO()
    img.save(new_data, format="PNG")
    return new_data.getvalue()

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

3 participants