Results 1 to 6 of 6

Thread: change gamma ramp in video card

  1. #1
    Join Date
    Mar 2006
    Posts
    74
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default change gamma ramp in video card

    In my app I need to be able to get and set the video card gamma ramp. In X11 this turned out to be fairly simple with code that looked like this:

    gamma_ramp.h

    Qt Code:
    1. class gamma_ramp
    2. {
    3. public:
    4. int screen;
    5. int size;
    6. unsigned short *red, *green, *blue;
    7.  
    8. gamma_ramp(int);
    9. ~gamma_ramp();
    10. void getGammaRamp();
    11. void setGammaRamp();
    12. void setLinearGammaRamp();
    13.  
    14. private:
    15. int getGammaRampSize(int);
    16. };
    To copy to clipboard, switch view to plain text mode 

    gamma_ramp-x11.cpp

    Qt Code:
    1. #include <stdio.h>
    2. #include <stdlib.h>
    3. #include <math.h>
    4. #include <sys/types.h>
    5. #include <time.h>
    6. #include <string.h>
    7.  
    8. // X11 stuff
    9. #include <X11/Xos.h>
    10. #include <X11/Xlib.h>
    11. #include <X11/Xutil.h>
    12. #include <X11/Xlibint.h>
    13. #include <X11/Xproto.h>
    14. #include <X11/Xatom.h>
    15. #include <X11/extensions/xf86vmode.h>
    16. #include <X11/extensions/dpms.h>
    17. #include <X11/extensions/Xinerama.h>
    18. #include "gamma_ramp.h"
    19.  
    20. gamma_ramp::gamma_ramp(int Screen)
    21. {
    22. screen = Screen;
    23. size = getGammaRampSize(screen);
    24. // now allocate the arrays
    25. red = new unsigned short[size];
    26. green = new unsigned short[size];
    27. blue = new unsigned short[size];
    28. }
    29.  
    30. gamma_ramp::~gamma_ramp()
    31. {
    32. delete[] red;
    33. delete[] green;
    34. delete[] blue;
    35. }
    36.  
    37. int gamma_ramp::getGammaRampSize(int Screen)
    38. {
    39. int size = 0;
    40. int event_base;
    41. int error_base;
    42. Display *dpy;
    43.  
    44. if ((dpy = XOpenDisplay(":0.0")) == NULL)
    45. {
    46. printf("failed to open display :0.0\n");
    47. }
    48. else
    49. {
    50. if (XF86VidModeQueryExtension(dpy, &event_base, &error_base) ==0)
    51. {
    52. printf("XF86VidModeQueryExtension failed\n");
    53. }
    54. else
    55. {
    56. if (!XF86VidModeGetGammaRampSize(dpy, Screen, &size))
    57. {
    58. printf("failed to get XF86VidModeGetGammaRampSize\n");
    59. }
    60. }
    61. }
    62. return size; // will be 0 if failed
    63. }
    64.  
    65. void gamma_ramp::getGammaRamp()
    66. {
    67. int event_base;
    68. int error_base;
    69. Display *dpy;
    70.  
    71. if ((dpy = XOpenDisplay(":0.0")) == NULL)
    72. {
    73. printf("failed to open display :0.0\n");
    74. }
    75. else
    76. {
    77. if (XF86VidModeQueryExtension(dpy, &event_base, &error_base) ==0)
    78. {
    79. printf("XF86VidModeQueryExtension failed\n");
    80. }
    81. else
    82. {
    83. XF86VidModeGetGammaRamp(dpy, screen, size,
    84. red, green, blue);
    85.  
    86. }
    87. }
    88. }
    89.  
    90. void gamma_ramp::setGammaRamp()
    91. {
    92. int event_base;
    93. int error_base;
    94. Display *dpy;
    95.  
    96. if ((dpy = XOpenDisplay(":0.0")) == NULL)
    97. {
    98. printf("failed to open display :0.0\n");
    99. }
    100. else
    101. {
    102. if (XF86VidModeQueryExtension(dpy, &event_base, &error_base) ==0)
    103. {
    104. printf("XF86VidModeQueryExtension failed\n");
    105. }
    106. else
    107. {
    108. XF86VidModeSetGammaRamp(dpy, screen, size,
    109. red, green, blue);
    110. }
    111. }
    112. }
    113.  
    114. void gamma_ramp::setLinearGammaRamp()
    115. {
    116. int event_base;
    117. int error_base;
    118. Display *dpy;
    119. gamma_ramp* temp;
    120.  
    121. temp = new gamma_ramp(screen);
    122.  
    123. for (int i=0; i< temp -> size; i++)
    124. {
    125. temp -> red[i] = temp -> green[i] = temp -> blue[i] = i * 256;
    126. }
    127.  
    128. if ((dpy = XOpenDisplay(":0.0")) == NULL)
    129. {
    130. printf("failed to open display :0.0\n");
    131. }
    132. else
    133. {
    134. if (XF86VidModeQueryExtension(dpy, &event_base, &error_base) ==0)
    135. {
    136. printf("XF86VidModeQueryExtension failed\n");
    137. }
    138. else
    139. {
    140. temp -> setGammaRamp();
    141. }
    142. }
    143. delete temp;
    144. }
    To copy to clipboard, switch view to plain text mode 

    and to get the gamma table I would use code like this:

    Qt Code:
    1. QDesktopWidget* desktop;
    2. desktop = new QDesktopWidget();
    3. screen = desktop -> screenNumber(this);
    4. gamma_ramp* gammaRamp = new gamma_ramp(screen);
    5. gammaRamp -> getGammaRamp();
    To copy to clipboard, switch view to plain text mode 

    Now I need to do this same type of thing for windows. Windows has has an API for this:

    Qt Code:
    1. BOOL WINAPI SetDeviceGammaRamp(
    2. HDC hDC,
    3. LPVOID lpRamp
    4. );
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. BOOL WINAPI GetDeviceGammaRamp(
    2. HDC hDC,
    3. LPVOID lpRamp
    4. );
    To copy to clipboard, switch view to plain text mode 

    How do I get the hDC value so that I am working with the correct gamma table for the monitor where the current widget is located? In Qt I can locate that screen with QDesktopWidget::screenNumber(QWdiget*) can I use that information to somehow get a Windows handle to that device?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: change gamma ramp in video card

    Maybe QWidget::getDC() will help?

  3. #3
    Join Date
    Mar 2006
    Posts
    74
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: change gamma ramp in video card

    I don't see this for Qt3. But perhaps I can look in the Qt4 code and create my own version of this based on it.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: change gamma ramp in video card

    Quote Originally Posted by hvengel View Post
    I don't see this for Qt3. But perhaps I can look in the Qt4 code and create my own version of this based on it.
    Sorry, I haven't noticed that you are using Qt3. AFAIR QWidget::winId() returns HWND on windows. Once you have it, you can get HDC through win API.

  5. #5
    Join Date
    Mar 2006
    Posts
    74
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: change gamma ramp in video card

    OK now I have the same basic question about OS/X. OS/X has these functions for setting the gamma ramp:

    CGDisplayErr CGSetDisplayTransferByTable (
    CGDirectDisplayID display,
    CGTableCount tableSize,
    const CGGammaValue * redTable,
    const CGGammaValue * greenTable,
    const CGGammaValue * blueTable
    );

    and

    CGDisplayErr CGGetDisplayTransferByTable (
    CGDirectDisplayID display,
    CGTableCount capacity,
    CGGammaValue * redTable,
    CGGammaValue * greenTable,
    CGGammaValue * blueTable,
    CGTableCount * sampleCount
    );

    Which are similar to X11 and Windows functions for the same thing but there are some differences. Like the gamma table values are floats in the range of 0.0 through 1.0 instead of unsigned shorts in the range of 0 to 2^16 on the other platforms. OK not a big deal. But how do I get from QDesktopWidget::screenNumber() to a CGDirectDisplayID so that I can make these calls? Are these the same thing or are they different? If they are different are there some functions for getting the CGDirectDisplayID available? I can't seem to find any docs about this.

  6. #6
    Join Date
    Mar 2006
    Posts
    74
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: change gamma ramp in video card

    OK I didn't mean to stump the band. So I will bump this to see if perhaps a new set of eyes might have an idea about how to get this working on a Mac.

Similar Threads

  1. [SOLVED] DirectShow Video Player Inside Qt
    By ToddAtWSU in forum Qt Programming
    Replies: 16
    Last Post: 3rd November 2011, 07:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.