#!/usr/local/bin/wish -f
if {$argc < 2} {puts "usage: image1 image2 ?zoom?"; exit 1}
set zoom 1

proc min {a b} {
    if {$a < $b} {return $a} else {return $b}
}

# unpack a list into variables
# e.g.  unpack {3 4 5} a b c
# slow; should be part of the language
proc unpack {list args} {
    # args is a list of vars in caller's scope
    set len [min [llength $list] [llength $args]]
    for {set i 0} {$i < $len} {incr i} {
	upvar [lindex $args $i] x
	set x [lindex $list $i]
    }
}

unpack $argv img1 img2 zoom

image create photo -file $img1
image create photo -file $img2

set img1 [image create photo]
$img1 copy image1 -subsample $zoom
set img2 [image create photo]
$img2 copy image2 -subsample $zoom

label .l1 -image $img1
label .l2 -image $img2

button .quit -text Quit -command {exit}

pack .l1 .l2 .quit

set old_x 0
set old_y 0

bind .l1 <1> {
    set old_x %x
    set old_y %y
}

bind .l2 <1> {
    puts "[expr $zoom*$old_y] [expr $zoom*$old_x] \
	    [expr $zoom*%y] [expr $zoom*%x]"         
}

# print the size of img1
puts "[expr $zoom*[image height $img1]] [expr $zoom*[image width $img1]]"
