⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdl_macwm.c

📁 SDL库 在进行视频显示程序spcaview安装时必须的库文件
💻 C
📖 第 1 页 / 共 2 页
字号:
				devCount = 0;												/* reset iteration */		hGDevice = GetDeviceList ();		do		{			pSysGammaOut->devGamma [devCount] = (precDeviceGamma) NewPtr (sizeof (recDeviceGamma));	  /* new device record */			if (pSysGammaOut->devGamma [devCount])					/* if we actually allocated memory */			{				pSysGammaOut->devGamma [devCount]->hGD = hGDevice;										  /* stuff handle */				pSysGammaOut->devGamma [devCount]->pDeviceGamma = (GammaTblPtr)GetDeviceGamma (hGDevice); /* copy gamma table */			}			else													/* otherwise dump record on exit */			 fail = true;			devCount++;												/* next device */			hGDevice = GetNextDevice (hGDevice);								} while (hGDevice);	}	if (!fail)														/* if we did not fail */		return (Ptr) pSysGammaOut;									/* return pointer to structure */	else	{		DisposeSystemGammas ((Ptr *) &pSysGammaOut);					/* otherwise dump the current structures (dispose does error checking) */		return NULL;												/* could not complete */	}}static void RestoreDeviceGamma (GDHandle hGD, Ptr pGammaTable){	VDSetEntryRecord setEntriesRec;	VDGammaRecord	gameRecRestore;	CTabHandle      hCTabDeviceColors;	Ptr				csPtr;	OSErr			err = noErr;		if (pGammaTable)												/* if we have a table to restore								 */	{		gameRecRestore.csGTable = pGammaTable;						/* setup restore record */		csPtr = (Ptr) &gameRecRestore;		err = Control((**hGD).gdRefNum, cscSetGamma, (Ptr) &csPtr);	/* restore gamma */		if ((noErr == err) && (8 == (**(**hGD).gdPMap).pixelSize))	/* if successful and on an 8 bit device */		{			hCTabDeviceColors = (**(**hGD).gdPMap).pmTable;			/* do SetEntries to force CLUT update */			setEntriesRec.csTable = (ColorSpec *) &(**hCTabDeviceColors).ctTable;			setEntriesRec.csStart = 0;			setEntriesRec.csCount = (**hCTabDeviceColors).ctSize;			csPtr = (Ptr) &setEntriesRec;						err = Control((**hGD).gdRefNum, cscSetEntries, (Ptr) &csPtr); /* SetEntries in CLUT */		}	}}static void RestoreSystemGammas (Ptr pSystemGammas){	short i;	precSystemGamma pSysGammaIn = (precSystemGamma) pSystemGammas;	if (pSysGammaIn)		for (i = 0; i < pSysGammaIn->numDevices; i++)			/* for all devices */			RestoreDeviceGamma (pSysGammaIn->devGamma [i]->hGD, (Ptr) pSysGammaIn->devGamma [i]->pDeviceGamma);	/* restore gamma */}static Ptr CreateEmptyGammaTable (short channels, short entries, short bits){	GammaTblPtr		pTableGammaOut = NULL;	short			tableSize, dataWidth;	dataWidth = (bits + 7) / 8;										/* number of bytes per entry */	tableSize = sizeof (GammaTbl) + (channels * entries * dataWidth);	pTableGammaOut = (GammaTblPtr) NewPtrClear (tableSize);			/* allocate new tabel */	if (pTableGammaOut)												/* if we successfully allocated */	{		pTableGammaOut->gVersion = 0;								/* set parameters based on input */		pTableGammaOut->gType = 0;		pTableGammaOut->gFormulaSize = 0;		pTableGammaOut->gChanCnt = channels;		pTableGammaOut->gDataCnt = entries;		pTableGammaOut->gDataWidth = bits;	}	return (Ptr)pTableGammaOut;										/* return whatever we allocated */}static Boolean SetDeviceGammaRampGD (GDHandle hGD, Ptr pRamp){	VDSetEntryRecord setEntriesRec;	VDGammaRecord	gameRecRestore;	GammaTblPtr		pTableGammaNew;	GammaTblPtr		pTableGammaCurrent = NULL;	CTabHandle      hCTabDeviceColors;	Ptr				csPtr;	OSErr			err;	short 			dataBits, entries, channels = 3;						/* force three channels in the gamma table */		if (pRamp)																/* ensure pRamp is allocated */	{		err= GetGammaTable (hGD, &pTableGammaCurrent);						/* get pointer to current table */		if ((noErr == err) && pTableGammaCurrent)		{			dataBits = pTableGammaCurrent->gDataWidth;						/* table must have same data width */			entries = pTableGammaCurrent->gDataCnt;							/* table must be same size */			pTableGammaNew = (GammaTblPtr) CreateEmptyGammaTable (channels, entries, dataBits); /* our new table */			if (pTableGammaNew)												/* if successful fill table */			{					unsigned char * pGammaBase = (unsigned char *) &pTableGammaNew->gFormulaData + pTableGammaNew->gFormulaSize; /* base of table */				if ((256 == entries) && (8 == dataBits)) 						/* simple case: direct mapping */					BlockMove ((Ptr)pRamp, (Ptr)pGammaBase, channels * entries); /* move everything */				else														/* tough case handle entry, channel and data size disparities */				{					short indexChan, indexEntry;					short bytesPerEntry = (dataBits + 7) / 8; 				/* size, in bytes, of the device table entries */					short shiftRightValue = 8 - dataBits;					/* number of right shifts ramp -> device */					shiftRightValue += ((bytesPerEntry - 1) * 8);  			/* multibyte entries and the need to map a byte at a time most sig. to least sig. */					for (indexChan = 0; indexChan < channels; indexChan++) /* for all the channels */						for (indexEntry = 0; indexEntry < entries; indexEntry++) /* for all the entries */						{							short currentShift = shiftRightValue;			/* reset current bit shift */							long temp = *((unsigned char *)pRamp + (indexChan << 8) + (indexEntry << 8) / entries); /* get data from ramp */							short indexByte;							for (indexByte = 0; indexByte < bytesPerEntry; indexByte++) /* for all bytes */							{								if (currentShift < 0)						/* shift data correctly for current byte */									*(pGammaBase++) = temp << -currentShift;								else									*(pGammaBase++) = temp >> currentShift;								currentShift -= 8;							/* increment shift to align to next less sig. byte */							}						}				}								/* set gamma */				gameRecRestore.csGTable = (Ptr) pTableGammaNew;				/* setup restore record */				csPtr = (Ptr) &gameRecRestore;				err = Control((**hGD).gdRefNum, cscSetGamma, (Ptr) &csPtr);	/* restore gamma (note, display drivers may delay returning from this until VBL) */								if ((8 == (**(**hGD).gdPMap).pixelSize) && (noErr == err))	/* if successful and on an 8 bit device */				{					hCTabDeviceColors = (**(**hGD).gdPMap).pmTable;			/* do SetEntries to force CLUT update */					setEntriesRec.csTable = (ColorSpec *) &(**hCTabDeviceColors).ctTable;					setEntriesRec.csStart = 0;					setEntriesRec.csCount = (**hCTabDeviceColors).ctSize;					csPtr = (Ptr) &setEntriesRec;					err = Control((**hGD).gdRefNum, cscSetEntries, (Ptr) &csPtr);	/* SetEntries in CLUT */				}				DisposeGammaTable ((Ptr) pTableGammaNew);					/* dump table */				if (noErr == err)					return true;			}		}	}	else																	/* set NULL gamma -> results in linear map */	{		gameRecRestore.csGTable = (Ptr) NULL;								/* setup restore record */		csPtr = (Ptr) &gameRecRestore;		err = Control((**hGD).gdRefNum, cscSetGamma, (Ptr) &csPtr);			/* restore gamma */				if ((8 == (**(**hGD).gdPMap).pixelSize) && (noErr == err))			/* if successful and on an 8 bit device */		{			hCTabDeviceColors = (**(**hGD).gdPMap).pmTable;					/* do SetEntries to force CLUT update */			setEntriesRec.csTable = (ColorSpec *) &(**hCTabDeviceColors).ctTable;			setEntriesRec.csStart = 0;			setEntriesRec.csCount = (**hCTabDeviceColors).ctSize;			csPtr = (Ptr) &setEntriesRec;			err = Control((**hGD).gdRefNum, cscSetEntries, (Ptr) &csPtr);	/* SetEntries in CLUT */		}		if (noErr == err)			return true;	}	return false;															/* memory allocation or device control failed if we get here */}/* end of ADC Gamma Ramp support code... */static Ptr systemGammaPtr;void Mac_QuitGamma(_THIS){	if (systemGammaPtr)	{		RestoreSystemGammas(systemGammaPtr);		DisposeSystemGammas(&systemGammaPtr);	}}static unsigned char shiftedRamp[3 * 256];int Mac_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 Mac_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;}#endif  /* SDL_MACCLASSIC_GAMMA_SUPPORT */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -