Changeset 1552 for trunk/gui/scripts/imageresult.tcl
- Timestamp:
- Jul 18, 2009, 5:11:41 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/imageresult.tcl
r1549 r1552 344 344 if {$_scale(current) == "?" || $_scale(default)} { 345 345 set _scale(current) $_scale(max) 346 set _scale(x) 0 347 set _scale(y) 0 346 set _scale(x) 0.5 347 set _scale(y) 0.5 348 348 } 349 349 350 350 set w [winfo width $itk_component(image)] 351 351 set h [winfo height $itk_component(image)] 352 $_image(final) configure -width $w -height $h353 352 set bg [$itk_component(image) cget -background] 354 set rgb [winfo rgb . $bg]355 set bg [format "#%03x%03x%03x" [lindex $rgb 0] [lindex $rgb 1] [lindex $rgb 2]]356 $_image(final) put $bg -to 0 0 $w $h357 353 358 354 set imh [_top image] 359 355 if {$imh != ""} { 356 set iw [image width $imh] 357 set ih [image height $imh] 358 360 359 if {$_scale(current) <= 1.0} { 361 set wz [expr {round($_scale(current)*$w)}] 362 set hz [expr {round($_scale(current)*$h)}] 360 # 361 # Scale the image up by creating a "zoom" image which 362 # is smaller than the current image. Sample a small 363 # part of the original image by copying into the "zoom" 364 # image, then scale that part up to the full "view" area. 365 # 366 set wz [expr {round($w*$_scale(current))}] 367 set hz [expr {round($h*$_scale(current))}] 368 if {$wz > $iw} { 369 set wz $iw 370 } 371 if {$hz > $ih} { 372 set hz $ih 373 } 374 375 set sx [expr {round($_scale(x)*$_max(w)-0.5*$wz)}] 376 if {$sx+$wz > $iw} { 377 set sx [expr {$iw-$wz}] 378 } 379 if {$sx < 0} { 380 set sx 0 381 } 382 383 set sy [expr {round($_scale(y)*$_max(h)-0.5*$hz)}] 384 if {$sy+$hz > $ih} { 385 set sy [expr {$ih-$hz}] 386 } 387 if {$sy < 0} { 388 set sy 0 389 } 390 363 391 if {$wz > 1 && $hz > 1} { 364 392 $_image(zoom) configure -width $wz -height $hz 365 $_image(zoom) put $bg -to 0 0 $wz $hz 366 set sx [expr {round($_scale(x)*$_scale(current))}]367 set sy [expr {round($_scale(y)*$_scale(current))}] 393 set wf [expr {round(double($wz)/$_scale(current))}] 394 set hf [expr {round(double($hz)/$_scale(current))}] 395 $_image(final) configure -width $wf -height $hf 368 396 $_image(zoom) copy $imh -from $sx $sy 369 397 blt::winop resample $_image(zoom) $_image(final) sinc 370 398 } 371 399 } else { 372 set iw [image width $imh] 373 set ih [image height $imh] 400 # 401 # Scale the image down by creating a "zoom" image which 402 # is smaller than the current image. Resize the original 403 # image to the smaller size, then copy into the current 404 # view. 405 # 374 406 set wz [expr {round(double($iw)/$_scale(current))}] 375 407 set hz [expr {round(double($ih)/$_scale(current))}] 376 408 if {$wz > 1 && $hz > 1} { 377 409 $_image(zoom) configure -width $wz -height $hz 378 410 $_image(zoom) put $bg -to 0 0 $wz $hz 379 411 blt::winop resample $imh $_image(zoom) sinc 380 $_image(final) copy $_image(zoom) -from $_scale(x) $_scale(y) 412 413 $_image(final) configure -width $wz -height $hz 414 $_image(final) copy $_image(zoom) -from 0 0 381 415 } 382 416 } … … 447 481 } 448 482 449 set wfac [expr {$_max(w)/double($w)}] 450 set hfac [expr {$_max(h)/double($h)}] 451 set _scale(max) [expr {($wfac > $hfac) ? $wfac : $hfac}] 483 if {$w < $h} { 484 if {$_max(w)/double($_max(h)) > $w/double($h)} { 485 set _scale(max) [expr {$_max(w)/double($w)}] 486 } else { 487 set _scale(max) [expr {$_max(h)/double($h)}] 488 } 489 } else { 490 if {$_max(w)/double($_max(h)) < $w/double($h)} { 491 set _scale(max) [expr {$_max(h)/double($h)}] 492 } else { 493 set _scale(max) [expr {$_max(w)/double($w)}] 494 } 495 } 452 496 } 453 497 return 1 … … 456 500 set _scale(current) $_scale(max) 457 501 set _scale(default) 1 458 set _scale(x) 0 459 set _scale(y) 0 502 set _scale(x) 0.5 503 set _scale(y) 0.5 460 504 } 461 505 in { 462 set _scale(current) [expr {$_scale(current)*0. 5}]506 set _scale(current) [expr {$_scale(current)*0.8}] 463 507 set _scale(default) 0 464 508 } … … 469 513 || $_max(h)/$_scale(current) > $h} { 470 514 # must be room left to zoom -- zoom out, but not beyond max 471 set _scale(current) [expr {$_scale(current)* 2.0}]472 if {$_scale(current) <$_scale(max)} {515 set _scale(current) [expr {$_scale(current)*1.25}] 516 if {$_scale(current) > $_scale(max)} { 473 517 set _scale(current) $_scale(max) 474 518 } 475 519 } else { 476 520 # no room left to zoom -- zoom out max 477 if {$_scale(max) < 1} { 478 set _scale(current) 1 479 } else { 480 set _scale(current) $_scale(max) 481 } 482 } 521 set _scale(current) $_scale(max) 522 } 523 524 # fix the center of view, in case it is now out of bounds 525 if {$_scale(current) > 1.0} { 526 set _scale(x) 0.5 527 set _scale(y) 0.5 528 } 529 530 # keep this zoom setting now that we've zoomed out 483 531 set _scale(default) 0 484 532 } … … 514 562 set hy [expr {round($_max(h)/$_scale(current))}] 515 563 if {$wx > $w || $hy > $h} { 516 set x [expr {$_scale(x0)-$x+$_scale(xclick)}] 517 if {$x > $wx-$w} {set x [expr {$wx-$w}]} 518 if {$x < 0} {set x 0} 519 520 set y [expr {$_scale(y0)-$y+$_scale(yclick)}] 521 if {$y > $hy-$h} {set y [expr {$hy-$h}]} 522 if {$y < 0} {set y 0} 523 564 set x [expr {$_scale(x0)-($x-$_scale(xclick))/double($wx)}] 565 set y [expr {$_scale(y0)-($y-$_scale(yclick))/double($hy)}] 566 if {$x*$_max(w) < 0.5*$w*$_scale(current)} { 567 set x [expr {0.5*$w*$_scale(current)/$_max(w)}] 568 } 569 if {$x*$_max(w) > $_max(w) - 0.5*$w*$_scale(current)} { 570 set x [expr {1 - 0.5*$w*$_scale(current)/$_max(w)}] 571 } 572 if {$y*$_max(h) < 0.5*$h*$_scale(current)} { 573 set y [expr {0.5*$h*$_scale(current)/$_max(h)}] 574 } 575 if {$y*$_max(h) > $_max(h) - 0.5*$h*$_scale(current)} { 576 set y [expr {1 - 0.5*$h*$_scale(current)/$_max(h)}] 577 } 524 578 set _scale(x) $x 525 579 set _scale(y) $y 526 580 } else { 527 set _scale(x) 0 528 set _scale(y) 0 581 set _scale(x) 0.5 582 set _scale(y) 0.5 529 583 } 530 584 $_dispatcher event -idle !rebuild
Note: See TracChangeset
for help on using the changeset viewer.