diff options
author | Kenneth Russel <[email protected]> | 2006-01-22 03:38:03 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2006-01-22 03:38:03 +0000 |
commit | 72acc211539803f1ef57d4331938afb48600398e (patch) | |
tree | 80d37e7c44d2c9a7bae74fc48434810526c8e80a /src/classes/com/sun/opengl/impl/windows | |
parent | ae26492c30051eb7c6c883b3c6397390f91afcae (diff) |
Fixed Issue 173: Adjust gamma, brightness and contrast
Added com.sun.opengl.util.Gamma supporting adjusting of gamma,
brightness, and contrast. API and implementation derived from code in
the LWJGL project. Added demos.gamma.TestGamma demo illustrating how
to use the APIs. Tested on Linux, Mac OS X and Windows. No Solaris
support at this time, although future Solaris releases, being based on
the Xorg server, will probably have support for the required
XF86VidMode extension.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@557 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/opengl/impl/windows')
-rw-r--r-- | src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java index b534a11fc..eab068bb4 100644 --- a/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java +++ b/src/classes/com/sun/opengl/impl/windows/WindowsGLDrawableFactory.java @@ -41,14 +41,11 @@ package com.sun.opengl.impl.windows; import java.awt.Component; import java.awt.Rectangle; -import java.io.File; -import java.lang.reflect.InvocationTargetException; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.ArrayList; -import java.util.List; +import java.nio.*; +import java.util.*; import javax.media.opengl.*; import com.sun.opengl.impl.*; +import com.sun.opengl.util.BufferUtil; public class WindowsGLDrawableFactory extends GLDrawableFactoryImpl { private static final boolean DEBUG = Debug.debug("WindowsGLDrawableFactory"); @@ -219,4 +216,50 @@ public class WindowsGLDrawableFactory extends GLDrawableFactoryImpl { public void unlockAWTForJava2D() { } + + //------------------------------------------------------ + // Gamma-related functionality + // + + private static final int GAMMA_RAMP_LENGTH = 256; + + protected int getGammaRampLength() { + return GAMMA_RAMP_LENGTH; + } + + protected boolean setGammaRamp(float[] ramp) { + short[] rampData = new short[3 * GAMMA_RAMP_LENGTH]; + for (int i = 0; i < GAMMA_RAMP_LENGTH; i++) { + short scaledValue = (short) (ramp[i] * 65535); + rampData[i] = scaledValue; + rampData[i + GAMMA_RAMP_LENGTH] = scaledValue; + rampData[i + 2 * GAMMA_RAMP_LENGTH] = scaledValue; + } + + long screenDC = WGL.GetDC(0); + boolean res = WGL.SetDeviceGammaRamp(screenDC, ShortBuffer.wrap(rampData)); + WGL.ReleaseDC(0, screenDC); + return res; + } + + protected Buffer getGammaRamp() { + ShortBuffer rampData = ShortBuffer.allocate(3 * GAMMA_RAMP_LENGTH); + long screenDC = WGL.GetDC(0); + boolean res = WGL.GetDeviceGammaRamp(screenDC, rampData); + WGL.ReleaseDC(0, screenDC); + if (!res) { + return null; + } + return rampData; + } + + protected void resetGammaRamp(Buffer originalGammaRamp) { + if (originalGammaRamp == null) { + // getGammaRamp failed earlier + return; + } + long screenDC = WGL.GetDC(0); + WGL.SetDeviceGammaRamp(screenDC, originalGammaRamp); + WGL.ReleaseDC(0, screenDC); + } } |