Jump to content

sRGB Display Gamma Correction


power1power1
 Share

Recommended Posts

Using ('?do=embed' frameborder='0' data-embedContent>>) among many other similar posts, I prepared this piece of code to utilize the approximate sRGB gamma function:

#include <WinAPI.au3>
_SetGamma(1.1, 1.0, 0.9)
Exit

Func _SetGamma($vRed, $vGreen, $vBlue)
   $n_ramp = DllStructCreate("short[" & (256*3) & "]")
   For $i = 0 to 255
      $rVar = 65535 * (($i/255) ^ (1/$vRed  ))
      $gVar = 65535 * (($i/255) ^ (1/$vGreen))
      $bVar = 65535 * (($i/255) ^ (1/$vBlue ))
      DllStructSetData($n_ramp, 1, Int($rVar), $i+1      ) ; red
      DllStructSetData($n_ramp, 1, Int($gVar), $i+1 + 256) ; green
      DllStructSetData($n_ramp, 1, Int($bVar), $i+1 + 512) ; blue
   Next
   $hDC = _WinAPI_GetDC(0)
   DllCall("gdi32.dll", "bool", "SetDeviceGammaRamp", "handle", $hDC, "ptr", DllStructGetPtr($n_ramp))
   _WinAPI_ReleaseDC(0, $hDC)
EndFunc

Now, if I could figure out how to change gamma only for the second monitor ...

Edited by power1power1
Link to comment
Share on other sites

  • 1 month later...

OK, after weeks of searching and testing different pieces of codes, here it is. This can adjust the gamma level of each display separately:

#include <WinAPI.au3>
_SetGamma(1, 1.1, 1.0, 0.9)
Exit

Func _SetGamma($iDisplay, $vRed, $vGreen, $vBlue)
   $n_ramp = DllStructCreate("short[" & (256*3) & "]")
   For $i = 0 to 255
      $rVar = 65535 * (($i/255) ^ (1/$vRed  ))
      $gVar = 65535 * (($i/255) ^ (1/$vGreen))
      $bVar = 65535 * (($i/255) ^ (1/$vBlue ))
      DllStructSetData($n_ramp, 1, Int($rVar), $i+1      ) ; red
      DllStructSetData($n_ramp, 1, Int($gVar), $i+1 + 256) ; green
      DllStructSetData($n_ramp, 1, Int($bVar), $i+1 + 512) ; blue
   Next
   $aDevice = _WinAPI_EnumDisplayDevices("", $iDisplay)
   $hDC = _WinAPI_CreateDC("DISPLAY", $aDevice[1])
   DllCall("gdi32.dll", "bool", "SetDeviceGammaRamp", "handle", $hDC, "ptr", DllStructGetPtr($n_ramp))
   _WinAPI_DeleteDC($hDC)
EndFunc

Func _WinAPI_CreateDC($sDriver, $sDevice)
    Local $aResult = DllCall("gdi32.dll", "hwnd", "CreateDC", "str", $sDriver, "str", $sDevice, "long", 0, "long", 0)
    Return $aResult[0]
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...