Skip to main content

Load and Scale JPEG Performance

3 replies [Last post]
pottsj
Offline
Joined: 2005-09-06

I am trying JAI to speed up loading and scaling JPEG images in Java. My source image is 3504x2336 from a digital camera and scaling it to 323x242. The source is below and the source image is at http://www.dcresource.com/reviews/canon/eos_20d-review/IMG_0628.JPG. Here are the results:

JAI: load & scale TOOK 00:00:01.427007124
ImageIO: load & scale TOOK 00:00:01.259069226
ImageMagick JNI: load & scale TOOK 00:00:00.602622616

As you can see, even java ImageIO lib using drawImage() scaled into second BufferedImage is faster and using ImageMagick though JNI is much faster.

I thought JAI is using mmx so should be faster as all the others are just C/C++ wrapped in java.

I have added the native dlls and exe to my system path so am not getting any waring messages so assume JAI is finding its libs ok.

Thanks

Jasper

long lSTART = System.nanoTime();
PlanarImage oImage = JAI.create("fileload", i_oImageFile.getAbsolutePath());
System.out.println("load image TOOK "+ TimePeriodFormat.formatNano(System.nanoTime()-lSTART));

lSTART = System.nanoTime();
double dScale = ImageUtils.calculateScaleFactor(oImage.getWidth(), oImage.getHeight(), i_iWidth, i_iHeight);
ParameterBlockJAI pb = new ParameterBlockJAI("scale");
pb.addSource(oImage);
pb.setParameter("xScale", (float)dScale); //x Scale Factor
pb.setParameter("yScale", (float)dScale); //y Scale Factor
pb.setParameter("xTrans", 0.0F); //x Translate amount
pb.setParameter("yTrans", 0.0F); //y Translate amount
pb.setParameter("interpolation", new InterpolationBilinear());
PlanarImage oScaledImage = JAI.create("scale", pb, null);
BufferedImage oResultImage = oScaledImage.getAsBufferedImage();
System.out.println("scale image TOOK "+ TimePeriodFormat.formatNano(System.nanoTime()-lSTART));
return oResultImage;

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
maule
Offline
Joined: 2006-08-22

I have done a lot of test with big images (6000*5000 pixel): we got good performances results with .TIF and .PNG images and a lot of problems with .JPG

I think the problem is in JPEG encoder/decoder (JAI don't wrap the JPEG encoder/decoder, so the standrad Java encoder/decoder is used).

Regards.

menders
Offline
Joined: 2006-02-14

According to my experiences JAI and ImageIO are faster when you are dealing with greyscale and bitonal images.

For color images, the JPEG encoder seems to be rather bad. I'm dealing with color images, which are TIFFs with JPEG compression. Reading these images is _fast_.

But when I want to write them as a JPEG (after scaling) this really is a problem. JPEG encoding is sooo slow, especially which big images:
encoding an images in 100dpi takes 4 seconds; the same image just with 150 dpi (means twice as much data) doesn't take twice as much time but 40 times as much (183 seconds).

If anybody knows better JPEG encoders, please let me know.

Ciao
Markus

Brian Burkhalter

Markus,

It may be that your images are BGR instead of RGB. If that is the case we just
checked into the CVS tree of jai-imageio-core an enhancement which should
allow BGR images to be written as fast as RGB images are.

Brian

On Tue, 31 Jan 2006, jai-imageio@javadesktop.org wrote:

> According to my experiences JAI and ImageIO are faster when you are dealing with greyscale and bitonal images.
>
> For color images, the JPEG encoder seems to be rather bad. I'm dealing with color images, which are TIFFs with JPEG compression. Reading these images is _fast_.
>
> But when I want to write them as a JPEG (after scaling) this really is a problem. JPEG encoding is sooo slow, especially which big images:
> encoding an images in 100dpi takes 4 seconds; the same image just with 150 dpi (means twice as much data) doesn't take twice as much time but 40 times as much (183 seconds).
>
> If anybody knows better JPEG encoders, please let me know.
>
> Ciao
> Markus
> ---
> [Message sent by forum member 'menders' (Markus Enders)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=141994
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net