proc ppm-photo ppm {
regsub -all {#[^\n]*\n} $ppm " " ppm ;# strip out comments
foreach {type w h max} $ppm break
foreach {r g b} [lrange $ppm 4 end] {
set r [expr {int(255.*$r/$max)}]
set g [expr {int(255.*$g/$max)}]
set b [expr {int(255.*$b/$max)}]
lappend row [format #%02X%02X%02X $r $g $b]
if {[llength $row] == $w} {
lappend rows $row
set row {}
}
}
set im [image create photo]
$im put $rows
set im
}#-- Testing: set data {P3
4 4
15
0 0 0 0 0 0 0 0 0 15 0 15
0 0 0 0 15 7 0 0 0 0 0 0
0 0 0 0 0 0 0 15 7 0 0 0
15 0 15 0 0 0 0 0 0 0 0 0
}
ppm-photo $data#-- produces the following image (zoomed by a factor of 9): Category Graphics