package net.xoetrope.optional.laf.synth.batik;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import net.xoetrope.optional.laf.ImageConverter;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.image.TIFFTranscoder;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
/**
* Wrap the Batik PNGTranscoder to support dynamic loading
* <p>Copyright (c) Xoetrope Ltd., 2001-2005<br>
* License: see license.txt
* $Revision: 1.1 $
*/
public class TiffTranscoderWrapper implements ImageConverter
{
/**
* Convert one image format to another
* @param is the input stream for the source image
* @param os the output steam for the resulting/converted image
* @param width the desired image width
* @param height the desired image height
* @return true for successful conversion, false otherwise
*/
public boolean convert( String name, InputStream is, OutputStream os, int width, int height )
{
try {
TIFFTranscoder trans = new TIFFTranscoder();
trans.addTranscodingHint( TIFFTranscoder.KEY_WIDTH, new Float( width ));
trans.addTranscodingHint( TIFFTranscoder.KEY_HEIGHT, new Float( height ));
TranscoderInput input = new TranscoderInput( is );
TranscoderOutput output = new TranscoderOutput( os );
trans.transcode( input, output );
os.flush();
os.close();
}
catch ( NoClassDefFoundError e ) {
return false;
}
catch ( TranscoderException e ) {
return false;
}
catch ( IOException e ) {
return false;
}
return true;
}
/**
* Get the extension of the file type that this converter produces
*/
public String getOutputExt()
{
return ".tif";
}
}