Check-in [acf8d9ca22]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Scan improvements
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:acf8d9ca22553691e2d9bd7125614148ab8f6e06
User & Date: bernd 2019-01-02 20:23:21
Context
2019-01-03
18:01
Bump version number check-in: cda45ac841 user: bernd tags: trunk, 0.8.5-20190103
2019-01-02
20:23
Scan improvements check-in: acf8d9ca22 user: bernd tags: trunk
19:02
scan with invertion, recent presentations check-in: 5210e44e87 user: bernd tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to android/qrscan-android.fs.

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
    hidekb hidestatus >changed  screen+keep
    c-open-back to camera
    program 0= IF
	['] VertexShader ['] FragmentShader create-program to program
    THEN
    cam-prepare  new-scantexes ;

Create sat%s 1.0e sf, 1.666e sf, 1.333e sf, 2.0e sf,
does> ( n -- ) swap sfloats + sf@ ;
Variable sat%-state

: draw-cam ( -- )
    0>framebuffer saturate% sf@ { f: sat }
    camera-init screen-orientation 1e 1e draw-scan sync
    cam-w cam-h scan-fb-raw >framebuffer
    1 1e 1e draw-scan
    scan-tex-raw linear-mipmap mipmap ;

previous previous








<
<
<
<

|







21
22
23
24
25
26
27




28
29
30
31
32
33
34
35
36
    hidekb hidestatus >changed  screen+keep
    c-open-back to camera
    program 0= IF
	['] VertexShader ['] FragmentShader create-program to program
    THEN
    cam-prepare  new-scantexes ;





: draw-cam ( -- )
    0>framebuffer
    camera-init screen-orientation 1e 1e draw-scan sync
    cam-w cam-h scan-fb-raw >framebuffer
    1 1e 1e draw-scan
    scan-tex-raw linear-mipmap mipmap ;

previous previous

Changes to qrscan.fs.

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
...
378
379
380
381
382
383
384



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
...
432
433
434
435
436
437
438

439
440
441
442
443
444
445
446
447
448
449
450

also opengl

: draw-scan ( direction xscale yscale -- )
    \G draw a scan rotated/tilted by scan matrix
    fover fnegate fover fnegate 0e { f: sx f: sy f: -sx f: -sy f: z }
    vi0 >v
     -sx  sy z >xyz n> rot>st   $FFFFFFFF rgba>c v+
      sx  sy z >xyz n> rot>st   $FFFFFFFF rgba>c v+
      sx -sy z >xyz n> rot>st   $FFFFFFFF rgba>c v+
     -sx -sy z >xyz n> rot>st   $FFFFFFFF rgba>c v+
    v> drop 0 i, 1 i, 2 i, 0 i, 2 i, 3 i,
    GL_TRIANGLES draw-elements ;

Variable scan-buf-raw
Variable scan-buf0
Variable scan-buf1
Variable red-buf
................................................................................
[ELSE]
    ' < alias ??
[THEN]

: rgb@ ( addr -- r g b )
    >r r@ c@ r@ 1+ c@ r> 2 + c@ ;

0 Value strip-xor

: rgb? ( addr -- rgbbit )
    rgb@
    blue-level#  ?? negate 2* swap
    green-level# ?? - 2* swap
    red-level#   ?? - strip-xor xor ;

: extract-strip ( addr u step -- strip ) rgbas { step }
    0 -rot bounds U+DO
	2* 2* I rgb? 3 and +
    step +LOOP ;

$51 buffer: guessbuf
................................................................................
    THEN  2drop rdrop ;

: search-corners ( -- )
    init-xy p0 !  p0 p0 cell+ 7 cells cmove \ fill all with the same contents
    scan-buf0 $@ drop
    scan-w dup negate DO
	scan-w dup negate DO
	    dup rgb dup 4 and IF  3 and 2 xor
		2* cells p0 + I J rot min²!
	    ELSE
		drop
	    THEN
	    rgba+
	LOOP
    LOOP  drop ;
................................................................................
	dist0 off dist0-max off dist0-min on
	dist1 off dist1-max off dist1-min on
    [THEN]
    scan-legit >guess
    >guessecc tag@ guesstag c!
    2dup guessecc $10 ecc-ok? ;




: tex-frame ( -- )
    program init-program set-uniforms
    unit-matrix MVPMatrix set-matrix
    unit-matrix MVMatrix set-matrix ;
: draw-scaled ( i -- )
    3 and sat%s saturate% sf!
    Saturate 1 saturate% glUniform1fv
    tex-frame scan-w 2* dup scan-fb >framebuffer
    scan-tex-raw linear-mipmap 0 scan-xy draw-scan
    scan-grab0  scan-fb-final >framebuffer ;
: sat-reset ( -- )
    sat saturate% sf!
    Saturate 1 saturate% glUniform1fv ;

previous

[IFDEF] android
    require android/qrscan-android.fs
    also android
[ELSE]
................................................................................
    ?legit IF  scan-legit? IF
	    guessecc $10 + c@ scan-result qr( ." took: " .time cr )
	    qr( save-png1 1 +to scan# )
	ELSE  2drop  THEN
    THEN ;

: scan-once ( -- )

    draw-cam qr( !time ) 3 0 DO
	I draw-scaled adapt-rgb
	7 to rgb-xor scan-it
	0 to rgb-xor scan-it
    LOOP  sat-reset
    ekey? IF  ekey dup k-volup = swap bl = or  IF  save-pngs  THEN  THEN ;
: scan-loop ( -- )
    1 level# +!@ >r  BEGIN  scan-once >looper level# @ r@ <= UNTIL
    rdrop ;

: scan-qr ( -- )
    [IFDEF] lastscan$  lastscan$ $free  [THEN]







|
|
|
|







 







|





|







 







|







 







>
>
>







|

|
|
<
|







 







>




|







130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
...
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398

399
400
401
402
403
404
405
406
...
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453

also opengl

: draw-scan ( direction xscale yscale -- )
    \G draw a scan rotated/tilted by scan matrix
    fover fnegate fover fnegate 0e { f: sx f: sy f: -sx f: -sy f: z }
    vi0 >v
     -sx  sy z >xyz n> rot>st   white# i>c v+
      sx  sy z >xyz n> rot>st   white# i>c v+
      sx -sy z >xyz n> rot>st   white# i>c v+
     -sx -sy z >xyz n> rot>st   white# i>c v+
    v> drop 0 i, 1 i, 2 i, 0 i, 2 i, 3 i,
    GL_TRIANGLES draw-elements ;

Variable scan-buf-raw
Variable scan-buf0
Variable scan-buf1
Variable red-buf
................................................................................
[ELSE]
    ' < alias ??
[THEN]

: rgb@ ( addr -- r g b )
    >r r@ c@ r@ 1+ c@ r> 2 + c@ ;

0 Value rgb-xor

: rgb? ( addr -- rgbbit )
    rgb@
    blue-level#  ?? negate 2* swap
    green-level# ?? - 2* swap
    red-level#   ?? - rgb-xor xor ;

: extract-strip ( addr u step -- strip ) rgbas { step }
    0 -rot bounds U+DO
	2* 2* I rgb? 3 and +
    step +LOOP ;

$51 buffer: guessbuf
................................................................................
    THEN  2drop rdrop ;

: search-corners ( -- )
    init-xy p0 !  p0 p0 cell+ 7 cells cmove \ fill all with the same contents
    scan-buf0 $@ drop
    scan-w dup negate DO
	scan-w dup negate DO
	    dup rgb? dup 4 and IF  3 and 2 xor
		2* cells p0 + I J rot min²!
	    ELSE
		drop
	    THEN
	    rgba+
	LOOP
    LOOP  drop ;
................................................................................
	dist0 off dist0-max off dist0-min on
	dist1 off dist1-max off dist1-min on
    [THEN]
    scan-legit >guess
    >guessecc tag@ guesstag c!
    2dup guessecc $10 ecc-ok? ;

Create sat%s 1.0e sf, 1.666e sf, 1.333e sf, 2.0e sf,
does> ( n -- ) swap sfloats + sf@ ;

: tex-frame ( -- )
    program init-program set-uniforms
    unit-matrix MVPMatrix set-matrix
    unit-matrix MVMatrix set-matrix ;
: draw-scaled ( i -- )
    3 and sat%s saturate% sf!
    Saturate 1 saturate% glUniform1fv
    tex-frame   scan-w 2* dup scan-fb >framebuffer
    scan-tex-raw linear-mipmap 0 scan-xy draw-scan
    scan-grab0  scan-w 2* dup scan-fb-final >framebuffer ;
: sat-reset ( sat -- )

    saturate% sf! Saturate 1 saturate% glUniform1fv ;

previous

[IFDEF] android
    require android/qrscan-android.fs
    also android
[ELSE]
................................................................................
    ?legit IF  scan-legit? IF
	    guessecc $10 + c@ scan-result qr( ." took: " .time cr )
	    qr( save-png1 1 +to scan# )
	ELSE  2drop  THEN
    THEN ;

: scan-once ( -- )
    saturate% sf@ { f: sat }
    draw-cam qr( !time ) 3 0 DO
	I draw-scaled adapt-rgb
	7 to rgb-xor scan-it
	0 to rgb-xor scan-it
    LOOP  sat sat-reset
    ekey? IF  ekey dup k-volup = swap bl = or  IF  save-pngs  THEN  THEN ;
: scan-loop ( -- )
    1 level# +!@ >r  BEGIN  scan-once >looper level# @ r@ <= UNTIL
    rdrop ;

: scan-qr ( -- )
    [IFDEF] lastscan$  lastscan$ $free  [THEN]