-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.tcl
101 lines (90 loc) · 3.18 KB
/
demo.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# demo.tcl - Copyright (C) 2011 Pat Thoyts <[email protected]>
#
# Demo the imgscale algorithms.
#
# usage: demo ?-crimp? imagefile ?factor?
# eg: demo frog.png 1.75
package require Tk
if {[package vsatisfies [package provide Tk] 8.5]} {
if {[catch {package require img::jpeg}]} {
lappend auto_path \
/opt/tcl/lib/teapot/package/win32-ix86/lib \
/opt/tcl/lib/teapot/package/tcl/lib
}
if {![package vsatisfies [package provide Tk] 8.6]} {
package require img::png
}
package require img::jpeg
package require img::gif
package require img::bmp
}
lappend auto_path [file dirname [info script]]
package require imgscale
proc bgerror {s} {
tk_messageBox -icon error -title "ImgScale Demo Error" \
-message $s
}
proc main {filename {scale 2.5}} {
variable uid
if {![info exists uid]} { variable uid 0 }
set img [image create photo -file $filename]
set width [expr {int([image width $img] * $scale)}]
set height [expr {int([image height $img] * $scale)}]
set scale1 [image create photo -height $height -width $width]
set scale2 [image create photo -height $height -width $width]
set scale3 [image create photo -height $height -width $width]
if {[info command crimp] ne {}} {
set data [crimp read tk $img]
foreach {name algo} [list $scale1 nneighbour $scale2 bilinear $scale3 bicubic] {
set t [lindex [time {crimp write 2tk $name \
[crimp resize -interpolate $algo $data $width $height]}] 0]
lappend result $algo $name $t
}
} else {
foreach {name algo} [list $scale1 nearest $scale2 average $scale3 bilinear] {
set t [lindex [time {imgscale::$algo $img $width $height $name 1}] 0]
lappend result $algo $name $t
}
}
set dlg [toplevel .demo[incr uid]]
wm title $dlg "[file tail $filename] - Imgscale Demo 1"
wm withdraw $dlg
set canvas [canvas $dlg.c -background SystemWindow]
if {[image width $img] < 200} {
$canvas create image 5 5 -image $img -anchor nw -tag ORIG
set x [expr {[image width $img] + (2 * 5)}]
} else {
set x 5
}
foreach {title name time} $result {
$canvas create image $x 5 -image $name -anchor nw
set bot [expr {5 + [image height $name]}]
$canvas create rectangle $x 5 [expr {$x + [image width $name]}] $bot
incr bot 2
$canvas create text $x $bot -anchor nw -text "$title ${time}ns"
incr x [image width $name]
incr x 5
}
$canvas configure -width $x
pack $canvas -fill both -expand 1
bind $dlg <Control-F2> {console show}
wm deiconify $dlg
tkwait window $dlg
return
}
if {!$tcl_interactive} {
if {![info exists initialized]} {
set initialized 1
wm withdraw .
if {[string match -crimp [lindex $argv 0]]} {
set argv [lrange $argv 1 end]
catch {package require crimp}
}
set r [catch [linsert $argv 0 main] err]
if {$r} {
tk_messageBox -icon error -title "ImgScale Demo Error" \
-message $err
}
exit $r
}
}