;TIM-DEMO       HOLO    0.4.1
;holo    -  demonstratie min-max met hologrammenbeeld
;verwacht:  beginbeeld in a
;versie IT
;Modified for Windows version TIM
;****************************************************
#include timdefs.h
 
parms
  int imode
endparms
int tl, gval, olddraw, loop, err
int bitplane, grijs

cls
if (ver 1) == MK_CORTEX1
  bitplane = 8
  grijs = 255
else
  bitplane = red
  grijs = 1
endif

             ;prepare environment
gval = set 1 1
dest p
show p
copy a

;     voer drempelingen uit met versch. dremp.waardes

*windispl h (imode+WINLUT1)

      ;only if image is FG image
if ((improp) & DIS_BIT)  == DIS_BIT
 zoom 1
      ;show running threshold by loading LUTs
 for tl = 20 to 255 step 3
  thre a tl /
  err = chk lut 2 5 4
 endfor

 for tl = 250 to 25 step -3
  thre a tl /
  err = chk lut 2 5 4
 endfor

 err = chk lut 2 3				 ;restore
 zoom 0
endif

             ;prepare LUTs
era x 1 2 3
err = chk lut 2 4	   ;red = 1, green = 2, blue = 3

xorln p 80 0 80 255 1
*windispl h (imode+WINLUT4+BITCOPY1)

dest q
era q
err = chk lut 2 4

line a 80
grav 
text 1 10 20 "line 80 from original image"
copy q b          ;keep graph
*windispl i (imode+NO_DITHER)	;always image copy (no dither), use LUT 3

dest r
err = chk lut 2 1			 ;BW lut
min a 15 
max 15
unif 11
dest s
max a 15
min 15
unif 11
sub s r
;         local contrast stretch
;dest p
dest r
sub a r         ;trek ondergrens glad

div r s 222     ;trek bovengrens naar maximum
era r 1 2 3
xorln r 79 0 80 255 2    ;draw line 79 to keep 80 original
*windispl h (imode+BITCOPY2)

err = chk lut 4
dest q
line r 80
olddraw = set 4 2
graf
text 2 25 20 "line 80 from corrected image"
or b q >b

*windispl i (imode+NO_DITHER)	;always image copy (no dither), use LUT 4

dest p
thre r
keep 1

dest s
label a 128     ;threshold original
thre 2           ;get rid of large white object (upper-left)
keep 2
or p s          ;use this as a seed and
lpr 2 1         ;propagate 
band 1 2 3      ;keep pixels which are in both bitplanes


bit 3
keep 1 2
*windispl i (imode+BITCOPY2)
;debug
zoom 1
lsk 2
bcop 2 1
lver 2
ldi6 2 1
;debug
binv 2
band 1 2 3
bcop 3 4
lskz 3 4
lps 3
lpr 3 4
bcop 3 2
lenp 2
ldi6 2 2
lsk 2
dest p
show p
and a 0xf8
or p s
bor 3 2 1
era 2 3
*windispl h (imode+BITCOPY1)
set 1 gval
set 4 olddraw

stop
