"Fossies" - the Fresh Open Source Software Archive

Member "tkscanfax1/scan-out.tcl" (22 Jul 2003, 6792 Bytes) of package /linux/misc/old/tkscanfax-1.1.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Tcl/Tk source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "scan-out.tcl" see the Fossies "Dox" file reference documentation.

    1 # This file is a part of TkScan.
    2 #
    3 
    4 #
    5 # Treatment of scanned image file
    6 
    7 proc Make_Output { prefix i } {
    8     global s c w file
    9 
   10     # Scanned image name
   11     set scanned "$c(tkscandir)/$prefix-$i.pnm"
   12 
   13     # Output file name
   14     # replace hhmmss to $prefix and # to $i in $file(name)
   15     set p [string last hhmmss $file(name)]
   16     if {$p >= 0} {
   17         set f1 [string range $file(name) 0 [expr $p-1]]
   18         set f2 $prefix
   19         set f3 [string range $file(name) [expr $p+6] end]
   20         set ftmp "$f1$f2$f3"
   21     } else {
   22         set ftmp $file(name)
   23     }
   24     set p [string last # $ftmp]
   25     if {$p >= 0} {
   26         set f1 [string range $ftmp 0 [expr $p-1]]
   27         set f2 $i
   28         set f3 [string range $ftmp [expr $p+1] end]
   29         set outfile $f1$f2$f3
   30     } else {
   31         set outfile $ftmp
   32     }
   33 
   34     # Move $scanned to $outfile
   35     exec mv -f $scanned $file(dir)/$outfile
   36     if {[info exist w(dirlist)] && [winfo exist $w(dirlist)]} {
   37         update_dir
   38     }
   39     stat_text "Scanning $s(curscan) / $s(nrect) ... $outfile"
   40     update
   41 
   42     # Do something more if necessary
   43     if $c(autoview) {
   44         View $file(dir)/$outfile $i
   45     }
   46     if $c(autoconvert) {
   47         Convert $file(dir)/$outfile
   48     }
   49     if $c(autoprint) {
   50         Print $file(dir)/$outfile $s(tx$i) $s(ty$i) $s(bx$i) $s(by$i)
   51     }
   52     if $c(autofax) {
   53         MakeFax $file(dir)/$outfile
   54     }
   55 
   56     # This is for using TkScan as fax scanner of TkFax.
   57     if $c(autofaxif) {
   58        fax_pbm2fax $file(dir)/$outfile
   59        exec rm -f $file(dir)/$outfile
   60     }
   61 }
   62 
   63 
   64 proc View { fn i } {
   65     global s c file
   66 
   67     # Which image editor?
   68     set ImageEditor $c($c(ImageEditor)command)
   69 
   70     # Which image editor window mode?
   71     if {$c(ImageEditorWinmode) == 1 || $s(nrect) == 0} {
   72         set geometry "-geometry [format "+%d+%d" [expr $i*100] [expr $i*25]]"
   73         set f $fn
   74     } else {
   75         if {$i < 2} { set file(scanned) "" }
   76         append file(scanned) " $fn"
   77         if {$i < $s(nrect)} { return }
   78         set geometry "-geometry +0+0"
   79         set f $file(scanned)
   80     }
   81 
   82     # Gamma correction supporting
   83     if {$s(gamma_support)==0} {
   84         switch $ImageEditor {
   85             xv { set gamma "-gamma $s(gamma) \
   86                 -cgamma $s(gamma_red) $s(gamma_green) $s(gamma_blue)"
   87             }
   88             display {
   89                 set gamma "-gamma $s(gamma_red)/$s(gamma_green)/$s(gamma_blue)"
   90             }
   91             gimp {
   92             }
   93         }
   94     } else { set gamma "" }
   95 
   96     # Launch image viewer
   97     exec sh -c "$ImageEditor $geometry $gamma $f" &
   98 }
   99 
  100 
  101 proc Convert { fn } {
  102     global file s c
  103 
  104     # Output filename
  105     set p [string last . $fn]
  106     if {$p < 0} {
  107         set prefix $fn
  108     } else {
  109         set prefix [string range $fn 0 [expr $p - 1]]
  110     }
  111     set outfile $prefix.$file(surfix)
  112 
  113     # Gamma correction supporting
  114     if {$s(gamma_support)==0} {
  115         set gamma "-gamma $s(gamma_red)/$s(gamma_green)/$s(gamma_blue)"
  116     } else {
  117         set gamma ""
  118     }
  119 
  120     # Run ImageMagic's convert
  121     exec sh -c "convert $gamma $fn $outfile" &
  122 }
  123 
  124 
  125 proc Print { fn tx ty bx by } {
  126     global pr s c
  127 
  128     # Extract prefix from file name
  129     set p [string last / $fn]
  130     set q [string last . $fn]
  131     if {$p < $q} {
  132         set prefix [string range $fn [expr $p+1] [expr $q-1]]
  133     } else {
  134         set prefix [string range $fn [expr $p+1] end]
  135     }
  136 
  137     # Setup print command and gamma correction
  138     set print $pr($pr(printer)command)
  139     if {$s(gamma_support)==0} {
  140         set gamma "-gamma $s(gamma_red)/$s(gamma_green)/$s(gamma_blue)"
  141     } else {
  142         set gamma ""
  143     }
  144 
  145     # Compare zoomed image size to paper size
  146     # If the zoomed image size is larger than the page, fit it to the page.
  147     switch $pr(paper) {
  148         A4      { set pwd 595. ; set pht 842. ; set offset 72 }
  149         Letter  { set pwd 612. ; set pht 792. ; set offset 72 }
  150         default { set pwd 595. ; set pht 842. ; set offset 72 }
  151     }
  152     set rwd [pixelto pt [expr $bx-$tx]]
  153     set rht [pixelto pt [expr $by-$ty]]
  154     set zoom [expr $pr(zoom).0/100.0]
  155     set iwd [expr $rwd*$zoom]
  156     set iht [expr $rht*$zoom]
  157     if {$iwd > $pwd} {
  158         set iwd $pwd
  159         set zoom [expr $pwd/$rwd]
  160         set iht [expr $rht*$zoom]
  161     }
  162     if {$iht > $pht} {
  163         set iht $pht
  164         set zoom [expr $pht/$rht]
  165         set iwd [expr $rwd*$zoom]
  166     }
  167 
  168     # Determine the offsets
  169     # If the offset requested is larger than the available space,
  170     # fit it to the latter.
  171     set xspace [expr $pwd-$iwd]
  172     switch $pr(xoffset) {
  173         x -
  174         X {
  175             if {$pr(zoom)==100} {
  176                 set xoffset [pixelto pt $tx]
  177             } else {
  178                 set xoffset [expr $xspace/2]
  179             }
  180         }
  181         c -
  182         C { set xoffset [expr $xspace/2] }
  183         l -
  184         L { set xoffset 0 }
  185         r -
  186         R { set xoffset $xspace }
  187         default {
  188             if { $pr(xoffset) < $xspace } {
  189                  set xoffset $pr(xoffset)
  190             } else {
  191                  set xoffset $xspace
  192             }
  193         }
  194     }
  195     set yspace [expr $pht-$iht]
  196     switch $pr(yoffset) {
  197         y -
  198         Y {
  199             if {$pr(zoom)==100} {
  200                 set yoffset [expr $pht-[pixelto pt $by]]
  201             } else {
  202                 set yoffset [expr $yspace/2]
  203             }
  204         }
  205         c -
  206         C { set yoffset [expr $yspace/2] }
  207         b -
  208         B { set yoffset 0 }
  209         t -
  210         T { set yoffset $yspace }
  211         default {
  212             if { $pr(yoffset) < $yspace } {
  213                  set yoffset $pr(yoffset)
  214             } else {
  215                  set yoffset $yspace
  216             }
  217         }
  218     }
  219 
  220     # ZOOM from screen size in percetage: This is really used for convert.
  221     set ZOOM [format "%0.0f" [expr $zoom*7200.0/$s(resolution).0]]
  222 
  223     # Run ImageMagic's convert to generate postscript file.
  224     set geometry [format "-geometry %0.0f%% -page +%0.0f+%0.0f" \
  225                   $ZOOM $xoffset $yoffset]
  226     set convertcmd "convert $gamma $geometry $fn $c(tkscandir)/$prefix.ps"
  227     if $c(autodelete) {
  228         set rmcmd ";rm -f $fn"
  229     } else {
  230         set rmcmd ""
  231     }
  232     set printcmd "$print $c(tkscandir)/$prefix.ps"
  233     set rmpscmd "rm -f $c(tkscandir)/$prefix.ps"
  234     exec sh -c "$convertcmd $rmcmd ; $printcmd ; $rmpscmd" &
  235 }
  236 
  237 proc MakeFax { fn } {
  238     global c
  239     set p [string last / $fn]
  240     set q [string last . $fn]
  241     if {$p >= 0} {
  242         set dirname [string range $fn 0 $p]
  243         set prefix [string range $fn [expr $p+1] [expr $q-1]]
  244     } else {
  245         set dirname ""
  246         set prefix [string range $fn [expr $p+1] end]
  247     }
  248     set fx $dirname$prefix.g3
  249     set mkfaxcmd "$c(pbmtofax) $fn > $fx"
  250     if $c(autodelete) {
  251         set rmcmd "rm -f $fn"
  252     }
  253     exec sh -c "$mkfaxcmd ; $rmcmd" &
  254 }
  255