A
atusc
I have to open tiff files quickly.
When I open a palette tif image at its original size it opens up
quickly but if I scale it down it takes a long time to display.
However a non-Palette tiff opens up quickly both original size and
scaled size.
Palette Tiff (Code is included below)
============
I noticed that the Frame pops up quickly when the show() method is
called but after that the Frame just sits for the image to be
displayed. It takes more than 30 seconds to pop up a single scaled
image after the frame has popped. If the image is not scaled down too
much the display is quicker.
What am I doing wrong? How can I display scaled Palette images
quickly. My actual application has to generate thumbnails as well so
displaying scaled images is very important for my application.
The code is included below:
import java.awt.*;
import java.awt.color.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.image.renderable.*;
import javax.media.jai.*;
import javax.media.jai.widget.*;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.TIFFDecodeParam;
import com.sun.media.jai.codec.ImageCodec;
import java.io.File;
import com.sun.media.jai.codec.SeekableStream;
import com.sun.media.jai.codec.FileSeekableStream;
public class PaletteToRGB extends Frame {
public static void main(String[] args) {
new PaletteToRGB(args[0]);
}
PaletteToRGB(String fileName) {
try {
File file = new File(fileName);
SeekableStream s = new FileSeekableStream(file);
TIFFDecodeParam param = null;
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s,
param);
//PlanarImage src = JAI.create("fileload", fileName);
//PlanarImage src =(PlanarImage)
JAI.create("PlanarImage",dec.decodeAsRenderedImage(0));
RenderedImage op =
new NullOpImage(dec.decodeAsRenderedImage(0),
null,
OpImage.OP_IO_BOUND,
null);
PlanarImage src = (PlanarImage) op;
PlanarImage dst = null;
if(src.getColorModel() instanceof IndexColorModel) {
IndexColorModel icm =
(IndexColorModel)src.getColorModel();
byte[][] data = new byte[3][icm.getMapSize()];
icm.getReds(data[0]);
icm.getGreens(data[1]);
icm.getBlues(data[2]);
LookupTableJAI lut = new LookupTableJAI(data);
dst = JAI.create("lookup", src, lut);
} else {
dst = src;
}
ParameterBlock pb = new ParameterBlock();
pb.addSource(dst);
pb.add(0.10F);
pb.add(0.10F);
pb.add(0.0F);
pb.add(0.0F);
RenderedOp scaledImage = JAI.create("scale", pb);
add(new ScrollingImagePanel(scaledImage, 640, 480));
pack();
show();
System.out.pritln("AFTER show()");//image display 30 sec after
this line
}catch(Exception e) {
System.out.println("EXCEPTION");
e.printStackTrace();
}
}
}
When I open a palette tif image at its original size it opens up
quickly but if I scale it down it takes a long time to display.
However a non-Palette tiff opens up quickly both original size and
scaled size.
Palette Tiff (Code is included below)
============
I noticed that the Frame pops up quickly when the show() method is
called but after that the Frame just sits for the image to be
displayed. It takes more than 30 seconds to pop up a single scaled
image after the frame has popped. If the image is not scaled down too
much the display is quicker.
What am I doing wrong? How can I display scaled Palette images
quickly. My actual application has to generate thumbnails as well so
displaying scaled images is very important for my application.
The code is included below:
import java.awt.*;
import java.awt.color.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.image.renderable.*;
import javax.media.jai.*;
import javax.media.jai.widget.*;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.TIFFDecodeParam;
import com.sun.media.jai.codec.ImageCodec;
import java.io.File;
import com.sun.media.jai.codec.SeekableStream;
import com.sun.media.jai.codec.FileSeekableStream;
public class PaletteToRGB extends Frame {
public static void main(String[] args) {
new PaletteToRGB(args[0]);
}
PaletteToRGB(String fileName) {
try {
File file = new File(fileName);
SeekableStream s = new FileSeekableStream(file);
TIFFDecodeParam param = null;
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s,
param);
//PlanarImage src = JAI.create("fileload", fileName);
//PlanarImage src =(PlanarImage)
JAI.create("PlanarImage",dec.decodeAsRenderedImage(0));
RenderedImage op =
new NullOpImage(dec.decodeAsRenderedImage(0),
null,
OpImage.OP_IO_BOUND,
null);
PlanarImage src = (PlanarImage) op;
PlanarImage dst = null;
if(src.getColorModel() instanceof IndexColorModel) {
IndexColorModel icm =
(IndexColorModel)src.getColorModel();
byte[][] data = new byte[3][icm.getMapSize()];
icm.getReds(data[0]);
icm.getGreens(data[1]);
icm.getBlues(data[2]);
LookupTableJAI lut = new LookupTableJAI(data);
dst = JAI.create("lookup", src, lut);
} else {
dst = src;
}
ParameterBlock pb = new ParameterBlock();
pb.addSource(dst);
pb.add(0.10F);
pb.add(0.10F);
pb.add(0.0F);
pb.add(0.0F);
RenderedOp scaledImage = JAI.create("scale", pb);
add(new ScrollingImagePanel(scaledImage, 640, 480));
pack();
show();
System.out.pritln("AFTER show()");//image display 30 sec after
this line
}catch(Exception e) {
System.out.println("EXCEPTION");
e.printStackTrace();
}
}
}