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 / GUI / August 2005

Tip: Looking for answers? Try searching our database.

Faster JPEG Decoder?

Thread view: 
jms3913@yahoo.com - 20 Aug 2005 00:14 GMT
I'm tring to find a better performance JPEG Decoder using java. I've
tried ImageIO, JAI and JPEGImageDecoder. The test program is attached
below. Here are the averaged numbers that I got for reading 1128 x 1024
x 8 bit jpeg images:

ImageIO  JAI.create  JPEGImageDecoder
-------  ----------  ----------------
295 ms   631 ms      161 ms
282 ms   616 ms      169 ms
295 ms   616 ms      158 ms

Currently we use JPEGImageDecoder which is the fastest of the three but
still it takes up a lot of CPU time.

Any suggestion? Thanks in advanced.

Also, just curious why JAI reader is that much slower compared with the
other two?

=========== test code ================
import java.io.File;
import java.io.FileInputStream;

import javax.imageio.ImageIO;
import javax.media.jai.JAI;
import javax.media.jai.RenderedImageAdapter;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageDecoder;

public class JPEGReaderTester {
   long start = 0, end = 0;

   enum ImageReadType {
       IMAGEIO("ImageIO"), JAI("JAI"), JPEGDECODER("JPEGDecoder");

       private String value = null;
       private ImageReadType(String s) {
           value = s;
       }

       public String value() {
           return value;
       }
   }

   private static long readFromImageIO(String filename) throws
Exception {
       File f = new File(filename);
       long start = System.currentTimeMillis();
       BufferedImage buff = ImageIO.read(f);
       long end = System.currentTimeMillis();
       return (end - start);
   }

   private static long readFromJAI(String filename) throws Exception {
       long start = System.currentTimeMillis();
       RenderedImage img = (RenderedImage) JAI.create("fileload",
filename);

       RenderedImageAdapter ria = new RenderedImageAdapter(img);
       BufferedImage bi = ria.getAsBufferedImage();
       long end = System.currentTimeMillis();
       return (end - start);
   }

   private static long readFromJPEGDecoder(String filename) throws
Exception {
       FileInputStream in = new java.io.FileInputStream(filename);
       long start = System.currentTimeMillis();
       JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
       BufferedImage jpeg = decoder.decodeAsBufferedImage();
       in.close();
       long end = System.currentTimeMillis();
       return (end - start);
   }

   private static long readImageFilesByType(ImageReadType type, String
filename) throws
         Exception {
       if (type == ImageReadType.IMAGEIO) {
           return readFromImageIO(filename);
       } else if (type == ImageReadType.JAI) {
           return readFromJAI(filename);
       } else if (type == ImageReadType.JPEGDECODER) {
           return readFromJPEGDecoder(filename);
       } else {
           return 0;
       }
   }

   private static void readImageFiles(ImageReadType type) {
       long total = 0;
       try {
           String[] files = {
                            "c:\\temp\\abc.jpg",
                            "c:\\temp\\efg.jpg"
           };

           for (int i = 0; i < files.length; i++) {
               total += readImageFilesByType(type, files[i]);
           }
           System.out.println("Average time for " + type.value() + "
takes: " +
                              total / files.length + " ms");
       } catch (Exception e) {
           e.printStackTrace();
       }
   }

   public static void main(String[] args) {
       readImageFiles(ImageReadType.IMAGEIO);
       readImageFiles(ImageReadType.JAI);
       readImageFiles(ImageReadType.JPEGDECODER);
   }
}
Roedy Green - 29 Aug 2005 08:56 GMT
>Currently we use JPEGImageDecoder which is the fastest of the three but
>still it takes up a lot of CPU time.
>
>Any suggestion? Thanks in advanced.

The obvious thing to consider is to predigest your images into some
other format that does not require so much processing to fluff it up.
They will probably be bigger.

When you create the jpg images you can control the
compression/quality.  Presumably lower quality images will display
faster.

If you are displaying them or scrolling over them, then you might look
into what speedups are possible with VolatileImage.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



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.