Advertisement

Regarding use of SetDeviceGammaRamp windows API winXP check

Started by December 04, 2008 05:22 PM
-1 comments, last by adimirea 15 years, 11 months ago
Okay, so first of all let me say I am not sure if this is the right place to post... I wanted to post on this thread http://www.gamedev.net/community/forums/topic.asp?topic_id=196752, but it is closed. In the last post someone asked how you could bypass the windows XP check for setting an inverse gamma ramp (which would get you a NEGATIVE image :) ) More precisely, if you do something like GetDeviceGammaRamp( getDC(NULL), γ); and then, to invert that ramp, do something like:


    for(int i=0; i < 256; i++)
    {
     gamma.Red   = 65535 - gamma.wRed;
     gamma.Blue  = 65535 - gamma.wBlue;
     gamma.Green = 65535 - gamma.wGreen;
    }

    SetDeviceGammaRamp(GetDC(NULL), (LPVOID)&GammaArray);

Then NOTHING would happen ( and if you would go about checking the last error by means of GetLastError() you would either get a "bad parameter" or the more revealing but still WRONG error "the specified ramp is not supported by the device". The solution is to simply bypass the winAPI functions (which are in gdi32.dll), and use two very similar functions, but this time in a NVIDIA-provided dll (nvcpl.dll) Enough talk, I'll just post the working code: ( I've been digging and google-ing this up for WEEKS, and I really feel there's not many places on the 'net covering this, if any ):


  typedef struct GAMMARAMP
    {
        WORD wRed[256];
        WORD wGreen[256];
        WORD wBlue[256];
    } GAMMARAMP, *PGAMMARAMP;

    HINSTANCE hCpl = LoadLibrary("nvcpl.dll");

    if(hCpl == NULL)
    {
        MessageBox(0,"LoadLibrary failed loading DLL", "LoadLibrary failed loading DLL", 0);
    }

    typedef BOOL (*ptrSetGammaRamp)(LPTSTR, DWORD, PGAMMARAMP);
    typedef BOOL (*ptrGetGammaRamp)(LPTSTR, PGAMMARAMP);

    ptrSetGammaRamp nvSetGamma;
    ptrGetGammaRamp nvGetGamma;

    GAMMARAMP Gamma;

    nvSetGamma = (ptrSetGammaRamp) GetProcAddress( hCpl, "NvColorSetGammaRamp");

    if(!nvSetGamma)
    {
     MessageBox(0,"GetProcAdress fail on nvSetGamma","GetProcAdress fail on nvSetGamma", 0);
    }

    nvGetGamma = (ptrGetGammaRamp) GetProcAddress( hCpl, "NvColorGetGammaRamp");

    if(!nvGetGamma)
    {
     MessageBox(0,"GetProcAdress fail on nvGetGamma","GetProcAdress fail on nvGetGamma", 0);
    }

    nvGetGamma("a0", Γ);

    for(int i=0; i < 256; i++)
    {
     Gamma.wRed   = 65535 - Gamma.wRed;
     Gamma.wBlue  = 65535 - Gamma.wBlue;
     Gamma.wGreen = 65535 - Gamma.wGreen;
    }

    nvSetGamma("a0", 0xFFFFFFFF, Γ);
ps: If anyone knows of a similar ATI .dll that has functions like these, please let me know here. I am working on a project that is basically about reducing eye strain for people like myself who spend >15hrs a day on the computer (or more :)) ) and part of that is this "negative image" thing (having a BLACK background is a true relief on your eyes, believe me). And of course, I want it to work on ATI cards too. :)

This topic is closed to new replies.

Advertisement