More scripts: Job
Syntax Highlighing:
comments, key words, predefined symbols, class members & methods, functions & classes
# TiffToJP2fromJob.sml
# Script called by a job file created with TiffToJP2getJobParms.sml.
# Converts a TIFF file to a JP2 file using parameters provided in the job file.
# Requires version 2009 of the TNT products. Script must be in the
# same directory as TiffToJP2getJobParms.sml.
# 15 January 2009
###################################################################
# uncomment the following preprocessor command to run in test mode
# with hard-coded job parameters outside of the Job Control environment
# $define TEST
################## variables read from the Job 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
##############################################################
################ Job parameters for test mode ###################
$ifdef TEST
# modify the inputPath$ below to reference an available TIFF file on your computer
inputPath$ = _context.ScriptDir + "/AzTIFF/3110901_ne.TIF";
outputDir$ = _context.ScriptDir;
compType$= "user";
compRatio = 15;
class STATUSCONTEXT status;
$endif
################# Other variables #############################
class STRING logfileName$; # variables for a log file to record processing information
class FILE logfile;
class DATETIME currentDT; # the current local date/time
# error checking procedure
numeric err;
proc ReportError(numeric linenum, numeric err) {
printf("FAILED -line: %d, error: %d\n", linenum - 1, err);
fprintf(logfile, "FAILED -line: %d, error: %d\n", linenum - 1, err);
PopupError(err);
}
###################### Main Program ##############################
clear();
# Open log file in the same directory as this script to append status information;
# If no log file is present, a new one will be created.
logfileName$ = _context.ScriptDir + "/TiffToJP2.log";
logfile = fopen(logfileName$, "a");
currentDT.SetCurrent(); # get current date and time and write to log
fprintf(logfile, "\nJob initiated %s Central Standard Time\n", currentDT);
# set up filepath for the input TIFF file using the path string from the job file
class FILEPATH inFilepath(inputPath$);
fprintf(logfile, "Input filename = %s\n", inFilepath);
# 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 directory designated in the job file
class FILEPATH outFilepath(outputDir$);
outFilepath.Append(filename$);
outFilepath.SetExtension("jp2");
fprintf(logfile, "output filepath = %s\n", outFilepath);
# print other processing parameters read from the job file
fprintf(logfile, "compType$ = %s\n", compType$);
fprintf(logfile, "compRatio = %.1f\n", compRatio);
# in TEST mode, print info to the console window
$ifdef TEST
print(inFilepath);
printf("input filename = %s\n", filename$);
printf("output filepath = %s\n", outFilepath);
printf("compType$ = %s\n", compType$);
printf("compRatio = %.1f\n", compRatio);
$endif
# PIPELINE SOURCE: TIFF file
class IMAGE_PIPELINE_SOURCE_TIFF sourceTIFF(inFilepath);
err = sourceTIFF.Initialize();
if (err < 0 )
ReportError(_context.CurrentLineNum, err);
else {
fprint(logfile, "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();
#targetJ2K.SetShowStatus(1);
if (err < 0 )
ReportError(_context.CurrentLineNum, err);
else {
fprint(logfile, "Target J2K file initialized");
}
# PROCESS THE PIPELINE
err = targetJ2K.Process();
if (err < 0)
ReportError(_context.CurrentLineNum, err);
else {
fprint(logfile, "Target processed");
}
fclose(logfile);