JDK-6231864 : Some images loaded via Toolkit or ImageIcon can't be accelerated
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 5.0,6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux,solaris_9
  • CPU: generic,x86
  • Submitted: 2005-02-22
  • Updated: 2010-04-02
  • Resolved: 2007-03-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
Some images loaded via Toolkit.createImage() (or ImageIcon, which uses the
Toolkit methods internally) cannot be accelerated.  Run the attached testcase
(ManagedTest.java) with tracing enabled, and note that we always render using
the sysmem-based surface:
% java -Dsun.java2d.trace=log ManagedTest

Note that this bug does not affect the way an application will look, but it
does make rendering certain images much slower than necessary.

###@###.### 2005-2-22 22:03:16 GMT
I am adding the test case (ManagedTest.java) here so it will be visible to members of the jdk-collaboration.dev.java.net community.

import java.awt.*;
import javax.swing.ImageIcon;

public class ManagedTest extends Canvas {

    private Image oimg, timg;

    public void paint(Graphics g) {
        if (oimg == null) {
            oimg = new ImageIcon("opaque.png").getImage();
            timg = new ImageIcon("translucent.png").getImage();
        }
        g.setColor(Color.yellow);
        g.fillRect(0, 0, getWidth(), getHeight());
        System.err.println("rendering opaque image");
        g.drawImage(oimg, 0, 0, null);
        System.err.println("rendering translucent image");
        g.drawImage(timg, 200, 0, null);
    }

    public static void main(String[] args) {
        ManagedTest t = new ManagedTest();
        Frame f = new Frame();
        f.add(t);
        f.setSize(500, 500);
        f.setVisible(true);
    }
}

Comments
EVALUATION This works again in JDK 7 now that 6205557 is fixed.
28-03-2007

EVALUATION This bug is actually being resolved as part of the fix for 6205557. I will commit this bug to jdk7 and transfer it to the RE for 6205557, so that we can mark it fixed when 6205557 is putback (sometime in the next few weeks).
03-01-2007

EVALUATION The root cause of this problem appears to be in ImageRepresentation.getOpaqueRGBImage(). This method grabs the underlying DataBuffer of the image and scans the pixels to see if they are all opaque. The act of grabbing the DataBuffer causes the raster to be marked "stolen", which means that the image has no hope of being accelerated. Another problem is that if all the pixels are opaque, we create a new opaque image using the original DataBuffer, and the action of calling createPackedRaster() with the original DataBuffer also causes the raster to be marked "stolen". The fix here will be to protect both these cases by calling raster.setStolen(false), since we are in control of the raster. ###@###.### 2005-2-22 22:12:37 GMT
22-02-2005

WORK AROUND Use ImageIO to load the images instead (these will be accelerated properly): BufferedImage img = ImageIO.read(new File("file.png")); ###@###.### 2005-2-22 22:03:16 GMT
22-02-2005