Gamma/brightness in Carbon

Member
Posts: 164
Joined: 2002.04
Post: #1
I use drawsprocket to change the brightness levels in OS 9, but the same call in X seems to work on every other frame or so, causing seizure-inducing flickering. Is there any way to fix this, or another way to change gamma?
Quote this message in a reply
Member
Posts: 156
Joined: 2002.11
Post: #2
There is a way to change the gamma by formula and/or restoring Colorsync settings.

The source code from this address comes with a working example of how to do it in Carbon (not sure whether it supports OS 9.0):

http://webpages.charter.net/fccovett/MyGameSource.dmg
Quote this message in a reply
Moderator
Posts: 522
Joined: 2002.04
Post: #3
I'd just use RezLib for your gamma stuff. I've had no problems with it. Unless there is a reason you're not using it?

-Jon
Quote this message in a reply
Member
Posts: 164
Joined: 2002.04
Post: #4
Ack, dmg Sad Can't open in 9

Would it be possible to use both Rezlib and Drawsprocket happily in the same program?
Quote this message in a reply
Member
Posts: 156
Joined: 2002.11
Post: #5
Code:
typedef struct
{
    CGDirectDisplayID    displayID;
    CGRect        displayBounds;
    CGGammaValue    redMin, redMax, redGamma, greenMin, greenMax, greenGamma, blueMin, blueMax, blueGamma;
}
DisplaySettings;


DisplaySettings     dispSettings = {};


void GetCurrentDisplayGammaSettings()    
{
    //----------------------------------------------------------------------
    // Fill out dispSettings with a display ID and the current gamma settings:
    
    dispSettings.displayID = kCGDirectMainDisplay;

    //----------------------------------------------------------------------
    
    CGGetDisplayTransferByFormula(
                  dispSettings.displayID,
                  &dispSettings.redMin, &dispSettings.redMax, &dispSettings.redGamma,
                  &dispSettings.greenMin, &dispSettings.greenMax, &dispSettings.greenGamma,
                  &dispSettings.blueMin, &dispSettings.blueMax, &dispSettings.blueGamma
                  );
    
    //----------------------------------------------------------------------
    // Get main display bounds:

    dispSettings.displayBounds = CGDisplayBounds( kCGDirectMainDisplay );
}

/----------------------------------------------------------------------

void FadeDisplayToBlack()
{
    //----------------------------------------------------------------------
    
    double fadeValue;

    //----------------------------------------------------------------------

    for( fadeValue = 1.0; fadeValue >= 0.0; fadeValue -= 0.01 )
    {
        CGSetDisplayTransferByFormula(
                      dispSettings.displayID,
                      dispSettings.redMin,    fadeValue * dispSettings.redMax,    dispSettings.redGamma,
                      dispSettings.greenMin,    fadeValue * dispSettings.greenMax,    dispSettings.greenGamma,
                      dispSettings.blueMin,    fadeValue * dispSettings.blueMax,    dispSettings.blueGamma
                      );
    }
}

//----------------------------------------------------------------------

void FadeDisplayFromBlack()
{
    //----------------------------------------------------------------------
    
    double fadeValue;

    //----------------------------------------------------------------------

    for( fadeValue = 0.0; fadeValue <= 1.0; fadeValue += 0.01 )
    {
        CGSetDisplayTransferByFormula(
                      dispSettings.displayID,
                                      dispSettings.redMin,    fadeValue * dispSettings.redMax,    dispSettings.redGamma,
                                      dispSettings.greenMin,    fadeValue * dispSettings.greenMax,    dispSettings.greenGamma,
                                      dispSettings.blueMin,    fadeValue * dispSettings.blueMax,    dispSettings.blueGamma
                      );
    }

    //----------------------------------------------------------------------
    // Restore the user's ColorSync settings, just to be sure:

    CGDisplayRestoreColorSyncSettings();
}
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #6
Quote:Originally posted by David
Would it be possible to use both Rezlib and Drawsprocket happily in the same program?


It *should* work since RezLib uses DisplayManager in Classic so there won't be any API conflicts, but you might run into other problems.

But - I'm assuming you want to use DSp in classic and RezLib in X? Why not just use CGDirectDisplay in X (like RezLib does) and forget RezLib, or just use RezLib for both 9 & X and forget about DrawSprocket?

I will mention that RezLib has it's faults though. One being that it doesn't support "overbright" gamma ramps in Classic (like setting DrawSprocket's gamma over 100), and the second problem is that it doesn't capture the screen when switching resolutions, so all other applications will be affected (often to the dismay of your users).

I have a Carbon REALbasic plugin that provides a common API for DrawSprocket/CGDirectDisplay (here - full C source included). You're welcome to swipe any code ya like from that.
Quote this message in a reply
Post Reply