Dynamic brightness and contrast adjustment

Started by Mr.Marbles, March 21, 2006, 05:12:03 PM

Previous topic - Next topic

Mr.Marbles

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

Melssj5

I dont know about the contrast, but why dont you use setAmbientLight (int, int, int), that sets the color of the total iluminacion that is the bright adjust, the darker the color is, the less the bright will be
Nada por ahora

Mr.Marbles

Melssj5,

Thank-you for the suggestion. Your solution has much better performance, but does not visually give the same effect. However, considering this solution also works for hardware rendering I will surely be using it insted.

Now if I can only find a way to play with contrast  :?

EgonOlsen

You may apply a TextureEffect on the textures to change their contrast...but that's exactly what you are asking for. What you want may be doable with pixel shaders in hardware but jPCT doesn't support them and wont do so in the foreseeable future.