Click here to Skip to main content
11,488,877 members (78,775 online)
Click here to Skip to main content

Gamma correction slider

, 3 Nov 2002 CPOL 130.7K 5.5K 29
Rate this:
Please Sign up or sign in to vote.
Slider control class to perform gamma correction.

Sample Image - Gamma_Manager.gif

Introduction

Gamma Manager is based on Gamma Slider control. This control allows to change gamma monitor on most graphic cards. The goal for this project is very simple and control is for VC6 & VC7.

The other day I downloaded a N64 emulator but the screen was so black that I did not see anything. I had thus to find this solution to lighten my screen. I know that the tools of my video chart make it possible to change gamma of my screen, but it is faster with this tool.

Implementation

The implementation of this slider control is very easy.

  1. Import GammaSlider.h and GammaSlider.cpp into your project.
  2. Include reference to the class control.
  3. Add slider control on a form.
  4. Use ClassWizard to declare variable name derived from CGammaSlider control.
  5. That's it, enjoy!

Under the hood

Windows provides two APIs GetDeviceGammaRamp/ SetDeviceGammaRamp to perform gamma correction. In fact we need to have a 3 dimensional buffer of 256 WORD to manipulate gamma correction. To change gamma, it is necessary to change the RGB value of each color contained in the buffer by a float factor between 0.0 and 2.0.

Example

  • We need to save current gamma for future restore.
    WORD m_RampSaved[256*3]; 
    if (!GetDeviceGammaRamp(::GetDC(NULL), m_RampSaved))
    {
        TRACE("WARNING: Cannot initialize DeviceGammaRamp.\n");
    }
  • To change gamma, cycle into ramp buffer and change RGB color where Gamma is the float factor.
    WORD ramp[256*3];
    for( int i=0; i<256; i++ ) {
        ramp[i+0] = ramp[i+256] = ramp[i+512] = 
        (WORD)min(65535, max(0, pow((i+1) / 256.0, Gamma) * 65535 + 0.5));
    }
    SetDeviceGammaRamp(::GetDC(NULL), ramp);
  • Now to trap slider control message, we need to use a special message ON_WM_HSCROLL_REFLECT() that can provide message to be dispatched into control class itself.

History

  • v1.1 - Added functions LoadSettings and SaveSettings
  • v1.0 - Initial release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

DCUtility
DCUtility
Canada Canada

Comments and Discussions

 
GeneralC#.Net version for setting brightnessness/contrast for your screen Pin
GamePlanner9-May-09 14:28
memberGamePlanner9-May-09 14:28 
Question!!Important!!I found a problem for Gamma correction slider!! Pin
strongpan19-Jan-09 19:57
memberstrongpan19-Jan-09 19:57 
General.Net version Pin
nasserdw3-Oct-07 0:49
membernasserdw3-Oct-07 0:49 
GeneralRe: .Net version Pin
fos3_cpp8-Jan-09 5:32
memberfos3_cpp8-Jan-09 5:32 
GeneralSetDeviceGammaRamp Operation Pin
nikki69010310-Dec-06 21:47
membernikki69010310-Dec-06 21:47 
QuestionSetDeviceGammaRamp Operation Pin
nikki69010310-Dec-06 20:53
membernikki69010310-Dec-06 20:53 
QuestionPOW Pin
beckers95610-Sep-06 5:19
memberbeckers95610-Sep-06 5:19 
AnswerRe: POW Pin
slawekkowalski25-Aug-07 5:22
memberslawekkowalski25-Aug-07 5:22 
GeneralDual Monitors Pin
srboisvert27-Jul-06 3:54
membersrboisvert27-Jul-06 3:54 
GeneralScreen Darkness Pin
georgeantohe8-Jun-06 10:38
membergeorgeantohe8-Jun-06 10:38 
GeneralRGB correction Pin
Robsori3-May-06 21:43
memberRobsori3-May-06 21:43 
GeneralCorrection for Geforce Card Pin
DigitalCAS28-Dec-03 8:04
memberDigitalCAS28-Dec-03 8:04 
GeneralRe: Correction for Geforce Card Pin
Synetech5-May-06 21:01
memberSynetech5-May-06 21:01 
QuestionIs this code free? Can it be used for any purposes? Pin
radiaki25-May-03 13:03
memberradiaki25-May-03 13:03 
AnswerRe: Is this code free? Can it be used for any purposes? Pin
Dany Cantin25-May-03 15:36
memberDany Cantin25-May-03 15:36 
Generalneed help for similar control in EVC++ for windows CE 3.0 Pin
deepmala24-Mar-03 22:58
memberdeepmala24-Mar-03 22:58 
GeneralHoping for help. Pin
jinxie31-Jan-03 1:21
memberjinxie31-Jan-03 1:21 
GeneralRe: Hoping for help. Pin
Christian Graus31-Jan-03 2:08
memberChristian Graus31-Jan-03 2:08 
GeneralAlso... Pin
Norm Almond4-Nov-02 22:14
memberNorm Almond4-Nov-02 22:14 
GeneralBug! Pin
Norm Almond4-Nov-02 22:03
memberNorm Almond4-Nov-02 22:03 
GeneralRe: Bug! Pin
Dany Cantin5-Nov-02 7:21
memberDany Cantin5-Nov-02 7:21 
GeneralRe: Bug! Pin
sirb22-Dec-08 3:56
membersirb22-Dec-08 3:56 
GeneralSaving Settings Pin
Norm Almond3-Nov-02 0:13
memberNorm Almond3-Nov-02 0:13 
GeneralRe: Saving Settings Pin
Dany Cantin3-Nov-02 17:10
memberDany Cantin3-Nov-02 17:10 
GeneralWow, what a GREAT guy! Pin
DeviantCoding1-Nov-02 16:34
memberDeviantCoding1-Nov-02 16:34 
GeneralRe: Wow, what a GREAT guy! Pin
Dany Cantin2-Nov-02 3:03
memberDany Cantin2-Nov-02 3:03 
GeneralRe: Wow, what a GREAT guy! Pin
C Parker M cCauley22-Mar-04 17:05
memberC Parker M cCauley22-Mar-04 17:05 
GeneralNice Pin
Norm Almond31-Oct-02 2:01
memberNorm Almond31-Oct-02 2:01 
GeneralRe: Nice Pin
Nick Parker1-Nov-02 20:10
editorNick Parker1-Nov-02 20:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 4 Nov 2002
Article Copyright 2002 by DCUtility
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid