TiffToJP2tntscript.sml

  Download

More scripts: TNTscript

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# TiffToJP2tntscript.sml
# Script called by TNTscript. 
# Requires version 2015 of TNTgis.
# 25 March 2015
####  variables passed by TNTscript from command line or SMLX file  #################
string inputPath$;		# complete directory path and name of input file
string outputDir$;		# complete path of output directory
string compType$;		# type of JPEG2000 compression; possible values = lossless, best, or user
numeric compRatio;	# compression ratio to set for user-defined lossy compression
# error checking procedure
numeric err;
proc ReportError(numeric linenum, numeric err) {
	printf("FAILED -line: %d, error: %d\n", linenum - 1, err); 
	}
######################  Main Program  ##############################
# set up filepath for the input TIFF file using the path string passed by TNTscript
class FILEPATH inFilepath(inputPath$);
# get the TIFF filename (minus extension) to use for naming the output JP2 file
class STRING filename$ = inFilepath.GetNameOnly();
# set up filepath for the output JP2 file in the designated directory 
class FILEPATH outFilepath(outputDir$);
outFilepath.Append(filename$);
outFilepath.SetExtension("jp2");
# print processing parameters to the console
printf("input filepath = %s\n",inFilepath);
printf("output filepath = %s\n", outFilepath);
printf("compType$ = %s\n", compType$);
printf("compRatio = %.1f\n", compRatio);
# PIPELINE SOURCE: TIFF file
class IMAGE_PIPELINE_SOURCE_TIFF sourceTIFF(inFilepath);
err = sourceTIFF.Initialize();
if (err < 0 )
	ReportError(_context.CurrentLineNum, err);
else {
	print("Source TIFF file initialized");
	}
# PIPELINE TARGET: J2K File with JPEG2000 Compression
class IMAGE_PIPELINE_TARGET_J2K_SETTINGS settings;
if (compType$ == "lossless") then
	settings.SetReversible(1);
else
	{
	settings.SetReversible(0);
	settings.SetTargetRatio(compRatio);
	}
class IMAGE_PIPELINE_TARGET_J2K targetJ2K(sourceTIFF, outFilepath, settings);
err = targetJ2K.Initialize();
if (err < 0 )
	ReportError(_context.CurrentLineNum, err);
else {
	print("Target J2K file initialized");
	}
# PROCESS THE PIPELINE
err = targetJ2K.Process();
if (err < 0)
		ReportError(_context.CurrentLineNum, err);
else {
	print("Target processed");
	}
print("Script processing completed.")