Пример #1
0
void gr_palette_step_up( int r, int g, int b )
{
	int i;
	ubyte *p;
	int temp;
	ColorSpec colors[256];
	GDHandle old_device;
//	PaletteHandle palette;
//	RGBColor color;
//	CTabHandle ctab;

	if (gr_palette_faded_out) return;

	if ( (r==last_r) && (g==last_g) && (b==last_b) ) return;

	last_r = r;
	last_g = g;
	last_b = b;

	p=gr_palette;
//	palette = GetPalette(GameWindow);
	for (i=0; i<256; i++ )	{
		colors[i].value = i;
//		temp = (int)(*p++) + r + gr_palette_gamma;
		temp = (int)(*p++) + r;
		if (temp<0) temp=0;
		else if (temp>63) temp=63;
		colors[i].rgb.red = gr_mac_gamma[temp];
//		temp = (int)(*p++) + g + gr_palette_gamma;
		temp = (int)(*p++) + g;
		if (temp<0) temp=0;
		else if (temp>63) temp=63;
		colors[i].rgb.green = gr_mac_gamma[temp];
//		temp = (int)(*p++) + b + gr_palette_gamma;
		temp = (int)(*p++) + b;
		if (temp<0) temp=0;
		else if (temp>63) temp=63;
		colors[i].rgb.blue = gr_mac_gamma[temp];
//		SetEntryColor(palette, i, &color);
	}
	old_device = GetGDevice();
	SetGDevice(GameMonitor);
	SetEntries(0, 255, colors);
	SetGDevice(old_device);
#if 0
	ctab = (CTabHandle)NewHandle(sizeof(ColorTable));
	Palette2CTab(palette, ctab);
	AnimatePalette(GameWindow, ctab, 0, 0, 256);
	ActivatePalette(GameWindow);
	DisposeHandle((Handle)ctab);

	if (GameGWorld != NULL) {
		ctab = (**GetGWorldPixMap(GameGWorld)).pmTable;	// get the color table for the gWorld.
		CTabChanged(ctab);
		(**ctab).ctSeed = (**(**(*(CGrafPtr)GameWindow).portPixMap).pmTable).ctSeed;
	}
#endif
}
Пример #2
0
void gr_palette_load( ubyte *pal )	
{
	int i, j;
	GDHandle old_device;
	ColorSpec colors[256];
//	PaletteHandle palette;
//	RGBColor color;
//	CTabHandle ctable;

	for (i=0; i<768; i++ ) {
// 		gr_current_pal[i] = pal[i] + gr_palette_gamma;
		gr_current_pal[i] = pal[i];
		if (gr_current_pal[i] > 63) gr_current_pal[i] = 63;
	}
	for (i = 0, j = 0; j < 256; j++) {
		colors[j].value = j;
		colors[j].rgb.red = gr_mac_gamma[gr_current_pal[i++]];
		colors[j].rgb.green = gr_mac_gamma[gr_current_pal[i++]];
		colors[j].rgb.blue = gr_mac_gamma[gr_current_pal[i++]];
	}
	old_device = GetGDevice();
	SetGDevice(GameMonitor);
	SetEntries(0, 255, colors);
	SetGDevice(old_device);

#if 0
	palette = GetPalette(GameWindow);
	for (i = 0; i < 768; i += 3) {
		color.red = gr_current_pal[i] << 9;
		color.green = gr_current_pal[i+1] << 9;
		color.blue = gr_current_pal[i+2] << 9;
		SetEntryColor(palette, i / 3, &color);
	}
	
	ctable = (CTabHandle)NewHandle(sizeof(ColorTable));
	Palette2CTab(palette, ctable);
	AnimatePalette(GameWindow, ctable, 0, 0, 256);
	ActivatePalette(GameWindow);
	
	DisposeHandle((Handle)ctable);

	if (GameGWorld != NULL) {
		ctable = (**GetGWorldPixMap(GameGWorld)).pmTable;	// get the color table for the gWorld.
		CTabChanged(ctable);
		(**ctable).ctSeed = (**(**(*(CGrafPtr)GameWindow).portPixMap).pmTable).ctSeed;
	}
#endif
	gr_palette_faded_out = 0;
	init_computed_colors();
}
Пример #3
0
void gr_palette_clear()
{
	int i;
	ColorSpec colors[256];
	GDHandle old_device;
//	PaletteHandle palette;
//	RGBColor color;
//	CTabHandle ctable;

	for (i = 0; i < 256; i++) {
		colors[i].value = i;
		colors[i].rgb.red = 0;
		colors[i].rgb.green = 0;
		colors[i].rgb.blue = 0;
	}
	old_device = GetGDevice();
	SetGDevice(GameMonitor);
	SetEntries(0, 255, colors);
	SetGDevice(old_device);

#if 0
	palette = GetPalette(GameWindow);
	for (i=0; i<256; i++) {
		color.red = 0x0;
		color.green = 0x0;
		color.blue = 0x0;
		SetEntryColor(palette, i, &color);
	}
	ctable = (CTabHandle)NewHandle(sizeof(ColorTable));
	Palette2CTab(palette, ctable);
	AnimatePalette(GameWindow, ctable, 0, 0, 256);
	ActivatePalette(GameWindow);
	
	DisposeHandle((Handle)ctable);

//  make the seeds match for the gworld clut and the window palette.  I don't know if
//  this is necessary, but it doesn't hurt.

	if (GameGWorld != NULL) {
		ctable = (**GetGWorldPixMap(GameGWorld)).pmTable;
		CTabChanged(ctable);
		(**ctable).ctSeed = (**(**(*(CGrafPtr)GameWindow).portPixMap).pmTable).ctSeed;
	}
#endif
	gr_palette_faded_out = 1;
}
Пример #4
0
void reset_debug_video_mode()
{
	ColorSpec color[2];
	GDHandle old_device;
	
	color[0].value = 255;
	color[0].rgb.red =  0xffff;
	color[0].rgb.blue = 0xffff;
	color[0].rgb.green = 0xffff;
	color[1].value = 0;
	color[1].rgb.red =  0x0;
	color[1].rgb.blue = 0x0;
	color[1].rgb.green = 0x0;
	SetGDevice(GameMonitor);
	old_device = GetGDevice();
	SetEntries(-1, 1, color);
	SetGDevice(old_device);
	gr_debug_mode = 0;
}
Пример #5
0
static int ROM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{
	CTabHandle cTab;
	int i;

	/* Get the colortable from the either the display or window */
	if ( (this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
		cTab = (**(**SDL_Display).gdPMap).pmTable;
	} else {
		cTab = SDL_CTab;
	}

	/* Verify the range of colors */
	if ( (firstcolor+ncolors) > ((**cTab).ctSize+1) ) {
		return(0);
	}
	
	/* Set the screen palette and update the display */
	for ( i=0; i< ncolors; ++i ) {
	        int j = firstcolor + i;
		(**cTab).ctTable[j].value = j;
		(**cTab).ctTable[j].rgb.red = colors[i].r << 8 | colors[i].r;
		(**cTab).ctTable[j].rgb.green = colors[i].g << 8 | colors[i].g;
		(**cTab).ctTable[j].rgb.blue = colors[i].b << 8 | colors[i].b;
	}

#if 0
	if ( (this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN )
#endif
	{
		GDevice **odisplay;
		odisplay = GetGDevice();
		SetGDevice(SDL_Display);
		SetEntries(0, (**cTab).ctSize, (ColorSpec *)&(**cTab).ctTable);
		SetGDevice(odisplay);
	}
	return(1);
}
Пример #6
0
/* ----------------------------------------------------------------------------
   tbitShutdown 
   Terminate TPS off-screen bitmap subsystem at shutdown. 
   Returns nothing.                
   ---------------------------------------------------------------------------- */
TPSAPI_DECLP( void )  tbitShutdown (void)
{
sWORD				i;
PixMapHandle 	hPixMap; 

	for (i = 0; i < _NrTPorts; i++)
	{
		if (_TPorts[i].pPort != nil)
		{
			SetPort((GrafPtr)_TPorts[i].pPort);
			SetPortPix(_TPorts[i].hOldPixMap);
			CloseCPort(_TPorts[i].pPort);
		}
	}
	tmemFreeNativePtr(_TPorts);
	_TPorts = nil;
	_NrTPorts = 0;
    if (_hTBitDevice != nil)
    {
    	hPixMap = (**_hTBitDevice).gdPMap;
    	if (hPixMap != nil)  
    	{
    		if ((**hPixMap).pmTable != nil)  
            	DisposCTable((**hPixMap).pmTable);
    		if ((**hPixMap).baseAddr != nil)  
            	DisposHandle((Handle)(**hPixMap).baseAddr);
        	DisposHandle((Handle)hPixMap);
    	}
    	if ((**_hTBitDevice).gdITable != nil)
        	DisposHandle((Handle)(**_hTBitDevice).gdITable);
        DisposHandle((Handle)_hTBitDevice);
		_hTBitDevice = nil;
    }
    if (_hColorTable != nil)
		DisposCTable(_hColorTable);
    _hColorTable = nil;
	TpsAssertW((_NrAllocBitmap == 0), "Internal bipmaps not freed by application!", &_NrAllocBitmap, 1);
	SetGDevice(_hStartupDevice);
	SetPort(_pStartupPort);
}
Пример #7
0
/* ----------------------------------------------------------------------------
   tbitStartup 
   Initialize TPS off-screen bitmap subsystem at startup. 
   Returns error code indicating success.                
   ---------------------------------------------------------------------------- */
TPSAPI_DECLP( BOOLEAN )  tbitStartup (uWORD NrPorts, uWORD depth, HNATIVE hColor)
{
sWORD				i;
Rect				Bounds;
OSErr				osError = noErr; 
SignedByte			saveState; 
PixMapHandle 		hPixMap = nil;						// handle to new off-screen PixMap 
short				bytesPerRow; 						// bytes per row in PixMap 

	fHasColorQuickdraw = tsysMacHasCQD(true);
/**  validations/initializations  **/
	TpsAssert((_TPorts == nil), "Bitmap subsystem was already been started up!");
	TpsAssert((hColor != nil), "Bitmap subsystem color table must be provided!");
	TpsAssert(tsysMacHasSys7(), "System 7 or greater required!");
	TpsAssert(fHasColorQuickdraw, "32Bit Color QuickDraw required!");
	TpsAssert(tsysMacHasGWorlds(), "QuickDraw Color GWorlds required!");
	GetPort(&_pStartupPort);
	_hStartupDevice = GetGDevice();

/**  clone the clut (to be used throughout)  **/
    saveState = HGetState((Handle)hColor);				// save color tableÕs current state
    HNoPurge((Handle)hColor);							// make sure it isnÕt purgeable 
    _hColorTable = (CTabHandle)hColor;
    osError = HandToHand((Handle *)&_hColorTable);
    HSetState((Handle)hColor, saveState);				// restore color tableÕs state
    if (osError != noErr)
	{
//		terrSetErrorCode(TERR_TMEMSECTION, TMEM_ERRALLOC);
		return FALSE;
	}

/**  create device (to be used throughout)  **/
	//SetRect(&Bounds, 0, 0, 1, 1);
	Bounds.left = 0;
	Bounds.top = 0;
	Bounds.right = 1;
	Bounds.bottom = 1;

	bytesPerRow = 16;									// 16 byte align rowbytes
    if ((hPixMap = (PixMapHandle)NewHandleClear(sizeof(PixMap))) == nil)
		goto Failure;
	if (_SetUpPixMap(depth, &Bounds, _hColorTable, bytesPerRow, hPixMap) != noErr)
		goto Failure;
    if ((_hTBitDevice = (GDHandle)NewHandleClear(sizeof(GDevice))) == nil)
		goto Failure;
	if (_CreateGDevice(hPixMap, _hTBitDevice) != noErr)
		goto Failure;

/**  create internal port list  **/
	if ((_TPorts = (TBitPort *)NewPtrClear(sizeof(TBitPort) * (NrPorts + 1))) == nil)
		goto Failure;
	
/**  create pool of off-screen ports  **/
	//SetRect(&Bounds, 0, 0, 1, 1);
	Bounds.left = 0;
	Bounds.top = 0;
	Bounds.right = 1;
	Bounds.bottom = 1;

	for (i = 0; i < NrPorts; i++)
	{
		if ((_TPorts[i].pPort = (CGrafPtr)NewPtrClear(sizeof(CGrafPort))) == nil)
			goto Failure;
	    OpenCPort(_TPorts[i].pPort); 
		_TPorts[i].hOldPixMap = (_TPorts[i].pPort)->portPixMap;
		SetPortPix(nil);
	}

/**  clean up and out  **/
	SetPort(_pStartupPort);
	SetGDevice(_hStartupDevice);
	_NrTPorts = NrPorts; 
	return TRUE;

Failure:
    if (hPixMap != nil)  
    {
    	if ((**hPixMap).pmTable != nil)  
            DisposCTable((**hPixMap).pmTable);
    	if ((**hPixMap).baseAddr != nil)  
            DisposHandle((Handle)(**hPixMap).baseAddr);
        DisposHandle((Handle)hPixMap);
    }
    if (_hTBitDevice != nil)
    {
    	if ((**_hTBitDevice).gdITable != nil)
			DisposHandle((Handle)(**_hTBitDevice).gdITable);
        DisposHandle((Handle)_hTBitDevice);
		_hTBitDevice = nil;
    }
	if (_TPorts != nil)
	{
		for (i = 0; i < NrPorts; i++)
		{
			if (_TPorts[i].pPort != nil)
			{
				SetPort((GrafPtr)_TPorts[i].pPort);
				SetPortPix(_TPorts[i].hOldPixMap);
				CloseCPort(_TPorts[i].pPort);
			}
		}
		tmemFreeNativePtr(_TPorts);
		_TPorts = nil;
	}
    if (_hColorTable != nil)
		DisposCTable(_hColorTable);
	SetGDevice(_hStartupDevice);
	SetPort(_pStartupPort);
//	terrSetErrorCode(TERR_TMEMSECTION, TMEM_ERRALLOC);
	return FALSE;
}
Пример #8
0
int gr_palette_fade_in(ubyte *pal, int nsteps, int allow_keys)	
{
	int i,j, k;
	ubyte c;
	fix fade_palette[768];
	fix fade_palette_delta[768];
	ColorSpec colors[256];
	GDHandle old_device;
//	PaletteHandle palette;
//	RGBColor color;
//	CTabHandle ctable;

	allow_keys  = allow_keys;

	if (!gr_palette_faded_out) return 0;

//	palette = GetPalette(GameWindow);

	for (i=0; i<768; i++ )	{
		gr_current_pal[i] = pal[i];
		fade_palette[i] = 0;
		fade_palette_delta[i] = i2f(pal[i]) / nsteps;
	}

	for (j=0; j<nsteps; j++ )	{
		for (i=0, k = 0; k<256; k++ )	{
			colors[k].value = k;
			fade_palette[i] += fade_palette_delta[i];
			if (fade_palette[i] > i2f(pal[i]) )
				fade_palette[i] = i2f(pal[i]);
//			c = f2i(fade_palette[i])+gr_palette_gamma;
			c = f2i(fade_palette[i]);
			if (c > 63) c = 63;
			colors[k].rgb.red = gr_mac_gamma[c];
			i++;
			fade_palette[i] += fade_palette_delta[i];
			if (fade_palette[i] > i2f(pal[i]) )
				fade_palette[i] = i2f(pal[i]);
//			c = f2i(fade_palette[i])+gr_palette_gamma;
			c = f2i(fade_palette[i]);
			if (c > 63) c = 63;
			colors[k].rgb.green = gr_mac_gamma[c];
			i++;
			fade_palette[i] += fade_palette_delta[i];
			if (fade_palette[i] > i2f(pal[i]) )
				fade_palette[i] = i2f(pal[i]);
//			c = f2i(fade_palette[i])+gr_palette_gamma;
			c = f2i(fade_palette[i]);
			if (c > 63) c = 63;
			colors[k].rgb.blue = gr_mac_gamma[c];
			i++;
		}
		old_device = GetGDevice();
		SetGDevice(GameMonitor);
		SetEntries(0, 255, colors);
		SetGDevice(old_device);
	}

#if 0
	for (i=0; i<768; i++ )	{
		gr_current_pal[i] = pal[i];
		fade_palette[i] = 0;
		fade_palette_delta[i] = i2f(pal[i]) / nsteps;
	}

	for (j=0; j<nsteps; j++ )	{
		for (i=0; i<768;  )	{
			fade_palette[i] += fade_palette_delta[i];
			if (fade_palette[i] > i2f(pal[i]) )
				fade_palette[i] = i2f(pal[i]);
			c = f2i(fade_palette[i])+gr_palette_gamma;
			if (c > 63) c = 63;
			color.red = c << 9;
			i++;
			fade_palette[i] += fade_palette_delta[i];
			if (fade_palette[i] > i2f(pal[i]) )
				fade_palette[i] = i2f(pal[i]);
			c = f2i(fade_palette[i])+gr_palette_gamma;
			if (c > 63) c = 63;
			color.green = c << 9;
			i++;
			fade_palette[i] += fade_palette_delta[i];
			if (fade_palette[i] > i2f(pal[i]) )
				fade_palette[i] = i2f(pal[i]);
			c = f2i(fade_palette[i])+gr_palette_gamma;
			if (c > 63) c = 63;
			color.blue = c << 9;
			i++;
			SetEntryColor(palette, (i / 3) - 1, &color);
		}
		ctable = (CTabHandle)NewHandle(sizeof(ColorTable));
		Palette2CTab(palette, ctable);
		AnimatePalette(GameWindow, ctable, 0, 0, 256);
		ActivatePalette(GameWindow);
		
		DisposeHandle((Handle)ctable);
	}
#endif
	gr_palette_faded_out = 0;
	return 0;
}