Displaying Palette Tiff Image using JAI (very slow when scale operation is performed)

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();
}
}
}
 
A

ak

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.

JAI imaging is not easy thing.
You must check many things.

1. ScrollingImagePanel is deprecated and buggy, may be you better use
DisplayJAI, if you can - use JadeDisplay.
2. Check if VM have enough memory.
3. Check your TileCache size (default size is mostly not anough).
4. Tile your image just after loading (if your tiff not tiled)
JAI.create("PlanarImage",dec.decodeAsRenderedImage(0));
this seems to be unused

5. Ask this question at http://swjscmail1.sun.com/archives/jai-interest.html
6. If these all doesn't work - take a look at ImageroReader (link below)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top