AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Solved] Brightness(Gamma) Control

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Wed May 21, 2008 8:27 am    Post subject: [Solved] Brightness(Gamma) Control Reply with quote

I'm trying to success my long hope. Lexikos adviced me on this issue
basically i'm trying to use these two API GetDeviceGammaRamp & SetDeviceGammaRamp
Code:
;from MSDN
;lpRamp : Pointer to a buffer containing the gamma ramp to be set. The gamma ramp is specified in three arrays of 256 WORD elements each, which contain the mapping between RGB values in the frame buffer and digital-analog-converter (DAC) values. The sequence of the arrays is red, green, blue. The RGB values must be stored in the most significant bits of each WORD to increase DAC independence.

BOOL WINAPI GetDeviceGammaRamp(
  HDC hDC,
  LPVOID lpRamp
);

BOOL WINAPI SetDeviceGammaRamp(
  HDC hDC,
  LPVOID lpRamp
);
my poorly try is here
Code:
hDC := DllCall("GetDC", "Int", 0)
VarSetCapacity(Gamma, 1536)
Result := DllCall("GetDeviceGammaRamp", "UInt", hdc, "UInt", &Gamma)
it returns 1 which is boolen True but i don't get the values in Gamma variable
i really don't get the numget/numput things.
but can anyone make me advance on this issue? i'm trying this simple dllcall for over a month Sad
hope i get advance this time.
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com


Last edited by heresy on Tue Jun 10, 2008 1:26 pm; edited 1 time in total
Back to top
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 2392

PostPosted: Wed May 21, 2008 12:30 pm    Post subject: Reply with quote

Code:
hDC := DllCall("GetDC", "UInt", 0)
VarSetCapacity(Gamma, 256 * 3 * 2)
Result := DllCall("GetDeviceGammaRamp", "UInt", hdc, "UInt", &Gamma)
loop 768
   result .= (Mod(A_Index-1, 16) ? "`t" : "`n") NumGet(Gamma, 2*A_Index-1, "UShort")
msgbox % result

Though I'm not sure what you'd do with such a thing...
_________________
My Home Thread
Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Back to top
View user's profile Send private message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Wed May 21, 2008 2:15 pm    Post subject: Reply with quote

thanks for answer [VxE] and hi again.
you're the only answerer for this issue for past one month Sad
as i told you, my goal is controlling brightness
i thought like GetDeviceGammaRamp would store 'current gamma' into variable.
but it seems not. what should i pass to SetDeviceGammaRamp then?
Code:
hDC := DllCall("GetDC", "UInt", 0)
VarSetCapacity(Gamma, 256 * 3 * 2)
Result := DllCall("GetDeviceGammaRamp", "UInt", hdc, "UInt", &Gamma)
loop 768
   result .= (Mod(A_Index-1, 16) ? "`t" : "`n") NumGet(Gamma, 2*A_Index-1, "UShort")
msgbox % result
NewGamma := NumGet(Gamma, 2*768-1, "UShort")
Result := DllCall("SetDeviceGammaRamp", "UInt", hdc, "UInt", &NewGamma)
msgbox % result ;failed
although i don't fully understand Numget/Numput things i was trying to get the value at the end of array and pass to SetDeviceGammaRamp
but failed. i just can't believe that we don't have wrapper for this. Sad
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2222

PostPosted: Wed May 21, 2008 5:22 pm    Post subject: Reply with quote

There are various ways to alter the gamma ramp, but what nirsoft does is this:
Code:
br := 128   ; brightness, in the range of 0 - 255, where 128 is normal
VarSetCapacity(gr, 512*3)
Loop,   256
{
   If  (nValue:=(br+128)*(A_Index-1))>65535
        nValue:=65535
   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", 0)
DllCall("SetDeviceGammaRamp", "Uint", hDC, "Uint", &gr)
DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)
Back to top
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 2392

PostPosted: Wed May 21, 2008 10:37 pm    Post subject: Reply with quote

lulz:
Code:
br := 128   ; brightness, in the range of 0 - 255, where 128 is normal
#WheelUp::
#WheelDown::
br += (InStr(A_ThisHotkey, "down") ? -8 : 8 )
If ( br > 256 )
   br := 256
If ( br < 0 )
   br := 0
VarSetCapacity(gr, 512*3)
Loop,   256
{
   If  (nValue:=(br+128)*(A_Index-1))>65535
        nValue:=65535
   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", 0)
DllCall("SetDeviceGammaRamp", "Uint", hDC, "Uint", &gr)
DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)
return

so that's how it works Razz
_________________
My Home Thread
Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2222

PostPosted: Thu May 22, 2008 2:01 am    Post subject: Reply with quote

BTW, I was not aware of (G)SetDeviceGammaRamp API before. I only knew IDirectDrawGammaControl object which I suspect the above APIs are wrapping.
Back to top
View user's profile Send private message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Thu May 22, 2008 7:04 am    Post subject: Reply with quote

Thanks for the answer Sean and welcome back.

that's exactly what i was trying for past few weeks. it works perfectly!
now we have wrapper for Gamma Ramp. Smile
this thread will be referenced many times from now as an answer thread for all the brightness control questions
i just couldn't believe that nobody was interesting on brightness control since autohotkey's born
once again, thanks for your help almighty Sean and thanks to [VxE] too.
--------
for studying purpose.
i coudln't get the Loop part. i just don't get that where the 65535 came from.
i mean why is it 256*256-1? if anyone can enlighten me on this. please
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
Guest






PostPosted: Thu May 22, 2008 2:30 pm    Post subject: Reply with quote

heresy wrote:
i just don't get that where the 65535 came from. i mean why is it 256*256-1?

65535, 0xFFFF in hex, is the highest possible unsigned short integer. If omitting the step, the actually assigned values for integers greater than 65535 will be totally different (lower) ones as the hi-word part will be truncated when casted into ushort. E.g., 65536 will be 0, 65537 will be 1 etc. I think this will result in failure.
Back to top
Sean



Joined: 12 Feb 2007
Posts: 2222

PostPosted: Thu May 22, 2008 2:31 pm    Post subject: Reply with quote

The above post was by me.
Back to top
View user's profile Send private message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Thu May 22, 2008 4:29 pm    Post subject: Reply with quote

Thanks for your help Sean
i didn't aware of that because i haven't experienced static typing languages before
much appreciated and it was good to see you coming back
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2222

PostPosted: Fri May 23, 2008 12:40 am    Post subject: Reply with quote

heresy wrote:
Thanks for your help Sean
i didn't aware of that because i haven't experienced static typing languages before
much appreciated and it was good to see you coming back

I can't stay in front of computer for long now, so I'm dubious that I'll be able to visit the forum frequently. Anyway thanks for the warm welcome.
Back to top
View user's profile Send private message
pojitonov
Guest





PostPosted: Sat Nov 14, 2009 11:52 pm    Post subject: Reply with quote

I added a progress bar to change the brightness, but I have it slightly wrong shows progress, who can help

Code:
#NoTrayIcon    ; не отображать иконку скрипта в трее
#MaxHotkeysPerInterval 200
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
SetBatchLines -1

br := 128   ; brightness, in the range of 0 - 255, where 128 is normal

#F2::
#F1::
Brght_Step = 8

; -------------------
; START CONFIGURATION
; -------------------
; The percentage by which to raise or lower the volume each time
; How long to display the volume level bar graphs (in milliseconds)
vol_DisplayTime = 1500
; Transparency of window (0-255)
vol_TransValue = 200
; Bar's background colour
vol_CW = EEEEEE   
vol_Width = 200  ; width of bar
vol_Thick = 20   ; thickness of bar
; Bar's screen position
vol_PosX := A_ScreenWidth/2 - vol_Width/2
vol_PosY := A_ScreenHeight/1.8 - vol_Thick/2
; --------------------
; END OF CONFIGURATION
; --------------------
vol_BarOptionsMaster = 1:B1 ZH%vol_Thick% ZX8 ZY4 W%vol_Width% X%vol_PosX% Y%vol_PosY% CW%vol_CW%


br += (InStr(A_ThisHotkey, "F1") ? -Brght_Step : Brght_Step )
If ( br > 256 )
   br := 256
If ( br < 0)
   br := 0
VarSetCapacity(gr, 512*3)
Loop,   256
{
   If  (nValue:=(br+128)*(A_Index-1))>65535
        nValue:=65535
   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", 0)
DllCall("SetDeviceGammaRamp", "Uint", hDC, "Uint", &gr)
DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)


vol_ShowBars:
; Get volumes in case the user or an external program changed them:
vol_Master := br
if vol_Master <> 128
{
  vol_Colour = Blue   
  vol_Text = Brightness
}
else
{
;  vol_Colour = Red
  vol_Text = Brightness (normal)

}


; To prevent the "flashing" effect, only create the bar window if it doesn't already exist:
IfWinNotExist, BrightnessOSDxyz
{
    Progress, %vol_BarOptionsMaster% CB%vol_Colour% CT%vol_Colour%, , %vol_Text%, BrightnessOSDxyz
    WinSet, Transparent, %vol_TransValue%, BrightnessOSDxyz
}


Progress, 1:%vol_Master% , , %vol_Text%
SetTimer, vol_BarOff, %vol_DisplayTime%
return


vol_BarOff:
SetTimer, vol_BarOff, off
Progress, 1:Off
return
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group