Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
display.tcl
00001 # $Id$
00002 
00003 # Display module high-level interface
00004 
00005 package require image
00006 package require display
00007 
00008 namespace eval display  {
00009 
00010     variable imageScale
00011 
00012     proc show { img {title "Jafar"} } {
00013   # Create a window to display an image
00014 
00015   variable imageScale
00016   
00017   set dx [$img width]
00018   set dy [$img height]
00019   
00020   image create photo "photo_$img" -format jfr -data $img
00021   
00022   toplevel .$img
00023   wm title .$img $title
00024   canvas .$img.$img -width $dx -height $dy
00025   .$img.$img create image 0 0 -anchor nw -image "photo_$img"
00026   pack .$img.$img
00027   bind .$img <Key-q> "::display::destroy $img"
00028   bind .$img <Key-r> "::display::refresh $img"
00029   bind .$img <Key-z> "::display::zoom $img 0.5"
00030   bind .$img <Key-Z> "::display::zoom $img 2"
00031   # bind .$img <ButtonPress-1> [concat {puts "(%x %y) [} $img {get %x %y ]"}]
00032 
00033   set imageScale($img) "1"
00034   return $img 
00035     }
00036 
00037     proc refresh { img } {
00038   # Refresh the image in a existing window
00039   variable imageScale
00040 
00041   if {$imageScale($img) != "1"} {
00042       # reload the (updated) Jafar image into the photo
00043       image create photo photo_tmp -format jfr -data $img
00044       # scale it
00045       tkPhotoScaleCopy photo_tmp "photo_$img" $imageScale($img)
00046       image delete photo_tmp
00047   } else {
00048       # reload the (updated) Jafar image into the photo
00049       "photo_$img" put $img -format jfr
00050   }
00051     }
00052     
00053     proc destroy { img } {
00054   # Destroy a window
00055 
00056   # unmap window
00057   wm withdraw .$img
00058   # destroy canvas
00059   ::destroy .$img.$img
00060   # destroy toplevel
00061   ::destroy .$img
00062   # delete image
00063   image delete "photo_$img"
00064     }
00065 
00066     proc blank { img {tag "jafar"} } {
00067   # blank the display, the image and the overlay
00068   "photo_$img" blank  
00069   clearOverlay $img $tag
00070     }
00071 
00072     proc zoom { img scale } {
00073   # zoom by scale the display
00074 
00075   variable imageScale
00076   if {$scale == 1} {return}
00077 
00078   set imageScale($img) [expr $scale * $imageScale($img)]
00079 
00080   refresh $img
00081 
00082   .$img.$img scale all 0 0 $scale $scale 
00083   .$img.$img configure -width [expr $imageScale($img) * [$img width]] -height [expr $imageScale($img) * [$img height]]
00084     }
00085 
00086     proc dumpEps { img filename } {
00087   # dump img (including overlay) to filename in eps format
00088   update
00089   .$img.$img postscript -file $filename
00090     }
00091 
00092     proc dumpAny {img filename } {
00093   # dump img (including overlay) to filename in any format.
00094   # The format is guessed from the filename extension, the
00095   # convertion is made by imagemagick (convert must be in your
00096   # path)
00097   
00098   set imageTmp "/tmp/jafar_display.eps"
00099   set convertBin "convert"
00100 
00101   display::dumpEps $img $imageTmp
00102 
00103   exec $convertBin $imageTmp $filename
00104   exec rm -f $imageTmp
00105     }
00106 
00107     proc showfile { filename } {
00108     # display an image from a file
00109       set image [image::Image_loadImage $filename]
00110       show $image $filename
00111     }
00112     proc showseqfile { filenamebase filenamesuffix start end { inc 1 } { nDigit 3 } } {
00113   # display a sequence of files
00114   set image [image::Image_loadImage "$filenamebase[format "%0${nDigit}d" $start]$filenamesuffix"]
00115   set img [show $image $filenamebase]
00116   for { set i [expr $start+1 ]  } { $i < $end } { set i [expr $i+$inc] } {
00117       image::delete_Image $image
00118       set image [image::Image_loadImage "$filenamebase[format "%0${nDigit}d" $i]$filenamesuffix"]
00119       image create photo "photo_$img" -format jfr -data $image
00120       wm title .$img "$filenamebase[format "%0${nDigit}d" $i]$filenamesuffix"
00121       .$img.$img create image 0 0 -anchor nw -image "photo_$img"
00122       update
00123   }
00124     }
00125 
00126 }
00127 
00128 package provide display 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:17 for Jafar by doxygen 1.7.6.1
LAAS-CNRS