BufferedImage.TYPE_CUSTOM conversion is painfully slow.

E

emp

Hello,

I am loading PNG's and the resulting BufferedImage is of TYPE_CUSTOM. I
need to convert it as drawing this type of image with Graphics2D is very
slow (at least on my machine). I am converting using
Graphics.drawImage(dest, 0, 0, null), which is very slow.
I have looked into image.getRGB() which I suspect drawImage is using, as
it is just as slow.

Anyone know a faster way? It is taking me 1 second to load the image and
1/2 a second to convert!

Thanks
-Ed
 
T

Thomas Fritsch

emp said:
I am loading PNG's and the resulting BufferedImage is of TYPE_CUSTOM. I
need to convert it as drawing this type of image with Graphics2D is very
slow (at least on my machine). I am converting using
Graphics.drawImage(dest, 0, 0, null), which is very slow.
I have looked into image.getRGB() which I suspect drawImage is using, as
it is just as slow.
BTW: You can check this by debugging with break-points in BufferedImage.

drawImage does not use BufferedImage.getRGB(int x, int y), which indeed
would be very slow.
Instead it uses BufferedImage.getRGB(int startX, int startY, int w, int
h, int[] rgbArray, int offset, int scansize) with chunks of h=10, which
is much faster. But speed still depends on other things like type of
ColorModel and Raster. It uses ColorModel.getRGB(Object) which is quite
slow for IndexColorModel, and faster for DirectColorModel.
Anyone know a faster way?
I see little chances to make it faster, because it is outside your
control how the PNG-Reader builds the BufferedImage.
It is taking me 1 second to load the image and
1/2 a second to convert!
I can't judge these times as slow or fast without knowing width and
height of your image.
 
T

Thomas Fritsch

Thomas said:
emp said:
I am loading PNG's and the resulting BufferedImage is of TYPE_CUSTOM.
I need to convert it as drawing this type of image with Graphics2D is
very slow (at least on my machine). I am converting using
Graphics.drawImage(dest, 0, 0, null), which is very slow.
I have looked into image.getRGB() which I suspect drawImage is using,
as it is just as slow.

BTW: You can check this by debugging with break-points in BufferedImage.

drawImage does not use BufferedImage.getRGB(int x, int y), which indeed
would be very slow.
Instead it uses BufferedImage.getRGB(int startX, int startY, int w, int
h, int[] rgbArray, int offset, int scansize) with chunks of h=10, which
is much faster. But speed still depends on other things like type of
ColorModel and Raster. It uses ColorModel.getRGB(Object) which is quite
slow for IndexColorModel, and faster for DirectColorModel.
Sorry, I confused things. The findings above apply to
drawImage(Image, AffineTransform, ImageObserver)
and probably not to your case
drawImage(Image, int x, int y, ImageObserver)
 
E

emp

Never mind, after sleeping on it I implemented my own special case
converters, it is now a nice 5x faster and my interface feels much faster :)
-Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top