Alex Holkner wrote:
> The buffer needs to be 3 arrays of 256 words (you have only allocated
> the same number of bytes). So:
>
> buf = ((c_uint16) * 256) * 3)()
>
> where buf[0] is the red ramp, buf[1] is the green ramp, etc.
>
> [GS]etDeviceGammaRamp needs a graphics device context, not an OpenGL
> context. So:
>
> ret = windll.gdi32.GetDeviceGammaRamp(win._dc, buf)
> ret = windll.gdi32.SetDeviceGammaRamp(win._dc, buf)
>
> (the byref is unnecessary; arrays are always passed as pointers in C).
>
> Alex.
Ah, thanks. I just figured both of those out the hard way. (I thought
words were 8bit for some reason). It works great now. Here's the demo.
I'm using numpy to create the gamma ramps.
Not sure if/how you want to incorporate this into pyglet. This is only
the win32 call, linux and osx would have to be figured out too. Maybe a
pyglet.window.Window.set_gamma(r, g, b) method, where you provide the 3
gamma values and it generates and sets the ramps for you? Or maybe make
it a Screen method since setting gamma affects the whole screen?
Martin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---
"""Demo of how to set screen gamma in win32 using ctypes
for a pyglet device context"""
from __future__ import division
import pyglet.window
import numpy as np
from ctypes import windll
import time
gamma = 2.2
def invramp(gamma):
"""Inverted gamma ramp"""
ramp = np.arange(256, dtype=np.uint16) / 255 # normalized linear ramp
ramp = np.power(ramp, 1 / gamma) * 255 # unnormalized inverted gamma ramp
return np.uint16(np.round(ramp)) # convert back to nearest ints
win = pyglet.window.Window()
origramps = np.empty((3, 256), dtype=np.uint16) # init R, G, and B ramps
# try and get gamma ramp
success = windll.gdi32.GetDeviceGammaRamp(win._dc, origramps.ctypes)
if not success: raise AssertionError, 'GetDeviceGammaRamp failed'
ramp = invramp(gamma=gamma)
ramps = np.asarray([ramp]*3) # identically inverted R, G, and B ramps
ramps.byteswap(True) # seems CPU and GPU have different endianness?
# try and set gamma ramp
success = windll.gdi32.SetDeviceGammaRamp(win._dc, ramps.ctypes)
if not success: raise AssertionError, 'SetDeviceGammaRamp failed'
time.sleep(3) # marvel at gamma corrected screen
# reset to original gamma
success = windll.gdi32.SetDeviceGammaRamp(win._dc, origramps.ctypes)
if not success: raise AssertionError, 'SetDeviceGammaRamp failed'