JDK-6296671 : Slow drawing of JAI_CODEC RenderedImages in JDK 1.5.0
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.1.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2005-07-13
  • Updated: 2010-04-02
  • Resolved: 2005-10-13
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
In JDK 1.5.0 using JAI 1.1.2_01, drawing of JPEG and TIFF RenderedImages returned by ImageCodec.createImageDecoder().decodeAsRenderedImage() is much slower than in previous versions.
TIFF images generally draw about 10 times slower, regardless of how they're drawn. JPEG images draw just as quickly as before if they lie completely within the viewport, but if they need to be clipped at all, performance is EXTREMELY slow (2000-3000 times slower). These problems do not occur with BufferedImage, which leads me to believe that the problem is in JAI_CODEC, but it may very well be a JDK 1.5.0 bug.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Load a large JPEG image into a RenderedImage (I was using a 4' world relief map at 5400x2700 pixels) using ImageCodec.createImageDecoder("JPEG"..).decodeAsRenderedImage()
2. Draw the image to a window such that part of it lies outside the viewport.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect it to draw just as quickly as it did in 1.4.2 and earlier.
ACTUAL -
It acutally draws 2000-3000 times more slowly.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
This is the code I was using for testing, with my 5400x2700 jpeg image as "testImage.jpg" in the user.dir folder. You'll have to create your own image to test with, since I can't attach the file. It opens a window, and you can click on the window to toggle between drawing the JPEG clipped and unclipped to see the difference in speed.

import com.sun.media.jai.codec.ImageCodec;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.*;
public class ImgBug {
	static RenderedImage testImage;
	static boolean drawClipped = true;
	public static void main (String[] args) {
		try {
			InputStream in = new FileInputStream(new File(System.getProperty("user.dir"), "testImage.jpg"));
			testImage = ImageCodec.createImageDecoder("JPEG", in, null).decodeAsRenderedImage();
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(-1);
		}
		JFrame frame = new JFrame();
		final JComponent component = new JComponent() {
				int count = 0;
				AffineTransform t = new AffineTransform();
				public void paintComponent (Graphics g) {
					if (drawClipped)
						t.setTransform(400.0 / testImage.getWidth(), 0.0, 0.0, 400.0 / testImage.getWidth(), -1.0, 150.0);
					else
						t.setTransform(400.0 / testImage.getWidth(), 0.0, 0.0, 400.0 / testImage.getWidth(), 200.0, 150.0);
					long startTime = System.currentTimeMillis();
					((Graphics2D)g).drawRenderedImage(testImage, t);
					System.out.println("drawing time: " + (System.currentTimeMillis() - startTime));
					drawClipped = !drawClipped;
				}
			};
		component.addMouseListener(new MouseAdapter() {
				public void mousePressed (MouseEvent evt) {
					((Component)evt.getSource()).repaint();
				}
			});
		frame.getContentPane().add(component);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(850, 650);
		frame.setVisible(true);
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I've got to tell our users not to upgrade to 1.5.0 until this is resolved, but other than that there's no impact, since it works fine in 1.4.2.
###@###.### 2005-07-13 23:36:42 GMT

Comments
EVALUATION This performance degradation is due to the recent fixes to be more exact about the sub-pixel dimensions of an image scale (see bug 4916948). The performance degradation was later fixed in 5.0update2 and Mustang under bug id 5073407 and this test case returned to the same or better performance levels as 1.4.2. This bug is a duplicate of 5073407.
13-10-2005