home products news downloads documentation support gallery online maps resellers search
TNTmips Downloads Menu

HOME

CONTACT US

CURRENT RELEASE
  TNT 2013

DEVELOPMENT VERSION
  TNT 2014

TNTmips Pro
PRIOR RELEASES
  TNT 2012

FREE SOFTWARE
  TNTmips Free
  TNTatlas
  TNTsdk

MORE DOWNLOADS
  HASP Key Driver
  Screen Recorder
  TNT Language Kits
  Sample Geodata
  TNT Scripts

DOCUMENTATION
  TNTmips Tutorials
  Tutorial Datasets
  Technical Guides
  Scripts
  Quick Guides

MORE INFO
  Download FAQs
  FTP
  Download Managers
  Find Reseller

SITE MAP


demogama.sml


# DemoGama.sml
#
# SML script to demonstrate gamma adjustment of gradient raster
#
# displays a grey scale gradient and applies gamma adjustment to top portion
#
# Buttons:
# 1. "Test Image"		create and display test image
# 2. "Adjust Gamma"	apply gamma adjustment to top portion of test image
# 3. "Undo"				undo gamma adjustment
# 4. "Exit"				exit script
# 
# Notes:
# 1. Works best in 24 bit mode - else the grey scale transitions will not be smooth
#
#
# AUTHOR: 			David Wilson
# 						MicroImages, Inc.
# REQUESTED BY:	
# CREATION DATE: 	Dec. 5, 1996
# REVISION LIST: 	March 10, 1997, Added to standard display window
#

#
# procedure and function definitions
#

# none used

#
# global data
#
class DISP h1;


# variables to keep track of open status of rasters
numeric r1IsOpen = false;
numeric r2IsOpen = false;

# 
# START OF SCRIPT
# 

clear();	# clear the console

# open a display window - add standard tools - set up buttons and title
h1 = DispOpen( 800, 640, 0, 0);
DispAddStandardTools(h1);
DispAddButtons(h1, "Test Image", "Adjust Gamma", "Undo", "Exit" );

# set up exitCondition - allows us to break out of while loop
numeric exitCondition = false;

while ( exitCondition == false ) {

	string button$ = DispWaitForButtonPress(h1);
	DispResetButtons(h1);

	if (button$ == "Test Image") {
		raster R1, R2;
		CreateTempRaster(R1, 40, 255, "8-bit unsigned");
		CreateTempRaster(R2, 40, 255, "8-bit unsigned");

		r1IsOpen = true;
		r2IsOpen = true;

		numeric line, col;
		for line = 1 to NumLins(R1) {
			for col = 1 to NumCols(R1) {
				R1[line, col] = col;
				R2[line, col] = col;
				}
			}
		CloseRaster(R1);	# must close it to flush buffers before displaying it
		DispAddRasterVar(h1, R1);	# this also opens R1
		DispRedrawFull(h1);
		}

	if (button$ == "Adjust Gamma") {

		numeric newGamma = PopupNum("Input Gamma Value", 1.00, .1, 10.0, 2);

		numeric gMax = GlobalMax( R1 );
		numeric gMin = GlobalMin( R1 );
		numeric gRange = gMax - gMin;
		numeric oneOverGamma = 1 / newGamma;
		numeric inV, inScale, norm, outV;

		for line = 1 to NumLins(R1) / 2 {
			for col = 1 to NumCols(R1) {

				inV = R1[line, col];
				inScale = ( inV - gMin ) / gRange;
				norm = pow( oneOverGamma, inScale );			# pow(x,y) is y to x power!
				outV = ( inV * ( norm - inScale ) + inV );

				R1[line, col] = outV;
				}
			}
		CloseRaster(R1);	# must close it to flush buffers before displaying it
		DispRedraw(h1);
		}

	if (button$ == "Undo") {
		R1 = R2;
		CloseRaster(R1);	# must close it to flush buffers before displaying it
		DispRedraw(h1);
		}

	if (button$ == "Exit") {
		exitCondition = true;
		}

	} # end of main loop

# do clean up
if ( r1IsOpen ) { DeleteTempRaster( R1 ); }
if ( r2IsOpen ) { DeleteTempRaster( R2 ); }
DispClose( h1 );

# 
# END OF SCRIPT
# 


Back Home ©MicroImages, Inc. 2013 Published in the United States of America
11th Floor - Sharp Tower, 206 South 13th Street, Lincoln NE 68508-2010   USA
Business & Sales: (402)477-9554  Support: (402)477-9562  Fax: (402)477-9559
Business info@microimages.com  Support support@microimages.com  Web webmaster@microimages.com

25 March 2009

page update: 26 May 11