Ok, here's my findings so far (and to be honest, they are a little worrying...).
Using the standard JPEG plugin for ImageIO bundled with the Oracle JRE:
BufferedImage image = ImageIO.read(file);
Reads the image in roughly 18 seconds on my computer (a MacBookPro/2.8GHz i7).
Using my JPEG plugin for ImageIO, which uses a slightly different code path (i.e., you can probably get the same results by obtaining the ImageReader
and invoking the readRaster()
method, then creating a BufferedImage
from that. The code is non-trivial, so please refer tho the project page if you like to see the code):
BufferedImage image = ImageIO.read(file);
Reads the image in roughly 8 seconds on my computer.
Using my BufferedImageFactory
class and the AWT Toolkit
:
BufferedImage image = new BufferedImageFactory(Toolkit.getDefaultToolkit().createImage(file.getAbsolutePath())).getBufferedImage();
Reads the image in ~2.5 seconds on my computer.
Using the deprecated JPEGImageDecoder
class from sun.awt.codec
:
BufferedImage image = new JPEGImageDecoderImpl(new FileInputStream(file)).decodeAsBufferedImage();
Reads the image in ~1.7 seconds on my computer.
So, this means that we should be able to read this image in less than 2 seconds, even in Java. The performance from the JPEGImageReader
is just ridiculous in this case, and I really like to know why. As already mentioned, it seems to have to with the progressive decoding, but still, it should be better than this.
Update:
Just for the fun of it, I created a quick PoC ImageReader
plugin backed by the LibJPEG-Turbo Java API. It's not very sophisticated yet, but it allows for code like:
BufferedImage image = ImageIO.read(file);
To read the image in < 1.5 seconds on my computer.
PS: I used to maintain ImageIO wrappers for JMagick (similar to the code mentioned by @Jordan Doyle, but it would allow you to program against the ImageIO API), however I stopped as it was too much work. Maybe I have to reconsider... At least it's worth checking out his solution as well, if you don't mind on relying on JNI/native code installation.