#!/usr/local/bin/wish -f

set tempfile "/tmp/tkscan.pgm"
set brightness 135
set contrast 200
set whitebal 128

proc rescan { } {
    global tempfile brightness contrast whitebal

#    puts "Calling ./qcam -c $contrast -b $brightness -w $whitebal > $tempfile"
    exec /usr/local/bin/qcam -c $contrast -b $brightness -w $whitebal > $tempfile
    image create photo qcamscan  -file $tempfile
}

canvas .c 
button .rescan -text "Rescan" -command "rescan"
button .quit -text "Quit" -command "exit"
frame .f
scale .f.bright -variable brightness -from 1 -to 255 -orient horiz -label Brightness
scale .f.contrast -variable contrast -from 1 -to 255 -orient horiz -label Contrast
scale .f.whitebal -variable whitebal -from 1 -to 255 -orient horiz -label "White Balance"
pack .f.bright .f.contrast .f.whitebal -fill x
rescan
.c create image 1 1 -anchor nw -image qcamscan
pack .c -fill both -expand 1
pack .f .rescan .quit -fill x