Sign in to follow this  

Regarding use of SetDeviceGammaRamp windows API winXP check

This topic is 3294 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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[i]   = 65535 - gamma.wRed[i];
     gamma.Blue[i]  = 65535 - gamma.wBlue[i];
     gamma.Green[i] = 65535 - gamma.wGreen[i];
    }

    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[i]   = 65535 - Gamma.wRed[i];
     Gamma.wBlue[i]  = 65535 - Gamma.wBlue[i];
     Gamma.wGreen[i] = 65535 - Gamma.wGreen[i];
    }

    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. :)

Share this post


Link to post
Share on other sites

This topic is 3294 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this