about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-07-13 05:19:00 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-07-13 05:19:00 -0700
commit2777479a9436197fa1fa82691873ac1d8a255c94 (patch)
tree505d296c2529ef1f5b91b2bd8c6483e5c0de95ce
parent23330d06c74e8f4bcbcbb36bca107f567411eb92 (diff)
downloadmu-2777479a9436197fa1fa82691873ac1d8a255c94.tar.gz
experiment: scaling pixels to 255 levels
This is strictly worse than before, both with barbara.pgm and more
subtly with t.pgm.
-rw-r--r--img.mu16
1 files changed, 14 insertions, 2 deletions
diff --git a/img.mu b/img.mu
index 6b37a3d9..1cf57567 100644
--- a/img.mu
+++ b/img.mu
@@ -27,8 +27,8 @@ fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk)
   var img-storage: image
   var img/esi: (addr image) <- address img-storage
   load-image img, data-disk
-#?   render-image screen, img, 0/x, 0/y, 0x300/width, 0x300/height
-  render-image screen, img, 0x20/x, 0x80/y, 0x258/width=600, 0x190/height=400
+  render-image screen, img, 0/x, 0/y, 0x300/width, 0x300/height
+#?   render-image screen, img, 0x20/x, 0x80/y, 0x258/width=600, 0x190/height=400
 #?   render-image screen, img, 0x20/x, 0x80/y, 0x12c/width=300, 0xc8/height=200
 #?   render-pgm-image screen, img, 0x220/x, 0x80/y, 0x12c/width=300, 0xc8/height=200
 }
@@ -455,6 +455,12 @@ fn dither-pgm-unordered _src: (addr image), _dest: (addr image) {
     var dest-height-a/ecx: (addr int) <- get dest, height
     copy-to *dest-height-a, tmp
   }
+  # compute scaling factor 255/max
+  var target-scale/eax: int <- copy 0xff
+  var scale-f/xmm7: float <- convert target-scale
+  var src-max-a/eax: (addr int) <- get src, max
+  var tmp-f/xmm0: float <- convert *src-max-a
+  scale-f <- divide tmp-f
   # transform 'data'
   var capacity/ebx: int <- copy src-width
   capacity <- multiply src-height
@@ -478,6 +484,12 @@ fn dither-pgm-unordered _src: (addr image), _dest: (addr image) {
       compare x, src-width
       break-if->=
       var initial-color/eax: byte <- _read-pgm-buffer src-data, x, y, src-width
+      # . scale to 255 levels
+      var initial-color-int/eax: int <- copy initial-color
+      var initial-color-f/xmm0: float <- convert initial-color-int
+      initial-color-f <- multiply scale-f
+      initial-color-int <- convert initial-color-f
+      var initial-color/eax: byte <- copy-byte initial-color-int
       var error/esi: int <- _read-dithering-error errors, x, y, src-width
       # error += (initial-color << 16)
       {