Script commands may be embedded into IMG files (or others) and execute image processor functions when a file is loaded into the viewer. The script commands must start at the 80th byte of the image file and contain AUTOSCRIPT as the first line.
This simple example will display a pop-up box and wait for the user to click on OK or Exit:
AUTOSCRIPT
pause “The script is
running”
exit
When the script is executed it inserts the image filename into the text variable: $imagefile The following is an example on how to retrieve the filename:
AUTOSCRIPT
pause “The name of this
file is: ” $imagefile
exit
The next example loads the palette file: color1.pal and sets the Window Width to 2.5, Level to 0.5:
AUTOSCRIPT
viewer palette color1.pal
viewer winlev 2.5 0.5
viewer notify
exit
The following example will insert a script file into an image file:
getfile $script “Select
Script file to Add”
getfile $imgfile “Select
the Image File”
# Read the script into
memory
getfilesize size $script
open $script byt
read 0 size 0
# Write it in the image
file at offset 80
open $imgfile byt
write 0 size 80
exit
Advanced Examples:
The following is an example of how to place a series of CT images into a single file of compressed images. Once the output file is created, a script is placed in the image file. When the file is loaded into the viewer, The images are de-compressed into individual files and loaded into the viewer for normal viewing/processing.
Procedure:
1) The user loads the desired images into the viewer
2) The CTSET.imp script file is run
from the viewer.
3) The user specifies the output file and the images are compressed
into the file.
4) The script file: OPENCTSET.imp is
placed into the output file and the operation is completed.
5) When the file is loaded into a viewer at a later time (perhaps after
being sent as an E-Mail attachment) the original files are decompressed
into temporary files and loaded into the viewer.
$cfile = $temppath "\ctemp.img"
# Clear out a block of
memory
a = 0
loop begin 4096
memory(a) = 0
a = a + 1
loop end
$listq = $temppath "\filelist.q"
input_file $listq
finput inum
finput inum
# Allocate 4 MB of memory
allocate 1000000
# Clear out a block of
memory
a = 0
loop begin 4096
memory(a) = 0
a = a + 1
loop end
$mfile = "*.set"
getfile $mfile "Select
an Output file"
# Start an output file
memory(20) = inum
delete $mfile
open $mfile int
write 0 4096 0
idx = 2048
offset = 4096
tot = 1
#
# Collect Images
#
*Main
finput $infile
compress -300
$infile $cfile
getfilesize size
$cfile
memory(idx) =
offset
memory(idx + 256)
= size
idx = idx + 1
kb = round(offset
/ 1024)
message "Image
Set Build: " tot " - " kb " KBytes"
tot = tot + 1
open $cfile byt
read 4096 size
0
open $mfile byt
write 4096 size
offset
offset = offset
+ size
inum = inum - 1
if inum > 0
goto Main
endif
# Add Offset table
open $mfile flt
write 2048 512 512
# Add Auto-Script file
$script = $basedir "\scripts\auto\openctset.imp"
getfilesize size $script
open $script byt
read 0 size 0
open $mfile byt
write 0 size 80
message "Ready..."
exit
autoscript
$ofile = $temppath "\set-01.img"
$list = $temppath "\filelist.q"
allocate 1000000
open $imagefile int
read 0 1 20
inum = memory(0)
open $imagefile flt
read 0 512 512
idx = 0
delete $list
print_file $list
fprint inum
fprint inum
viewer writeback on
viewer notify
a = 1
tot = inum
*Main
message "Loading
Image Set: " a " of " tot
a = a + 1
offset = memory(idx)
size = memory(idx
+ 256)
idx = idx + 1
open $imagefile
byt
read 1024 size
offset
open $ofile byt
write 1024 size
0
open null
fprint $ofile
viewer display
$ofile
viewer notify
nextfile $ofile
inum = inum - 1
if inum > 0
goto Main
endif
viewer loadlist $list
viewer prior
viewer notify
message "Ready..."
exit