Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
atusc - 04 Jun 2004 01:21 GMT
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();
       }
   }
}
ak - 04 Jun 2004 06:24 GMT
> 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)

Signature

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

myself - 02 Mar 2006 10:19 GMT
sir,

i jus wanna download a free JAI API jar files.but in sun.com ,i have seen the
jar files is in .exe.i need it as a jar file.pls tell me the solution.i need
a free api for commercial use.
thanks
myself - 02 Mar 2006 07:13 GMT
i jus wanna download a free JAI API jar files.but in sun.com ,i have seen the
jar files is in .exe.i need it as a jar file.pls tell me the solution.i need
a free api for commercial use.
thanks


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.