com.sun.media.jai.codec.ImageDecoder oDecoder;
RenderedImage oRenderedImg;
javax.media.jai.PlanarImage oPlI;
javax.media.jai.PlanarImage oScI;
ParameterBlock oBlk;
com.sun.media.jai.codec.ImageEncoder oImgEnc;
String sInputURI;
InputStream oInputStream;
URL oURI;
if (DebugFile.trace) {
DebugFile.writeln("Begin Image.drawJAIImage([OutputStream], " + String.valueOf(iThumbWidth) + "," + String.valueOf(iThumbHeight) + "," + String.valueOf(fQuality) + ")");
DebugFile.incIdent();
}
sInputURI = getString(DB.path_image);
if (sInputURI.startsWith("http://") || sInputURI.startsWith("https://")) {
if (DebugFile.trace) DebugFile.writeln("new URL(" + sInputURI + ")");
oURI = new URL(sInputURI);
oInputStream = oURI.openStream();
}
else {
if (DebugFile.trace) DebugFile.writeln("new FileInputStream(" + sInputURI + ")");
try {
oInputStream = new FileInputStream(sInputURI);
} catch (FileNotFoundException fnf) {
if (DebugFile.trace) DebugFile.decIdent();
throw new FileNotFoundException(fnf.getMessage());
}
}
oDecoder = com.sun.media.jai.codec.ImageCodec.createImageDecoder(getImageCodec(), oInputStream, null);
oRenderedImg = oDecoder.decodeAsRenderedImage();
if (getImageType().equals("gif")) {
// Increase color depth to 16M RGB
try {
javax.media.jai.ImageLayout layout = new javax.media.jai.ImageLayout();
ColorModel cm = new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_sRGB),
new int[] {8,8,8}, false, false,
Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
layout.setColorModel(cm);
layout.setSampleModel(cm.createCompatibleSampleModel(oRenderedImg.getWidth(),oRenderedImg.getHeight()));
RenderingHints hints = new RenderingHints(javax.media.jai.JAI.KEY_IMAGE_LAYOUT, layout);
javax.media.jai.ParameterBlockJAI pb = new javax.media.jai.ParameterBlockJAI( "format" );
pb.addSource( oRenderedImg );
oRenderedImg = javax.media.jai.JAI.create( "format", pb, hints );
} catch (IllegalArgumentException iae) {
if (DebugFile.trace) DebugFile.writeln(iae.getMessage() + " " + oRenderedImg.getColorModel().getClass().getName() + " " + oRenderedImg.getSampleModel().getClass().getName());
}
// End increase color depth
} // gif
oPlI = javax.media.jai.PlanarImage.wrapRenderedImage(oRenderedImg);
int iImageWidth = oPlI.getWidth();
int iImageHeight = oPlI.getHeight();
if (DebugFile.trace) DebugFile.writeln("image width " + String.valueOf(iImageWidth));
if (DebugFile.trace) DebugFile.writeln("image height " + String.valueOf(iImageHeight));
float thumbRatio = ((float) iThumbWidth) / ((float) iThumbHeight);
if (DebugFile.trace) DebugFile.writeln("thumb ratio " + String.valueOf(thumbRatio));
float imageRatio = ((float) iImageWidth) / ((float) iImageHeight);
if (DebugFile.trace) DebugFile.writeln("image ratio " + String.valueOf(imageRatio));
if (thumbRatio < imageRatio)
iThumbHeight = (int)(iThumbWidth / imageRatio);
else
iThumbWidth = (int)(iThumbHeight * imageRatio);
float scaleW = ((float) iThumbWidth) / ((float) iImageWidth);
if (DebugFile.trace) DebugFile.writeln("scale width " + String.valueOf(scaleW));
float scaleH = ((float) iThumbHeight) / ((float) iImageHeight);
if (DebugFile.trace) DebugFile.writeln("scale height " + String.valueOf(scaleH));
oBlk = new ParameterBlock();
oBlk.addSource(oPlI);
oBlk.add(scaleW);
oBlk.add(scaleH);
oBlk.add(0.0f);
oBlk.add(0.0f);
oBlk.add(new javax.media.jai.InterpolationBilinear());
if (DebugFile.trace) DebugFile.writeln("JAI.create (\"scale\", [ParameterBlock], null)");
oScI = javax.media.jai.JAI.create("scale", oBlk, null); // scale image NOW !