Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Displaying Palette Tiff Image using JAI (very slow when scale operation is performed)

Reply
Thread Tools

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

 
 
atusc
Guest
Posts: n/a
 
      06-04-2004
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();
}
}
}
 
Reply With Quote
 
 
 
 
ak
Guest
Posts: n/a
 
      06-04-2004
> 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)

--
http://uio.dev.java.net
http://reader.imagero.com


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JAI Problem - TIFF Image to JPEG conversion surendra Java 1 06-21-2008 07:39 AM
Creating tiled image from multiple tiff sources in JAI Michael David Pedersen Java 2 07-22-2004 09:59 PM
Wrong image size of JPG after TIFF to JPG conversion with JAI Roland Java 0 05-12-2004 03:52 PM
convert a tiff image to another format (using JAI ?) cyril Java 1 09-08-2003 01:29 PM
JAI, Image I/O, TIFF Images, and ImageReadParam Chuck Taylor Java 1 09-04-2003 12:21 AM



Advertisments