Index: src/video/macdsp/SDL_dspvideo.c =================================================================== --- src/video/macdsp/SDL_dspvideo.c (revision 3019) +++ src/video/macdsp/SDL_dspvideo.c (working copy) @@ -148,6 +148,7 @@ #include "../maccommon/SDL_macwm_c.h" #include "../maccommon/SDL_macmouse_c.h" #include "../maccommon/SDL_macevents_c.h" +#include "../maccommon/MacGamma.h" /* Initialization/Query functions */ static int DSp_VideoInit(_THIS, SDL_PixelFormat *vformat); @@ -158,6 +159,9 @@ static int DSp_CreatePalette(_THIS); static int DSp_DestroyPalette(_THIS); static void DSp_VideoQuit(_THIS); +void DSp_QuitGamma(_THIS); +int DSp_SetGammaRamp(_THIS, Uint16 *ramp); +int DSp_GetGammaRamp(_THIS, Uint16 *ramp); static int DSp_GetMainDevice (_THIS, GDHandle *device); static void DSp_IsHWAvailable (_THIS, SDL_PixelFormat *vformat); @@ -297,6 +301,8 @@ device->UnlockHWSurface = DSp_UnlockHWSurface; device->FlipHWSurface = DSp_FlipHWSurface; device->FreeHWSurface = DSp_FreeHWSurface; + device->SetGammaRamp = DSp_SetGammaRamp; + device->GetGammaRamp = DSp_GetGammaRamp; #if SDL_VIDEO_OPENGL device->GL_MakeCurrent = Mac_GL_MakeCurrent; device->GL_SwapBuffers = DSp_GL_SwapBuffers; @@ -1371,6 +1377,51 @@ return(1); } +static Ptr systemGammaPtr; + +void DSp_QuitGamma(_THIS) +{ + if (systemGammaPtr) + { + RestoreSystemGammas(systemGammaPtr); + DisposeSystemGammas(&systemGammaPtr); + } +} + +static unsigned char shiftedRamp[3 * 256]; + +int DSp_SetGammaRamp(_THIS, Uint16 *ramp) +{ + int i; + if (!systemGammaPtr) + systemGammaPtr = GetSystemGammas(); + for (i = 0; i < 3 * 256; i++) + { + shiftedRamp[i] = ramp[i] >> 8; + } + + if (SetDeviceGammaRampGD(GetMainDevice(), (Ptr) shiftedRamp)) + return 0; + else + return -1; +} + +int DSp_GetGammaRamp(_THIS, Uint16 *ramp) +{ + if (GetDeviceGammaRampGD(GetMainDevice(), (Ptr) shiftedRamp)) + { + int i; + for (i = 0; i < 3 * 256; i++) + { + shiftedRamp[i] = ramp[i] << 8; + } + return 0; + } + else + return -1; +} + + void DSp_VideoQuit(_THIS) { int i; @@ -1380,6 +1431,7 @@ /* Free Palette and restore original */ DSp_DestroyPalette (this); + DSp_QuitGamma(this); /* Free list of video modes */ if ( SDL_modelist != NULL ) { Index: src/video/macrom/SDL_romvideo.c =================================================================== --- src/video/macrom/SDL_romvideo.c (revision 3019) +++ src/video/macrom/SDL_romvideo.c (working copy) @@ -51,6 +51,7 @@ #include "../maccommon/SDL_macwm_c.h" #include "../maccommon/SDL_macmouse_c.h" #include "../maccommon/SDL_macevents_c.h" +#include "../maccommon/MacGamma.h" /* Initialization/Query functions */ static int ROM_VideoInit(_THIS, SDL_PixelFormat *vformat); @@ -59,6 +60,9 @@ static int ROM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); static void ROM_VideoQuit(_THIS); +void ROM_QuitGamma(_THIS); +int ROM_SetGammaRamp(_THIS, Uint16 *ramp); +int ROM_GetGammaRamp(_THIS, Uint16 *ramp); /* Hardware surface functions */ static int ROM_AllocHWSurface(_THIS, SDL_Surface *surface); @@ -158,6 +162,8 @@ device->UnlockHWSurface = ROM_UnlockHWSurface; device->FlipHWSurface = NULL; device->FreeHWSurface = ROM_FreeHWSurface; + device->SetGammaRamp = ROM_SetGammaRamp; + device->GetGammaRamp = ROM_GetGammaRamp; #if SDL_VIDEO_OPENGL device->GL_MakeCurrent = Mac_GL_MakeCurrent; device->GL_SwapBuffers = Mac_GL_SwapBuffers; @@ -700,6 +706,50 @@ return(1); } +static Ptr systemGammaPtr; + +void ROM_QuitGamma(_THIS) +{ + if (systemGammaPtr) + { + RestoreSystemGammas(systemGammaPtr); + DisposeSystemGammas(&systemGammaPtr); + } +} + +static unsigned char shiftedRamp[3 * 256]; + +int ROM_SetGammaRamp(_THIS, Uint16 *ramp) +{ + int i; + if (!systemGammaPtr) + systemGammaPtr = GetSystemGammas(); + for (i = 0; i < 3 * 256; i++) + { + shiftedRamp[i] = ramp[i] >> 8; + } + + if (SetDeviceGammaRampGD(GetMainDevice(), (Ptr) shiftedRamp)) + return 0; + else + return -1; +} + +int ROM_GetGammaRamp(_THIS, Uint16 *ramp) +{ + if (GetDeviceGammaRampGD(GetMainDevice(), (Ptr) shiftedRamp)) + { + int i; + for (i = 0; i < 3 * 256; i++) + { + ramp[i] = shiftedRamp[i] << 8; + } + return 0; + } + else + return -1; +} + void ROM_VideoQuit(_THIS) { int i; @@ -721,6 +771,7 @@ SDL_CPal = nil; } RestoreDeviceClut(GetMainDevice()); + ROM_QuitGamma(this); /* Free list of video modes */ if ( SDL_modelist != NULL ) {