From eb6cee60221e86119b696db5156457b2b49297ec Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 10 Jul 2021 20:41:34 -0700 Subject: . --- img.mu | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/img.mu b/img.mu index 3d8d1113..f9f2d6e9 100644 --- a/img.mu +++ b/img.mu @@ -109,7 +109,7 @@ fn render-image screen: (addr screen), _img: (addr image), xmin: int, ymin: int, break-if-!= var img2-storage: image var img2/edi: (addr image) <- address img2-storage - dither-pgm-with-monochrome img, img2 + dither-pgm-unordered-monochrome img, img2 render-pbm-image screen, img2, xmin, ymin, width, height return } @@ -360,7 +360,7 @@ fn nearest-grey level-255: byte -> _/eax: int { return result } -fn dither-pgm-with-monochrome _src: (addr image), _dest: (addr image) { +fn dither-pgm-unordered-monochrome _src: (addr image), _dest: (addr image) { var src/esi: (addr image) <- copy _src var dest/edi: (addr image) <- copy _dest # copy 'width' @@ -391,10 +391,10 @@ fn dither-pgm-with-monochrome _src: (addr image), _dest: (addr image) { var src-data-ah/eax: (addr handle array byte) <- get src, data var _src-data/eax: (addr array byte) <- lookup *src-data-ah var src-data/esi: (addr array byte) <- copy _src-data - _unordered-monochrome-dither src-data, src-width, src-height, buffer, dest-data + _dither-pgm-unordered-monochrome src-data, src-width, src-height, buffer, dest-data } -fn _unordered-monochrome-dither src: (addr array byte), width: int, height: int, buf: (addr array int), dest: (addr array byte) { +fn _dither-pgm-unordered-monochrome src: (addr array byte), width: int, height: int, buf: (addr array int), dest: (addr array byte) { var y/edx: int <- copy 0 { compare y, height @@ -405,9 +405,9 @@ fn _unordered-monochrome-dither src: (addr array byte), width: int, height: int, compare x, width break-if->= #? psd "x", x, 3/fg, x, y - var error/ebx: int <- _read-buffer buf, x, y, width - $_unordered-monochrome-dither:update-error: { - var curr/eax: byte <- _read-byte-buffer src, x, y, width + var error/ebx: int <- _read-pgm-buffer buf, x, y, width + $_dither-pgm-unordered-monochrome:update-error: { + var curr/eax: byte <- _read-pgm-byte-buffer src, x, y, width var curr-int/eax: int <- copy curr 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 @@ -416,14 +416,14 @@ fn _unordered-monochrome-dither src: (addr array byte), width: int, height: int, { break-if->= #? psd "p", 0, 0x14/fg, x, y - _write-byte-buffer dest, x, y, width, 0/black - break $_unordered-monochrome-dither:update-error + _write-pgm-byte-buffer dest, x, y, width, 0/black + break $_dither-pgm-unordered-monochrome:update-error } #? psd "p", 1, 0xf/fg, x, y - _write-byte-buffer dest, x, y, width, 1/white + _write-pgm-byte-buffer dest, x, y, width, 1/white error <- subtract 0xff0000 } - _diffuse-monochrome-dithering-errors buf, x, y, width, height, error + _diffuse-dithering-error-floyd-steinberg buf, x, y, width, height, error x <- increment loop } @@ -440,7 +440,7 @@ fn _unordered-monochrome-dither src: (addr array byte), width: int, height: int, # # Error is currently a fixed-point number with 16-bit fraction. But # interestingly this function doesn't care about that. -fn _diffuse-monochrome-dithering-errors buf: (addr array int), x: int, y: int, width: int, height: int, error: int { +fn _diffuse-dithering-error-floyd-steinberg buf: (addr array int), x: int, y: int, width: int, height: int, error: int { { compare error, 0 break-if-!= @@ -466,7 +466,7 @@ fn _diffuse-monochrome-dithering-errors buf: (addr array int), x: int, y: int, w tmp <- multiply delta var xright/edx: int <- copy x xright <- increment - _accumulate-error buf, xright, y, width, tmp + _accumulate-pgm-error buf, xright, y, width, tmp } var y/ebx: int <- copy y { @@ -484,30 +484,30 @@ fn _diffuse-monochrome-dithering-errors buf: (addr array int), x: int, y: int, w tmp <- multiply delta var xleft/edx: int <- copy x xleft <- decrement - _accumulate-error buf, xleft, ybelow, width, tmp + _accumulate-pgm-error buf, xleft, ybelow, width, tmp } { var tmp/eax: int <- copy 5 tmp <- multiply delta - _accumulate-error buf, x, ybelow, width, tmp + _accumulate-pgm-error buf, x, ybelow, width, tmp } { compare x, width-1 break-if->= var xright/edx: int <- copy x xright <- increment - _accumulate-error buf, xright, ybelow, width, delta + _accumulate-pgm-error buf, xright, ybelow, width, delta } #? 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 +fn _accumulate-pgm-error buf: (addr array int), x: int, y: int, width: int, error: int { + var curr/ebx: int <- _read-pgm-buffer buf, x, y, width curr <- add error - _write-buffer buf, x, y, width, curr + _write-pgm-buffer buf, x, y, width, curr } -fn _read-buffer _buf: (addr array int), x: int, y: int, width: int -> _/ebx: int { +fn _read-pgm-buffer _buf: (addr array int), x: int, y: int, width: int -> _/ebx: int { var buf/esi: (addr array int) <- copy _buf var idx/ecx: int <- copy y idx <- multiply width @@ -517,7 +517,7 @@ fn _read-buffer _buf: (addr array int), x: int, y: int, width: int -> _/ebx: int return *result-a } -fn _write-buffer _buf: (addr array int), x: int, y: int, width: int, val: int { +fn _write-pgm-buffer _buf: (addr array int), x: int, y: int, width: int, val: int { var buf/esi: (addr array int) <- copy _buf var idx/ecx: int <- copy y idx <- multiply width @@ -529,7 +529,7 @@ fn _write-buffer _buf: (addr array int), x: int, y: int, width: int, val: int { copy-to *dest-a, src } -fn _read-byte-buffer _buf: (addr array byte), x: int, y: int, width: int -> _/eax: byte { +fn _read-pgm-byte-buffer _buf: (addr array byte), x: int, y: int, width: int -> _/eax: byte { var buf/esi: (addr array byte) <- copy _buf var idx/ecx: int <- copy y idx <- multiply width @@ -539,7 +539,7 @@ fn _read-byte-buffer _buf: (addr array byte), x: int, y: int, width: int -> _/ea return result } -fn _write-byte-buffer _buf: (addr array byte), x: int, y: int, width: int, val: byte { +fn _write-pgm-byte-buffer _buf: (addr array byte), x: int, y: int, width: int, val: byte { var buf/esi: (addr array byte) <- copy _buf var idx/ecx: int <- copy y idx <- multiply width @@ -568,7 +568,7 @@ fn show-errors buf: (addr array int), width: int, height: int, x: int, y: int { { compare x, width break-if->= - var error/ebx: int <- _read-buffer buf, x, y, width + var error/ebx: int <- _read-pgm-buffer buf, x, y, width psd "e", error, 5/fg, x, y x <- increment loop -- cgit 1.4.1-2-gfad0 iv>
decaddb4 ^
















9ea76483 ^
decaddb4 ^

c062697c ^

decaddb4 ^

c82d0176 ^
decaddb4 ^
c062697c ^
decaddb4 ^

e853b94e ^
7da71d03 ^
decaddb4 ^

15ab959d ^

decaddb4 ^



c82d0176 ^
decaddb4 ^
c062697c ^
decaddb4 ^

e853b94e ^
7da71d03 ^
decaddb4 ^



c062697c ^

c82d0176 ^
c062697c ^



e853b94e ^
7da71d03 ^
c062697c ^





c82d0176 ^
c062697c ^



e853b94e ^
7da71d03 ^
c062697c ^



32f6079f ^

c82d0176 ^
32f6079f ^



e853b94e ^
7da71d03 ^
32f6079f ^




9ea76483 ^
32f6079f ^
c82d0176 ^
32f6079f ^



e853b94e ^
7da71d03 ^
32f6079f ^



decaddb4 ^








7ac221e4 ^
decaddb4 ^
7ac221e4 ^
decaddb4 ^
7ac221e4 ^
decaddb4 ^


15ab959d ^

9ea76483 ^
15ab959d ^
9ea76483 ^
15ab959d ^
9ea76483 ^
15ab959d ^

9ea76483 ^




























decaddb4 ^













3d45bf38 ^












































c062697c ^






























































3ba63579 ^
c062697c ^

3ba63579 ^
32f6079f ^





























15ab959d ^


































9cc16d04 ^
15ab959d ^






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398