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/x11 | |
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/x11')
-rw-r--r-- | src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java | 103 |
1 files changed, 101 insertions, 2 deletions
diff --git a/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java b/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java index 289d06e93..4b8840e59 100644 --- a/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java +++ b/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java @@ -43,9 +43,9 @@ import java.awt.Component; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; +import java.nio.*; import java.security.*; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import javax.media.opengl.*; import com.sun.gluegen.runtime.*; import com.sun.opengl.impl.*; @@ -468,4 +468,103 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl { action.run(); } } + + //---------------------------------------------------------------------- + // Gamma-related functionality + // + + boolean gotGammaRampLength; + int gammaRampLength; + protected synchronized int getGammaRampLength() { + if (gotGammaRampLength) { + return gammaRampLength; + } + + int[] size = new int[1]; + lockToolkit(); + long display = getDisplayConnection(); + boolean res = GLX.XF86VidModeGetGammaRampSize(display, + GLX.DefaultScreen(display), + size, 0); + unlockToolkit(); + if (!res) + return 0; + gotGammaRampLength = true; + gammaRampLength = size[0]; + return gammaRampLength; + } + + protected boolean setGammaRamp(float[] ramp) { + int len = ramp.length; + short[] rampData = new short[len]; + for (int i = 0; i < len; i++) { + rampData[i] = (short) (ramp[i] * 65535); + } + + lockToolkit(); + long display = getDisplayConnection(); + boolean res = GLX.XF86VidModeSetGammaRamp(display, + GLX.DefaultScreen(display), + rampData.length, + rampData, 0, + rampData, 0, + rampData, 0); + unlockToolkit(); + return res; + } + + protected Buffer getGammaRamp() { + int size = getGammaRampLength(); + ShortBuffer rampData = ShortBuffer.allocate(3 * size); + rampData.position(0); + rampData.limit(size); + ShortBuffer redRampData = rampData.slice(); + rampData.position(size); + rampData.limit(2 * size); + ShortBuffer greenRampData = rampData.slice(); + rampData.position(2 * size); + rampData.limit(3 * size); + ShortBuffer blueRampData = rampData.slice(); + lockToolkit(); + long display = getDisplayConnection(); + boolean res = GLX.XF86VidModeGetGammaRamp(display, + GLX.DefaultScreen(display), + size, + redRampData, + greenRampData, + blueRampData); + unlockToolkit(); + if (!res) + return null; + return rampData; + } + + protected void resetGammaRamp(Buffer originalGammaRamp) { + if (originalGammaRamp == null) + return; // getGammaRamp failed originally + ShortBuffer rampData = (ShortBuffer) originalGammaRamp; + int capacity = rampData.capacity(); + if ((capacity % 3) != 0) { + throw new IllegalArgumentException("Must not be the original gamma ramp"); + } + int size = capacity / 3; + rampData.position(0); + rampData.limit(size); + ShortBuffer redRampData = rampData.slice(); + rampData.position(size); + rampData.limit(2 * size); + ShortBuffer greenRampData = rampData.slice(); + rampData.position(2 * size); + rampData.limit(3 * size); + ShortBuffer blueRampData = rampData.slice(); + lockToolkit(); + long display = getDisplayConnection(); + GLX.XF86VidModeSetGammaRamp(display, + GLX.DefaultScreen(display), + size, + redRampData, + greenRampData, + blueRampData); + unlockToolkit(); + } } |