Speeding up writing to JPG file
Posted by Cmar on Jul 13, 2016; 1:49pm
URL: https://forum.jogamp.org/Speeding-up-writing-to-JPG-file-tp4036909.html
Hello,
I have been working on an application that needs to render directly to the disk. The output image is pretty big (2550x2362 to be precise).
Currently, I'm using a GLOffscreenAutoDrawable and an AWTGLReadBufferUtil. I render the drawable, then use the buffer utility to write the data to a BufferedImage, and then output said image to a jpg file (the format is important) using standard Java functions.
Correct me if I'm wrong, but isn't it an overkill writing to the BufferedImage first and THEN to the jpg? I know we can't just dump pixels to the jpg file (as it needs to do the whole compression thing), but I assume the Java functions do that when writing the BufferedImage, so the writing to BufferedImage itself doesn't use compression. If I can skip that step and write directly to the file with compression, it might improve the overall speed of the whole process.
The methods that look like they'd be better (i.e. reading into a GLReadBufferUtil and then outputting to a jpg) are actually much worse in performance, because they seem to be allocating new data each time, whereas the AWT utility tries to reuse and update its data.
Unfortunately, the process of writing to the BufferedImage is the bottleneck of the whole operation, as it adds 40-50 milliseconds for each image output (and it stacks up when exporting multiple images). The rendering itself doesn't take long for most inputs. The AWTGLReadBufferUtil utility is reusing the same BufferedImage (I checked), so it's not that.
My guess is that it's not possible to apply the compression unless the data is copied elsewhere for processing, but I want to make sure that this is the case. That being said... is there ANY way I can speed this up? Any help is appreciated.
Thank you.