Floyd–Steinberg dithering

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder: http://www.swissmicros.com/dm42/decoder/

You can then copy/paste the listing and post it in "code" tags.
Post Reply
wginolas
Posts: 1
Joined: Sun Mar 08, 2020 2:57 pm

Floyd–Steinberg dithering

Post by wginolas » Mon Mar 09, 2020 1:15 pm

Hi, I wrote program which plots the result of a 2D function as grayscale value.
Since the display can only display black and white pixels, I am using
Floyd–Steinberg dithering.

Here are some examples:

BALL
Image

GRAD
Image

MAND
Image

RING
Image

When you run FPLOT you will be asked for

1. XMIN, XMAX, YMIN, YMAX
2. The name of the program to call for every pixel
3. The screen resolution to use (Low: 200x120, High: 400x240)

The input for the chosen function is:
X: The coordinates of the current pixel as complex value

The output of the chosen function should be:
X: The color the pixel should get (0 => black, 1 => white)

Code: Select all

00 { 579-Byte Prgm }
01▸LBL "FPLOT"
02 MVAR "XMIN"
03 MVAR "XMAX"
04 MVAR "YMIN"
05 MVAR "YMAX"
06▸LBL A
07 VARMENU "FPLOT"
08 "Ready"
09 PROMPT
10 CLA
11 SF 25
12 RCL "FCN"
13 CF 25
14 STR?
15 ARCL ST X
16 AON
17 STOP
18 AOFF
19 ALENG
20 X=0?
21 GTO A
22 ASTO "FCN"
23 CLA
24 CLMENU
25 "Resolution?"
26 AVIEW
27 "High"
28 KEY 1 XEQ 81
29 "Low"
30 KEY 2 XEQ 82
31 MENU
32 STOP
33 STO "GrMod"
34 EXITALL
35 1
36 1
37 NEWMAT
38 LSTO "M"
39 RCL "XMIN"
40 RCL "YMIN"
41 COMPLEX
42 LSTO "CY"
43 LSTO "C"
44 RCL "XMAX"
45 RCL "XMIN"
46 -
47 RCL "ResX"
48 ÷
49 LSTO "SX"
50 0
51 RCL "YMAX"
52 RCL "YMIN"
53 -
54 RCL "ResY"
55 ÷
56 COMPLEX
57 LSTO "SY"
58 CLLCD
59 RCL "ResY"
60 1ᴇ3
61 ÷
62 1
63 +
64 LSTO "Y"
65▸LBL 10
66 2
67 RCL "ResX"
68 2
69 +
70 DIM "M"
71 INDEX "M"
72 1
73 2
74 STOIJ
75 RCL "ResX"
76 1ᴇ3
77 ÷
78 1
79 +
80 LSTO "X"
81▸LBL 11
82 RCL "C"
83 XEQ IND "FCN"
84 1
85 X>Y?
86 R↓
87 X<0?
88 0
89 XEQ 30
90 FS? 00
91 GTO 12
92 RCL "Y"
93 RCL "X"
94 PIXEL
95▸LBL 12
96 RCL "SX"
97 STO+ "C"
98 ISG "X"
99 GTO 11
100 DELR
101 RCL "SY"
102 STO+ "CY"
103 RCL "CY"
104 STO "C"
105 ISG "Y"
106 GTO 10
107 PRLCD
108 STOP
109 "CALC PIXEL"
110▸LBL 30
111 RCLEL
112 +
113 CF 00
114 0.5
115 X<Y?
116 SF 00
117 R↓
118 FS? 00
119 1
120 FC? 00
121 0
122 -
123 J-
124 I+
125 RCL ST X
126 0.1875
127 ×
128 RCLEL
129 +
130 STOEL
131 R↓
132 J+
133 RCL ST X
134 0.3125
135 ×
136 RCLEL
137 +
138 STOEL
139 R↓
140 J+
141 RCL ST X
142 0.0625
143 ×
144 RCLEL
145 +
146 STOEL
147 R↓
148 I-
149 0.4375
150 ×
151 RCLEL
152 +
153 STOEL
154 RTN
155▸LBL 81
156 3
157 RTN
158▸LBL 82
159 2
160 RTN
161▸LBL 99
162 END

Code: Select all

163▸LBL "MAND"
164 0
165 0.016
166 LSTO "I"
167 R↓
168▸LBL 00
169 X↑2
170 RCL+ ST Y
171 RCL ST X
172 ABS
173 2
174 X<Y?
175 GTO 99
176 R↓
177 R↓
178 ISG "I"
179 GTO 00
180▸LBL 99
181 RCL "I"
182 IP
183 16
184 ÷
185 RTN
186 END

Code: Select all

187▸LBL "RING"
188 ABS
189 SIN
190 1
191 +
192 2
193 ÷
194 END

Code: Select all

195▸LBL "GRAD"
196 COMPLEX
197 X<>Y
198 END

Code: Select all

199▸LBL "BALL"
200 RCL ST X
201 ABS
202 1
203 X<Y?
204 RTN
205 RCL ST Z
206 0.5
207 -0.5
208 COMPLEX
209 -
210 ABS
211 0.7
212 ×
213 -
214 END
Attachments
fplot.raw
(582 Bytes) Downloaded 18 times

Post Reply