Click here to Skip to main content
15,867,330 members
Articles / Desktop Programming / MFC
Article

Gamma correction slider

Rate me:
Please Sign up or sign in to vote.
4.71/5 (12 votes)
3 Nov 2002CPOL1 min read 175.1K   7.3K   34   29
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)


Written By
CEO
Canada Canada

Comments and Discussions

 
GeneralRe: Bug! Pin
DCUtility5-Nov-02 6:21
professionalDCUtility5-Nov-02 6:21 
GeneralRe: Bug! Pin
sirb22-Dec-08 2:56
sirb22-Dec-08 2:56 
GeneralSaving Settings Pin
NormDroid2-Nov-02 23:13
professionalNormDroid2-Nov-02 23:13 
GeneralRe: Saving Settings Pin
DCUtility3-Nov-02 16:10
professionalDCUtility3-Nov-02 16:10 
GeneralWow, what a GREAT guy! Pin
DeviantCoding1-Nov-02 15:34
DeviantCoding1-Nov-02 15:34 
GeneralRe: Wow, what a GREAT guy! Pin
DCUtility2-Nov-02 2:03
professionalDCUtility2-Nov-02 2:03 
GeneralRe: Wow, what a GREAT guy! Pin
Parker M cCauley22-Mar-04 16:05
Parker M cCauley22-Mar-04 16:05 
GeneralNice Pin
NormDroid31-Oct-02 1:01
professionalNormDroid31-Oct-02 1:01 
GeneralRe: Nice Pin
Nick Parker1-Nov-02 19:10
protectorNick Parker1-Nov-02 19:10 

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

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