From 272432ce759dbfa2b886fa86af4ba08d0689b59d Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 13 Jul 2021 17:00:55 -0700 Subject: [PATCH] get rid of our ugly rounding code It turns out "truncating" the last 4 bits is actually more accurate, because it divides up the palette evenly. Before: 0-7 -> 0 8-0x17 -> 1 0x18-0x27 -> 2 ... 0xd8-0xe7 -> 0xe 0xe8-0xff -> 0xf The first interval is just 8 shades, and the final interval is 24 shades. --- img.mu | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/img.mu b/img.mu index 73aea245..0d58fb0d 100644 --- a/img.mu +++ b/img.mu @@ -487,14 +487,7 @@ fn dither-pgm-unordered _src: (addr image), _dest: (addr image) { break-if-<= nearest-color <- copy 0xf0 } - # . round to nearest multiple of 0x10 - { - var tmp/ecx: int <- copy nearest-color - tmp <- and 0xf - compare tmp, 8 - break-if-< - nearest-color <- add 8 - } + # . truncate last 4 bits nearest-color <- and 0xf0 # error -= (nearest-color << 16) {