Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video SDL-1.2
authorRyan C. Gordon
Fri, 15 Jun 2007 06:29:52 +0000
branchSDL-1.2
changeset 39627cdb1d7fc93b
parent 3961 4b093ecae4a7
child 3963 a9ad5257f794
Support for Gamma Ramps on Mac OS Classic in both the macrom and macdsp video
targets, thanks to Gregory Smith!

Fixes Bugzilla #431.
src/video/maccommon/SDL_macwm.c
src/video/maccommon/SDL_macwm_c.h
src/video/macdsp/SDL_dspvideo.c
src/video/macrom/SDL_romvideo.c
     1.1 --- a/src/video/maccommon/SDL_macwm.c	Fri Jun 15 05:41:22 2007 +0000
     1.2 +++ b/src/video/maccommon/SDL_macwm.c	Fri Jun 15 06:29:52 2007 +0000
     1.3 @@ -30,6 +30,15 @@
     1.4  #include <Strings.h>
     1.5  #endif
     1.6  
     1.7 +#if SDL_MACCLASSIC_GAMMA_SUPPORT
     1.8 +#include <Devices.h>
     1.9 +#include <Files.h>
    1.10 +#include <MacTypes.h>
    1.11 +#include <QDOffscreen.h>
    1.12 +#include <Quickdraw.h>
    1.13 +#include <Video.h>
    1.14 +#endif
    1.15 +
    1.16  #include "SDL_stdinc.h"
    1.17  #include "SDL_macwm_c.h"
    1.18  
    1.19 @@ -42,3 +51,392 @@
    1.20  	if (SDL_Window)
    1.21  		SetWTitle(SDL_Window, ptitle); /* MJS */
    1.22  }
    1.23 +
    1.24 +#if SDL_MACCLASSIC_GAMMA_SUPPORT
    1.25 +/*
    1.26 + * ADC Gamma Ramp support...
    1.27 + *
    1.28 + * Mac Gamma Ramp code was originally from sample code provided by
    1.29 + *  Apple Developer Connection, and not written specifically for SDL:
    1.30 + * "Contains: Functions to enable Mac OS device gamma adjustments using 3 channel 256 element 8 bit gamma ramps
    1.31 + *  Written by: Geoff Stahl (ggs)
    1.32 + *  Copyright: Copyright (c) 1999 Apple Computer, Inc., All Rights Reserved
    1.33 + *  Disclaimer: You may incorporate this sample code into your applications without
    1.34 + *              restriction, though the sample code has been provided "AS IS" and the
    1.35 + *              responsibility for its operation is 100% yours.  However, what you are
    1.36 + *              not permitted to do is to redistribute the source as "DSC Sample Code"
    1.37 + *              after having made changes. If you're going to re-distribute the source,
    1.38 + *              we require that you make it clear in the source that the code was
    1.39 + *              descended from Apple Sample Code, but that you've made changes."
    1.40 + * (The sample code has been integrated into this file, and thus is modified from the original Apple sources.)
    1.41 + */
    1.42 +
    1.43 +typedef struct recDeviceGamma											/* storage for device handle and gamma table */
    1.44 +{
    1.45 +	GDHandle hGD;												/* handle to device */
    1.46 +	GammaTblPtr pDeviceGamma;									/* pointer to device gamma table */
    1.47 +} recDeviceGamma;
    1.48 +typedef recDeviceGamma * precDeviceGamma;
    1.49 +
    1.50 +typedef struct recSystemGamma											/* storage for system devices and gamma tables */
    1.51 +{
    1.52 +	short numDevices;											/* number of devices */
    1.53 +	precDeviceGamma * devGamma;									/* array of pointers to device gamma records */
    1.54 +} recSystemGamma;
    1.55 +typedef recSystemGamma * precSystemGamma;
    1.56 +
    1.57 +static Ptr CopyGammaTable (GammaTblPtr pTableGammaIn)
    1.58 +{
    1.59 +	GammaTblPtr		pTableGammaOut = NULL;
    1.60 +	short			tableSize, dataWidth;
    1.61 +
    1.62 +	if (pTableGammaIn)												/* if there is a table to copy  */
    1.63 +	{
    1.64 +		dataWidth = (pTableGammaIn->gDataWidth + 7) / 8;			/* number of bytes per entry */
    1.65 +		tableSize = sizeof (GammaTbl) + pTableGammaIn->gFormulaSize +
    1.66 +					(pTableGammaIn->gChanCnt * pTableGammaIn->gDataCnt * dataWidth);
    1.67 +		pTableGammaOut = (GammaTblPtr) NewPtr (tableSize);			/* allocate new table */
    1.68 +		if (pTableGammaOut)											
    1.69 +			BlockMove( (Ptr)pTableGammaIn, (Ptr)pTableGammaOut, tableSize);	/* move everything */
    1.70 +	}
    1.71 +	return (Ptr)pTableGammaOut;										/* return whatever we allocated, could be NULL */
    1.72 +}
    1.73 +
    1.74 +static OSErr GetGammaTable (GDHandle hGD, GammaTblPtr * ppTableGammaOut)
    1.75 +{
    1.76 +	VDGammaRecord   DeviceGammaRec;
    1.77 +	CntrlParam		cParam;
    1.78 +	OSErr			err;
    1.79 +	
    1.80 +	cParam.ioCompletion = NULL;										/* set up control params */
    1.81 +	cParam.ioNamePtr = NULL;
    1.82 +	cParam.ioVRefNum = 0;
    1.83 +	cParam.ioCRefNum = (**hGD).gdRefNum;
    1.84 +	cParam.csCode = cscGetGamma;									/* Get Gamma commnd to device */
    1.85 +	*(Ptr *)cParam.csParam = (Ptr) &DeviceGammaRec;					/* record for gamma */
    1.86 +
    1.87 +	err = PBStatusSync( (ParmBlkPtr)&cParam );						/* get gamma */
    1.88 +	
    1.89 +	*ppTableGammaOut = (GammaTblPtr)(DeviceGammaRec.csGTable);		/* pull table out of record */
    1.90 +	
    1.91 +	return err;	
    1.92 +}
    1.93 +
    1.94 +static Ptr GetDeviceGamma (GDHandle hGD)
    1.95 +{
    1.96 +	GammaTblPtr		pTableGammaDevice = NULL;
    1.97 +	GammaTblPtr		pTableGammaReturn = NULL;	
    1.98 +	OSErr			err;
    1.99 +	
   1.100 +	err = GetGammaTable (hGD, &pTableGammaDevice);					/* get a pointer to the devices table */
   1.101 +	if ((noErr == err) && pTableGammaDevice)						/* if succesful */
   1.102 +		pTableGammaReturn = (GammaTblPtr) CopyGammaTable (pTableGammaDevice); /* copy to global */
   1.103 +
   1.104 +	return (Ptr) pTableGammaReturn;
   1.105 +}
   1.106 +
   1.107 +static void DisposeGammaTable (Ptr pGamma)
   1.108 +{
   1.109 +	if (pGamma)
   1.110 +		DisposePtr((Ptr) pGamma);									/* get rid of it */
   1.111 +}
   1.112 +
   1.113 +static void DisposeSystemGammas (Ptr* ppSystemGammas)
   1.114 +{
   1.115 +	precSystemGamma pSysGammaIn;
   1.116 +	if (ppSystemGammas)
   1.117 +	{
   1.118 +		pSysGammaIn = (precSystemGamma) *ppSystemGammas;
   1.119 +		if (pSysGammaIn)
   1.120 +		{
   1.121 +			short i;
   1.122 +			for (i = 0; i < pSysGammaIn->numDevices; i++)		/* for all devices */
   1.123 +				if (pSysGammaIn->devGamma [i])						/* if pointer is valid */
   1.124 +				{
   1.125 +					DisposeGammaTable ((Ptr) pSysGammaIn->devGamma [i]->pDeviceGamma); /* dump gamma table */
   1.126 +					DisposePtr ((Ptr) pSysGammaIn->devGamma [i]);					   /* dump device info */
   1.127 +				}
   1.128 +			DisposePtr ((Ptr) pSysGammaIn->devGamma);				/* dump device pointer array		 */
   1.129 +			DisposePtr ((Ptr) pSysGammaIn);							/* dump system structure */
   1.130 +			*ppSystemGammas = NULL;
   1.131 +		}	
   1.132 +	}
   1.133 +}
   1.134 +
   1.135 +static Boolean GetDeviceGammaRampGD (GDHandle hGD, Ptr pRamp)
   1.136 +{
   1.137 +	GammaTblPtr		pTableGammaTemp = NULL;
   1.138 +	long 			indexChan, indexEntry;
   1.139 +	OSErr			err;
   1.140 +	
   1.141 +	if (pRamp)															/* ensure pRamp is allocated */
   1.142 +	{
   1.143 +		err = GetGammaTable (hGD, &pTableGammaTemp);					/* get a pointer to the current gamma */
   1.144 +		if ((noErr == err) && pTableGammaTemp)							/* if successful */
   1.145 +		{															
   1.146 +			/* fill ramp */
   1.147 +			unsigned char * pEntry = (unsigned char *) &pTableGammaTemp->gFormulaData + pTableGammaTemp->gFormulaSize; /* base of table */
   1.148 +			short bytesPerEntry = (pTableGammaTemp->gDataWidth + 7) / 8; /* size, in bytes, of the device table entries */
   1.149 +			short shiftRightValue = pTableGammaTemp->gDataWidth - 8; 	 /* number of right shifts device -> ramp */
   1.150 +			short channels = pTableGammaTemp->gChanCnt;	
   1.151 +			short entries = pTableGammaTemp->gDataCnt;									
   1.152 +			if (3 == channels)											/* RGB format */
   1.153 +			{															/* note, this will create runs of entries if dest. is bigger (not linear interpolate) */
   1.154 +				for (indexChan = 0; indexChan < channels; indexChan++)
   1.155 +					for (indexEntry = 0; indexEntry < 256; indexEntry++)
   1.156 +						*((unsigned char *) pRamp + (indexChan * 256) + indexEntry) = 
   1.157 +						  *(pEntry + indexChan * entries * bytesPerEntry + indexEntry * entries * bytesPerEntry / 256) >> shiftRightValue;
   1.158 +			}
   1.159 +			else														/* single channel format */
   1.160 +			{
   1.161 +				for (indexChan = 0; indexChan < 768; indexChan += 256)	/* repeat for all 3 channels (step by ramp size) */
   1.162 +					for (indexEntry = 0; indexEntry < 256; indexEntry++) /* for all entries set vramp value */
   1.163 +						*((unsigned char *) pRamp + indexChan + indexEntry) = 
   1.164 +						  *(pEntry + indexEntry * entries * bytesPerEntry / 256) >> shiftRightValue;
   1.165 +			}
   1.166 +			return true;
   1.167 +		}
   1.168 +	}
   1.169 +	return false;
   1.170 +}
   1.171 +
   1.172 +static Ptr GetSystemGammas (void)
   1.173 +{
   1.174 +	precSystemGamma pSysGammaOut;									/* return pointer to system device gamma info */
   1.175 +	short devCount = 0;												/* number of devices attached */
   1.176 +	Boolean fail = false;
   1.177 +	GDHandle hGDevice;
   1.178 +	
   1.179 +	pSysGammaOut = (precSystemGamma) NewPtr (sizeof (recSystemGamma)); /* allocate for structure */
   1.180 +	
   1.181 +	hGDevice = GetDeviceList ();							/* top of device list */
   1.182 +	do																/* iterate */
   1.183 +	{
   1.184 +		devCount++;													/* count devices					 */
   1.185 +		hGDevice = GetNextDevice (hGDevice);						/* next device */
   1.186 +	} while (hGDevice);
   1.187 +	
   1.188 +	pSysGammaOut->devGamma = (precDeviceGamma *) NewPtr (sizeof (precDeviceGamma) * devCount); /* allocate for array of pointers to device records */
   1.189 +	if (pSysGammaOut)
   1.190 +	{
   1.191 +		pSysGammaOut->numDevices = devCount;						/* stuff count */
   1.192 +		
   1.193 +		devCount = 0;												/* reset iteration */
   1.194 +		hGDevice = GetDeviceList ();
   1.195 +		do
   1.196 +		{
   1.197 +			pSysGammaOut->devGamma [devCount] = (precDeviceGamma) NewPtr (sizeof (recDeviceGamma));	  /* new device record */
   1.198 +			if (pSysGammaOut->devGamma [devCount])					/* if we actually allocated memory */
   1.199 +			{
   1.200 +				pSysGammaOut->devGamma [devCount]->hGD = hGDevice;										  /* stuff handle */
   1.201 +				pSysGammaOut->devGamma [devCount]->pDeviceGamma = (GammaTblPtr)GetDeviceGamma (hGDevice); /* copy gamma table */
   1.202 +			}
   1.203 +			else													/* otherwise dump record on exit */
   1.204 +			 fail = true;
   1.205 +			devCount++;												/* next device */
   1.206 +			hGDevice = GetNextDevice (hGDevice);						
   1.207 +		} while (hGDevice);
   1.208 +	}
   1.209 +	if (!fail)														/* if we did not fail */
   1.210 +		return (Ptr) pSysGammaOut;									/* return pointer to structure */
   1.211 +	else
   1.212 +	{
   1.213 +		DisposeSystemGammas ((Ptr *) &pSysGammaOut);					/* otherwise dump the current structures (dispose does error checking) */
   1.214 +		return NULL;												/* could not complete */
   1.215 +	}
   1.216 +}
   1.217 +
   1.218 +static void RestoreDeviceGamma (GDHandle hGD, Ptr pGammaTable)
   1.219 +{
   1.220 +	VDSetEntryRecord setEntriesRec;
   1.221 +	VDGammaRecord	gameRecRestore;
   1.222 +	CTabHandle      hCTabDeviceColors;
   1.223 +	Ptr				csPtr;
   1.224 +	OSErr			err = noErr;
   1.225 +	
   1.226 +	if (pGammaTable)												/* if we have a table to restore								 */
   1.227 +	{
   1.228 +		gameRecRestore.csGTable = pGammaTable;						/* setup restore record */
   1.229 +		csPtr = (Ptr) &gameRecRestore;
   1.230 +		err = Control((**hGD).gdRefNum, cscSetGamma, (Ptr) &csPtr);	/* restore gamma */
   1.231 +
   1.232 +		if ((noErr == err) && (8 == (**(**hGD).gdPMap).pixelSize))	/* if successful and on an 8 bit device */
   1.233 +		{
   1.234 +			hCTabDeviceColors = (**(**hGD).gdPMap).pmTable;			/* do SetEntries to force CLUT update */
   1.235 +			setEntriesRec.csTable = (ColorSpec *) &(**hCTabDeviceColors).ctTable;
   1.236 +			setEntriesRec.csStart = 0;
   1.237 +			setEntriesRec.csCount = (**hCTabDeviceColors).ctSize;
   1.238 +			csPtr = (Ptr) &setEntriesRec;
   1.239 +			
   1.240 +			err = Control((**hGD).gdRefNum, cscSetEntries, (Ptr) &csPtr); /* SetEntries in CLUT */
   1.241 +		}
   1.242 +	}
   1.243 +}
   1.244 +
   1.245 +static void RestoreSystemGammas (Ptr pSystemGammas)
   1.246 +{
   1.247 +	short i;
   1.248 +	precSystemGamma pSysGammaIn = (precSystemGamma) pSystemGammas;
   1.249 +	if (pSysGammaIn)
   1.250 +		for (i = 0; i < pSysGammaIn->numDevices; i++)			/* for all devices */
   1.251 +			RestoreDeviceGamma (pSysGammaIn->devGamma [i]->hGD, (Ptr) pSysGammaIn->devGamma [i]->pDeviceGamma);	/* restore gamma */
   1.252 +}
   1.253 +
   1.254 +static Ptr CreateEmptyGammaTable (short channels, short entries, short bits)
   1.255 +{
   1.256 +	GammaTblPtr		pTableGammaOut = NULL;
   1.257 +	short			tableSize, dataWidth;
   1.258 +
   1.259 +	dataWidth = (bits + 7) / 8;										/* number of bytes per entry */
   1.260 +	tableSize = sizeof (GammaTbl) + (channels * entries * dataWidth);
   1.261 +	pTableGammaOut = (GammaTblPtr) NewPtrClear (tableSize);			/* allocate new tabel */
   1.262 +
   1.263 +	if (pTableGammaOut)												/* if we successfully allocated */
   1.264 +	{
   1.265 +		pTableGammaOut->gVersion = 0;								/* set parameters based on input */
   1.266 +		pTableGammaOut->gType = 0;
   1.267 +		pTableGammaOut->gFormulaSize = 0;
   1.268 +		pTableGammaOut->gChanCnt = channels;
   1.269 +		pTableGammaOut->gDataCnt = entries;
   1.270 +		pTableGammaOut->gDataWidth = bits;
   1.271 +	}
   1.272 +	return (Ptr)pTableGammaOut;										/* return whatever we allocated */
   1.273 +}
   1.274 +
   1.275 +static Boolean SetDeviceGammaRampGD (GDHandle hGD, Ptr pRamp)
   1.276 +{
   1.277 +	VDSetEntryRecord setEntriesRec;
   1.278 +	VDGammaRecord	gameRecRestore;
   1.279 +	GammaTblPtr		pTableGammaNew;
   1.280 +	GammaTblPtr		pTableGammaCurrent = NULL;
   1.281 +	CTabHandle      hCTabDeviceColors;
   1.282 +	Ptr				csPtr;
   1.283 +	OSErr			err;
   1.284 +	short 			dataBits, entries, channels = 3;						/* force three channels in the gamma table */
   1.285 +	
   1.286 +	if (pRamp)																/* ensure pRamp is allocated */
   1.287 +	{
   1.288 +		err= GetGammaTable (hGD, &pTableGammaCurrent);						/* get pointer to current table */
   1.289 +		if ((noErr == err) && pTableGammaCurrent)
   1.290 +		{
   1.291 +			dataBits = pTableGammaCurrent->gDataWidth;						/* table must have same data width */
   1.292 +			entries = pTableGammaCurrent->gDataCnt;							/* table must be same size */
   1.293 +			pTableGammaNew = (GammaTblPtr) CreateEmptyGammaTable (channels, entries, dataBits); /* our new table */
   1.294 +			if (pTableGammaNew)												/* if successful fill table */
   1.295 +			{	
   1.296 +				unsigned char * pGammaBase = (unsigned char *) &pTableGammaNew->gFormulaData + pTableGammaNew->gFormulaSize; /* base of table */
   1.297 +				if ((256 == entries) && (8 == dataBits)) 						/* simple case: direct mapping */
   1.298 +					BlockMove ((Ptr)pRamp, (Ptr)pGammaBase, channels * entries); /* move everything */
   1.299 +				else														/* tough case handle entry, channel and data size disparities */
   1.300 +				{
   1.301 +					short indexChan, indexEntry;
   1.302 +					short bytesPerEntry = (dataBits + 7) / 8; 				/* size, in bytes, of the device table entries */
   1.303 +					short shiftRightValue = 8 - dataBits;					/* number of right shifts ramp -> device */
   1.304 +					shiftRightValue += ((bytesPerEntry - 1) * 8);  			/* multibyte entries and the need to map a byte at a time most sig. to least sig. */
   1.305 +					for (indexChan = 0; indexChan < channels; indexChan++) /* for all the channels */
   1.306 +						for (indexEntry = 0; indexEntry < entries; indexEntry++) /* for all the entries */
   1.307 +						{
   1.308 +							short currentShift = shiftRightValue;			/* reset current bit shift */
   1.309 +							long temp = *((unsigned char *)pRamp + (indexChan << 8) + (indexEntry << 8) / entries); /* get data from ramp */
   1.310 +							short indexByte;
   1.311 +							for (indexByte = 0; indexByte < bytesPerEntry; indexByte++) /* for all bytes */
   1.312 +							{
   1.313 +								if (currentShift < 0)						/* shift data correctly for current byte */
   1.314 +									*(pGammaBase++) = temp << -currentShift;
   1.315 +								else
   1.316 +									*(pGammaBase++) = temp >> currentShift;
   1.317 +								currentShift -= 8;							/* increment shift to align to next less sig. byte */
   1.318 +							}
   1.319 +						}
   1.320 +				}
   1.321 +				
   1.322 +				/* set gamma */
   1.323 +				gameRecRestore.csGTable = (Ptr) pTableGammaNew;				/* setup restore record */
   1.324 +				csPtr = (Ptr) &gameRecRestore;
   1.325 +				err = Control((**hGD).gdRefNum, cscSetGamma, (Ptr) &csPtr);	/* restore gamma (note, display drivers may delay returning from this until VBL) */
   1.326 +				
   1.327 +				if ((8 == (**(**hGD).gdPMap).pixelSize) && (noErr == err))	/* if successful and on an 8 bit device */
   1.328 +				{
   1.329 +					hCTabDeviceColors = (**(**hGD).gdPMap).pmTable;			/* do SetEntries to force CLUT update */
   1.330 +					setEntriesRec.csTable = (ColorSpec *) &(**hCTabDeviceColors).ctTable;
   1.331 +					setEntriesRec.csStart = 0;
   1.332 +					setEntriesRec.csCount = (**hCTabDeviceColors).ctSize;
   1.333 +					csPtr = (Ptr) &setEntriesRec;
   1.334 +					err = Control((**hGD).gdRefNum, cscSetEntries, (Ptr) &csPtr);	/* SetEntries in CLUT */
   1.335 +				}
   1.336 +				DisposeGammaTable ((Ptr) pTableGammaNew);					/* dump table */
   1.337 +				if (noErr == err)
   1.338 +					return true;
   1.339 +			}
   1.340 +		}
   1.341 +	}
   1.342 +	else																	/* set NULL gamma -> results in linear map */
   1.343 +	{
   1.344 +		gameRecRestore.csGTable = (Ptr) NULL;								/* setup restore record */
   1.345 +		csPtr = (Ptr) &gameRecRestore;
   1.346 +		err = Control((**hGD).gdRefNum, cscSetGamma, (Ptr) &csPtr);			/* restore gamma */
   1.347 +		
   1.348 +		if ((8 == (**(**hGD).gdPMap).pixelSize) && (noErr == err))			/* if successful and on an 8 bit device */
   1.349 +		{
   1.350 +			hCTabDeviceColors = (**(**hGD).gdPMap).pmTable;					/* do SetEntries to force CLUT update */
   1.351 +			setEntriesRec.csTable = (ColorSpec *) &(**hCTabDeviceColors).ctTable;
   1.352 +			setEntriesRec.csStart = 0;
   1.353 +			setEntriesRec.csCount = (**hCTabDeviceColors).ctSize;
   1.354 +			csPtr = (Ptr) &setEntriesRec;
   1.355 +			err = Control((**hGD).gdRefNum, cscSetEntries, (Ptr) &csPtr);	/* SetEntries in CLUT */
   1.356 +		}
   1.357 +		if (noErr == err)
   1.358 +			return true;
   1.359 +	}
   1.360 +	return false;															/* memory allocation or device control failed if we get here */
   1.361 +}
   1.362 +
   1.363 +/* end of ADC Gamma Ramp support code... */
   1.364 +
   1.365 +static Ptr systemGammaPtr;
   1.366 +
   1.367 +void Mac_QuitGamma(_THIS)
   1.368 +{
   1.369 +	if (systemGammaPtr)
   1.370 +	{
   1.371 +		RestoreSystemGammas(systemGammaPtr);
   1.372 +		DisposeSystemGammas(&systemGammaPtr);
   1.373 +	}
   1.374 +}
   1.375 +
   1.376 +static unsigned char shiftedRamp[3 * 256];
   1.377 +
   1.378 +int Mac_SetGammaRamp(_THIS, Uint16 *ramp)
   1.379 +{
   1.380 +	int i;
   1.381 +	if (!systemGammaPtr)
   1.382 +		systemGammaPtr = GetSystemGammas();
   1.383 +	for (i = 0; i < 3 * 256; i++)
   1.384 +	{
   1.385 +		shiftedRamp[i] = ramp[i] >> 8;
   1.386 +	}
   1.387 +
   1.388 +	if (SetDeviceGammaRampGD(GetMainDevice(), (Ptr) shiftedRamp))
   1.389 +		return 0;
   1.390 +	else
   1.391 +		return -1;
   1.392 +}
   1.393 +
   1.394 +int Mac_GetGammaRamp(_THIS, Uint16 *ramp)
   1.395 +{
   1.396 +	if (GetDeviceGammaRampGD(GetMainDevice(), (Ptr) shiftedRamp))
   1.397 +	{
   1.398 +		int i;
   1.399 +		for (i = 0; i < 3 * 256; i++)
   1.400 +		{
   1.401 +			ramp[i] = shiftedRamp[i] << 8;
   1.402 +		}
   1.403 +		return 0;
   1.404 +	}
   1.405 +	else
   1.406 +		return -1;
   1.407 +}
   1.408 +
   1.409 +#endif  /* SDL_MACCLASSIC_GAMMA_SUPPORT */
   1.410 +
   1.411 +
     2.1 --- a/src/video/maccommon/SDL_macwm_c.h	Fri Jun 15 05:41:22 2007 +0000
     2.2 +++ b/src/video/maccommon/SDL_macwm_c.h	Fri Jun 15 06:29:52 2007 +0000
     2.3 @@ -26,3 +26,16 @@
     2.4  /* Functions to be exported */
     2.5  extern void Mac_SetCaption(_THIS, const char *title, const char *icon);
     2.6  
     2.7 +/*
     2.8 + * There's no Carbonized gamma support in Mac OS X, since PBStatusSync() and
     2.9 + *  Control() aren't supported in OS X's Carbonlib. Use the Quartz driver
    2.10 + *  instead.
    2.11 + */
    2.12 +#define SDL_MACCLASSIC_GAMMA_SUPPORT ((defined(__APPLE__) && defined(__MACH__)) == 0)
    2.13 +
    2.14 +#if SDL_MACCLASSIC_GAMMA_SUPPORT
    2.15 +extern void Mac_QuitGamma(_THIS);
    2.16 +extern int Mac_SetGammaRamp(_THIS, Uint16 *ramp);
    2.17 +extern int Mac_GetGammaRamp(_THIS, Uint16 *ramp);
    2.18 +#endif
    2.19 +
     3.1 --- a/src/video/macdsp/SDL_dspvideo.c	Fri Jun 15 05:41:22 2007 +0000
     3.2 +++ b/src/video/macdsp/SDL_dspvideo.c	Fri Jun 15 06:29:52 2007 +0000
     3.3 @@ -297,6 +297,10 @@
     3.4  	device->UnlockHWSurface = DSp_UnlockHWSurface;
     3.5  	device->FlipHWSurface   = DSp_FlipHWSurface;
     3.6  	device->FreeHWSurface   = DSp_FreeHWSurface;
     3.7 +#if SDL_MACCLASSIC_GAMMA_SUPPORT
     3.8 +	device->SetGammaRamp    = Mac_SetGammaRamp;
     3.9 +	device->GetGammaRamp    = Mac_GetGammaRamp;
    3.10 +#endif
    3.11  #if SDL_VIDEO_OPENGL
    3.12  	device->GL_MakeCurrent  = Mac_GL_MakeCurrent;
    3.13  	device->GL_SwapBuffers  = DSp_GL_SwapBuffers;
    3.14 @@ -1381,6 +1385,10 @@
    3.15  	/* Free Palette and restore original */
    3.16  	DSp_DestroyPalette (this);
    3.17  
    3.18 +#if SDL_MACCLASSIC_GAMMA_SUPPORT
    3.19 +	Mac_QuitGamma(this);
    3.20 +#endif
    3.21 +
    3.22  	/* Free list of video modes */
    3.23  	if ( SDL_modelist != NULL ) {
    3.24  		for ( i=0; SDL_modelist[i]; i++ ) {
     4.1 --- a/src/video/macrom/SDL_romvideo.c	Fri Jun 15 05:41:22 2007 +0000
     4.2 +++ b/src/video/macrom/SDL_romvideo.c	Fri Jun 15 06:29:52 2007 +0000
     4.3 @@ -158,6 +158,10 @@
     4.4  	device->UnlockHWSurface = ROM_UnlockHWSurface;
     4.5  	device->FlipHWSurface = NULL;
     4.6  	device->FreeHWSurface = ROM_FreeHWSurface;
     4.7 +#if SDL_MACCLASSIC_GAMMA_SUPPORT
     4.8 +	device->SetGammaRamp = Mac_SetGammaRamp;
     4.9 +	device->GetGammaRamp = Mac_GetGammaRamp;
    4.10 +#endif
    4.11  #if SDL_VIDEO_OPENGL
    4.12  	device->GL_MakeCurrent = Mac_GL_MakeCurrent;
    4.13  	device->GL_SwapBuffers = Mac_GL_SwapBuffers;
    4.14 @@ -725,6 +729,10 @@
    4.15  	}
    4.16  	RestoreDeviceClut(GetMainDevice());
    4.17  
    4.18 +#if SDL_MACCLASSIC_GAMMA_SUPPORT
    4.19 +	Mac_QuitGamma(this);
    4.20 +#endif
    4.21 +
    4.22  	/* Free list of video modes */
    4.23  	if ( SDL_modelist != NULL ) {
    4.24  		for ( i=0; SDL_modelist[i]; ++i ) {