src/video/photon/SDL_phyuv.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 06 Mar 2002 11:23:08 +0000
changeset 297 f6ffac90895c
parent 252 e8157fcb3114
child 370 ba72f259bc88
permissions -rw-r--r--
Updated copyright information for 2002
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@297
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  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@252
    20
    slouken@libsdl.org
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
/* This is the QNX Realtime Platform version for SDL YUV video overlays */
slouken@0
    29
slouken@0
    30
#include <stdlib.h>
slouken@0
    31
#include <string.h>
slouken@0
    32
//#include <ncurses.h> //only for bool
slouken@0
    33
#ifndef bool
slouken@0
    34
#define bool char
slouken@0
    35
#define TRUE 1
slouken@0
    36
#define FALSE 0
slouken@0
    37
#endif
slouken@0
    38
#include <errno.h>
slouken@0
    39
slouken@0
    40
#include <Ph.h>
slouken@0
    41
#include <Pt.h>
slouken@0
    42
slouken@0
    43
#include "SDL_error.h"
slouken@0
    44
#include "SDL_video.h"
slouken@0
    45
#include "SDL_phyuv_c.h"
slouken@0
    46
#include "SDL_yuvfuncs.h"
slouken@0
    47
slouken@0
    48
#if 0  //just for reference
slouken@0
    49
/* YUV data formats			FourCC		   Layout		H sample (YUV)	V sample (YUV)	BPP */
slouken@0
    50
#define Pg_VIDEO_FORMAT_IYU1		0x31555949	/* U2Y2Y2V2Y2Y2		144		111		12  */
slouken@0
    51
#define Pg_VIDEO_FORMAT_IYU2		0x32555949	/* U4Y4V4U4Y4V4		111		111		24  */
slouken@0
    52
#define Pg_VIDEO_FORMAT_UYVY		0x59565955	/* U8Y8V8Y8		122		111		16  */
slouken@0
    53
#define Pg_VIDEO_FORMAT_YUY2		0x32595559	/* Y8U8Y8V8		122		111		16  */
slouken@0
    54
#define Pg_VIDEO_FORMAT_YVYU		0x55595659	/* Y8V8Y8U8		122		111		16  */
slouken@0
    55
#define Pg_VIDEO_FORMAT_V422		0x56343232	/* V8Y8U8Y8		122		111		16  */
slouken@0
    56
#define Pg_VIDEO_FORMAT_CLJR		0x524a4c43	/* V6U6Y5Y5Y5Y5		133		111		8   */
slouken@0
    57
#define Pg_VIDEO_FORMAT_YVU9		0x39555659	/* Planar YVU		144		144		9   */
slouken@0
    58
#define Pg_VIDEO_FORMAT_YV12		0x32315659	/* Planar YUV		122		122		12  */
slouken@0
    59
slouken@0
    60
/* There seems to be no FourCC that matches this */
slouken@0
    61
#define Pg_VIDEO_FORMAT_YUV420		0x00000100	/* Planar YUV		122		111		16  */
slouken@0
    62
slouken@0
    63
/* These formats are the same as YV12, except the U and V planes do not have to contiguously follow the Y plane */
slouken@0
    64
/* but they're all the same to us, since we always have 3 plane pointers */
slouken@0
    65
#define Pg_VIDEO_FORMAT_CLPL	Pg_VIDEO_FORMAT_YV12	/* Cirrus Logic Planar format */
slouken@0
    66
#define Pg_VIDEO_FORMAT_VBPL	Pg_VIDEO_FORMAT_YV12	/* VooDoo Banshee planar format */
slouken@0
    67
slouken@0
    68
#define SDL_YV12_OVERLAY	0x32315659	/* Planar mode: Y + V + U */
slouken@0
    69
#define SDL_IYUV_OVERLAY	0x56555949	/* Planar mode: Y + U + V */
slouken@0
    70
#define SDL_YUY2_OVERLAY	0x32595559	/* Packed mode: Y0+U0+Y1+V0 */
slouken@0
    71
#define SDL_UYVY_OVERLAY	0x59565955	/* Packed mode: U0+Y0+V0+Y1 */
slouken@0
    72
#define SDL_YVYU_OVERLAY	0x55595659	/* Packed mode: Y0+V0+Y1+U0 */
slouken@0
    73
slouken@0
    74
#endif 
slouken@0
    75
slouken@0
    76
slouken@0
    77
#define OVERLAY_STATE_UNINIT  0
slouken@0
    78
#define OVERLAY_STATE_ACTIVE 1
slouken@0
    79
slouken@0
    80
/* The functions used to manipulate software video overlays */
slouken@0
    81
static struct private_yuvhwfuncs ph_yuvfuncs = {
slouken@0
    82
	ph_LockYUVOverlay,
slouken@0
    83
	ph_UnlockYUVOverlay,
slouken@0
    84
	ph_DisplayYUVOverlay,
slouken@0
    85
	ph_FreeYUVOverlay
slouken@0
    86
};
slouken@0
    87
slouken@0
    88
slouken@0
    89
typedef struct {
slouken@0
    90
  int id;
slouken@0
    91
  int width, height;
slouken@0
    92
  int data_size;              /* bytes */
slouken@0
    93
  int num_planes;
slouken@0
    94
  int *pitches;               /* bytes */
slouken@0
    95
  int *offsets;               /* bytes */
slouken@0
    96
  char *data;
slouken@0
    97
  void *obdata;     
slouken@0
    98
} XvImage;
slouken@0
    99
slouken@0
   100
slouken@0
   101
struct private_yuvhwdata {
slouken@0
   102
	XvImage *image;	
slouken@0
   103
	FRAMEDATA *CurrentFrameData;
slouken@0
   104
	FRAMEDATA *FrameData0;
slouken@0
   105
	FRAMEDATA *FrameData1;
slouken@0
   106
	PgScalerProps_t	props;
slouken@0
   107
	PgScalerCaps_t		caps;
slouken@0
   108
	PgVideoChannel_t *channel;
slouken@0
   109
	SDL_Rect CurrentWindow;
slouken@0
   110
	long format;
slouken@0
   111
	int screen_width;
slouken@0
   112
	int screen_height ;
slouken@0
   113
	int screen_bpp ;    //2
slouken@0
   114
	bool planar;
slouken@0
   115
	bool scaler_on ;
slouken@0
   116
	int current;
slouken@0
   117
	long YStride;
slouken@0
   118
	long VStride;
slouken@0
   119
	long UStride;
slouken@0
   120
	long chromakey;
slouken@0
   121
	unsigned long State;
slouken@0
   122
	long flags;
slouken@0
   123
};
slouken@0
   124
slouken@0
   125
extern PgVideoChannel_t * PgCreateVideoChannel(unsigned type, unsigned flags);
slouken@0
   126
extern int PgGetScalerCapabilities( PgVideoChannel_t *channel, int format_index, PgScalerCaps_t *vcaps );
slouken@0
   127
extern int PgConfigScalerChannel(PgVideoChannel_t *channel, PgScalerProps_t *props);
slouken@0
   128
extern void PgDestroyVideoChannel(PgVideoChannel_t *channel);
slouken@0
   129
extern PgColor_t PgGetOverlayChromaColor(void);
slouken@0
   130
slouken@0
   131
void
slouken@0
   132
grab_ptrs2(PgVideoChannel_t *channel, FRAMEDATA *Frame0, FRAMEDATA *Frame1 )
slouken@0
   133
{
slouken@0
   134
slouken@0
   135
	/* Buffers have moved; re-obtain the pointers */
slouken@0
   136
	Frame0->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane1);
slouken@0
   137
	Frame1->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane2);
slouken@0
   138
	Frame0->U = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane1);
slouken@0
   139
	Frame1->U = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane2);
slouken@0
   140
	Frame0->V = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane1);
slouken@0
   141
	Frame1->V = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane2);
slouken@0
   142
slouken@0
   143
}
slouken@0
   144
slouken@0
   145
SDL_Overlay *ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display)
slouken@0
   146
{
slouken@0
   147
	SDL_Overlay *overlay;
slouken@0
   148
	struct private_yuvhwdata *hwdata;
slouken@0
   149
	int xv_port;
slouken@0
   150
	int rtncode;
slouken@0
   151
//	PhRect_t rect;
slouken@0
   152
//	PhSysInfo_t info;
slouken@0
   153
//	PhRegion_t region;
slouken@0
   154
//	short x, y;
slouken@0
   155
	PtArg_t argt;
slouken@0
   156
	int i =0;
slouken@0
   157
//	bool bCont = TRUE;
slouken@0
   158
	int Priority[20];
slouken@0
   159
	int Type[20];
slouken@0
   160
	int entries, select, highest;
slouken@0
   161
slouken@0
   162
	PhDCSetCurrent(0);  //Need to set draw context to window esp. if we we in Offscreeen mode
slouken@0
   163
slouken@0
   164
	/* Create the overlay structure */
slouken@0
   165
	overlay = (SDL_Overlay *)malloc(sizeof *overlay);
slouken@0
   166
	if ( overlay == NULL ) {
slouken@0
   167
		SDL_OutOfMemory();
slouken@0
   168
		return(NULL);
slouken@0
   169
	}
slouken@0
   170
	memset(overlay, 0, (sizeof *overlay));
slouken@0
   171
slouken@0
   172
	/* Fill in the basic members */
slouken@0
   173
	overlay->format = format;
slouken@0
   174
	overlay->w = width;
slouken@0
   175
	overlay->h = height;
slouken@0
   176
	
slouken@0
   177
	/* Set up the YUV surface function structure */
slouken@0
   178
	overlay->hwfuncs = &ph_yuvfuncs;
slouken@0
   179
slouken@0
   180
	/* Create the pixel data and lookup tables */
slouken@0
   181
	hwdata = (struct private_yuvhwdata *)malloc(sizeof *hwdata);
slouken@0
   182
	overlay->hwdata = hwdata;
slouken@0
   183
	if ( hwdata == NULL ) {
slouken@0
   184
		SDL_OutOfMemory();
slouken@0
   185
		SDL_FreeYUVOverlay(overlay);
slouken@0
   186
		return(NULL);
slouken@0
   187
	}
slouken@0
   188
	
slouken@0
   189
		if (overlay->hwdata->channel == NULL)
slouken@0
   190
	{
slouken@0
   191
	
slouken@0
   192
  
slouken@0
   193
		if ((overlay->hwdata->channel = PgCreateVideoChannel(Pg_VIDEO_CHANNEL_SCALER,0)) == NULL) 
slouken@0
   194
		{
slouken@0
   195
			SDL_SetError("Create channel failed:%s\n", strerror( errno ));
slouken@0
   196
			free(overlay->hwdata);
slouken@0
   197
			free(overlay);
slouken@0
   198
			return(NULL);
slouken@0
   199
		}
slouken@0
   200
#if 0
slouken@0
   201
		overlay->hwdata->caps.size = sizeof (overlay->hwdata->caps);
slouken@0
   202
		PgGetScalerCapabilities(overlay->hwdata->channel, 0, &(overlay->hwdata->caps));
slouken@0
   203
		if (overlay->hwdata->caps.flags & Pg_SCALER_CAP_DOUBLE_BUFFER)
slouken@0
   204
			overlay->hwdata->props.flags |= Pg_SCALER_PROP_DOUBLE_BUFFER;
slouken@0
   205
#endif	
slouken@0
   206
	}
slouken@0
   207
slouken@0
   208
overlay->hwdata->CurrentWindow.x = 0;
slouken@0
   209
overlay->hwdata->CurrentWindow.y = 0;
slouken@0
   210
overlay->hwdata->CurrentWindow.w = 320;
slouken@0
   211
overlay->hwdata->CurrentWindow.h = 240;
slouken@0
   212
slouken@0
   213
slouken@0
   214
slouken@0
   215
overlay->hwdata->State = OVERLAY_STATE_UNINIT;
slouken@0
   216
slouken@0
   217
overlay->hwdata->screen_bpp = 2;
slouken@0
   218
overlay->hwdata->scaler_on = FALSE;
slouken@0
   219
slouken@0
   220
overlay->hwdata->screen_width = 1024;
slouken@0
   221
overlay->hwdata->screen_height  = 768;
slouken@0
   222
slouken@0
   223
overlay->hwdata->FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA)));
slouken@0
   224
overlay->hwdata->FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA)));
slouken@0
   225
slouken@0
   226
overlay->hwdata->caps.size = sizeof(overlay->hwdata->caps);
slouken@0
   227
slouken@0
   228
slouken@0
   229
//Note you really don't need to do this for SDL as you are given a format, but this is a good example
slouken@0
   230
slouken@0
   231
xv_port = -1;
slouken@0
   232
i=0;
slouken@0
   233
	
slouken@0
   234
while(PgGetScalerCapabilities(overlay->hwdata->channel, i++, &(overlay->hwdata->caps)) == 0) 
slouken@0
   235
{
slouken@0
   236
slouken@0
   237
		if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_YV12) //in SDL
slouken@0
   238
		{
slouken@0
   239
			
slouken@0
   240
			Priority[i-1] = 0;
slouken@0
   241
			Type[i-1] = Pg_VIDEO_FORMAT_YV12;
slouken@0
   242
			if(format == Pg_VIDEO_FORMAT_YV12)
slouken@0
   243
			{
slouken@0
   244
				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YV12;
slouken@0
   245
				xv_port = 1; //supported
slouken@0
   246
				Priority[i-1] = 100; //force selected
slouken@0
   247
			}
slouken@0
   248
			
slouken@0
   249
		}
slouken@0
   250
		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_YVU9) //in SDL
slouken@0
   251
		{
slouken@0
   252
			
slouken@0
   253
			Priority[i-1] = 0;
slouken@0
   254
			Type[i-1] = Pg_VIDEO_FORMAT_YVU9;			
slouken@0
   255
			if(format == Pg_VIDEO_FORMAT_YVU9)
slouken@0
   256
			{
slouken@0
   257
				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YVU9;
slouken@0
   258
				xv_port = 1; //supported
slouken@0
   259
				Priority[i-1] = 100; //force selected
slouken@0
   260
			}
slouken@0
   261
			
slouken@0
   262
		}
slouken@0
   263
#if 0 //this part of SDL is YUV specific
slouken@0
   264
		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_RGB555)
slouken@0
   265
		{
slouken@0
   266
			
slouken@0
   267
			Priority[i-1] = 3;
slouken@0
   268
			Type[i-1] = Pg_VIDEO_FORMAT_RGB555;			
slouken@0
   269
		}
slouken@0
   270
		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_RGB565)
slouken@0
   271
		{
slouken@0
   272
			
slouken@0
   273
			Priority[i-1] =  2;
slouken@0
   274
			Type[i-1] = Pg_VIDEO_FORMAT_RGB565;			
slouken@0
   275
		}
slouken@0
   276
		else if(overlay->hwdata->caps.format == Pg_VIDEO_FORMAT_RGB8888)
slouken@0
   277
		{
slouken@0
   278
			
slouken@0
   279
			Priority[i-1] = 1;
slouken@0
   280
			Type[i-1] = Pg_VIDEO_FORMAT_RGB8888;			
slouken@0
   281
		}
slouken@0
   282
#endif
slouken@0
   283
		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_IYU1)
slouken@0
   284
		{
slouken@0
   285
			
slouken@0
   286
			Priority[i-1] = 0;
slouken@0
   287
			Type[i-1] = Pg_VIDEO_FORMAT_IYU1;
slouken@0
   288
			
slouken@0
   289
		}
slouken@0
   290
		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_IYU2)
slouken@0
   291
		{
slouken@0
   292
			
slouken@0
   293
			Priority[i-1] = 0;
slouken@0
   294
			Type[i-1] = Pg_VIDEO_FORMAT_IYU2;			
slouken@0
   295
		}
slouken@0
   296
slouken@0
   297
		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_UYVY) //in SDL
slouken@0
   298
		{
slouken@0
   299
			
slouken@0
   300
			Priority[i-1] = 7;
slouken@0
   301
			Type[i-1] = Pg_VIDEO_FORMAT_UYVY;
slouken@0
   302
			if(format == Pg_VIDEO_FORMAT_UYVY)
slouken@0
   303
			{
slouken@0
   304
				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_UYVY;
slouken@0
   305
				xv_port = 1; //supported
slouken@0
   306
				Priority[i-1] = 100; //force selected
slouken@0
   307
			}
slouken@0
   308
			
slouken@0
   309
		}
slouken@0
   310
		else if(overlay->hwdata->caps.format == Pg_VIDEO_FORMAT_YUY2) //in SDL
slouken@0
   311
		{
slouken@0
   312
			
slouken@0
   313
			Priority[i-1] = 8;
slouken@0
   314
			Type[i-1] = Pg_VIDEO_FORMAT_YUY2;			
slouken@0
   315
			if(format == Pg_VIDEO_FORMAT_YUY2)
slouken@0
   316
			{
slouken@0
   317
				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YUY2;
slouken@0
   318
				xv_port = 1; //supported
slouken@0
   319
				Priority[i-1] = 100; //force selected
slouken@0
   320
			}
slouken@0
   321
			
slouken@0
   322
		}
slouken@0
   323
		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_YVYU) //in SDL
slouken@0
   324
		{
slouken@0
   325
			
slouken@0
   326
			Priority[i-1] = 4;
slouken@0
   327
			Type[i-1] = Pg_VIDEO_FORMAT_YVYU;	
slouken@0
   328
			
slouken@0
   329
			if(format == Pg_VIDEO_FORMAT_YVYU)
slouken@0
   330
			{
slouken@0
   331
				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YVYU;
slouken@0
   332
				xv_port = 1; //supported
slouken@0
   333
				Priority[i-1] = 100; //force selected
slouken@0
   334
				
slouken@0
   335
			}
slouken@0
   336
		
slouken@0
   337
		}
slouken@0
   338
		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_V422)
slouken@0
   339
		{
slouken@0
   340
			
slouken@0
   341
			Priority[i-1] = 5;
slouken@0
   342
			Type[i-1] = Pg_VIDEO_FORMAT_V422;			
slouken@0
   343
		}		
slouken@0
   344
		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_CLJR)
slouken@0
   345
		{
slouken@0
   346
			
slouken@0
   347
			Priority[i-1] = 6;
slouken@0
   348
			Type[i-1] = Pg_VIDEO_FORMAT_CLJR;		
slouken@0
   349
		}	
slouken@0
   350
		else
slouken@0
   351
		{
slouken@0
   352
		
slouken@0
   353
		Priority[i-1] = 0;
slouken@0
   354
		}
slouken@0
   355
			
slouken@0
   356
overlay->hwdata->caps.size = sizeof(overlay->hwdata->caps);
slouken@0
   357
}
slouken@0
   358
slouken@0
   359
	if ( xv_port == -1 )
slouken@0
   360
	{
slouken@0
   361
		SDL_SetError("No available video ports for requested format");
slouken@0
   362
		return(NULL);
slouken@0
   363
	}
slouken@0
   364
 
slouken@0
   365
//Pick the highest priority format
slouken@0
   366
entries = i -2;
slouken@0
   367
highest = Priority[0]; //make first entry top at begining
slouken@0
   368
select = 0;
slouken@0
   369
slouken@0
   370
for (i = 1; i < entries; i++)
slouken@0
   371
{
slouken@0
   372
slouken@0
   373
slouken@0
   374
   if(Priority[i] > highest)
slouken@0
   375
   {
slouken@0
   376
      highest = Priority[i];
slouken@0
   377
      select  = i;
slouken@0
   378
   }
slouken@0
   379
} 
slouken@0
   380
slouken@0
   381
 
slouken@0
   382
 
slouken@0
   383
 overlay->hwdata->caps.size = sizeof (overlay->hwdata->caps	);
slouken@0
   384
PgGetScalerCapabilities(overlay->hwdata->channel, select, &(overlay->hwdata->caps));
slouken@0
   385
overlay->hwdata->props.format = overlay->hwdata->caps.format ;
slouken@0
   386
slouken@0
   387
    overlay->hwdata->format = overlay->hwdata->props.format;  //to make easier for apps to use
slouken@0
   388
slouken@0
   389
slouken@0
   390
	overlay->hwdata->props.size = sizeof (overlay->hwdata->props);
slouken@0
   391
    overlay->hwdata->props.src_dim.w = width;   
slouken@0
   392
    overlay->hwdata->props.src_dim.h = height;   
slouken@0
   393
	
slouken@0
   394
	overlay->hwdata->chromakey = PgGetOverlayChromaColor();
slouken@0
   395
slouken@0
   396
	// Set chromakey in video widget so we can see overlay data
slouken@0
   397
	/* I don't know where the container widget is!!!, I guess it is in hidden->window*/
slouken@0
   398
	
slouken@0
   399
	PtEnter(0);
slouken@0
   400
	PtSetArg( &argt, Pt_ARG_FILL_COLOR, overlay->hwdata->chromakey, 0 );
slouken@0
   401
	PtSetResources( window, 1, &argt ); 
slouken@0
   402
	PtLeave(0);
slouken@0
   403
slouken@0
   404
slouken@0
   405
	fflush( stderr );
slouken@0
   406
slouken@0
   407
	overlay->hwdata->props.viewport.ul.x = overlay->hwdata->CurrentWindow.x;
slouken@0
   408
	overlay->hwdata->props.viewport.ul.y = overlay->hwdata->CurrentWindow.y;
slouken@0
   409
	//Next line MIGHT have x and y reversed!!!!!!!!!!!!
slouken@0
   410
	overlay->hwdata->props.viewport.lr.x = overlay->hwdata->CurrentWindow.x +overlay->hwdata->CurrentWindow.w;
slouken@0
   411
	overlay->hwdata->props.viewport.lr.y = overlay->hwdata->CurrentWindow.y + overlay->hwdata->CurrentWindow.h;
slouken@0
   412
		
slouken@0
   413
slouken@0
   414
slouken@0
   415
	overlay->hwdata->props.flags =
slouken@0
   416
	    ~Pg_SCALER_PROP_SCALER_ENABLE | Pg_SCALER_PROP_DOUBLE_BUFFER ;
slouken@0
   417
slouken@0
   418
	if (overlay->hwdata->chromakey) {
slouken@0
   419
		overlay->hwdata->props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE;
slouken@0
   420
		overlay->hwdata->props.color_key = overlay->hwdata->chromakey;
slouken@0
   421
		overlay->hwdata->props.color_key_mask = 0xffffff;
slouken@0
   422
	} 
slouken@0
   423
	else
slouken@0
   424
	{
slouken@0
   425
		overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_CHROMA_ENABLE;
slouken@0
   426
	}
slouken@0
   427
slouken@0
   428
slouken@0
   429
	overlay->hwdata->scaler_on = FALSE;
slouken@0
   430
slouken@0
   431
slouken@0
   432
slouken@0
   433
 rtncode =    PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));	
slouken@0
   434
	switch(rtncode)
slouken@0
   435
	{
slouken@0
   436
	case -1:
slouken@0
   437
		SDL_SetError("PgConfigScalerChannel failed\n");
slouken@0
   438
		SDL_FreeYUVOverlay(overlay);
slouken@0
   439
		return(NULL);
slouken@0
   440
   		break;
slouken@0
   441
	case 1:
slouken@0
   442
		grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
slouken@0
   443
		break;
slouken@0
   444
	case 0:
slouken@0
   445
	default:
slouken@0
   446
   		break;
slouken@0
   447
	}
slouken@0
   448
slouken@0
   449
slouken@0
   450
	grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
slouken@0
   451
slouken@0
   452
if(overlay->hwdata->channel->yplane1 != NULL)			
slouken@0
   453
	overlay->hwdata->YStride = overlay->hwdata->channel->yplane1->pitch;
slouken@0
   454
if(overlay->hwdata->channel->uplane1 != NULL)			
slouken@0
   455
	overlay->hwdata->UStride = overlay->hwdata->channel->uplane1->pitch;
slouken@0
   456
if(overlay->hwdata->channel->vplane1 != NULL)			
slouken@0
   457
	overlay->hwdata->VStride = overlay->hwdata->channel->vplane1->pitch;
slouken@0
   458
slouken@0
   459
slouken@0
   460
	overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
slouken@0
   461
slouken@0
   462
slouken@0
   463
slouken@0
   464
	if (overlay->hwdata->current == -1)
slouken@0
   465
	{
slouken@0
   466
		SDL_SetError("PgNextFrame failed, bailing out\n");
slouken@0
   467
		SDL_FreeYUVOverlay(overlay);
slouken@0
   468
		return(NULL);
slouken@0
   469
	}
slouken@0
   470
        
slouken@0
   471
        //set current frame for double buffering
slouken@0
   472
	if(overlay->hwdata->current == 0)
slouken@0
   473
	{
slouken@0
   474
		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
slouken@0
   475
	}
slouken@0
   476
	else
slouken@0
   477
	{
slouken@0
   478
		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
slouken@0
   479
	}
slouken@0
   480
    
slouken@0
   481
	overlay->hwdata->State = OVERLAY_STATE_ACTIVE;
slouken@0
   482
slouken@0
   483
slouken@0
   484
	/* We're all done.. */
slouken@0
   485
	return(overlay);
slouken@0
   486
}
slouken@0
   487
slouken@0
   488
int ph_LockYUVOverlay(_THIS, SDL_Overlay *overlay)
slouken@0
   489
{
slouken@0
   490
//int rtncode;
slouken@0
   491
slouken@0
   492
if(overlay == NULL)
slouken@0
   493
   return 0;
slouken@0
   494
slouken@0
   495
//set current frame for double buffering
slouken@0
   496
	if(overlay->hwdata->current == 0)
slouken@0
   497
	{
slouken@0
   498
		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
slouken@0
   499
	}
slouken@0
   500
	else
slouken@0
   501
	{
slouken@0
   502
		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
slouken@0
   503
	}
slouken@0
   504
slouken@0
   505
	//Lock gets the pointer and passes it to the app. The app writes all yuv data into overlay->pixels
slouken@0
   506
//Note this is defined as Uint8 **pixels;				/* Read-write */	
slouken@0
   507
	overlay->pixels = &overlay->hwdata->CurrentFrameData->Y; 
slouken@0
   508
	overlay->pitches  = &overlay->hwdata->YStride;
slouken@0
   509
		
slouken@0
   510
	return(0);
slouken@0
   511
}
slouken@0
   512
slouken@0
   513
void ph_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay)
slouken@0
   514
{
slouken@0
   515
int rtncode;
slouken@0
   516
slouken@0
   517
if(overlay == NULL)
slouken@0
   518
   return ;
slouken@0
   519
slouken@0
   520
		if(overlay->hwdata->scaler_on == FALSE) 
slouken@0
   521
		{
slouken@0
   522
			
slouken@0
   523
		
slouken@0
   524
		overlay->hwdata->props.flags |= Pg_SCALER_PROP_SCALER_ENABLE;
slouken@0
   525
        rtncode =PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
slouken@0
   526
        	switch(rtncode)
slouken@0
   527
			{
slouken@0
   528
				case -1:
slouken@0
   529
					SDL_SetError("PgConfigScalerChannel failed\n");
slouken@0
   530
					SDL_FreeYUVOverlay(overlay);
slouken@0
   531
   					break;
slouken@0
   532
				case 1:
slouken@0
   533
					grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
slouken@0
   534
					overlay->hwdata->scaler_on = TRUE;
slouken@0
   535
					break;
slouken@0
   536
				case 0:
slouken@0
   537
					default:
slouken@0
   538
					overlay->hwdata->scaler_on = TRUE;
slouken@0
   539
   					break;
slouken@0
   540
			}
slouken@0
   541
//This would be the best place to draw chromakey but we do not have a SDL_Surface in the args
slouken@0
   542
//This means we might see a chromakey flicker at startup
slouken@0
   543
		}
slouken@0
   544
		overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
slouken@0
   545
slouken@0
   546
slouken@0
   547
	if (overlay->hwdata->current == -1) {
slouken@0
   548
		SDL_SetError("PgNextVideoFrame failed\n");
slouken@0
   549
		SDL_FreeYUVOverlay(overlay);	
slouken@0
   550
		return;	
slouken@0
   551
	}
slouken@0
   552
slouken@0
   553
	overlay->pixels = NULL;
slouken@0
   554
}
slouken@0
   555
slouken@0
   556
int ph_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
slouken@0
   557
{
slouken@0
   558
int rtncode;
slouken@0
   559
slouken@0
   560
if(overlay == NULL)
slouken@0
   561
   return 0;
slouken@0
   562
slouken@0
   563
slouken@0
   564
	/*SDL_Rect CurrentWindow*/
slouken@0
   565
//If CurrentWindow has change, move the viewport
slouken@0
   566
if((overlay->hwdata->CurrentWindow.x != dstrect->x) ||
slouken@0
   567
  (overlay->hwdata->CurrentWindow.y != dstrect->y) ||
slouken@0
   568
  (overlay->hwdata->CurrentWindow.w != dstrect->w) ||
slouken@0
   569
  (overlay->hwdata->CurrentWindow.h != dstrect->h))
slouken@0
   570
{
slouken@0
   571
		if(overlay->hwdata->State == OVERLAY_STATE_UNINIT)
slouken@0
   572
		return -1;
slouken@0
   573
slouken@0
   574
	overlay->hwdata->CurrentWindow.x = dstrect->x;
slouken@0
   575
  	overlay->hwdata->CurrentWindow.y = dstrect->y;
slouken@0
   576
  	overlay->hwdata->CurrentWindow.w = dstrect->w;
slouken@0
   577
  	overlay->hwdata->CurrentWindow.h = dstrect->h;
slouken@0
   578
slouken@0
   579
	overlay->hwdata->props.viewport.ul.x = overlay->hwdata->CurrentWindow.x;
slouken@0
   580
	overlay->hwdata->props.viewport.ul.y = overlay->hwdata->CurrentWindow.y;
slouken@0
   581
	//Next line MIGHT have x and y reversed!!!!!!!!!!!!
slouken@0
   582
	overlay->hwdata->props.viewport.lr.x = overlay->hwdata->CurrentWindow.x +overlay->hwdata->CurrentWindow.w;
slouken@0
   583
	overlay->hwdata->props.viewport.lr.y = overlay->hwdata->CurrentWindow.y + overlay->hwdata->CurrentWindow.h;
slouken@0
   584
slouken@0
   585
	
slouken@0
   586
     rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
slouken@0
   587
slouken@0
   588
	switch(rtncode)
slouken@0
   589
	{
slouken@0
   590
	case -1:
slouken@0
   591
		SDL_SetError("PgConfigScalerChannel failed\n");
slouken@0
   592
		SDL_FreeYUVOverlay(overlay);
slouken@0
   593
		return(0);
slouken@0
   594
   		break;
slouken@0
   595
	case 1:
slouken@0
   596
		grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
slouken@0
   597
		break;
slouken@0
   598
	case 0:
slouken@0
   599
	default:
slouken@0
   600
   		break;
slouken@0
   601
	}
slouken@0
   602
}
slouken@0
   603
slouken@0
   604
slouken@0
   605
//JB the X11 file did this. We do this in SDL_unlock, we need to confirm that lock and unlock are called for each frame!
slouken@0
   606
//	XvShmPutImage(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
slouken@0
   607
//	              hwdata->image, 0, 0, overlay->w, overlay->h,
slouken@0
   608
//	              dstrect->x, dstrect->y, dstrect->w, dstrect->h, False);	           
slouken@0
   609
/*  This is what this call is
slouken@0
   610
int XvShmPutImage (
slouken@0
   611
   Display *dpy,
slouken@0
   612
   XvPortID port,
slouken@0
   613
   Drawable d,
slouken@0
   614
   GC gc,
slouken@0
   615
   XvImage *image,
slouken@0
   616
   int src_x,
slouken@0
   617
   int src_y,
slouken@0
   618
   unsigned int src_w,
slouken@0
   619
   unsigned int src_h,
slouken@0
   620
   int dest_x, 
slouken@0
   621
   int dest_y,
slouken@0
   622
   unsigned int dest_w,
slouken@0
   623
   unsigned int dest_h,
slouken@0
   624
   Bool send_event
slouken@0
   625
)
slouken@0
   626
*/
slouken@0
   627
slouken@0
   628
	return(0);
slouken@0
   629
}
slouken@0
   630
slouken@0
   631
void ph_FreeYUVOverlay(_THIS, SDL_Overlay *overlay)
slouken@0
   632
{
slouken@0
   633
	//struct private_yuvhwdata *hwdata;
slouken@0
   634
slouken@0
   635
	if(overlay == NULL)
slouken@0
   636
		return;
slouken@0
   637
	
slouken@0
   638
	if(overlay->hwdata == NULL)
slouken@0
   639
		return;
slouken@0
   640
	
slouken@0
   641
	overlay->hwdata->State = OVERLAY_STATE_UNINIT;
slouken@0
   642
slouken@0
   643
	if( overlay->hwdata->channel == NULL )
slouken@0
   644
	{
slouken@0
   645
		return;
slouken@0
   646
	}	
slouken@0
   647
slouken@0
   648
	PgDestroyVideoChannel(overlay->hwdata->channel);
slouken@0
   649
slouken@0
   650
	overlay->hwdata->channel = NULL;
slouken@0
   651
	overlay->hwdata->CurrentFrameData = NULL;  
slouken@0
   652
	
slouken@0
   653
	free(overlay->hwdata->FrameData0);
slouken@0
   654
	free(overlay->hwdata->FrameData1);
slouken@0
   655
	overlay->hwdata->FrameData0 = NULL;
slouken@0
   656
	overlay->hwdata->FrameData1 = NULL;
slouken@0
   657
	free(overlay->hwdata);
slouken@0
   658
slouken@0
   659
}