Posted to tcl by hypnotoad at Fri Apr 24 15:16:29 GMT 2020view raw

  1. method stencil_render {sn image_zoom} {
  2. my variable stendat stencil_alpha stencil_alpha_mode stencil_zoom
  3. if {[info exists stencil_zoom($sn)]} {
  4. if { $stencil_zoom($sn) eq $image_zoom } {
  5. if {![catch {image height stencil.$sn}]} {
  6. ###
  7. # If the image exists at the same magnification, return it
  8. ###
  9. return stencil.$sn
  10. }
  11. }
  12. }
  13. set scaley 1.0
  14.  
  15. set info [my stencil_info $sn]
  16. dict with info {}
  17.  
  18. set file [my stencil_file $sn]
  19. if {![file exists $file]} {
  20. set file [tk_getOpenFile -parent . -filetypes [irm::image_types]]
  21. if {$file==""} {
  22. return
  23. }
  24. irm::image_package $file
  25. if {[catch {image create photo stencil -file $file} err]} {
  26. taotk::dialog -icon error -type ok -parent . -message $err
  27. return
  28. }
  29. }
  30. if { $image_zoom > 4.0 } {
  31. ###
  32. # Crop image
  33. ###
  34. set ans [::taotk::dialog -type okcancel -message "
  35. Stencil $sn is zoomed in to a factor of $image_zoom : 1.
  36. This may tie up a lot of system memory.
  37.  
  38. Press cancel to abort."]
  39. if { $ans == "cancel" } {
  40. puts "Stencil magnification exceeded ($image_zoom)"
  41. ###
  42. # Clip a window
  43. ###
  44. return {}
  45. }
  46. }
  47. image create photo stencil.raw -file $file
  48. image create photo stencil.$sn
  49.  
  50. set wid [image width stencil.raw]
  51. set hgt [image height stencil.raw]
  52. set newwid [expr {int($wid * $image_zoom)}]
  53. set newhgt [expr {int($hgt * $image_zoom * $scaley)}]
  54. set stendat($sn) [list wid $wid hgt $hgt zoom $image_zoom scale $image_zoom]
  55.  
  56. # Alpha blending is slow on most platforms
  57. if {[my cget stencil_alpha_mode]} {
  58. ::shapes::image_scale stencil.raw $newwid $newhgt stencil.$sn [my cget stencil_alpha]
  59. } else {
  60. ::shapes::image_desat_scale stencil.raw $newwid $newhgt stencil.$sn [my cget stencil_alpha]
  61. }
  62. image delete stencil.raw
  63. set stencil_zoom($sn) $image_zoom
  64. return stencil.$sn
  65. }