about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-07-13 17:00:55 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-07-13 17:00:55 -0700
commit272432ce759dbfa2b886fa86af4ba08d0689b59d (patch)
tree997998225cc57f57fdca9e4dea0173502ba85f6f
parent62a2afe0d842534f00decb9e8e4c85cdbcf36bff (diff)
downloadmu-272432ce759dbfa2b886fa86af4ba08d0689b59d.tar.gz
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.
-rw-r--r--img.mu9
1 files changed, 1 insertions, 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)
       {