24bits performances

Hi, i wrote a simple 2d test application that displays 100 copies of the same tile, loaded by ImageIO.read().
I made 2 copies of the image file:

  • a transparent GIF (8bits)
  • a transparent PNG (24bits)

The problem is that when i render the scene using the GIF tile i reach about 900fps, when i use the PNG i get only 22fps.

The only optimization I’m explicitly using, is the double buffering.
I tried to load my tile into a VolatileImageObject, but the result doesn’t change, I think that JDK 1.5 automatically loads the tile in the video memory.

Can anyone help me? thanks.

System.setProperty(“sun.java2d.translaccel”,“true”);
System.setProperty(“sun.java2d.accthreshold”, “0”);
System.setProperty(“sun.java2d.ddscale”,“true”); //*
System.setProperty(“sun.java2d.ddforcevram”, “true”);

(* = scaling is either filtered or not… depends on the graphic card)

And it’s 32 bit. 8 bit for each channel (red, blue, green and alpha).

PNG loading with ImageIO is broken for some images. It probably arranges the bits in some not so favourable way. Sun knows about it and i guess? they are working on it.

  • Use Toolkit to load the png and you’ll see a big improvement.

or

You can also just make a new BufferedImage and copy the old one to the new one and the speed is up there again.

You will still have to use the:

System.setProperty(“sun.java2d.translaccel”,“true”);
(or start with -Dsun.java2d.translaccel=true)

to get some real speed with translucent images though.

Cheers,
Mikael

Is anyone interested in making a more substantial graphics tester? I posted one here -

Other Thread

It would nice to have an app that would give you options such as -

  • Full screen vs windowed
  • Setting various system properties such as transAccel
  • Doing pageFlipping vs VolatileImage

Having one app that people could use to see what modes seem to give them trouble and which don’t seems like a useful tool to me.

Dr. A>

Thanks, I almost solved the problem copying the BufferedImage into another BufferedImage and setting that 4 system properties.

I tried to use Toolkit to load the image but I couldn’t do it… it doesn’t load anything and doesn’t throw any Exception…
Image image = Toolkit.getDefaultToolkit().createImage( myPNGFile.toURL() );

So, now i get 200fps that is better than the old 22 fps, but a lot slower than the 900fps i got loading an 8bits GIF!

If you copy it you don’t have to use toolkit. You can use either. And you should use:

Image image = Toolkit.getDefaultToolkit().getImage( myPNGFile.toURL() );

If you want to use toolkit to load the image.

Make sure that you get an accelerated (called managed) BufferedImage to copy to. If you use 1.5 you’ll always get one, for 1.4 only about half of the different approaches to get a new BufferedImage will return a managed one. Look at Chet Haase’s articles for more info on images. There at:

http://community.java.net/javadesktop/

a i bit down.

Cheers,
Mikael

So, now i get 200fps that is better than the old 22 fps, but
a lot slower than the 900fps i got loading an 8bits GIF!

“A lot” slower huh? Well, you do much more there so of course it’s slower. 4 bytes instead of one. Read back, multiply yadda yadda instead of a simple check.

I mean… you aren’t surprised that running 500m takes longer than running 100m right? :stuck_out_tongue:

In theory once the images get accelerated, there shouldn’t be any difference between 8 and 24-bit images. But in this case our code uses different mechanisms for accelerating these types of images, which may be the reason for the performance difference.