src/video/photon/SDL_phyuv.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 28 May 2002 19:31:32 +0000
changeset 380 bce7171e7a85
parent 370 ba72f259bc88
child 571 8e3ce997621c
permissions -rw-r--r--
Date: Wed, 22 May 2002 22:30:58 +0300
From: "Mike Gorchak" <mike@malva.com.ua>
Subject: One more QNX patch

Hi !

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