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

Support swapping of word pairs on odd rows #7

Open
mkst opened this issue Mar 28, 2023 · 0 comments
Open

Support swapping of word pairs on odd rows #7

mkst opened this issue Mar 28, 2023 · 0 comments

Comments

@mkst
Copy link
Contributor

mkst commented Mar 28, 2023

From https://www.moria.us/blog/2020/11/n64-part20-tmem-format-and-mip-maps#creating-and-loading-mipmapped-assets:

for odd-numbered rows, swap each pair of 4-byte blocks.

Here's a crappy function I used in conker (not allowed to attach it):

def swap(data, width, height, bpp):
    res = b''

    bytes_per_row = int(width * bpp >> 3)
    for i in range(height):
        row = data[i*bytes_per_row:i*bytes_per_row+bytes_per_row]
        if i % 2 == 1:
            out = b''
            if bpp == 32:
                for j in range(len(row) // 16):
                    out += row[16*j+8:16*j+16] + row[16*j:16*j+8]
            else:
                for j in range(len(row) // 8):
                    out += row[8*j+4:8*j+8] + row[8*j:8*j+4]
            res += out
        else:
            res += row
    return res

Open questions:

  • What do we currently do with non-8-byte-length'd rows?
    • Throw an exception?
  • Where is the best place to add this logic (after the iterator? as sometimes that's pulling back 1 byte and we need to work on 8 bytes at a time)

Example:
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