I need to be able to manipulate the video card gamma tables in my cross platform application. This code needs to be able to do this for each display on multi-display systems based on the location of the dialog that the user is interacting with. I have this working on X11 and Windows and on OS/X the code is far enough along that it will manipulate the gamma table of CGMainDisplayID but I have been unable to find any documentation or any other source on how to get from something I can get from Qt such as QDesktopWidget::screenNumber() or this -> winID() to a handle that can be used to manipulate the video card gamma for a specific display.
The code in my dialog looks like this:
#if defined (Q_WS_WIN)
screen = (int) this -> winId ();
#elif defined(Q_WS_MAC) // FIXME
screen = (int) this -> winId ();
#elif defined(Q_WS_X11) // this is an X11 system
screen = desktop -> screenNumber(pixmapColor -> mapToGlobal(pixmapColor -> pos()));
#else
#error "Your system is not supported yet. The video gamma setting code will need to be updated to support your system."
#endif[
gamma_ramp gammaRamp = new gamma_ramp(screen);
gammaRamp->setGammaRamp();
...
#if defined (Q_WS_WIN)
screen = (int) this -> winId ();
#elif defined(Q_WS_MAC) // FIXME
screen = (int) this -> winId ();
#elif defined(Q_WS_X11) // this is an X11 system
screen = desktop -> screenNumber(pixmapColor -> mapToGlobal(pixmapColor -> pos()));
#else
#error "Your system is not supported yet. The video gamma setting code will need to be updated to support your system."
#endif[
gamma_ramp gammaRamp = new gamma_ramp(screen);
gammaRamp->setGammaRamp();
...
To copy to clipboard, switch view to plain text mode
For X11 this is very simple to use as the above boils down to a call to XF86VidModeGetGammaRamp(...) where the screenNumber value is passed in as the second parameter. On Windows it is a little more involved since winID needs to be translated into a handle and the called code looks looks like this:
void gamma_ramp::getGammaRamp()
{
HDC hDisplayDC;
HRESULT hr;
hDisplayDC = GetDCEx((HWND) screen, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
hr = GetDeviceGammaRamp(hDisplayDC, (LPVOID) ramp_buffer);
ReleaseDC((HWND) screen, hDisplayDC);
this -> convertPrivShort2ramp_type();
}
void gamma_ramp::getGammaRamp()
{
HDC hDisplayDC;
HRESULT hr;
hDisplayDC = GetDCEx((HWND) screen, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
hr = GetDeviceGammaRamp(hDisplayDC, (LPVOID) ramp_buffer);
ReleaseDC((HWND) screen, hDisplayDC);
this -> convertPrivShort2ramp_type();
}
To copy to clipboard, switch view to plain text mode
This is much closer to what needs to happen on OS/X where the code currently looks like this:
void gamma_ramp::getGammaRamp()
{
CGTableCount count;
CGDisplayErr error_code;
// FIXME only does the main display
CGDirectDisplayID dspID = CGMainDisplayID();
error_code = CGGetDisplayTransferByTable (dspID,
(CGTableCount) size,
&ramp_buffer[0],
&ramp_buffer[size],
&ramp_buffer[size*2],
&count);
for (int i=0; i < size; ++i)
{
red[i] = interpol(ramp_buffer, i, size, count);
green[i] = interpol(ramp_buffer + size, i, size, count);
blue[i] = interpol(ramp_buffer + size*2, i, size, count);
}
}
void gamma_ramp::getGammaRamp()
{
CGTableCount count;
CGDisplayErr error_code;
// FIXME only does the main display
CGDirectDisplayID dspID = CGMainDisplayID();
error_code = CGGetDisplayTransferByTable (dspID,
(CGTableCount) size,
&ramp_buffer[0],
&ramp_buffer[size],
&ramp_buffer[size*2],
&count);
for (int i=0; i < size; ++i)
{
red[i] = interpol(ramp_buffer, i, size, count);
green[i] = interpol(ramp_buffer + size, i, size, count);
blue[i] = interpol(ramp_buffer + size*2, i, size, count);
}
}
To copy to clipboard, switch view to plain text mode
As you can see currently the OS/X code only uses the main display:
CGDirectDisplayID dspID = CGMainDisplayID();
CGDirectDisplayID dspID = CGMainDisplayID();
To copy to clipboard, switch view to plain text mode
What I need is a way to get from winID(), screenNumber() or something that is Qt supplied to a CGDirectDisplayID and I have been desperately looking for anything about how to do this. Anything about this would be helpful such as a possible source of documentation or perhaps a link to a forum that specializes in Qt OS/X. Even the programmer who worked on the OS/X code didn't have any idea how to handle this and he works on a large Qt open source project. I should add that he did get this code to the point where it builds and will work on the main display gamma table. So I am very grateful for his efforts.
Bookmarks