src/video/photon/SDL_ph_video.c
author Sam Lantinga <slouken@lokigames.com>
Thu, 26 Apr 2001 16:45:43 +0000
changeset 0 74212992fb08
child 19 8cc4dbfab9ab
permissions -rw-r--r--
Initial revision
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@0
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@0
     6
    modify it under the terms of the GNU Library General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@0
     8
    version 2 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@0
    13
    Library General Public License for more details.
slouken@0
    14
slouken@0
    15
    You should have received a copy of the GNU Library General Public
slouken@0
    16
    License along with this library; if not, write to the Free
slouken@0
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@0
    20
    slouken@devolution.com
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#ifdef SAVE_RCSID
slouken@0
    24
static char rcsid =
slouken@0
    25
 "@(#) $Id$";
slouken@0
    26
#endif
slouken@0
    27
slouken@0
    28
#include <stdlib.h>
slouken@0
    29
#include <stdio.h>
slouken@0
    30
#include <unistd.h>
slouken@0
    31
#include <string.h>
slouken@0
    32
#include <sys/ioctl.h>
slouken@0
    33
slouken@0
    34
#include "SDL.h"
slouken@0
    35
#include "SDL_error.h"
slouken@0
    36
#include "SDL_timer.h"
slouken@0
    37
#include "SDL_thread.h"
slouken@0
    38
#include "SDL_video.h"
slouken@0
    39
#include "SDL_mouse.h"
slouken@0
    40
#include "SDL_endian.h"
slouken@0
    41
#include "SDL_sysvideo.h"
slouken@0
    42
#include "SDL_pixels_c.h"
slouken@0
    43
#include "SDL_events_c.h"
slouken@0
    44
#include "SDL_ph_video.h"
slouken@0
    45
#include "SDL_ph_modes_c.h"
slouken@0
    46
#include "SDL_ph_image_c.h"
slouken@0
    47
#include "SDL_ph_events_c.h"
slouken@0
    48
#include "SDL_ph_mouse_c.h"
slouken@0
    49
#include "SDL_phyuv_c.h"
slouken@0
    50
#include "blank_cursor.h"
slouken@0
    51
slouken@0
    52
static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat);
slouken@0
    53
static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
slouken@0
    54
                int width, int height, int bpp, Uint32 flags);
slouken@0
    55
static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
slouken@0
    56
static void ph_VideoQuit(_THIS);
slouken@0
    57
static void ph_DeleteDevice(SDL_VideoDevice *device);
slouken@0
    58
slouken@0
    59
static int ph_Available(void)
slouken@0
    60
{
slouken@0
    61
slouken@0
    62
        return 1;
slouken@0
    63
}
slouken@0
    64
slouken@0
    65
static SDL_VideoDevice *ph_CreateDevice(int devindex)
slouken@0
    66
{
slouken@0
    67
    SDL_VideoDevice *device;
slouken@0
    68
slouken@0
    69
    /* Initialize all variables that we clean on shutdown */
slouken@0
    70
    device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
slouken@0
    71
    if ( device ) {
slouken@0
    72
        memset(device, 0, (sizeof *device));
slouken@0
    73
        device->hidden = (struct SDL_PrivateVideoData *)
slouken@0
    74
                malloc((sizeof *device->hidden));
slouken@0
    75
        device->gl_data = NULL;
slouken@0
    76
    }
slouken@0
    77
    if ( (device == NULL) || (device->hidden == NULL) ) {
slouken@0
    78
        SDL_OutOfMemory();
slouken@0
    79
        ph_DeleteDevice(device);
slouken@0
    80
        return(0);
slouken@0
    81
    }
slouken@0
    82
    memset(device->hidden, 0, (sizeof *device->hidden));
slouken@0
    83
slouken@0
    84
    /* Set the driver flags */
slouken@0
    85
    device->handles_any_size = 1; //JB not true for fullscreen
slouken@0
    86
slouken@0
    87
    /* Set the function pointers */
slouken@0
    88
	device->CreateYUVOverlay = ph_CreateYUVOverlay;
slouken@0
    89
    device->VideoInit = ph_VideoInit;
slouken@0
    90
    device->ListModes = ph_ListModes;
slouken@0
    91
    device->SetVideoMode = ph_SetVideoMode;
slouken@0
    92
    device->ToggleFullScreen =  ph_ToggleFullScreen;
slouken@0
    93
    device->UpdateMouse = NULL;	
slouken@0
    94
    device->SetColors = ph_SetColors;
slouken@0
    95
    device->UpdateRects =  NULL; //set in ph_ResizeImage
slouken@0
    96
    device->VideoQuit = ph_VideoQuit;
slouken@0
    97
    device->AllocHWSurface = ph_AllocHWSurface;
slouken@0
    98
    device->CheckHWBlit = NULL;
slouken@0
    99
    device->FillHWRect = NULL;
slouken@0
   100
    device->SetHWColorKey = NULL;
slouken@0
   101
    device->SetHWAlpha = NULL;
slouken@0
   102
    device->LockHWSurface = ph_LockHWSurface;
slouken@0
   103
    device->UnlockHWSurface = ph_UnlockHWSurface;
slouken@0
   104
    device->FlipHWSurface = ph_FlipHWSurface;
slouken@0
   105
    device->FreeHWSurface = ph_FreeHWSurface;
slouken@0
   106
    device->SetCaption = NULL;
slouken@0
   107
    device->SetIcon = NULL;
slouken@0
   108
    device->IconifyWindow = NULL;
slouken@0
   109
    device->GrabInput = NULL;
slouken@0
   110
    device->GetWMInfo = NULL;
slouken@0
   111
    device->FreeWMCursor = ph_FreeWMCursor;
slouken@0
   112
    device->CreateWMCursor = ph_CreateWMCursor;
slouken@0
   113
    device->ShowWMCursor = ph_ShowWMCursor;
slouken@0
   114
    device->WarpWMCursor = ph_WarpWMCursor;
slouken@0
   115
    device->CheckMouseMode = ph_CheckMouseMode;
slouken@0
   116
    device->InitOSKeymap = ph_InitOSKeymap;
slouken@0
   117
    device->PumpEvents = ph_PumpEvents;
slouken@0
   118
slouken@0
   119
    device->free = ph_DeleteDevice;
slouken@0
   120
slouken@0
   121
    return device;
slouken@0
   122
}
slouken@0
   123
slouken@0
   124
VideoBootStrap X11_bootstrap = {
slouken@0
   125
        "photon", "QNX Photon video output",
slouken@0
   126
	ph_Available, ph_CreateDevice
slouken@0
   127
};
slouken@0
   128
slouken@0
   129
static void ph_DeleteDevice(SDL_VideoDevice *device)
slouken@0
   130
{
slouken@0
   131
slouken@0
   132
    if ( device ) {
slouken@0
   133
        if ( device->hidden ) {
slouken@0
   134
            free(device->hidden);
slouken@0
   135
            device->hidden = NULL;
slouken@0
   136
        }
slouken@0
   137
        if ( device->gl_data ) {
slouken@0
   138
            free(device->gl_data);
slouken@0
   139
            device->gl_data = NULL;
slouken@0
   140
        }
slouken@0
   141
        free(device);
slouken@0
   142
        device = NULL;
slouken@0
   143
    }
slouken@0
   144
}
slouken@0
   145
slouken@0
   146
static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
slouken@0
   147
{
slouken@0
   148
	PtArg_t arg[1];
slouken@0
   149
    PhDim_t dim;
slouken@0
   150
	PgColor_t ph_palette[_Pg_MAX_PALETTE];
slouken@0
   151
	int i;
slouken@0
   152
	unsigned long *tempptr;
slouken@0
   153
	int rtnval;
slouken@0
   154
	PgDisplaySettings_t mysettings;
slouken@0
   155
	PgVideoModeInfo_t my_mode_info;
slouken@0
   156
	
slouken@0
   157
     if( NULL == ( event = malloc( EVENT_SIZE ) ) )
slouken@0
   158
          exit( EXIT_FAILURE );
slouken@0
   159
slouken@0
   160
	/* Create a widget 'window' to capture events */
slouken@0
   161
    dim.w=0; //JB test320;
slouken@0
   162
    dim.h=0; //JB test240;
slouken@0
   163
    //We need to return BytesPerPixel as it in used by CreateRGBsurface
slouken@0
   164
	
slouken@0
   165
    PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0);
slouken@0
   166
    
slouken@0
   167
/*    
slouken@0
   168
    PtSetArg(&arg[1], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, Pt_RESIZE_XY_AS_REQUIRED);
slouken@0
   169
    PtSetArg(&arg[2], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT |
slouken@0
   170
                        Ph_WM_STATE_ISMAX |
slouken@0
   171
                        Ph_WM_STATE_ISFOCUS);
slouken@0
   172
slouken@0
   173
    PtSetArg(&arg[3], Pt_ARG_WINDOW_RENDER_FLAGS,Pt_FALSE,~0);
slouken@0
   174
    PtSetArg(&arg[4], Pt_ARG_WINDOW_MANAGED_FLAGS,Pt_TRUE,
slouken@0
   175
                        Ph_WM_FFRONT |
slouken@0
   176
                        Ph_WM_CLOSE |
slouken@0
   177
                        Ph_WM_TOFRONT |
slouken@0
   178
                        Ph_WM_CONSWITCH);
slouken@0
   179
*/    
slouken@0
   180
    
slouken@0
   181
    
slouken@0
   182
	window=PtAppInit(NULL, NULL, NULL, 1, arg);
slouken@0
   183
slouken@0
   184
  	if(window == NULL)
slouken@0
   185
  	{
slouken@0
   186
  		printf("PtAppInit failed\n");
slouken@0
   187
        PtExit(EXIT_FAILURE);
slouken@0
   188
  	}
slouken@0
   189
slouken@0
   190
    //PgSetDrawBufferSize(16 *1024);
slouken@0
   191
   	PgSetRegion(PtWidgetRid(window));
slouken@0
   192
    PgSetClipping(0,NULL);
slouken@0
   193
    PtRealizeWidget(window);
slouken@0
   194
slouken@0
   195
slouken@0
   196
    /* Get the available video modes */
slouken@0
   197
//    if(ph_GetVideoModes(this) < 0)
slouken@0
   198
//        return -1;
slouken@0
   199
slouken@0
   200
	/* Create the blank cursor */
slouken@0
   201
	SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask,
slouken@0
   202
                (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT,
slouken@0
   203
                   (int)BLANK_CHOTX, (int)BLANK_CHOTY);
slouken@0
   204
slouken@0
   205
	if(SDL_BlankCursor == NULL)
slouken@0
   206
	  printf("could not create blank cursor\n");
slouken@0
   207
     /* Get the video mode */
slouken@0
   208
         if (PgGetVideoMode( &mysettings ) < 0)
slouken@0
   209
            {
slouken@0
   210
                fprintf(stderr,"ph_VideoInit:  PgGetVideoMode failed\n");
slouken@0
   211
      			//QNX6/Patch A always fails return code even though call succeeds. fixed Patch B
slouken@0
   212
            }
slouken@0
   213
        
slouken@0
   214
         if (PgGetVideoModeInfo(mysettings.mode, &my_mode_info) < 0)
slouken@0
   215
            {
slouken@0
   216
                fprintf(stderr,"ph_VideoInit:  PgGetVideoModeInfo failed\n");
slouken@0
   217
            }
slouken@0
   218
       //We need to return BytesPerPixel as it in used by CreateRGBsurface
slouken@0
   219
       vformat->BitsPerPixel = my_mode_info.bits_per_pixel;
slouken@0
   220
       vformat->BytesPerPixel = vformat->BitsPerPixel/8;
slouken@0
   221
 
slouken@0
   222
       //return a palette if we are in 256 color mode           
slouken@0
   223
		if(vformat->BitsPerPixel == 8)
slouken@0
   224
		{
slouken@0
   225
			vformat->palette = malloc(sizeof(SDL_Palette));
slouken@0
   226
			memset(vformat->palette, 0, sizeof(SDL_Palette));
slouken@0
   227
			vformat->palette->ncolors = 256;
slouken@0
   228
			vformat->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color));
slouken@0
   229
			
slouken@0
   230
			//fill the palette
slouken@0
   231
			rtnval = PgGetPalette(ph_palette);
slouken@0
   232
			if(rtnval < 0)
slouken@0
   233
			   printf("ph_VideoInit:  PgGetPalette failed\n");
slouken@0
   234
			   
slouken@0
   235
       	tempptr = (unsigned long *)vformat->palette->colors;
slouken@0
   236
slouken@0
   237
			for(i=0;i<256; i++)
slouken@0
   238
			{
slouken@0
   239
  				*tempptr = (((unsigned long)ph_palette[i]) << 8);
slouken@0
   240
  				tempptr++;
slouken@0
   241
slouken@0
   242
			}		
slouken@0
   243
		
slouken@0
   244
		}
slouken@0
   245
slouken@0
   246
slouken@0
   247
	currently_fullscreen = 0;
slouken@0
   248
    return 0;
slouken@0
   249
}
slouken@0
   250
slouken@0
   251
static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
slouken@0
   252
                int width, int height, int bpp, Uint32 flags)
slouken@0
   253
{
slouken@0
   254
    PhRegion_t region_info;
slouken@0
   255
    PgDisplaySettings_t settings;
slouken@0
   256
	PgVideoModeInfo_t mode_info;
slouken@0
   257
    int mode, actual_width, actual_height;
slouken@0
   258
	PtArg_t arg[5];
slouken@0
   259
	PhDim_t dim;	
slouken@0
   260
		int rtnval;
slouken@0
   261
	SDL_Rect ** mymodelist;
slouken@0
   262
	SDL_PixelFormat myformat;
slouken@0
   263
	PgColor_t ph_palette[_Pg_MAX_PALETTE];
slouken@0
   264
	int i;
slouken@0
   265
	unsigned long *tempptr;
slouken@0
   266
slouken@0
   267
	actual_width = width;
slouken@0
   268
	actual_height = height;
slouken@0
   269
slouken@0
   270
slouken@0
   271
    /* Lock the event thread, in multi-threading environments */
slouken@0
   272
    SDL_Lock_EventThread();
slouken@0
   273
slouken@0
   274
slouken@0
   275
     /* Initialize the window */
slouken@0
   276
    if (flags & SDL_FULLSCREEN) //Direct Context , assume SDL_HWSURFACE also set
slouken@0
   277
    {
slouken@0
   278
slouken@0
   279
/*  
slouken@0
   280
	if (old_video_mode==-1)
slouken@0
   281
	{
slouken@0
   282
		PgGetGraphicsHWCaps(&graphics_card_caps);
slouken@0
   283
		old_video_mode=graphics_card_caps.current_video_mode;
slouken@0
   284
		old_refresh_rate=graphics_card_caps.current_rrate;
slouken@0
   285
	}
slouken@0
   286
*/    	
slouken@0
   287
    	  	
slouken@0
   288
    	  	  	
slouken@0
   289
    	  	  	  	  	
slouken@0
   290
        /* Get the video mode and set it */
slouken@0
   291
        if (bpp == 0)
slouken@0
   292
        {
slouken@0
   293
            if (PgGetVideoMode( &settings ) < 0)
slouken@0
   294
            {
slouken@0
   295
                fprintf(stderr,"error: PgGetVideoMode failed\n");
slouken@0
   296
            }
slouken@0
   297
            if (PgGetVideoModeInfo(settings.mode, &mode_info) < 0)
slouken@0
   298
            {
slouken@0
   299
                fprintf(stderr,"error: PgGetVideoModeInfo failed\n");
slouken@0
   300
            }
slouken@0
   301
            bpp = mode_info.bits_per_pixel;
slouken@0
   302
        }
slouken@0
   303
        if (flags & SDL_ANYFORMAT)
slouken@0
   304
        {
slouken@0
   305
            if ((mode = get_mode_any_format(width, height, bpp)) == 0)
slouken@0
   306
            {
slouken@0
   307
                fprintf(stderr,"error: get_mode_any_format failed\n");
slouken@0
   308
                exit(1);
slouken@0
   309
            }
slouken@0
   310
        }
slouken@0
   311
        else
slouken@0
   312
        {
slouken@0
   313
            if ((mode = get_mode(width, height, bpp)) == 0)
slouken@0
   314
            {
slouken@0
   315
                 	fprintf(stderr,"error: get_mode failed\n");
slouken@0
   316
                	exit(1);
slouken@0
   317
            }
slouken@0
   318
               
slouken@0
   319
           
slouken@0
   320
        }
slouken@0
   321
        settings.mode = mode;
slouken@0
   322
        settings.refresh = 0;
slouken@0
   323
        settings.flags  = 0;       
slouken@0
   324
             
slouken@0
   325
        
slouken@0
   326
        if (PgSetVideoMode( &settings ) < 0)
slouken@0
   327
        {
slouken@0
   328
            fprintf(stderr,"error: PgSetVideoMode failed\n");
slouken@0
   329
        }
slouken@0
   330
slouken@0
   331
		/* Get the true height and width */
slouken@0
   332
		
slouken@0
   333
      current->flags = (flags|(~SDL_RESIZABLE)); //no resize for Direct Context
slouken@0
   334
slouken@0
   335
		 /* Begin direct mode */
slouken@0
   336
		 ph_EnterFullScreen(this);
slouken@0
   337
slouken@0
   338
       
slouken@0
   339
slouken@0
   340
    } //end fullscreen flag
slouken@0
   341
    else if (flags & SDL_HWSURFACE)  /* Use offscreen memory iff SDL_HWSURFACE flag is set */
slouken@0
   342
    {
slouken@0
   343
      // Hardware surface is Offsceen Context.  ph_ResizeImage handles the switch
slouken@0
   344
      current->flags = (flags|(~SDL_RESIZABLE)); //no stretch blit in offscreen context
slouken@0
   345
    }
slouken@0
   346
    else // must be SDL_SWSURFACE
slouken@0
   347
    {
slouken@0
   348
     current->flags = (flags|SDL_RESIZABLE); //yes we can resize as this is a software surface
slouken@0
   349
     }
slouken@0
   350
slouken@0
   351
slouken@0
   352
	//If we are setting video to use the palette make sure we have allocated memory for it
slouken@0
   353
	if(bpp == 8)
slouken@0
   354
	{
slouken@0
   355
		current->format->palette = malloc(sizeof(SDL_Palette));
slouken@0
   356
		memset(current->format->palette, 0, sizeof(SDL_Palette));
slouken@0
   357
		current->format->palette->ncolors = 256;
slouken@0
   358
		current->format->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color));
slouken@0
   359
		//fill the palette
slouken@0
   360
		rtnval = PgGetPalette(ph_palette);
slouken@0
   361
slouken@0
   362
       tempptr = (unsigned long *)current->format->palette->colors;
slouken@0
   363
slouken@0
   364
		for(i=0;i<256; i++)
slouken@0
   365
		{
slouken@0
   366
  			*tempptr = (((unsigned long)ph_palette[i]) << 8);
slouken@0
   367
  			tempptr++;
slouken@0
   368
slouken@0
   369
		}
slouken@0
   370
	}
slouken@0
   371
slouken@0
   372
slouken@0
   373
	//Current window dimensions
slouken@0
   374
	PtGetResource( window, Pt_ARG_DIM, &dim, 0 );
slouken@0
   375
	
slouken@0
   376
	//If we need to resize the window
slouken@0
   377
	if((dim.w != width)||(dim.h != height))
slouken@0
   378
	{
slouken@0
   379
	    dim.w=width;
slouken@0
   380
    	dim.h=height; 
slouken@0
   381
    	PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0);
slouken@0
   382
		PtSetResources( window, 1, arg ); 	
slouken@0
   383
       current->w = width;
slouken@0
   384
       current->h = height;
slouken@0
   385
       current->format->BitsPerPixel = bpp;
slouken@0
   386
		current->format->BytesPerPixel = bpp/8;
slouken@0
   387
       current->pitch = SDL_CalculatePitch(current);
slouken@0
   388
       //Must call at least once it setup image planes 
slouken@0
   389
       ph_ResizeImage(this, current, flags);
slouken@0
   390
    }
slouken@0
   391
slouken@0
   392
slouken@0
   393
    SDL_Unlock_EventThread();
slouken@0
   394
slouken@0
   395
    /* We're done! */
slouken@0
   396
    return(current);
slouken@0
   397
}
slouken@0
   398
slouken@0
   399
static void ph_VideoQuit(_THIS)
slouken@0
   400
{
slouken@0
   401
		
slouken@0
   402
	if(SDL_Image != NULL)
slouken@0
   403
	{
slouken@0
   404
	  	    ph_DestroyImage(this, SDL_VideoSurface); 
slouken@0
   405
	
slouken@0
   406
	}
slouken@0
   407
slouken@0
   408
	if (currently_fullscreen)
slouken@0
   409
	{
slouken@0
   410
		PdDirectStop( directContext );
slouken@0
   411
		PdReleaseDirectContext( directContext );
slouken@0
   412
		directContext=0;	
slouken@0
   413
		currently_fullscreen = 0;
slouken@0
   414
	}
slouken@0
   415
	
slouken@0
   416
}
slouken@0
   417
slouken@0
   418
slouken@0
   419
static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
slouken@0
   420
{
slouken@0
   421
	PgColor_t *in, *out;
slouken@0
   422
	int i, j;
slouken@0
   423
	int alloct_all = 1;
slouken@0
   424
slouken@0
   425
    	colors = this->screen->format->palette->colors;
slouken@0
   426
slouken@0
   427
	in = alloca( ncolors*sizeof(PgColor_t)  );
slouken@0
   428
	if ( in == NULL  ) {
slouken@0
   429
		return 0;
slouken@0
   430
	}
slouken@0
   431
	memset(in,0,ncolors*sizeof(PgColor_t));
slouken@0
   432
slouken@0
   433
    out = alloca( ncolors*sizeof(PgColor_t)  );
slouken@0
   434
    if ( out == NULL  ) {
slouken@0
   435
		return 0;
slouken@0
   436
    }
slouken@0
   437
	
slouken@0
   438
	for (i=0,j=firstcolor;i<ncolors;i++,j++)
slouken@0
   439
	{
slouken@0
   440
		in[i] |= colors[j].r<<16 ;
slouken@0
   441
		in[i] |= colors[j].g<<8 ;
slouken@0
   442
		in[i] |= colors[j].b ; 
slouken@0
   443
	}
slouken@0
   444
slouken@0
   445
	if ( (this->screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE ) 
slouken@0
   446
	{
slouken@0
   447
		if( PgSetPalette( in, 0, 0, ncolors, Pg_PALSET_HARD, 0) < 0 )
slouken@0
   448
		{
slouken@0
   449
			fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_HARD)  failed\n");
slouken@0
   450
			return 0;
slouken@0
   451
		}  
slouken@0
   452
	}
slouken@0
   453
	else 
slouken@0
   454
	{
slouken@0
   455
		if ( PgColorMatch(ncolors, in, out) < 0 )
slouken@0
   456
        {
slouken@0
   457
            fprintf(stderr,"error: PgColorMatch failed\n");
slouken@0
   458
            return 0;
slouken@0
   459
        }
slouken@0
   460
		for (i=0;i<ncolors;i++)
slouken@0
   461
		{
slouken@0
   462
			if (memcmp(&in[i],&out[i],sizeof(PgColor_t)))
slouken@0
   463
			{
slouken@0
   464
				alloct_all = 0;
slouken@0
   465
				break;
slouken@0
   466
			}
slouken@0
   467
		}
slouken@0
   468
        if( PgSetPalette( out, 0, 0, ncolors, Pg_PALSET_SOFT, 0) < 0 )
slouken@0
   469
        {
slouken@0
   470
            fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_SOFT) failed\n");
slouken@0
   471
            return 0;
slouken@0
   472
        }
slouken@0
   473
	}
slouken@0
   474
	return alloct_all;
slouken@0
   475
}
slouken@0
   476
slouken@0
   477
static int ph_ResizeWindow(_THIS,
slouken@0
   478
            SDL_Surface *screen, int w, int h, Uint32 flags)
slouken@0
   479
{
slouken@0
   480
	PhWindowEvent_t winevent;
slouken@0
   481
slouken@0
   482
	memset( &winevent, 0, sizeof(winevent) ); 
slouken@0
   483
	winevent.event_f = Ph_WM_RESIZE;
slouken@0
   484
	winevent.size.w = w;
slouken@0
   485
	winevent.size.h = h;
slouken@0
   486
	winevent.rid = PtWidgetRid( window );
slouken@0
   487
	if (PtForwardWindowEvent( &winevent ) < 0)
slouken@0
   488
	{
slouken@0
   489
		fprintf(stderr,"error: PtForwardWindowEvent failed.\n");
slouken@0
   490
	}
slouken@0
   491
	current_w = w;
slouken@0
   492
	current_h = h;
slouken@0
   493
    return(0);
slouken@0
   494
}
slouken@0
   495
slouken@0
   496