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

Discussion in 'Java' started by atusc, Jun 4, 2004.

  1. atusc

    atusc Guest

    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();
    }
    }
    }
    atusc, Jun 4, 2004
    #1
    1. Advertising

  2. atusc

    ak Guest

    > 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
    ak, Jun 4, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chuck Taylor
    Replies:
    1
    Views:
    8,275
    Chuck Taylor
    Sep 4, 2003
  2. cyril
    Replies:
    1
    Views:
    778
    cyril
    Sep 8, 2003
  3. surendra
    Replies:
    1
    Views:
    8,264
    dipakPardesi
    Jun 21, 2008
  4. Roland
    Replies:
    0
    Views:
    1,042
    Roland
    May 12, 2004
  5. Michael David Pedersen
    Replies:
    2
    Views:
    3,577
    Michael David Pedersen
    Jul 22, 2004
Loading...

Share This Page