RenderedImage oRenderedImg;
PlanarImage oPlI;
RenderedOp oScI;
ParameterBlock oBlk;
ImageEncoder oImgEnc;
ImageDecoder oDecoder;
Log.out.debug("Begin Picture.drawJAIImage("+sCodec+","+String.valueOf(iThumbWidth)+","+String.valueOf(iThumbHeight)+")");
oDecoder = com.sun.media.jai.codec.ImageCodec.createImageDecoder(sCodec, imgSrc, null);
oRenderedImg = oDecoder.decodeAsRenderedImage();
if (sCodec.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);
ParameterBlockJAI pb = new ParameterBlockJAI( "format" );
pb.addSource( oRenderedImg );
oRenderedImg = javax.media.jai.JAI.create( "format", pb, hints );
} catch (IllegalArgumentException iae) {
}
// End increase color depth
} // gif
oPlI = PlanarImage.wrapRenderedImage(oRenderedImg);
int iImageWidth = oPlI.getWidth();
int iImageHeight = oPlI.getHeight();
float thumbRatio = ((float) iThumbWidth) / ((float) iThumbHeight);
float imageRatio = ((float) iImageWidth) / ((float) iImageHeight);
if (thumbRatio < imageRatio)
iThumbHeight = (int)(iThumbWidth / imageRatio);
else
iThumbWidth = (int)(iThumbHeight * imageRatio);
float scaleW = ((float) iThumbWidth) / ((float) iImageWidth);
float scaleH = ((float) iThumbHeight) / ((float) iImageHeight);
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());
oScI = JAI.create("scale", oBlk, null); // scale image NOW !
oImgEnc = ImageCodec.createImageEncoder( "jpeg", outStr, null );
if (null==oImgEnc) {
throw new NullPointerException("Cannot create ImageEncoder for jpeg");
}
else {
oImgEnc.encode( oScI ); // write encoded data to given output stream
oImgEnc =null;
}
Log.out.debug("End Picture.drawJAIImage()");