Re: Speeding up writing to JPG file
Posted by Ryan on Jul 21, 2016; 8:48pm
URL: https://forum.jogamp.org/Speeding-up-writing-to-JPG-file-tp4036909p4036952.html
I can confirm that TurboJpeg is a massive improvement over the current implementation for both reading in jpegs as textures and writing jpegs. There are a few issues such as trying to reduce the byte array copies as the official JNI wrapper for TurboJpeg does not support NIO.
I'm planning to open source what Im working on, if anyone is interested in helping out, i will go through the process early to get more eyes on it.
The example code for writing a jpeg is pretty simple and dropped compression time from ~30ms to 1ms on my sample
public InputStream encode(ByteBuffer buffer, Dimension dimension) throws IOException {
final byte[] unneccessaryCopy;
if (buffer.hasArray()) {
unneccessaryCopy = buffer.array();
} else {
unneccessaryCopy = new byte[buffer.remaining()];
buffer.get(unneccessaryCopy);
}
try (TJCompressor compressor = new TJCompressor(unneccessaryCopy, 0, 0, dimension.width, 0, dimension.height, TJ.PF_RGBX)) {
compressor.setJPEGQuality(90);
compressor.setSubsamp(TJ.SAMP_420);
return new ByteArrayInputStream(compressor.compress(0),0,compressor.getCompressedSize());
} catch (Exception ex) {
throw new IOException("Error in turbojpeg comressor: " + ex.getMessage(), ex);
}
}
Ryan Barker
Software Architect
Eharmony.com