diff options
Diffstat (limited to 'img.mu')
-rw-r--r-- | img.mu | 135 |
1 files changed, 47 insertions, 88 deletions
diff --git a/img.mu b/img.mu index eab6a04a..0f8d4b6c 100644 --- a/img.mu +++ b/img.mu @@ -411,7 +411,6 @@ fn _unordered-monochrome-dither src: (addr array byte), width: int, height: int, curr-int <- shift-left 0x10 # we have 32 bits; we'll use 16 bits for the fraction and leave 8 for unanticipated overflow error <- add curr-int #? psd "e", error, 5/fg, x, y -#? draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, error, 7/fg 0/bg compare error, 0x800000 { break-if->= @@ -424,17 +423,6 @@ fn _unordered-monochrome-dither src: (addr array byte), width: int, height: int, error <- subtract 0xff0000 } _diffuse-monochrome-dithering-errors buf, x, y, width, height, error -#? { -#? compare y, 3 -#? break-if-!= -#? compare x, 4 -#? break-if->= -#? { -#? var b/eax: byte <- read-key 0/keyboard -#? compare b, 0 -#? loop-if-= -#? } -#? } x <- increment loop } @@ -444,51 +432,6 @@ fn _unordered-monochrome-dither src: (addr array byte), width: int, height: int, } } -fn show-errors buf: (addr array int), width: int, height: int, x: int, y: int { - compare y, 1 - { - break-if-= - return - } - compare x, 0 - { - break-if-= - return - } - var y/edx: int <- copy 0 - { - compare y, height - break-if->= - var x/ecx: int <- copy 0 - { - compare x, width - break-if->= - var error/ebx: int <- _read-buffer buf, x, y, width - psd "e", error, 5/fg, x, y - x <- increment - loop - } - move-cursor-to-left-margin-of-next-line 0/screen - y <- increment - loop - } -} - -fn psd s: (addr array byte), d: int, fg: int, x: int, y: int { -#? { -#? compare y, 3 -#? break-if-= -#? return -#? } -#? { -#? compare x, 4 -#? break-if-< -#? return -#? } - draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, s, 7/fg 0/bg - draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, d, fg 0/bg -} - # Use Floyd-Steinberg algorithm for turning an image of greyscale pixels into # one of pure black or white pixels. # @@ -507,25 +450,9 @@ fn _diffuse-monochrome-dithering-errors buf: (addr array int), x: int, y: int, w var height-1/edi: int <- copy height height-1 <- decrement # delta = error/16 - show-errors buf, width, height, x, y - { - compare y, 1 - break-if-!= - compare x, 0 - break-if-!= - draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, error, 3/fg 0/bg - move-cursor-to-left-margin-of-next-line 0/screen - } +#? show-errors buf, width, height, x, y var delta/ecx: int <- copy error delta <- shift-right-signed 4 - { - compare y, 1 - break-if-!= - compare x, 0 - break-if-!= - draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, delta, 2/fg 0/bg - move-cursor-to-left-margin-of-next-line 0/screen - } # In Floyd-Steinberg, each pixel X transmits its errors to surrounding # pixels in the following proportion: # X 7/16 @@ -540,7 +467,6 @@ fn _diffuse-monochrome-dithering-errors buf: (addr array int), x: int, y: int, w xright <- increment _accumulate-error buf, xright, y, width, tmp } -#? show-errors buf, width, height, x, y var y/ebx: int <- copy y { compare y, height-1 @@ -550,8 +476,6 @@ fn _diffuse-monochrome-dithering-errors buf: (addr array int), x: int, y: int, w var ybelow: int copy-to ybelow, y increment ybelow -#? var ybelow/edi: int <- copy y -#? ybelow <- increment { compare x, 0 break-if-<= @@ -561,13 +485,11 @@ fn _diffuse-monochrome-dithering-errors buf: (addr array int), x: int, y: int, w xleft <- decrement _accumulate-error buf, xleft, ybelow, width, tmp } -#? show-errors buf, width, height, x, y { var tmp/eax: int <- copy 5 tmp <- multiply delta _accumulate-error buf, x, ybelow, width, tmp } -#? show-errors buf, width, height, x, y { compare x, width-1 break-if->= @@ -575,21 +497,13 @@ fn _diffuse-monochrome-dithering-errors buf: (addr array int), x: int, y: int, w xright <- increment _accumulate-error buf, xright, ybelow, width, delta } - show-errors buf, width, height, x, y +#? show-errors buf, width, height, x, y } fn _accumulate-error buf: (addr array int), x: int, y: int, width: int, error: int { var curr/ebx: int <- _read-buffer buf, x, y, width curr <- add error -#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "{", 7/fg 0/bg -#? move-cursor-to-left-margin-of-next-line 0/screen -#? show-errors buf, width, 3/height _write-buffer buf, x, y, width, curr -#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "===", 7/fg 0/bg -#? move-cursor-to-left-margin-of-next-line 0/screen -#? show-errors buf, width, 3/height -#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "}", 7/fg 0/bg -#? move-cursor-to-left-margin-of-next-line 0/screen } fn _read-buffer _buf: (addr array int), x: int, y: int, width: int -> _/ebx: int { @@ -634,6 +548,51 @@ fn _write-byte-buffer _buf: (addr array byte), x: int, y: int, width: int, val: copy-byte-to *dest-a, src } +fn show-errors buf: (addr array int), width: int, height: int, x: int, y: int { + compare y, 1 + { + break-if-= + return + } + compare x, 0 + { + break-if-= + return + } + var y/edx: int <- copy 0 + { + compare y, height + break-if->= + var x/ecx: int <- copy 0 + { + compare x, width + break-if->= + var error/ebx: int <- _read-buffer buf, x, y, width + psd "e", error, 5/fg, x, y + x <- increment + loop + } + move-cursor-to-left-margin-of-next-line 0/screen + y <- increment + loop + } +} + +fn psd s: (addr array byte), d: int, fg: int, x: int, y: int { +#? { +#? compare y, 3 +#? break-if-= +#? return +#? } +#? { +#? compare x, 4 +#? break-if-< +#? return +#? } + draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, s, 7/fg 0/bg + draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, d, fg 0/bg +} + # import a color ascii "pixmap" (each pixel consists of 3 shades of r/g/b from 0 to 255) fn initialize-image-from-ppm _self: (addr image), in: (addr stream byte) { var self/esi: (addr image) <- copy _self |