diff options
| author | Sylvie <35663410+Rangi42@users.noreply.github.com> | 2024-10-07 12:04:01 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-07 12:04:01 -0400 |
| commit | a6715ef164f5d111d5d6937f9f523d5964952050 (patch) | |
| tree | 23f1a788fa9aa4fd8ad11caa121e3061910b69a6 /tools | |
| parent | Consistently format WRAM values (#476) (diff) | |
| download | pokeyellow-a6715ef164f5d111d5d6937f9f523d5964952050.tar.gz pokeyellow-a6715ef164f5d111d5d6937f9f523d5964952050.tar.xz pokeyellow-a6715ef164f5d111d5d6937f9f523d5964952050.zip | |
Rewrite `transpose_tiles` to be in-place (#475)
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/pkmncompress.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/tools/pkmncompress.c b/tools/pkmncompress.c index a890fc53..60d6fd0f 100644 --- a/tools/pkmncompress.c +++ b/tools/pkmncompress.c @@ -44,15 +44,18 @@ int read_bit(uint8_t *data) { } void transpose_tiles(uint8_t *data, int width) { - int size = width * width * 0x10; - uint8_t *transposed = xmalloc(size); + int size = width * width; for (int i = 0; i < size; i++) { - int j = (i / 0x10) * width * 0x10; - j = (j % size) + 0x10 * (j / size) + (i % 0x10); - transposed[j] = data[i]; + int j = (i * width + i / width) % size; + if (i < j) { + uint8_t tmp[0x10]; + uint8_t *p = data + i * COUNTOF(tmp); + uint8_t *q = data + j * COUNTOF(tmp); + memcpy(tmp, p, COUNTOF(tmp)); + memcpy(p, q, COUNTOF(tmp)); + memcpy(q, tmp, COUNTOF(tmp)); + } } - memcpy(data, transposed, size); - free(transposed); } void compress_plane(uint8_t *plane, int width) { |
