}
catch ( UnknownImageTypeException e ) {
metadata = new ImageMetadata( this );
}
final LCTIFFWriter writer;
try {
if ( tiffOptions.multilayer.getValue() ) {
File originalFile = imageInfo.getFile();
if ( exportFile.equals( originalFile ) ) {
tempFile = File.createTempFile( "LightZone", "tif" );
FileUtil.copyFile( originalFile, tempFile );
originalFile = tempFile;
}
writer = new LCTIFFWriter(
exportFile.getAbsolutePath(),
originalFile.getAbsolutePath(),
tiffOptions.resizeWidth.getValue(),
tiffOptions.resizeHeight.getValue(),
tiffOptions.resolution.getValue(),
tiffOptions.resolutionUnit.getValue()
);
} else {
writer = new LCTIFFWriter(
options.getExportFile().getAbsolutePath(),
tiffOptions.resizeWidth.getValue(),
tiffOptions.resizeHeight.getValue(),
tiffOptions.resolution.getValue(),
tiffOptions.resolutionUnit.getValue()
);
}
writer.setIntField(
TIFF_COMPRESSION,
tiffOptions.lzwCompression.getValue() ?
TIFF_COMPRESSION_LZW : TIFF_COMPRESSION_NONE
);
ICC_Profile profile = ColorProfileInfo.getExportICCProfileFor(
tiffOptions.colorProfile.getValue()
);
if ( profile == null )
profile = JAIContext.sRGBExportColorProfile;
writer.setICCProfile( profile );
if ( lznDoc != null ) {
final byte[] buf = XMLUtil.encodeDocument( lznDoc, false );
writer.setByteField( TIFF_LIGHTZONE, buf );
}
writer.putMetadata( metadata );
writer.putImageStriped( image, thread );
// TODO: allow users to write tiled TIFFs if they want
// writer.putImageTiled( image, thread );
writer.dispose();
}
catch ( LCImageLibException e ) {
final IOException ioe = new IOException( "TIFF export failed" );
ioe.initCause( e );
throw ioe;