[Java] Looking for the fastest possible way to replace a color in a BufferedImage.
Over the past few months, I've been working on a Unicode terminal display in Java using Swing. For the most part, the render performance has been good, but I'm running into a pretty big bottleneck during one of the pre-render stages.
The terminal is a collection of some arbitrary amount of character cells. Each cell can have a unique character, character color, and background color.
When rendering, only a small number of these cells are actually going to be updated on each draw. In some cases, the user may opt to redraw every cell on each draw call.
In the first case, where only a portion of the total cells are being redrawn, the render times are often 0-2ms.
In the second case, where all of the cells are being redrawn, the render times are often 80-120ms. Though I may have reduced this to 50-80ms through some caching.
During the pre-render stage, each cell retrieves a BufferedImage containing the character to be drawn in the cell. The image has a transparent background while the character itself is comprised of white pixels.
I'm using LookupOps to change the character's color and the background's color before drawing the image on a Canvas.
The LookupOp is taking between ~15-20 nanoseconds per image and this results in an increase in render time of ~30-40 milliseconds. I would like to get this down to ~1-10 milliseconds.
The lookup operation is created within the newOperation function here.
The render code is within the draw function here.
Thanks for any help. I'm open to doing some large rewrites if necessary.
Submitted July 10, 2017 at 03:05PM by Hobblton
via reddit http://ift.tt/2tHhUw4