Re: resizing JPEGs (with Img and photo image)
- From: spooky130@xxxxxxx
- Date: Tue, 31 Jul 2007 00:19:59 GMT
In article <1185787636.163193.269820@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Donal K. Fellows <donal.k.fellows@xxxxxxxxx> wrote:
spooky130@xxxxxxx wrote:
2) The amount that I need to resize the image is not an integral
amount, it's a percentage (or, better still, a specific size
in pixels). Specifically (for the Gulf close-up), the image
needs to be resized from 720x480 (1.5:1) to 1324x980 (1.35:1)
Ah yes, the lameness of the image resizing code (and as the maintainer
of that code I can say that it is lame with absolute certainty!) While
a combination of -zoom and -subsample would work, *don't do that*.
Ok. :-)
Instead, you need a resizing engine. A good place to start looking is
http://wiki.tcl.tk/10520
Ok, I'm looking at that now...but it still seems to assume only one
variable for the amount to expand by.... I need one value each for X
and Y (again, the aspect ratio has to change for the satellite imagery
to fit to the map, due to the different views/projections.... What
would it take...never mind...I've already done it. :-) It probably
needs more cleanup (e.g., I left the old $coef just laying about, and
probably should change it to $xcoef and/or $ycoef), but I'll leave that
to someone who better understands the code. For now, simple tests
indicate that this works, and it's too hot in here to sit at this
computer much longer, so....
Once again, never mind.... It works with the demo provided, but once I
try to work it into JStrack, it fails (see below in the code)....
Here's another procedure I added: expandxy ...
Changes are marked as: ;# <----- jdg
proc expandxy {image xcoef ycoef} { ;# <----- jdg
set coef $xcoef ;# why? just 'cause.... ;# <----- jdg
# check coef
if {$coef < 1.0} \
{ error "bad coef \"$coef\": should not be less than 1.0" }
if {$coef - int($coef) < 1.e-4} \
{ return [optim $image [expr {int($coef)}]] }
# get the old image content
set width [image width $image]
set height [image height $image]
if {$width * $height == 0} { error "bad image" }
# create corresponding planes
for {set y 0} {$y < $height} {incr y} \
{
set r:row {}
set g:row {}
set b:row {}
for {set x 0} {$x < $width} {incr x} \
{
foreach {r g b} [$image get $x $y] break
foreach c {r g b} { lappend $c:row [set $c] }
}
foreach c {r g b} { lappend $c:data [set $c:row] }
}
# compute the new image content
set Width [expr {round($width * $xcoef)}] ;# <----- jdg
set Height [expr {round($height * $ycoef)}] ;# <----- jdg
set ey 0
set y2 0
set cy2 $Height
for {set Y 0} {$Y < $Height} {incr Y} \
{
set r:Row {}
set g:Row {}
set b:Row {}
# y1 is the top coordinate in the old image
set y1 $y2
set cy1 [expr {$Height - $cy2}]
incr ey $height
set y2 [expr {$ey / $Height}]
set cy2 [expr {$ey % $Height}]
if {$y1 == $y2} { set cy1 $cy2 }
set ex 0
set x2 0
set cx2 $Width
for {set X 0} {$X < $Width} {incr X} \
{
set x1 $x2
set cx1 [expr {$Width - $cx2}]
incr ex $width
set x2 [expr {$ex / $Width}]
set cx2 [expr {$ex % $Width}]
if {$x1 == $x2} { set cx1 $cx2 }
# compute pixel
foreach c {r g b} { set $c 0; set _$c 0 }
for {set y $y1} {$y <= $y2} {incr y} \
{
# compute y coef
switch $y \
$y1 { set cy $cy1 } \
$y2 { set cy $cy2 } \
default { set cy $height }
if {$cy == 0} { continue }
if {$cy > $height} { set cy $height }
for {set x $x1} {$x <= $x2} {incr x} \
{
# compute x coef
switch $x \
$x1 { set cx $cx1 } \
$x2 { set cx $cx2 } \
default { set cx $width }
if {$cx == 0} { continue }
if {$cx > $width} { set cx $width }
# weight each initial pixel by cx & cy
set cxy [expr {$cx * $cy / double($width) / $height}]
foreach c {r g b} \
{
# FAILS HERE...... (used puts/flush stdout to find exact spot)
set comp [lindex [set $c:data] $y $x] ;# <-- FAILS HERE
# FAILS HERE......
#
# the lindex above, when added to JStrack (which has a canvas named
# .c ... not sure if that matters or not, but renaming .c above made no
# difference) causes an error: wrong # of args. both tests are using
# Tcl/Tk 8.4, but the test with JStrack is running under Windows at the
# moment (this machine is too slow for repeated tests with loading
# satellite imagery).
#
incr $c [expr {round($comp * $cxy)}]
set _$c [expr {[set _$c] + $cxy}]
}
}
}
set _ {}
foreach c {r g b} \
{
set comp [set $c]
if {$comp > 255} { set comp 255 }
lappend $c:Row $comp
lappend _ [set _$c]
}
}
foreach c {r g b} { lappend $c:Data [set $c:Row] }
}
# crisping
for {set Y 0} {$Y < $Height} {incr Y} \
{
set Row {}
for {set X 0} {$X < $Width} {incr X} \
{
if {$X == 0 || $X == $Width - 1 || $Y == 0 || $Y == $Height - 1} \
{
foreach c {r g b} { set $c [lindex [set $c:Data] $Y $X] }
} \
else \
{
foreach c {r g b} \
{
set c00 [lindex [set $c:Data] [expr {$Y - 1}] [expr {$X - 1}]]
set c01 [lindex [set $c:Data] [expr {$Y - 1}] [expr {$X - 0}]]
set c02 [lindex [set $c:Data] [expr {$Y - 1}] [expr {$X + 1}]]
set c10 [lindex [set $c:Data] [expr {$Y + 0}] [expr {$X - 1}]]
set c11 [lindex [set $c:Data] [expr {$Y + 0}] [expr {$X - 0}]]
set c12 [lindex [set $c:Data] [expr {$Y + 0}] [expr {$X + 1}]]
set c20 [lindex [set $c:Data] [expr {$Y + 1}] [expr {$X - 1}]]
set c21 [lindex [set $c:Data] [expr {$Y + 1}] [expr {$X - 0}]]
set c22 [lindex [set $c:Data] [expr {$Y + 1}] [expr {$X + 1}]]
set cc [expr {int(1.4 * $c11 - 0.05 * ($c00 + $c01 + $c02 + $c10 + $c12 + $c20 + $c21 + $c22))}]
if {$cc < 0} { set cc 0 }
if {$cc > 255} { set cc 255 }
set $c $cc
}
}
lappend Row [format #%02x%02x%02x $r $g $b]
}
lappend Data $Row
}
# create the new image
set Image [image create photo]
# fill the new image
$Image put $Data
# return the new image
return $Image
}
Anyone see an obvious error? I'm stuck at the $c:data (I'm really not
familiar with namespaces and such, and can't parse that one)....
but I suspect you may be better off going to http://wiki.tcl.tk/9775
(i.e. TclMagick) which is far more capable (and faster) than scripted
versions.
....and TclMagick, if I read correctly, in turn requires ImageMagick,
which is a bit much to ask users to install just to be able to view
satellite imagery superimposed over (ok, under) the chart/storm plot.
I'm looking for a simple, all Tcl and/or Tk solution (something like
requiring a library that's widely available is ok, e.g., the code
requires Img to even display the satellite imagery at all)..
Thanks,
--jim
--
73 DE N5IAL (/4) MiSTie #49997 < Running FreeBSD 6.1 >
spooky130@xxxxxxx ICBM/Hurricane: 30.39735N 86.60439W
Do not look into waveguide with remaining eye!
.
- Follow-Ups:
- Re: resizing JPEGs (with Img and photo image)
- From: spooky130
- Re: resizing JPEGs (with Img and photo image)
- References:
- resizing JPEGs (with Img and photo image)
- From: spooky130
- Re: resizing JPEGs (with Img and photo image)
- From: Donal K. Fellows
- resizing JPEGs (with Img and photo image)
- Prev by Date: Re: How to delete posted messages from here?
- Next by Date: Tcl script fails on some platforms
- Previous by thread: Re: TclMagick, GraphicMagick and the registry (WAS: Re: resizing JPEGs (with Img and photo image))
- Next by thread: Re: resizing JPEGs (with Img and photo image)
- Index(es):
Relevant Pages
|