Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Changing Display gamma [SOLVED]

Changing Display gamma [SOLVED]

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
10 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Valentinor
    wrote on last edited by
    #1

    Hi, What should I use to change the display's gamma? I tried looking on google, but I don't see anywhere how to do it. Can you give me a link, or an example of changing the value? I need it to be able to change it when I want and faster, I could go each time in "Display Color Calibration" and change it from there, but that takes time, and I can't add a key shortcut to certain values. Just as a note, I want to change gamma, not brightness.

    J 1 Reply Last reply
    0
    • V Valentinor

      Hi, What should I use to change the display's gamma? I tried looking on google, but I don't see anywhere how to do it. Can you give me a link, or an example of changing the value? I need it to be able to change it when I want and faster, I could go each time in "Display Color Calibration" and change it from there, but that takes time, and I can't add a key shortcut to certain values. Just as a note, I want to change gamma, not brightness.

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      See Using gamma correction | Microsoft Docs[^] and follow the links to the relevant functions like the SetDeviceGammaRamp function | Microsoft Docs[^].

      V 1 Reply Last reply
      0
      • J Jochen Arndt

        See Using gamma correction | Microsoft Docs[^] and follow the links to the relevant functions like the SetDeviceGammaRamp function | Microsoft Docs[^].

        V Offline
        V Offline
        Valentinor
        wrote on last edited by
        #3

        I tried looking at "Windows Graphics Device Interface" and "Microsoft Direct3D 9’s" but without an example to understand, I got lost in the parameters types they ask. I would like to make it kinda like the slider from "Display Color Calibration" (Calibrate Display Color, as you find it in search box), the difference will be that I will add a function so you can add some default key shortcuts to certain gamma values. I'm used to code in Java, but there is no way to change gamma using that.

        J 1 Reply Last reply
        0
        • V Valentinor

          I tried looking at "Windows Graphics Device Interface" and "Microsoft Direct3D 9’s" but without an example to understand, I got lost in the parameters types they ask. I would like to make it kinda like the slider from "Display Color Calibration" (Calibrate Display Color, as you find it in search box), the difference will be that I will add a function so you can add some default key shortcuts to certain gamma values. I'm used to code in Java, but there is no way to change gamma using that.

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          You have to generate a table that is passed to the setter function. That is what the calibration does too: It generates the table according to the slider position. But I do't know the formula (and the range used by the calibration tool). If you only need a few selections, you can use the getter function to read the table for different calibration settings.

          V 1 Reply Last reply
          0
          • J Jochen Arndt

            You have to generate a table that is passed to the setter function. That is what the calibration does too: It generates the table according to the slider position. But I do't know the formula (and the range used by the calibration tool). If you only need a few selections, you can use the getter function to read the table for different calibration settings.

            V Offline
            V Offline
            Valentinor
            wrote on last edited by
            #5

            I found the following code in a post, and this note but I didn't figured out what is the min and the max value the float factor should have. Is this the formula you were talking about?

            Quote:

            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);

            I got it from this article (it does contain the source code, but the GUI code is very different from JavaFX): Gamma correction slider[^]

            J 1 Reply Last reply
            0
            • V Valentinor

              I found the following code in a post, and this note but I didn't figured out what is the min and the max value the float factor should have. Is this the formula you were talking about?

              Quote:

              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);

              I got it from this article (it does contain the source code, but the GUI code is very different from JavaFX): Gamma correction slider[^]

              J Offline
              J Offline
              Jochen Arndt
              wrote on last edited by
              #6

              Looks good, but I have not tested it. But you do know that this is the C/C++ board and Java would be off topic? However, all you have to do is converting the Algorithm to Java (should be no problem), check how to call Windows API functions from Java, and create the GUI according to your requirements. The GUI from that article is an example. Even a C++ developer using that code would create his own GUI controls and windows instead of using those from the example.

              V 2 Replies Last reply
              0
              • J Jochen Arndt

                Looks good, but I have not tested it. But you do know that this is the C/C++ board and Java would be off topic? However, all you have to do is converting the Algorithm to Java (should be no problem), check how to call Windows API functions from Java, and create the GUI according to your requirements. The GUI from that article is an example. Even a C++ developer using that code would create his own GUI controls and windows instead of using those from the example.

                V Offline
                V Offline
                Valentinor
                wrote on last edited by
                #7

                Quote:

                But you do know that this is the C/C++ board and Java would be off topic?

                Yeah I know, that is why I didn't asked questions about java. I only made a comparison between the 2 of them.

                Quote:

                However, all you have to do is converting the Algorithm to Java

                I know how to use native functions. I missed this part in that article "float factor between 0.0 and 2.0" Thanks for your help.

                1 Reply Last reply
                0
                • J Jochen Arndt

                  Looks good, but I have not tested it. But you do know that this is the C/C++ board and Java would be off topic? However, all you have to do is converting the Algorithm to Java (should be no problem), check how to call Windows API functions from Java, and create the GUI according to your requirements. The GUI from that article is an example. Even a C++ developer using that code would create his own GUI controls and windows instead of using those from the example.

                  V Offline
                  V Offline
                  Valentinor
                  wrote on last edited by
                  #8

                  So, I did a few tests with that formula for set gamma, and I found out that the range 0.0-2.0 isn't actually good. I gave values between 0.0-0.2 and nothing happened, then I tried some values between 0.3-4.0 and it was working. So there are values OVER 2.0 that are working and the values under 0.3 aren't working at all. Can it be that the formula isn't actually correct or that the range he gave is wrong? Or maybe he thought that those values are what users may want?

                  J 1 Reply Last reply
                  0
                  • V Valentinor

                    So, I did a few tests with that formula for set gamma, and I found out that the range 0.0-2.0 isn't actually good. I gave values between 0.0-0.2 and nothing happened, then I tried some values between 0.3-4.0 and it was working. So there are values OVER 2.0 that are working and the values under 0.3 aren't working at all. Can it be that the formula isn't actually correct or that the range he gave is wrong? Or maybe he thought that those values are what users may want?

                    J Offline
                    J Offline
                    Jochen Arndt
                    wrote on last edited by
                    #9

                    I suggest to read about Gamma correction - Wikipedia[^] to understand it. Note also that the default value for Windows is 2.2. Anything far away from that will display weird. Very low values will simply result in most - if not all - table values to be set to zero. Similar for very high values which will result in 0xFFFF. That means that there is a range of useful Gamma values while all others will be clipped (note the max() and min() calls in the formula).

                    V 1 Reply Last reply
                    0
                    • J Jochen Arndt

                      I suggest to read about Gamma correction - Wikipedia[^] to understand it. Note also that the default value for Windows is 2.2. Anything far away from that will display weird. Very low values will simply result in most - if not all - table values to be set to zero. Similar for very high values which will result in 0xFFFF. That means that there is a range of useful Gamma values while all others will be clipped (note the max() and min() calls in the formula).

                      V Offline
                      V Offline
                      Valentinor
                      wrote on last edited by
                      #10

                      Thanks for you help!

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups