Esempio n. 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
}
Esempio n. 2
0
File: MacGraph.c Progetto: rolk/ug
static void MacSetPaletteEntry (long index, short r, short g, short b)
{
  RGBColor newColor;
  PaletteHandle myPalette;

  myPalette = GetPalette(MAC_WIN(currgw));
  newColor.red = 2*r;
  newColor.green = 2*g;
  newColor.blue = 2*b;
  SetEntryColor(myPalette,(short) index,&newColor);
  ActivatePalette(MAC_WIN(currgw));
}
Esempio n. 3
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();
}
Esempio n. 4
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;
}
Esempio n. 5
0
File: MacGraph.c Progetto: rolk/ug
static void MacSetNewPalette (long start, long count, short *r, short *g, short *b)
{
  RGBColor newColor;
  PaletteHandle myPalette;
  long i;

  myPalette = GetPalette(MAC_WIN(currgw));
  assert(myPalette!=NULL);
  for (i=start; i<start+count; i++)
  {
    newColor.red = r[i];
    newColor.green = g[i];
    newColor.blue = b[i];
    SetEntryColor(myPalette,(short) i,&newColor);
  }
  ActivatePalette(MAC_WIN(currgw));
}
Esempio n. 6
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;
}
Esempio n. 7
0
static SDL_Surface *ROM_SetVideoMode(_THIS, SDL_Surface *current,
				int width, int height, int bpp, Uint32 flags)
{
	Rect wrect, orect;
#if TARGET_API_MAC_CARBON
	Rect tmprect;
#endif

	/* Free any previous video mode */
	ROM_UnsetVideoMode(this, current);

	/* Create the ROM window and SDL video surface */
	current->flags = 0;		/* Clear flags */
	current->w = width;
	current->h = height;
	SetRect(&wrect, 0, 0, width, height);
	if ( SDL_Window ) {
		/* If we recreate the window, don't move it around */
#if TARGET_API_MAC_CARBON
		orect = *GetWindowPortBounds(SDL_Window, &tmprect);
#else
		orect = SDL_Window->portRect;
#endif
		OffsetRect(&wrect, orect.left, orect.top);
	} else {
		/* Center the window the first time we show it */
		OffsetRect(&wrect,
		(SDL_modelist[0]->w-width)/2, (SDL_modelist[0]->h-height)/2);
	}

#if defined(__MACOSX__) && !USE_QUICKTIME
	/* Hum.. fullscreen mode is broken */
	flags &= ~SDL_FULLSCREEN;
#endif
	if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
		/* Create the fullscreen window and use screen bits */
		current->flags |= SDL_HWSURFACE|SDL_FULLSCREEN;
		if ( SDL_Window ) {
			DisposeWindow(SDL_Window);
		}
#if USE_QUICKTIME
		BeginFullScreen(&fullscreen_ctx, nil, 0,0, &SDL_Window, nil, 0);
#else
		SDL_Window = NewCWindow(nil, &wrect, "\p", true, plainDBox,
						(WindowPtr)-1, false, 0);
		ROM_HideMenuBar(this);
#endif
		current->pitch = (**(**SDL_Display).gdPMap).rowBytes & 0x3FFF;
		current->pixels = (**(**SDL_Display).gdPMap).baseAddr;
		this->UpdateRects = ROM_DirectUpdate;
	} else {
		GWorldPtr memworld;
		PixMapHandle pixmap;
		int style;

		style = noGrowDocProc;
		if ( flags & SDL_NOFRAME ) {
			style = plainDBox;
			current->flags |= SDL_NOFRAME;
		} else
		if ( flags & SDL_RESIZABLE ) {
			style = zoomDocProc;
			current->flags |= SDL_RESIZABLE;
		}
		if ( SDL_Window && (style == current_style) ) {
			/* Resize existing window, if necessary */
			if ( ((orect.right-orect.left) != width) ||
			     ((orect.bottom-orect.top) != height) ) {
				SizeWindow(SDL_Window, width, height, false);
			}
		} else {
			/* Recreate the window in the new style */
			if ( SDL_Window ) {
				DisposeWindow(SDL_Window);
			}
			SDL_Window = NewCWindow(nil, &wrect, "\p", true,
			                        style, (WindowPtr)-1, true, 0);

			/* Set the window title, if any */
			{ char *title;
				SDL_WM_GetCaption(&title, NULL);
				if ( title ) {
					Mac_SetCaption(this, title, NULL);
				}
			}
		}
		current_style = style;
		SetPalette(SDL_Window, SDL_CPal, false);
		ActivatePalette(SDL_Window);
		if ( NewGWorld(&memworld, 0,
#if TARGET_API_MAC_CARBON
			       GetWindowPortBounds(SDL_Window, &tmprect),
#else
			       &SDL_Window->portRect,
#endif
			       SDL_CTab, nil, 0) != noErr ) {
			SDL_SetError("NewGWorld() failed");
			return(NULL);
		}
		SetWRefCon(SDL_Window, (long)memworld);
		pixmap = GetGWorldPixMap(memworld);
		LockPixels(pixmap);
		current->pitch = (**pixmap).rowBytes & 0x3FFF;
		current->pixels = GetPixBaseAddr(pixmap);
		this->UpdateRects = ROM_WindowUpdate;
	}
	SetPortWindowPort(SDL_Window);
	SelectWindow(SDL_Window);

	/* Handle OpenGL support */
	if ( flags & SDL_OPENGL ) {
		if ( Mac_GL_Init(this) == 0 ) {
			current->flags |= SDL_OPENGL;
		} else {
			current = NULL;
		}
	}
	
	if ( (flags & SDL_HWPALETTE) && (flags & SDL_FULLSCREEN) )
	   current->flags |= SDL_HWPALETTE;
	   
	/* We're live! */
	return(current);
}
Esempio n. 8
0
File: ugView.c Progetto: rolk/ug
static int RasterizeFile (FILE *stream, AWindowRecord *myWindow, short wx, short wy)
{
  char *buffer;                                                 /* input buffer						*/
  long blockSize;                                               /* METABUFFERSIZE					*/
  long blockUsed;                                               /* actual buffer size used			*/
  long itemCounter;                                             /* number of commands in buffer		*/
  char *data;                                                           /* data pointer in buffer			*/
  short fx,fy;                                                  /* file screen size					*/
  Fixed sx,sy;                                                  /* scaling factors					*/
  int i,error,j,size;
  char opCode;
  short x,y,r,g,b,n,lw,ts,m,ms,w;
  short x1,y1,x2,y2;
  short xx[SIZE],yy[SIZE];
  PolyHandle myPoly;
  char s[CSIZE];
  unsigned char c;
  RGBColor newColor;
  PaletteHandle myPalette;
  long l;

  /* get file parameters */
  rewind(stream);
  error = fread(&blockSize,4,1,stream); if (error!=1) return(1);       /* block size */
  error = fread(&fx,2,1,stream);            if (error!=1) return(1);       /* x size */
  error = fread(&fy,2,1,stream);        if (error!=1) return(1);       /* y size */

  /* compute scaling factors */
  sx = FixRatio(wx-1,fx-1);
  sy = FixRatio(wy-1,fy-1);

  /* default values */
  lw = 1;
  ts = 12;
  m = 0;
  ms = 6;

  /* allocate input buffer */
  buffer = malloc(blockSize);
  if (buffer==NULL) return(1);

  SetPort((GrafPtr)(myWindow->theWindow));
  EraseRect(&(myWindow->usableRect));

  /* loop through the blocks */
  while (!feof(stream))
  {
    /* read block parameters */
    error = fread(&blockUsed,4,1,stream);    if (error!=1) {free(buffer); return(1);}
    error = fread(&itemCounter,4,1,stream);  if (error!=1) {free(buffer); return(1);}
    error = fread(buffer,blockUsed,1,stream);if (error!=1) {free(buffer); return(1);}

    /* init pointer to next item */
    data = buffer;

    /* for all items */
    for (i=0; i<itemCounter; i++)
    {
      /* get op code */
      opCode = *(data++);

      switch (opCode)
      {
      case opMove :
        x = *((short *)data);
        data += 2;
        y = *((short *)data);
        data += 2;
        TRFMX(x);
        TRFMY(y);
        MoveTo(x,y);
        break;

      case opDraw :
        x = *((short *)data);
        data += 2;
        y = *((short *)data);
        data += 2;
        TRFMX(x);
        TRFMY(y);
        LineTo(x,y);
        break;

      case opPolyline :
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        MoveTo(xx[0],yy[0]);
        for (j=1; j<n; j++) LineTo(xx[j],yy[j]);
        break;

      case opPolygon :
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        if (n<3) break;
        myPoly = OpenPoly();
        MoveTo(xx[0],yy[0]);
        for (j=1; j<n; j++) LineTo(xx[j],yy[j]);
        LineTo(xx[0],yy[0]);
        ClosePoly();
        PaintPoly(myPoly);
        FramePoly(myPoly);
        KillPoly(myPoly);
        break;

      case opPolymark :
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        for (j=0; j<n; j++) Marker(m,ms,xx[j],yy[j]);
        break;

      case opText :
        n = *((short *)data);
        data += 2;
        if (n>=CSIZE-1) {free(buffer); return(2);}
        memcpy(s,data,n);
        s[n] = 0;
        data += n;
        DrawString((ConstStr255Param)c2pstr(s));
        break;

      case opCenteredText :
        x = *((short *)data);
        data += 2;
        y = *((short *)data);
        data += 2;
        TRFMX(x);
        TRFMY(y);
        n = *((short *)data);
        data += 2;
        if (n>=CSIZE-1) {free(buffer); return(2);}
        memcpy(s,data,n);
        s[n] = 0;
        data += n;
        c2pstr(s);
        w = StringWidth((ConstStr255Param)s);
        MoveTo(x-w/2,y+ts/2);
        DrawString((ConstStr255Param)s);
        break;

      case opSetLineWidth :
        n = *((short *)data);
        data += 2;
        lw = n;
        PenSize(n,n);
        break;

      case opSetTextSize :
        n = *((short *)data);
        data += 2;
        ts = n;
        TextSize(n);
        break;

      case opSetMarker :
        n = *((short *)data);
        data += 2;
        m = n;
        break;

      case opSetMarkerSize :
        n = *((short *)data);
        data += 2;
        ms = n;
        break;

      case opSetColor :
        c = *((unsigned char *)data);
        data++;
        PmForeColor((short)c);
        break;

      case opSetEntry :
        c = *((unsigned char *)data);
        data++;
        r = (short) (*((unsigned char *)data));
        data++;
        g = (short) (*((unsigned char *)data));
        data++;
        b = (short) (*((unsigned char *)data));
        data++;
        myPalette = GetPalette(myWindow->theWindow);
        myWindow->red[c]   = newColor.red   = r<<8;
        myWindow->green[c] = newColor.green = g<<8;
        myWindow->blue[c]  = newColor.blue  = b<<8;
        SetEntryColor(myPalette,(short) c,&newColor);
        ActivatePalette(myWindow->theWindow);
        break;

      case opSetPalette :
        x = (short) (*((unsigned char *)data));
        data++;
        y = (short) (*((unsigned char *)data));
        data++;
        myPalette = GetPalette(myWindow->theWindow);
        for (j=x; j<=y; j++)
        {
          r = (short) (*((unsigned char *)data));
          data++;
          g = (short) (*((unsigned char *)data));
          data++;
          b = (short) (*((unsigned char *)data));
          data++;
          myWindow->red[j]   = newColor.red   = r<<8;
          myWindow->green[j] = newColor.green = g<<8;
          myWindow->blue[j]  = newColor.blue  = b<<8;
          SetEntryColor(myPalette,(short) j,&newColor);
        }
        ActivatePalette(myWindow->theWindow);
        break;

      case opNewLine :
        lw = *((unsigned char *)data);
        data++;
        c = *((unsigned char *)data);
        data++;
        x1 = *((short *)data);
        data += 2;
        y1 = *((short *)data);
        data += 2;
        x2 = *((short *)data);
        data += 2;
        y2 = *((short *)data);
        data += 2;
        TRFMX(x1);
        TRFMY(y1);
        TRFMX(x2);
        TRFMY(y2);
        PenSize(lw,lw);
        PmForeColor((short)c);
        MoveTo(x1,y1);
        LineTo(x2,y2);
        break;

      case opNewPolyline :
        lw = *((unsigned char *)data);
        data++;
        c = *((unsigned char *)data);
        data++;
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        PenSize(lw,lw);
        PmForeColor((short)c);
        MoveTo(xx[0],yy[0]);
        for (j=1; j<n; j++) LineTo(xx[j],yy[j]);
        break;

      case opNewPolygon :
        c = *((unsigned char *)data);
        data++;
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        if (n<3) break;
        PmForeColor((short)c);
        myPoly = OpenPoly();
        MoveTo(xx[0],yy[0]);
        for (j=1; j<n; j++) LineTo(xx[j],yy[j]);
        LineTo(xx[0],yy[0]);
        ClosePoly();
        PaintPoly(myPoly);
        FramePoly(myPoly);
        KillPoly(myPoly);
        break;

      case opNewPolymark :
        m = *((unsigned char *)data);
        data++;
        ms = *((unsigned char *)data);
        data++;
        c = *((unsigned char *)data);
        data++;
        n = *((short *)data);
        data += 2;
        if (n>=SIZE) {free(buffer); return(2);}
        size = n<<1;
        memcpy(xx,data,size);
        data += size;
        memcpy(yy,data,size);
        data += size;
        for (j=0; j<n; j++)
        {
          TRFMX(xx[j]);
          TRFMY(yy[j]);
        }
        PmForeColor((short)c);
        for (j=0; j<n; j++) Marker(m,ms,xx[j],yy[j]);
        break;

      case opNewText :
        ts = *((unsigned char *)data);
        data++;
        c = *((unsigned char *)data);
        data++;
        x = *((short *)data);
        data += 2;
        y = *((short *)data);
        data += 2;
        TRFMX(x);
        TRFMY(y);
        n = *((short *)data);
        data += 2;
        if (n>=CSIZE-1) {free(buffer); return(2);}
        memcpy(s,data,n);
        s[n] = 0;
        data += n;
        MoveTo(x,y);
        TextSize(ts);
        PmForeColor((short)c);
        DrawString((ConstStr255Param)c2pstr(s));
        break;

      case opNewCenteredText :
        ts = *((unsigned char *)data);
        data++;
        c = *((unsigned char *)data);
        data++;
        x = *((short *)data);
        data += 2;
        y = *((short *)data);
        data += 2;
        TRFMX(x);
        TRFMY(y);
        n = *((short *)data);
        data += 2;
        if (n>=CSIZE-1) {free(buffer); return(2);}
        memcpy(s,data,n);
        s[n] = 0;
        data += n;
        c2pstr(s);
        w = StringWidth((ConstStr255Param)s);
        TextSize(ts);
        PmForeColor((short)c);
        MoveTo(x-w/2,y+ts/2);
        DrawString((ConstStr255Param)c2pstr(s));
        break;

      default :
        break;
      }
    }
  }

  return(0);
}