Does it exist?
If not, is there any good documentation on PNG decoding (specifically true color alpha, that’s all I need).
Does it exist?
If not, is there any good documentation on PNG decoding (specifically true color alpha, that’s all I need).
Slick uses Matthias Mann’s PNGDecoder http://l33tlabs.org/#downloads
it’s quite good, although there could be more documentation
http://wiki.l33tlabs.org/bin/view/TWL/Using+the+TWL+PNGDecoder
now i’m no lawyer but isn’t there something in the license disallowing commercial use for that? at least without permission?
and how would you get a BufferedImage from that?
the PNGDecoder above is BSD License, so you can use it for commercial use.
yeah common problem. I’m not an expert at this and have to fiddle around myself to get stuff like that to work.
my first guess would be to use the BufferedImage.setData method
which requires a Raster, so you use a WriteableRaster
it has a lot of methods like setPixel and setPixels
so from the ByteBuffer, PNGDecoder creates you have to make a Rastern, then apply it.
How exactly and if it is fast - not sure.
but when working with java2D I have just use ImageIO.read which does PNGs aswell of course
Does the ByteBuffer just contain the pixel data as bytes? like
byte 0 = Red
byte 1 = Green
byte 2 = Blue
byte 3 = Alpha
… repeat
(not necessarily in that order?)
yeah don’t ask me, I would guess so
but absolutely no idea, could be entirely different
Depends on the value returned by BufferedImage.getType(), and/or the value passed into the constructor.
When I did a mini-project recently which involved hacking around with pngs I found the spec pretty good.
Question: given that you talk about true-colour alpha being all you need, is it fair to assume that you’re in full control of the creation of the images you want to later read? If so, is there a particular reason for using png?
It’s the best image format there is. Sharp, no artifacts like jpg, stilll not as big as bmp obviously, and supports transparency which is obviously the most important, and there are few other formats that do this well.
Even Ps3 XMB uses pngs.
But if png decoding is proving a bottleneck for you, perhaps you should consider using a raw bitmap format and sticking it in your jar. The compression may not be quite as good as png, but the reconstruction would be faster.
size is also important, because I’m working with potentially hundreds of images of large sizes :\
the fastest thing right now is loading the PNG with ImageIO (I tried this method and other PNG decoders, but they are just slower? I found a great PNG encoder though, that is faster than ImageIO)
I did not write PNGDecoder to be used with BufferedImage - it is intended to be used with OpenGL and it decodes into formats understood by OpenGL. And for that it is probably the fastest decoder (and it is small).
As for the byte order - just look at the Format enum (eg RGBA, BGRA etc).