I'm trying to implement a way of changing the brightness and contrast of the rendered image dynamically through user controls (GUI). This is proving to be a difficult task. It seems that the only way to post-process a rendered image is by using the getPixels() of the framebuffer and modifying those values. The problem is that this solution only works for software rendering, is there any way to do this for hardware rendering?
Here's the code which effectively plays with the brightness of the rendered framebuffer:
// this is in the rendering loop
Image image = frameBuffer.getOutputBuffer();
BufferedImage buffImage = new BufferedImage(image.getWidth(null),
image.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics g = buffImage.getGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
// gainAdjustment is the brightness; where 1.0 is 100%
RescaleOp op = new RescaleOp(gainAdjustment, 0, null);
buffImage = op.filter(buffImage, null);
int [] pixels = frameBuffer.getPixels();
buffImage.getRGB(0, 0, buffImage.getWidth(),
buffImage.getHeight(), pixels, 0,
buffImage.getWidth());
buffer.refresh();
I still haven't found a way to play with the contrast... but I think my biggest problem is that playing with the FrameBuffer's pixels has no effect in hardware mode :cry:
I'm opened to any suggestions