Skip to content

Commit

Permalink
Simplify mingle_2bpp_planes
Browse files Browse the repository at this point in the history
Fixes pret#891
  • Loading branch information
Rangi42 committed Apr 17, 2022
1 parent dc12171 commit 8c77d6b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tools/bpp2png.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void mingle_2bpp_planes(uint8_t *bpp_data, long size) {
for (long i = 0; i < size; i += 2) {
// Interleave aka "mingle" bits
// <https://graphics.stanford.edu/~seander/bithacks.html#Interleave64bitOps>
#define EXPAND_PLANE(b) (((b) * 0x0101010101010101ULL & 0x8040201008040201ULL) * 0x0102040810204081ULL)
uint16_t r = ((EXPAND_PLANE(bpp_data[i]) >> 49) & 0x5555) | ((EXPAND_PLANE(bpp_data[i + 1]) >> 48) & 0xAAAA);
#define EXPAND_PLANE(b) (((((b) * 0x0101010101010101ULL & 0x8040201008040201ULL) * 0x0102040810204081ULL) >> 48) & 0xAAAA)
uint16_t r = (EXPAND_PLANE(bpp_data[i]) >> 1) | EXPAND_PLANE(bpp_data[i + 1]);
bpp_data[i] = r >> 8;
bpp_data[i + 1] = r & 0xff;
}
Expand Down

0 comments on commit 8c77d6b

Please sign in to comment.