leadwerks.gamma

BlitzMax Forums/BlitzMax Module Tweaks/leadwerks.gamma

JoshK(Posted 2007) [#1]
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



xlsior(Posted 2007) [#2]
Ooooh. will play around with that one when I get home. Gamma was one of the things I definitely missed after switching to BlitzMax.

(I tend to run my screen pretty dark so I don't feel like my eyeballs are burning out of my head... And sometimes things that look great on my PC are.. um... not so great on others.)