Click here to Skip to main content
Licence CPOL
First Posted 24 Oct 2002
Views 112,755
Bookmarked 27 times

Gamma correction slider

By | 3 Nov 2002 | Article
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)

About the Author

DCUtility

Other
DCUtility
Canada Canada

Member

Home Page

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralC#.Net version for setting brightnessness/contrast for your screen PinmemberGamePlanner13:28 9 May '09  
Question!!Important!!I found a problem for Gamma correction slider!! Pinmemberstrongpan18:57 19 Jan '09  
General.Net version Pinmembernasserdw23:49 2 Oct '07  
GeneralRe: .Net version Pinmemberfos3_cpp4:32 8 Jan '09  
GeneralSetDeviceGammaRamp Operation Pinmembernikki69010320:47 10 Dec '06  
QuestionSetDeviceGammaRamp Operation Pinmembernikki69010319:53 10 Dec '06  
QuestionPOW Pinmemberbeckers9564:19 10 Sep '06  
AnswerRe: POW Pinmemberslawekkowalski4:22 25 Aug '07  
GeneralDual Monitors Pinmembersrboisvert2:54 27 Jul '06  
GeneralScreen Darkness Pinmembergeorgeantohe9:38 8 Jun '06  
GeneralRGB correction PinmemberRobsori20:43 3 May '06  
GeneralCorrection for Geforce Card PinmemberDigitalCAS7:04 28 Dec '03  
GeneralRe: Correction for Geforce Card PinmemberSynetech20:01 5 May '06  
Well it's too late for DigitalCAS, but in case anyone else stumbles across here and wonders the same thing, what DigitalCAS was experiencing was the overlay surface. The video player was using the overlay to output the video faster (in hardware). The overlay surface is not affected by monitor color adjustments and that's why the video was unaffected. The S3 worked because it did not support an overlay.
 
It's possible to adjust the video by either disabling the video acceleration in the media player or to run a program that uses the overlay before running the media player which then has to do software rendering of the video.
 
HTH Cool | :cool:
 
--
Synetech

QuestionIs this code free? Can it be used for any purposes? Pinmemberradiaki12:03 25 May '03  
AnswerRe: Is this code free? Can it be used for any purposes? PinmemberDany Cantin14:36 25 May '03  
Generalneed help for similar control in EVC++ for windows CE 3.0 Pinmemberdeepmala21:58 24 Mar '03  
GeneralHoping for help. Pinmemberjinxie0:21 31 Jan '03  
GeneralRe: Hoping for help. PinmemberChristian Graus1:08 31 Jan '03  
GeneralAlso... PinmemberNorm Almond21:14 4 Nov '02  
GeneralBug! PinmemberNorm Almond21:03 4 Nov '02  
GeneralRe: Bug! PinmemberDany Cantin6:21 5 Nov '02  
GeneralRe: Bug! Pinmembersirb2:56 22 Dec '08  
GeneralSaving Settings PinmemberNorm Almond23:13 2 Nov '02  
GeneralRe: Saving Settings PinmemberDany Cantin16:10 3 Nov '02  
GeneralWow, what a GREAT guy! PinmemberDeviantCoding15:34 1 Nov '02  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 4 Nov 2002
Article Copyright 2002 by DCUtility
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid