Author Topic: Dynamic brightness and contrast adjustment  (Read 2444 times)

Offline Mr.Marbles

  • int
  • **
  • Posts: 81
    • View Profile
Dynamic brightness and contrast adjustment
« on: March 21, 2006, 05:12:03 pm »
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:

Code: [Select]

// 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

Offline Melssj5

  • double
  • *****
  • Posts: 715
    • View Profile
Dynamic brightness and contrast adjustment
« Reply #1 on: March 21, 2006, 05:50:31 pm »
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

Offline Mr.Marbles

  • int
  • **
  • Posts: 81
    • View Profile
Dynamic brightness and contrast adjustment
« Reply #2 on: March 21, 2006, 06:44:59 pm »
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  :?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Dynamic brightness and contrast adjustment
« Reply #3 on: March 22, 2006, 06:44:40 pm »
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.