src/video/cocoa/SDL_cocoawindow.m
changeset 5466 006883d5fa51
parent 5406 1517da4ab6b1
child 5478 6b65ff3cee62
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Thu Mar 10 01:03:43 2011 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Fri Mar 11 08:49:20 2011 -0800
     1.3 @@ -856,7 +856,58 @@
     1.4      [pool release];
     1.5  }
     1.6  
     1.7 -NSPoint origin;
     1.8 +int
     1.9 +Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
    1.10 +{
    1.11 +    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
    1.12 +    CGDirectDisplayID display_id = ((SDL_DisplayData *)display->driverdata)->display;
    1.13 +    const uint32_t tableSize = 256;
    1.14 +    CGGammaValue redTable[tableSize];
    1.15 +    CGGammaValue greenTable[tableSize];
    1.16 +    CGGammaValue blueTable[tableSize];
    1.17 +    uint32_t i;
    1.18 +    float inv65535 = 1.0f / 65535.0f;
    1.19 +
    1.20 +    /* Extract gamma values into separate tables, convert to floats between 0.0 and 1.0 */
    1.21 +    for (i = 0; i < 256; i++) {
    1.22 +        redTable[i] = ramp[0*256+i] * inv65535;
    1.23 +        greenTable[i] = ramp[1*256+i] * inv65535;
    1.24 +        blueTable[i] = ramp[2*256+i] * inv65535;
    1.25 +    }
    1.26 +
    1.27 +    if (CGSetDisplayTransferByTable(display_id, tableSize,
    1.28 +                                    redTable, greenTable, blueTable) != CGDisplayNoErr) {
    1.29 +        SDL_SetError("CGSetDisplayTransferByTable()");
    1.30 +        return -1;
    1.31 +    }
    1.32 +    return 0;
    1.33 +}
    1.34 +
    1.35 +int
    1.36 +Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
    1.37 +{
    1.38 +    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
    1.39 +    CGDirectDisplayID display_id = ((SDL_DisplayData *)display->driverdata)->display;
    1.40 +    const uint32_t tableSize = 256;
    1.41 +    CGGammaValue redTable[tableSize];
    1.42 +    CGGammaValue greenTable[tableSize];
    1.43 +    CGGammaValue blueTable[tableSize];
    1.44 +    uint32_t i, tableCopied;
    1.45 +
    1.46 +    if (CGGetDisplayTransferByTable(display_id, tableSize,
    1.47 +                                    redTable, greenTable, blueTable, &tableCopied) != CGDisplayNoErr) {
    1.48 +        SDL_SetError("CGGetDisplayTransferByTable()");
    1.49 +        return -1;
    1.50 +    }
    1.51 +
    1.52 +    for (i = 0; i < tableCopied; i++) {
    1.53 +        ramp[0*256+i] = (Uint16)(redTable[i] * 65535.0f);
    1.54 +        ramp[1*256+i] = (Uint16)(greenTable[i] * 65535.0f);
    1.55 +        ramp[2*256+i] = (Uint16)(blueTable[i] * 65535.0f);
    1.56 +    }
    1.57 +    return 0;
    1.58 +}
    1.59 +
    1.60  void
    1.61  Cocoa_SetWindowGrab(_THIS, SDL_Window * window)
    1.62  {