I modified this to work without importing maxgui (Windows only):
Strict
Module Leadwerks.Gamma
ModuleInfo "Version: 1.0.3"
ModuleInfo "Author: Joshua Klint"
ModuleInfo "Copyright: Leadwerks Corporation"
ModuleInfo "www.leadwerks.com"
Import pub.win32
Import brl.bank
OnEnd RestoreGamma
Extern "Win32"
Function SetDeviceGammaRamp:Int(hdc,lpRamp:Byte Ptr)="SetDeviceGammaRamp@8"
Function GetDeviceGammaRamp:Int(hdc,lpRamp:Byte Ptr)="GetDeviceGammaRamp@8"
Function GetDesktopWindow:Int()
EndExtern
Private
Global LWGAMMALEVEL#=1.0
Global GAMMARAMP:TBank
Public
Function SetGamma(scale#)
LWGAMMALEVEL=scale
Local hwnd,hdc
Local ramp:TBank
Local n,r
hwnd=GetDesktopWindow()
hdc=getdc(hwnd)
If Not GAMMARAMP
GAMMARAMP=CreateBank(256*3*2)
GetDeviceGammaRamp hdc,BankBuf(GAMMARAMP)
EndIf
ramp:TBank=CreateBank(GAMMARAMP.size())
CopyBank GAMMARAMP,0,ramp,0,GAMMARAMP.size()
For n=0 To ramp.size()/2-1
r=PeekByte(ramp,n*2+1)*scale
If r>255 r=255
PokeByte ramp,n*2+1,r
Next
SetDeviceGammaRamp hdc,BankBuf(ramp)
ramp=Null
EndFunction
Function RestoreGamma()
Local hwnd,hdc
If GAMMARAMP
hwnd=GetDesktopWindow()
hdc=getdc(hwnd)
SetDeviceGammaRamp hdc,BankBuf(GAMMARAMP)
LWGAMMALEVEL=1.0
EndIf
EndFunction
|