[Class] Monitor (Brightness, Contrast, Gamma Ramp)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
jNizM
Posts: 3201
Joined: 30 Sep 2013, 01:33
Contact:

Re: Class Monitor (Brightness, Contrast & Gamma)

03 Sep 2015, 01:09

I downloaded the source from the Backlight page and it looks like he works with SetMonitorBrightness / GetMonitorBrightness too.
So normaly it should work for you.

Tested with:
- Windows 7 Enterprise - x64
- Windows 7 Ultimate - x64
- Windows 8.1 Enterprise N - x64
- 22" Widescreen Display by Asus
- 24" Widescreen Display

Did you include the lib in your script?
Minimum supported client: Windows Vista
Minimum supported server: Windows Server 2008
[AHK] v2.0.18 | [WIN] 11 Pro (23H2) | [GitHub] Profile
Bleep

Re: Class Monitor (Brightness, Contrast & Gamma)

03 Sep 2015, 07:10

jNizM wrote:I downloaded the source from the Backlight page and it looks like he works with SetMonitorBrightness / GetMonitorBrightness too.
So normaly it should work for you.
Hmm, that's odd. I'm using Win 8.1 Pro and a Dell 2711 which seems to support backlight control via software seeing as the Rainmeter widget worked, but if yours uses the same functions I'm not sure what could be causing the problem.

For reference when I launch your regular Class Monitor GUI script it only detects the Gamma setting, the Brightness and Contrast inputs are blank. When I enter a value and click 'Set' the monitor flashes briefly but no change in brightness.
jNizM wrote:Did you include the lib in your script?
The Class_Monitor.ahk? If so yes, had it in the same directory. Unless you mean something else.
Peixoto
Posts: 24
Joined: 18 Aug 2015, 11:20

Re: Class Monitor (Brightness, Contrast & Gamma)

13 Sep 2015, 17:39

Great work, here goes my two cents

Your small GUI program calls Monitor.SetDeviceGammaRamp() to change the gamma, but that method does not change the gamma, but the brightness. To change the gamma you have to set the gamma ramp using a "gamma function" instead of a linear function and then change the value of gamma. Here a small piece of code i wrote that changes gamma and brightness: try it out with gamma going from 0.1 to 2.2 (it's actually the inverse of gamma), you will see how it's different from brightness

Code: Select all

SetDeviceGammaRamp(brightness, gamma=1.0)
{
	(brightness > 256) ? brightness := 256
	(brightness < 0) ? brightness := 0
	VarSetCapacity(gr, 512*3)
	x := 1/gamma
	Loop, 256
	{
		(nValue:=(brightness+128)*(A_Index-1))>65535 ? nValue:=65535
		nValue := (nValue**x/65535**x)*65535 ; here's where we change the gamma
		NumPut(nValue, gr,      2*(A_Index-1), "Ushort")
		NumPut(nValue, gr,  512+2*(A_Index-1), "Ushort")
		NumPut(nValue, gr, 1024+2*(A_Index-1), "Ushort")
	}
	hDC := DllCall("GetDC", "Uint", hwin)
	DllCall("SetDeviceGammaRamp", "Uint", hDC, "Uint", &gr) 
	DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)
}
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: Class Monitor (Brightness, Contrast & Gamma)

14 Sep 2015, 06:29

Hi, Now it may be similar to f. lux as change the color temperature of it?
User avatar
jNizM
Posts: 3201
Joined: 30 Sep 2013, 01:33
Contact:

Re: Class Monitor (Brightness, Contrast & Gamma)

14 Sep 2015, 07:50

I work on it atm..
- MonitorBrightness
- MonitorContrast
- MonitorColorTemperature
- MonitorRedGreenOrBlueDrive
- MonitorRedGreenOrBlueGain
[AHK] v2.0.18 | [WIN] 11 Pro (23H2) | [GitHub] Profile
User avatar
bichlepa
Posts: 183
Joined: 15 Aug 2014, 06:44
Location: Germany
Contact:

Re: Class Monitor (Brightness, Contrast & Gamma)

14 Sep 2015, 10:57

Thank you for those functions!
I have included them to AutoHotFlow. There are now two new actions: Set monitor settings and Get monitor settings. With this you can change the brightness, contrast, gamma, color gain and color temperature.

I've extended the class a little bit. There are two new functions for getting and setting the color gain for each color. You can download it here.

Why did you comment out the functions for setting and getting the color temperature? It works on one of my monitors, although not for every temperature.
Scripting is too complicated? Try AutoHotFlow, the graphical automation tool! Written in AutoHotkey.
User avatar
jNizM
Posts: 3201
Joined: 30 Sep 2013, 01:33
Contact:

Re: Class Monitor (Brightness, Contrast & Gamma)

15 Sep 2015, 06:25

Hi bichlepa,

I need to fix a mistake in my class. The new version will be available in 1 or 2 days (incl. new GUI).

Latest Beta:
- Class_Monitor.ahk (Beta)
- Class_Monitor_GUI_Classic.ahk (Beta)
Image
[AHK] v2.0.18 | [WIN] 11 Pro (23H2) | [GitHub] Profile
Bleep

Re: Class Monitor (Brightness, Contrast & Gamma)

16 Sep 2015, 06:59

Peixoto wrote:Great work, here goes my two cents

Your small GUI program calls Monitor.SetDeviceGammaRamp() to change the gamma, but that method does not change the gamma, but the brightness.
I wonder if this is the reason changing the brightness wasn't working for me.
jNizM wrote:Hi bichlepa,

I need to fix a mistake in my class. The new version will be available in 1 or 2 days (incl. new GUI).

Latest Beta:
- Class_Monitor.ahk (Beta)
- Class_Monitor_GUI_Classic.ahk (Beta)
Getting this error when launching Class_Monitor_GUI_Classic.ahk (and also the script you provided to me earlier): http://i.imgur.com/hJftEhj.png
User avatar
jNizM
Posts: 3201
Joined: 30 Sep 2013, 01:33
Contact:

Re: Class Monitor (Brightness, Contrast & Gamma)

16 Sep 2015, 07:12

@Bleep
Install the latest AutoHotkey Version

Ref:
- ObjRawSet
- Changelog (1.1.21.00 - March 28, 2015)
- Changelog (1.1.22.04 - August 19, 2015)
[AHK] v2.0.18 | [WIN] 11 Pro (23H2) | [GitHub] Profile
User avatar
jNizM
Posts: 3201
Joined: 30 Sep 2013, 01:33
Contact:

Re: Class Monitor (Brightness, Contrast & Gamma)

16 Sep 2015, 07:13

Image

Code: Select all

; GLOBAL SETTINGS ===============================================================================================================

#Warn
#NoEnv
#SingleInstance Force
SetBatchLines -1

global Reset     := 128
global LoadRed   := Brightness.Get().Red
global LoadGreen := Brightness.Get().Green
global LoadBlue  := Brightness.Get().Blue
global LoadAll   := ((LoadRed = LoadGreen) && (LoadRed = LoadBlue) && (LoadGreen = LoadBlue)) ? LoadRed : " - "

; GUI ===========================================================================================================================

Gui, Margin, 5, 5
Gui, Font, s16 w800 q4 c76B900, MS Shell Dlg 2
Gui, Add, Text, xm ym w240 0x0201, % "Display Brightness"


Gui, Font, s9 w400 q1 c000000, MS Shell Dlg 2
Gui, Add, GroupBox, xm y+15 w240 h110, % "Change Brightness (RGB)"

Gui, Font, s9 w400 q1 c000000, MS Shell Dlg 2
Gui, Add, Text, xp+10 yp+25 w70 h22 0x0200, % "Red"
Gui, Add, Edit, x+1 yp w80 h22 0x2002 Limit3 hwndhEdit1 vBRed
Gui, Add, UpDown, Range0-255, % LoadRed
Gui, Font, s9 w400 q1 csilver, MS Shell Dlg 2
Gui, Add, Text, x+5 yp w65 h22 0x0200, % "(0 - 255)"

Gui, Font, s9 w400 q1 c000000, MS Shell Dlg 2
Gui, Add, Text, xs+10 y+4 w70 h22 0x0200, % "Green"
Gui, Add, Edit, x+1 yp w80 h22 0x2002 Limit3 hwndhEdit2 vBGreen
Gui, Add, UpDown, Range0-255, % LoadGreen
Gui, Font, s9 w400 q1 csilver, MS Shell Dlg 2
Gui, Add, Text, x+5 yp w65 h22 0x0200, % "(0 - 255)"

Gui, Font, s9 w400 q1 c000000, MS Shell Dlg 2
Gui, Add, Text, xs+10 y+4 w70 h22 0x0200, % "Blue"
Gui, Add, Edit, x+1 yp w80 h22 0x2002 Limit3 hwndhEdit3 vBBlue
Gui, Add, UpDown, Range0-255, % LoadBlue
Gui, Font, s9 w400 q1 csilver, MS Shell Dlg 2
Gui, Add, Text, x+5 yp w65 h22 0x0200, % "(0 - 255)"


Gui, Font, s9 w400 q1 c000000, MS Shell Dlg 2
Gui, Add, GroupBox, xm y+15 w240 h60, % "Change Brightness (ALL)"

Gui, Font, s9 w400 q1 c000000, MS Shell Dlg 2
Gui, Add, Text, xp+10 yp+25 w70 h22 0x0200, % "All"
Gui, Add, Edit, x+1 yp w80 h22 0x2002 Limit3 hwndhEdit4 vBAll
Gui, Add, UpDown, Range0-255, % LoadAll
Gui, Font, s9 w400 q1 csilver, MS Shell Dlg 2
Gui, Add, Text, x+5 yp w65 h22 0x0200, % "(0 - 255)"


Gui, Add, Button, xm+20 y+20 w70 gSetRGBSettings, % "Set RGB"
Gui, Add, Button, x+5 yp w70 gSetALLSettings, % "Set ALL"
Gui, Add, Button, x+5 yp w70 gResetSettings, % "Reset"

Gui, Show, AutoSize
return

; SCRIPT ========================================================================================================================

SetRGBSettings:
    Gui, Submit, NoHide
    Brightness.Set(BRed, BGreen, BBlue)
    GuiControl,, BAll,   % (BRed = BGreen) && (BRed = BBlue) && (BGreen = BBlue) ? BRed : " - "
return

SetALLSettings:
    Gui, Submit, NoHide
    if BAll is digit
    {
        Brightness.Set(BAll, BAll, BAll)
        GuiControl,, BRed,   % BAll
        GuiControl,, BGreen, % BAll
        GuiControl,, BBlue,  % BAll
    }
    else
        MsgBox % BAll " is no digit"
return

ResetSettings:
    Brightness.Set(Reset, Reset, Reset)
    GuiControl,, BRed,   % Reset
    GuiControl,, BGreen, % Reset
    GuiControl,, BBlue,  % Reset
    GuiControl,, BAll,   % Reset
return

; EXIT ==========================================================================================================================

GuiClose:
GuiEscape:
ExitApp

; FUNCTIONS =====================================================================================================================

Class Brightness
{
    Get()                                                                         ; http://msdn.com/library/dd316946(vs.85,en-us)
    {
        VarSetCapacity(buf, 1536, 0)
        DllCall("gdi32.dll\GetDeviceGammaRamp", "Ptr", hDC := DllCall("user32.dll\GetDC", "Ptr", 0, "Ptr"), "Ptr", &buf)
        CLR := {}
        CLR.Red   := NumGet(buf,        2, "UShort") - 128
        CLR.Green := NumGet(buf,  512 + 2, "UShort") - 128
        CLR.Blue  := NumGet(buf, 1024 + 2, "UShort") - 128
        return CLR, DllCall("user32.dll\ReleaseDC", "Ptr", 0, "Ptr", hDC)
    }

    Set(ByRef red := 128, ByRef green := 128, ByRef blue := 128)                  ; http://msdn.com/library/dd372194(vs.85,en-us)
    {
        loop % VarSetCapacity(buf, 1536, 0) / 6
        {
            NumPut((r := (red   + 128) * (A_Index - 1)) > 65535 ? 65535 : r, buf,        2 * (A_Index - 1), "UShort")
            NumPut((g := (green + 128) * (A_Index - 1)) > 65535 ? 65535 : g, buf,  512 + 2 * (A_Index - 1), "UShort")
            NumPut((b := (blue  + 128) * (A_Index - 1)) > 65535 ? 65535 : b, buf, 1024 + 2 * (A_Index - 1), "UShort")
        }
        ret := DllCall("gdi32.dll\SetDeviceGammaRamp", "Ptr", hDC := DllCall("user32.dll\GetDC", "Ptr", 0, "Ptr"), "Ptr", &buf)
        return ret, DllCall("user32.dll\ReleaseDC", "Ptr", 0, "Ptr", hDC)
    }
}

; ===============================================================================================================================
[AHK] v2.0.18 | [WIN] 11 Pro (23H2) | [GitHub] Profile
Bleep

Re: Class Monitor (Brightness, Contrast & Gamma)

18 Sep 2015, 00:11

jNizM wrote:@Bleep
Install the latest AutoHotkey Version
Thanks, this did the trick. Your GUI script now works for detecting and setting brightness and contrast :D

Tried the script you made for me on the last page and it actually adjusted the brightness this time, but only for one brightness step and after that the hotkeys failed to change the brightness :/ For what it's worth I changed the default hotkeys in the script to +^!- (Ctrl+Shift+Alt+-) for increasing brightness and +^!= (Ctrl+Shift+Alt+=) for decreasing the brightness as my keyboard lacks numpad keys.
kilimra
Posts: 7
Joined: 30 Dec 2015, 16:47

Re: Class Monitor (Brightness, Contrast & Gamma)

23 Jan 2016, 03:19

Hi jNizM,
You can post a simple example to modify the color temperature?
I try to use SetMonitorColorTemperature() AND GetMonitorColorTemperature(), But to no avail.
I hope it can replace flux. ;)
thanks.
User avatar
jNizM
Posts: 3201
Joined: 30 Sep 2013, 01:33
Contact:

Re: Class Monitor (Brightness, Contrast & Gamma)

26 Apr 2017, 02:36

Update:
Rewritten
[AHK] v2.0.18 | [WIN] 11 Pro (23H2) | [GitHub] Profile
ZergShadow
Posts: 19
Joined: 02 Aug 2017, 23:22

Re: Class Monitor (Brightness, ColorTemperature)

03 Aug 2017, 10:49

How to make two settings to work with different hot keys?
User avatar
jNizM
Posts: 3201
Joined: 30 Sep 2013, 01:33
Contact:

Re: Class Monitor (Brightness, ColorTemperature)

04 Aug 2017, 03:26

Update:
- Bug fixes (thx to jee)
- Added Hotkey example
[AHK] v2.0.18 | [WIN] 11 Pro (23H2) | [GitHub] Profile
ZergShadow
Posts: 19
Joined: 02 Aug 2017, 23:22

Re: Class Monitor (Brightness, ColorTemperature)

04 Aug 2017, 04:15

jNizM wrote:Update:
- Bug fixes (thx to jee)
- Added Hotkey example
can i make hotkey f1 f2 or just f1 two different options? and its nice to make contrast and brightness separate like in nvidia control panel.
User avatar
jNizM
Posts: 3201
Joined: 30 Sep 2013, 01:33
Contact:

Re: Class Monitor (Brightness, ColorTemperature)

04 Aug 2017, 04:21

Example for F1 and F2

Code: Select all

; GLOBAL SETTINGS ===============================================================================================================

#NoEnv
#SingleInstance Force
#Persistent

SetBatchLines -1

; SCRIPT ========================================================================================================================

F1::Monitor.SetBrightness(100, 100, 90)    ; Red - Green - Blue
F2::Monitor.SetBrightness(90,  90,  80)    ; Red - Green - Blue

; INCLUDES ======================================================================================================================

#Include Class_Monitor.ahk

; ===============================================================================================================================
[AHK] v2.0.18 | [WIN] 11 Pro (23H2) | [GitHub] Profile
ZergShadow
Posts: 19
Joined: 02 Aug 2017, 23:22

Re: Class Monitor (Brightness, ColorTemperature)

04 Aug 2017, 11:34

jNizM wrote:Example for F1 and F2

Code: Select all

; GLOBAL SETTINGS ===============================================================================================================

#NoEnv
#SingleInstance Force
#Persistent

SetBatchLines -1

; SCRIPT ========================================================================================================================

F1::Monitor.SetBrightness(100, 100, 90)    ; Red - Green - Blue
F2::Monitor.SetBrightness(90,  90,  80)    ; Red - Green - Blue

; INCLUDES ======================================================================================================================

#Include Class_Monitor.ahk

; ===============================================================================================================================
Is it hard to make contrast aand brightness separated??
User avatar
Chunjee
Posts: 1601
Joined: 18 Apr 2014, 19:05
Contact:

Re: Class Monitor (Brightness, ColorTemperature)

27 Sep 2017, 05:41

I used this in a project recently. If it made any money I'd send you a big cut, the class works perfectly.

Image
User avatar
jNizM
Posts: 3201
Joined: 30 Sep 2013, 01:33
Contact:

Re: Class Monitor (Brightness, ColorTemperature)

28 Sep 2017, 01:59

Glad it works for you. Report any bugs or requests you got.
[AHK] v2.0.18 | [WIN] 11 Pro (23H2) | [GitHub] Profile

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: wilkster and 46 guests