shithub: pokecrystal

Download patch

ref: 8c77d6b6d3303fdb75aa4b4fab9f8f9d299438e0
parent: dc121712feab286bb1533b7de6b98e26c1033785
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Sun Apr 17 11:27:31 EDT 2022

Simplify mingle_2bpp_planes

Fixes #891

--- a/tools/bpp2png.c
+++ b/tools/bpp2png.c
@@ -70,8 +70,8 @@
 	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;
 	}