More scripts: Dialog
Syntax Highlighing:
comments, key words, predefined symbols, class members & methods, functions & classes
# StdDisp.sml
#
# SML script to present standard display interface to user.
# Displays side by side copies to show before and after versions of raster
#
# Buttons:
# 1. "Open" read in raster
# 2. "Custom" place custom functions here
# 3. "Undo" undo gamma
# 4. "Save" save resulting output raster
# 5. "Exit" exit script
#
# Notes:
# 1. input and output raster must be 8-bit unsigned - this could be modified to work with other types
#
#
# AUTHOR: David Wilson
# MicroImages, Inc.
# REQUESTED BY:
# CREATION DATE: March 6, 1997
# REVISION LIST: Revision 1.1 March 10, 1997 Added to standard display window
# Revision 1.2 March 17, 1967 Added CreatePyramid() to save file section
# Revision 1.3 July 14, 1999 Added declaration of h1
# global variables
class DISP h1;
class RVC_RASTER Rtemp;
#
# procedure and function definitions
#
# procedure to update the screen after modifications to data
# display message passed to it
proc redrawScreen( string msg$ ) {
CloseRaster(Rtemp); # must close it to flush buffers before displaying it
DispRedraw(h1);
DispSetMessage( h1, msg$ );
}
#
# global data
#
# variables used for showing status of operations
string gStatusBarRight$ = "..........";
string gStatusBarLeft$ = "**********";
numeric gSizeStatusBar = 10;
# variables to keep track of open status of rasters
numeric rInIsOpen = false;
numeric rOutIsOpen = false;
numeric rTempIsOpen = false;
# set up range data values - for 8-bit unsigned only
numeric minData = 0;
numeric maxData = 255;
numeric lowerRange = minData;
numeric upperRange = maxData;
#
# START OF SCRIPT
#
clear(); # clear the console
# open a display window - add standard tools - set up buttons and title
h1 = DispOpen(800, 600, 20, 20);
DispAddStandardTools(h1);
DispAddButtons(h1, "Open", "Custom", "Undo", "Save", "Exit" );
DispSetTitle( h1, "SML Script - adjust image gamma" );
# set up exitCondition - allows us to break out of while loop
numeric exitCondition = false;
while ( exitCondition == false ) {
# display message showing current range
string message$ = sprintf( "Range: 3d - %3d Ready for input", lowerRange, upperRange);
DispSetMessage( h1, message$ );
# wait for button press
string button$ = DispWaitForButtonPress(h1);
DispResetButtons(h1);
if (button$ == "Open") {
raster Rin;
GetInputRaster(Rin); # get the input raster
if ( RastType(Rin) != "8-bit unsigned" ) {
PopupMessage( "This SML script only works with 8 bit unsigned raster types." );
CloseRaster(Rin); # close it
}
rInIsOpen = true;
if ( rInIsOpen ) {
# now create two side by side copies - one for comparison
CreateTempRaster(Rtemp, NumLins(Rin), NumCols(Rin) * 2, RastType(Rin));
rTempIsOpen = true;
numeric numColumns = NumCols(Rin);
numeric numLines = NumLins(Rin);
numeric stepSize = int( numLines / 10 );
numeric status = 0; # set up to display status bar
numeric r, c;
for r = 1 to numLines {
for c = 1 to numColumns {
Rtemp[r,c] = Rin[r,c];
Rtemp[r,c + numColumns] = Rin[r,c];
}
if ( !int( r % stepSize) ) { # status bar code
status = status + 1;
string status$ = left$(gStatusBarLeft$, status)
+ left$(gStatusBarRight$, gSizeStatusBar - status);
message$ = sprintf( "Making Working Copy of File: %s", status$);
DispSetMessage( h1, message$ );
}
}
# don't use redraw screen - must create layer here
class GRE_LAYER_RASTER layerRtemp;
CloseRaster(Rtemp); # must close it to flush buffers before displaying it
layerRtemp = DispAddRasterVar(h1, Rtemp); # this also opens R1
DispRedrawFull(h1);
DispSetMessage( h1, "Make Working Copy of File: Done" );
} # end of if ( rInIsOpen )
} # end of "Open"
if (button$ == "Custom") {
# Add custom code here !
if ( rInIsOpen == false ) {
PopupMessage( "Error - No file open" );
}
else {
# standard loop with status bar update
# variables need for status bar
numColumns = NumCols(Rin);
numLines = NumLins(Rin);
stepSize = int( numLines / 10 );
status = 0; # set up to display status bar
for r = 1 to numLines {
for c = 1 to numColumns {
# insert custom code here !
# invert data to show something happening
Rtemp[r, c + numColumns] = maxData - Rtemp[r, c];
}
# handle status bar update
if ( !int( r % stepSize) ) {
status = status + 1;
status$ = left$(gStatusBarLeft$, status)
+ left$(gStatusBarRight$, gSizeStatusBar - status);
message$ = sprintf( "Inverting Image: %s", status$ );
DispSetMessage( h1, message$ );
}
}
redrawScreen( "Custom - Done" );
} # end of else
} # end of "Custom"
if (button$ == "Undo") {
# copy left side of temp raster to right side
if ( rInIsOpen == false ) {
PopupMessage( "Error - No file open" );
}
else {
numColumns = NumCols(Rin);
numLines = NumLins(Rin);
stepSize = int( numLines / 10 );
status = 0; # set up to display status bar
for r = 1 to numLines {
for c = 1 to numColumns {
Rtemp[r,c + numColumns] = Rtemp[r,c];
}
if ( !int( r % stepSize) ) {
status = status + 1;
status$ = left$(gStatusBarLeft$, status)
+ left$(gStatusBarRight$, gSizeStatusBar - status);
message$ = sprintf( "Undo Invert Image: %s", status$ );
DispSetMessage( h1, message$ );
}
}
redrawScreen( "Undo - Done" );
} # end of else
} # end of "Undo"
if (button$ == "Save") {
# copy right side of temp raster to left side
# open dialog for output file to save results to
if ( rInIsOpen == false ) {
PopupMessage( "Error - No file open" );
}
else {
raster Rout;
GetOutputRaster( Rout, NumLins(Rin), NumCols(Rin), RastType(Rin) );
rOutIsOpen = true;
SetScale(Rout, LinScale(Rin), ColScale(Rin));
CopySubobjects(Rin, Rout);
numColumns = NumCols(Rin);
numLines = NumLins(Rin);
stepSize = int( numLines / 10 );
status = 0; # set up to display status bar
for r = 1 to NumLins(Rin) {
for c = 1 to NumCols(Rin) {
Rout[r,c] = Rtemp[r,c + numColumns]; # write new data to output file
Rtemp[r,c] = Rtemp[r,c + numColumns]; # update left side of temp file
}
if ( !int( r % stepSize) ) {
status = status + 1;
status$ = left$(gStatusBarLeft$, status)
+ left$(gStatusBarRight$, gSizeStatusBar - status);
message$ = sprintf( "%s%s", "Saving File: ", status$ );
DispSetMessage( h1, message$ );
}
}
CreatePyramid(Rout); # Revision 1.2
CloseRaster(Rout); # close the output raster
redrawScreen( "Saving File - Done" );
} # end of else
} # end of "Save"
if (button$ == "Exit") {
exitCondition = true;
}
} # end of main loop
# do clean up
if ( rTempIsOpen ) DeleteTempRaster(Rtemp);
if ( rInIsOpen ) CloseRaster( Rin );
if ( rOutIsOpen ) CloseRaster( Rout );
DispClose(h1);
#
# END OF SCRIPT
#