Skip to content

Commit

Permalink
Rewrite transpose_tiles to be in-place (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 authored Oct 7, 2024
1 parent a8f2614 commit a6715ef
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions tools/pkmncompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a6715ef

Please sign in to comment.