Image pixels encoding / decoding not using BufferedImage etc

This isn’t quite a JOGL topic, but it’s relevant to my use of JOGL.

I’m interested in finding Java code which efficiently encodes / decodes an image stored just in a byte array. The encoded form I want to use when I distribute my game, I have no interest in using it with Java2D only as data to load into an OpenGL texture.

The spur to this is how slow loading JPG / PNG images to OpenGL textures in Java is for me on a Mac, and I want to eliminate some of the overheads.

Are DXTn-compressed textures an option? They’re pretty portable and well-supported, and give you the advantage of a certain amount of compression.

there’s the Raster class to provide you this functionnality : http://java.sun.com/j2se/1.4.2/docs/api/javax/imageio/ImageReader.html#readRaster(int,%20javax.imageio.ImageReadParam)
And the JAI/JIIO extension with FileChannel’s provides some faster decoding.

ImageReader ir = ImageIO.getImageReadersByMimeType("image/jpeg");
try{
        ir.setInput(new FileChannelImageInputStream(new RandomAccessFile("yourFileName.jpg", "rws")));
        Raster raster = ir.readRaster(ir.getMinIndex(), ir.getDefaultReadParam()); // there's the Raster
} catch(IOException e) { e.printStackTrace(); } finally {
        // thereafter, construct your image with IIOImage or BufferedImage or other class that supports Raster's
}

IIOImage(Raster, List, IIOMetadata)
Is that a good solution ?
::slight_smile:

Thanks for the replies! I’ll follow those up. I ought to check out the Targa file format as well.