src/video/photon/SDL_phyuv.c
changeset 571 8e3ce997621c
parent 380 bce7171e7a85
child 663 8bedd6d61642
     1.1 --- a/src/video/photon/SDL_phyuv.c	Mon Jan 20 01:37:07 2003 +0000
     1.2 +++ b/src/video/photon/SDL_phyuv.c	Mon Jan 20 01:38:37 2003 +0000
     1.3 @@ -29,11 +29,6 @@
     1.4  
     1.5  #include <stdlib.h>
     1.6  #include <string.h>
     1.7 -#ifndef bool
     1.8 -#define bool char
     1.9 -#define TRUE 1
    1.10 -#define FALSE 0
    1.11 -#endif
    1.12  #include <errno.h>
    1.13  
    1.14  #include <Ph.h>
    1.15 @@ -44,606 +39,426 @@
    1.16  #include "SDL_phyuv_c.h"
    1.17  #include "SDL_yuvfuncs.h"
    1.18  
    1.19 -#if 0  //just for reference
    1.20 -/* YUV data formats			FourCC		   Layout		H sample (YUV)	V sample (YUV)	BPP */
    1.21 -#define Pg_VIDEO_FORMAT_IYU1		0x31555949	/* U2Y2Y2V2Y2Y2		144		111		12  */
    1.22 -#define Pg_VIDEO_FORMAT_IYU2		0x32555949	/* U4Y4V4U4Y4V4		111		111		24  */
    1.23 -#define Pg_VIDEO_FORMAT_UYVY		0x59565955	/* U8Y8V8Y8		122		111		16  */
    1.24 -#define Pg_VIDEO_FORMAT_YUY2		0x32595559	/* Y8U8Y8V8		122		111		16  */
    1.25 -#define Pg_VIDEO_FORMAT_YVYU		0x55595659	/* Y8V8Y8U8		122		111		16  */
    1.26 -#define Pg_VIDEO_FORMAT_V422		0x56343232	/* V8Y8U8Y8		122		111		16  */
    1.27 -#define Pg_VIDEO_FORMAT_CLJR		0x524a4c43	/* V6U6Y5Y5Y5Y5		133		111		8   */
    1.28 -#define Pg_VIDEO_FORMAT_YVU9		0x39555659	/* Planar YVU		144		144		9   */
    1.29 -#define Pg_VIDEO_FORMAT_YV12		0x32315659	/* Planar YUV		122		122		12  */
    1.30 -
    1.31 -/* There seems to be no FourCC that matches this */
    1.32 -#define Pg_VIDEO_FORMAT_YUV420		0x00000100	/* Planar YUV		122		111		16  */
    1.33 -
    1.34 -/* These formats are the same as YV12, except the U and V planes do not have to contiguously follow the Y plane */
    1.35 -/* but they're all the same to us, since we always have 3 plane pointers */
    1.36 -#define Pg_VIDEO_FORMAT_CLPL	Pg_VIDEO_FORMAT_YV12	/* Cirrus Logic Planar format */
    1.37 -#define Pg_VIDEO_FORMAT_VBPL	Pg_VIDEO_FORMAT_YV12	/* VooDoo Banshee planar format */
    1.38 -
    1.39 -#define SDL_YV12_OVERLAY	0x32315659	/* Planar mode: Y + V + U */
    1.40 -#define SDL_IYUV_OVERLAY	0x56555949	/* Planar mode: Y + U + V */
    1.41 -#define SDL_YUY2_OVERLAY	0x32595559	/* Packed mode: Y0+U0+Y1+V0 */
    1.42 -#define SDL_UYVY_OVERLAY	0x59565955	/* Packed mode: U0+Y0+V0+Y1 */
    1.43 -#define SDL_YVYU_OVERLAY	0x55595659	/* Packed mode: Y0+V0+Y1+U0 */
    1.44 -
    1.45 -#endif 
    1.46 -
    1.47 -
    1.48 -#define OVERLAY_STATE_UNINIT  0
    1.49 +#define OVERLAY_STATE_UNINIT 0
    1.50  #define OVERLAY_STATE_ACTIVE 1
    1.51  
    1.52  /* The functions used to manipulate software video overlays */
    1.53  static struct private_yuvhwfuncs ph_yuvfuncs = {
    1.54 -	ph_LockYUVOverlay,
    1.55 -	ph_UnlockYUVOverlay,
    1.56 -	ph_DisplayYUVOverlay,
    1.57 -	ph_FreeYUVOverlay
    1.58 +    ph_LockYUVOverlay,
    1.59 +    ph_UnlockYUVOverlay,
    1.60 +    ph_DisplayYUVOverlay,
    1.61 +    ph_FreeYUVOverlay
    1.62  };
    1.63  
    1.64 -
    1.65 -typedef struct {
    1.66 -  int id;
    1.67 -  int width, height;
    1.68 -  int data_size;              /* bytes */
    1.69 -  int num_planes;
    1.70 -  int *pitches;               /* bytes */
    1.71 -  int *offsets;               /* bytes */
    1.72 -  char *data;
    1.73 -  void *obdata;     
    1.74 -} XvImage;
    1.75 -
    1.76 -
    1.77  struct private_yuvhwdata {
    1.78 -	XvImage *image;	
    1.79 -	FRAMEDATA *CurrentFrameData;
    1.80 -	FRAMEDATA *FrameData0;
    1.81 -	FRAMEDATA *FrameData1;
    1.82 -	PgScalerProps_t	props;
    1.83 -	PgScalerCaps_t	caps;
    1.84 -	PgVideoChannel_t *channel;
    1.85 -	SDL_Rect CurrentWindow;
    1.86 -	long format;
    1.87 -	int screen_width;
    1.88 -	int screen_height ;
    1.89 -	int screen_bpp ;    //2
    1.90 -	bool planar;
    1.91 -	bool scaler_on ;
    1.92 -	int current;
    1.93 -	long YStride;
    1.94 -	long VStride;
    1.95 -	long UStride;
    1.96 -	long chromakey;
    1.97 -	unsigned long State;
    1.98 -	long flags;
    1.99 +    FRAMEDATA* CurrentFrameData;
   1.100 +    FRAMEDATA* FrameData0;
   1.101 +    FRAMEDATA* FrameData1;
   1.102 +    PgScalerProps_t   props;
   1.103 +    PgScalerCaps_t    caps;
   1.104 +    PgVideoChannel_t* channel;
   1.105 +    PhArea_t CurrentWindow;
   1.106 +    long format;
   1.107 +    int planar;
   1.108 +    int scaler_on;
   1.109 +    int current;
   1.110 +    long YStride;
   1.111 +    long VStride;
   1.112 +    long UStride;
   1.113 +    int ischromakey;
   1.114 +    long chromakey;
   1.115 +    unsigned long State;
   1.116 +    long flags;
   1.117 +    int locked;
   1.118  };
   1.119  
   1.120 -extern PgVideoChannel_t * PgCreateVideoChannel(unsigned type, unsigned flags);
   1.121 -extern int PgGetScalerCapabilities( PgVideoChannel_t *channel, int format_index, PgScalerCaps_t *vcaps );
   1.122 -extern int PgConfigScalerChannel(PgVideoChannel_t *channel, PgScalerProps_t *props);
   1.123 -extern void PgDestroyVideoChannel(PgVideoChannel_t *channel);
   1.124 -extern PgColor_t PgGetOverlayChromaColor(void);
   1.125 +int grab_ptrs2(PgVideoChannel_t* channel, FRAMEDATA* Frame0, FRAMEDATA* Frame1 )
   1.126 +{
   1.127 +    int planes = 0;
   1.128  
   1.129 -void
   1.130 -grab_ptrs2(PgVideoChannel_t *channel, FRAMEDATA *Frame0, FRAMEDATA *Frame1 )
   1.131 -{
   1.132 +    /* Buffers have moved; re-obtain the pointers */
   1.133 +    Frame0->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane1);
   1.134 +    Frame1->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane2);
   1.135 +    Frame0->U = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane1);
   1.136 +    Frame1->U = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane2);
   1.137 +    Frame0->V = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane1);
   1.138 +    Frame1->V = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane2);
   1.139  
   1.140 -	/* Buffers have moved; re-obtain the pointers */
   1.141 -	Frame0->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane1);
   1.142 -	Frame1->Y = (unsigned char *)PdGetOffscreenContextPtr(channel->yplane2);
   1.143 -	Frame0->U = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane1);
   1.144 -	Frame1->U = (unsigned char *)PdGetOffscreenContextPtr(channel->uplane2);
   1.145 -	Frame0->V = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane1);
   1.146 -	Frame1->V = (unsigned char *)PdGetOffscreenContextPtr(channel->vplane2);
   1.147 +    if (Frame0->Y)
   1.148 +        planes++;
   1.149  
   1.150 +    if (Frame0->U)
   1.151 +        planes++;
   1.152 +
   1.153 +    if (Frame0->V)
   1.154 +        planes++;
   1.155 +
   1.156 +    return planes;
   1.157  }
   1.158  
   1.159  SDL_Overlay* ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display)
   1.160  {
   1.161 -	SDL_Overlay *overlay;
   1.162 -	struct private_yuvhwdata *hwdata;
   1.163 -	int xv_port;
   1.164 -	int rtncode;
   1.165 -//	PhRect_t rect;
   1.166 -//	PhSysInfo_t info;
   1.167 -//	PhRegion_t region;
   1.168 -//	short x, y;
   1.169 -	PtArg_t argt;
   1.170 -	int i =0;
   1.171 -//	bool bCont = TRUE;
   1.172 -	int Priority[20];
   1.173 -	int Type[20];
   1.174 -	int entries, select, highest;
   1.175 +    SDL_Overlay *overlay;
   1.176 +    struct private_yuvhwdata *hwdata;
   1.177 +    int xv_port;
   1.178 +    int rtncode;
   1.179 +    int planes;
   1.180 +    int i=0;
   1.181 +    PhPoint_t pos;
   1.182  
   1.183 -	PhDCSetCurrent(0);  //Need to set draw context to window esp. if we we in Offscreeen mode
   1.184 +    /* Create the overlay structure */
   1.185 +    overlay = calloc(1, sizeof(SDL_Overlay));
   1.186  
   1.187 -	/* Create the overlay structure */
   1.188 -	overlay = (SDL_Overlay *)malloc(sizeof(SDL_Overlay));
   1.189 -        memset(overlay, 0x00, sizeof(SDL_Overlay));
   1.190 -	if ( overlay == NULL ) {
   1.191 -		SDL_OutOfMemory();
   1.192 -		return(NULL);
   1.193 -	}
   1.194 -	memset(overlay, 0, (sizeof *overlay));
   1.195 +    if (overlay == NULL) {
   1.196 +        SDL_OutOfMemory();
   1.197 +        return (NULL);
   1.198 +    }
   1.199  
   1.200 -	/* Fill in the basic members */
   1.201 -	overlay->format = format;
   1.202 -	overlay->w = width;
   1.203 -	overlay->h = height;
   1.204 +    /* Fill in the basic members */
   1.205 +    overlay->format = format;
   1.206 +    overlay->w = width;
   1.207 +    overlay->h = height;
   1.208  	
   1.209 -	/* Set up the YUV surface function structure */
   1.210 -	overlay->hwfuncs = &ph_yuvfuncs;
   1.211 +    /* Set up the YUV surface function structure */
   1.212 +    overlay->hwfuncs = &ph_yuvfuncs;
   1.213  
   1.214 -	/* Create the pixel data and lookup tables */
   1.215 -	hwdata = (struct private_yuvhwdata *)malloc(sizeof(struct private_yuvhwdata));
   1.216 -        memset(hwdata, 0x00, sizeof(struct private_yuvhwdata));
   1.217 -	overlay->hwdata = hwdata;
   1.218 -	if ( hwdata == NULL ) {
   1.219 -		SDL_OutOfMemory();
   1.220 -		SDL_FreeYUVOverlay(overlay);
   1.221 -		return(NULL);
   1.222 -	}
   1.223 -	
   1.224 +    /* Create the pixel data and lookup tables */
   1.225 +    hwdata = calloc(1, sizeof(struct private_yuvhwdata));
   1.226 +
   1.227 +    overlay->hwdata = hwdata;
   1.228 +    if (hwdata == NULL) {
   1.229 +        SDL_OutOfMemory();
   1.230 +        SDL_FreeYUVOverlay(overlay);
   1.231 +        return(NULL);
   1.232 +    }
   1.233 +
   1.234 +    PhDCSetCurrent(0);
   1.235      if (overlay->hwdata->channel == NULL)
   1.236      {
   1.237          if ((overlay->hwdata->channel = PgCreateVideoChannel(Pg_VIDEO_CHANNEL_SCALER,0)) == NULL) 
   1.238          {
   1.239 -            SDL_SetError("ph_CreateYUVOverlay(): Create channel failed: %s\n", strerror( errno ));
   1.240 -            free(overlay->hwdata);
   1.241 -            free(overlay);
   1.242 -            return (NULL);
   1.243 +            SDL_SetError("ph_CreateYUVOverlay(): Create channel failed: %s\n", strerror(errno));
   1.244 +            SDL_FreeYUVOverlay(overlay);
   1.245 +
   1.246 +            return(NULL);
   1.247 +
   1.248          }
   1.249      }
   1.250  
   1.251 -    overlay->hwdata->CurrentWindow.x = 0;
   1.252 -    overlay->hwdata->CurrentWindow.y = 0;
   1.253 -    overlay->hwdata->CurrentWindow.w = 320;
   1.254 -    overlay->hwdata->CurrentWindow.h = 240;
   1.255 -
   1.256 +    PtGetAbsPosition(window, &pos.x, &pos.y);
   1.257 +    overlay->hwdata->CurrentWindow.pos.x = pos.x;
   1.258 +    overlay->hwdata->CurrentWindow.pos.y = pos.y;
   1.259 +    overlay->hwdata->CurrentWindow.size.w = width;
   1.260 +    overlay->hwdata->CurrentWindow.size.h = height;
   1.261      overlay->hwdata->State = OVERLAY_STATE_UNINIT;
   1.262 -
   1.263 -    overlay->hwdata->screen_bpp = 2;
   1.264 -    overlay->hwdata->scaler_on = FALSE;
   1.265 -    overlay->hwdata->screen_width = 1024;
   1.266 -    overlay->hwdata->screen_height  = 768;
   1.267 -
   1.268 -    overlay->hwdata->FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
   1.269 -    overlay->hwdata->FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
   1.270 -    memset(overlay->hwdata->FrameData0, 0x00, (size_t)(sizeof(FRAMEDATA)));
   1.271 -    memset(overlay->hwdata->FrameData1, 0x00, (size_t)(sizeof(FRAMEDATA)));
   1.272 -
   1.273 -    overlay->hwdata->caps.size = sizeof(overlay->hwdata->caps);
   1.274 -
   1.275 -//Note you really don't need to do this for SDL as you are given a format, but this is a good example
   1.276 +    overlay->hwdata->FrameData0 = (FRAMEDATA *) calloc(1, sizeof(FRAMEDATA));
   1.277 +    overlay->hwdata->FrameData1 = (FRAMEDATA *) calloc(1, sizeof(FRAMEDATA));
   1.278  
   1.279      xv_port = -1;
   1.280      i=0;
   1.281 +    
   1.282 +    overlay->hwdata->ischromakey=0;
   1.283  
   1.284 -while(PgGetScalerCapabilities(overlay->hwdata->channel, i++, &(overlay->hwdata->caps)) == 0) 
   1.285 -{
   1.286 -		if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_YV12) //in SDL
   1.287 -		{
   1.288 -			
   1.289 -			Priority[i-1] = 0;
   1.290 -			Type[i-1] = Pg_VIDEO_FORMAT_YV12;
   1.291 -			if(format == Pg_VIDEO_FORMAT_YV12)
   1.292 -			{
   1.293 -				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YV12;
   1.294 -				xv_port = 1; //supported
   1.295 -				Priority[i-1] = 100; //force selected
   1.296 -			}
   1.297 -			
   1.298 -		}
   1.299 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_YVU9) //in SDL
   1.300 -		{
   1.301 -			
   1.302 -			Priority[i-1] = 0;
   1.303 -			Type[i-1] = Pg_VIDEO_FORMAT_YVU9;			
   1.304 -			if(format == Pg_VIDEO_FORMAT_YVU9)
   1.305 -			{
   1.306 -				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YVU9;
   1.307 -				xv_port = 1; //supported
   1.308 -				Priority[i-1] = 100; //force selected
   1.309 -			}
   1.310 -			
   1.311 -		}
   1.312 -#if 0 //this part of SDL is YUV specific
   1.313 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_RGB555)
   1.314 -		{
   1.315 -			
   1.316 -			Priority[i-1] = 3;
   1.317 -			Type[i-1] = Pg_VIDEO_FORMAT_RGB555;			
   1.318 -		}
   1.319 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_RGB565)
   1.320 -		{
   1.321 -			
   1.322 -			Priority[i-1] =  2;
   1.323 -			Type[i-1] = Pg_VIDEO_FORMAT_RGB565;			
   1.324 -		}
   1.325 -		else if(overlay->hwdata->caps.format == Pg_VIDEO_FORMAT_RGB8888)
   1.326 -		{
   1.327 -			
   1.328 -			Priority[i-1] = 1;
   1.329 -			Type[i-1] = Pg_VIDEO_FORMAT_RGB8888;			
   1.330 -		}
   1.331 -#endif
   1.332 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_IYU1)
   1.333 -		{
   1.334 -			
   1.335 -			Priority[i-1] = 0;
   1.336 -			Type[i-1] = Pg_VIDEO_FORMAT_IYU1;
   1.337 -			
   1.338 -		}
   1.339 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_IYU2)
   1.340 -		{
   1.341 -			
   1.342 -			Priority[i-1] = 0;
   1.343 -			Type[i-1] = Pg_VIDEO_FORMAT_IYU2;			
   1.344 -		}
   1.345 +    do {
   1.346 +        memset(&overlay->hwdata->caps, 0x00, sizeof(PgScalerCaps_t));
   1.347 +        overlay->hwdata->caps.size = sizeof(PgScalerCaps_t);
   1.348 +        rtncode = PgGetScalerCapabilities(overlay->hwdata->channel, i, &overlay->hwdata->caps);
   1.349 +        if (rtncode==0)
   1.350 +        { 
   1.351 +            if (overlay->hwdata->caps.format==format)
   1.352 +            {
   1.353 +               if ((overlay->hwdata->caps.flags & Pg_SCALER_CAP_DST_CHROMA_KEY) == Pg_SCALER_CAP_DST_CHROMA_KEY)
   1.354 +               {
   1.355 +                   overlay->hwdata->ischromakey=1;
   1.356 +               }
   1.357 +               xv_port=1;
   1.358 +               break;
   1.359 +            }
   1.360 +        }
   1.361 +        else
   1.362 +        {
   1.363 +           break;
   1.364 +        }
   1.365 +        i++;
   1.366 +    } while(1);
   1.367  
   1.368 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_UYVY) //in SDL
   1.369 -		{
   1.370 -			
   1.371 -			Priority[i-1] = 7;
   1.372 -			Type[i-1] = Pg_VIDEO_FORMAT_UYVY;
   1.373 -			if(format == Pg_VIDEO_FORMAT_UYVY)
   1.374 -			{
   1.375 -				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_UYVY;
   1.376 -				xv_port = 1; //supported
   1.377 -				Priority[i-1] = 100; //force selected
   1.378 -			}
   1.379 -			
   1.380 -		}
   1.381 -		else if(overlay->hwdata->caps.format == Pg_VIDEO_FORMAT_YUY2) //in SDL
   1.382 -		{
   1.383 -			
   1.384 -			Priority[i-1] = 8;
   1.385 -			Type[i-1] = Pg_VIDEO_FORMAT_YUY2;			
   1.386 -			if(format == Pg_VIDEO_FORMAT_YUY2)
   1.387 -			{
   1.388 -				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YUY2;
   1.389 -				xv_port = 1; //supported
   1.390 -				Priority[i-1] = 100; //force selected
   1.391 -			}
   1.392 -			
   1.393 -		}
   1.394 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_YVYU) //in SDL
   1.395 -		{
   1.396 -			
   1.397 -			Priority[i-1] = 4;
   1.398 -			Type[i-1] = Pg_VIDEO_FORMAT_YVYU;	
   1.399 -			
   1.400 -			if(format == Pg_VIDEO_FORMAT_YVYU)
   1.401 -			{
   1.402 -				overlay->hwdata->props.format =  Pg_VIDEO_FORMAT_YVYU;
   1.403 -				xv_port = 1; //supported
   1.404 -				Priority[i-1] = 100; //force selected
   1.405 -				
   1.406 -			}
   1.407 -		
   1.408 -		}
   1.409 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_V422)
   1.410 -		{
   1.411 -			
   1.412 -			Priority[i-1] = 5;
   1.413 -			Type[i-1] = Pg_VIDEO_FORMAT_V422;			
   1.414 -		}		
   1.415 -		else if(overlay->hwdata->caps.format  == Pg_VIDEO_FORMAT_CLJR)
   1.416 -		{
   1.417 -			
   1.418 -			Priority[i-1] = 6;
   1.419 -			Type[i-1] = Pg_VIDEO_FORMAT_CLJR;		
   1.420 -		}	
   1.421 -		else
   1.422 -		{
   1.423 -		
   1.424 -		Priority[i-1] = 0;
   1.425 -		}
   1.426 -			
   1.427 -overlay->hwdata->caps.size = sizeof(overlay->hwdata->caps);
   1.428 -}
   1.429  
   1.430 -	if ( xv_port == -1 )
   1.431 -	{
   1.432 -		SDL_SetError("No available video ports for requested format");
   1.433 -		return(NULL);
   1.434 -	}
   1.435 +    if (xv_port == -1)
   1.436 +    {
   1.437 +        SDL_SetError("No available video ports for requested format\n");
   1.438 +        SDL_FreeYUVOverlay(overlay);
   1.439 +        return(NULL);
   1.440 +    }
   1.441   
   1.442 -//Pick the highest priority format
   1.443 -entries = i -2;
   1.444 -highest = Priority[0]; //make first entry top at begining
   1.445 -select = 0;
   1.446 -
   1.447 -for (i = 1; i < entries; i++)
   1.448 -{
   1.449 -
   1.450 -
   1.451 -   if(Priority[i] > highest)
   1.452 -   {
   1.453 -      highest = Priority[i];
   1.454 -      select  = i;
   1.455 -   }
   1.456 -} 
   1.457 -
   1.458 - 
   1.459 - 
   1.460 - overlay->hwdata->caps.size = sizeof (overlay->hwdata->caps	);
   1.461 -PgGetScalerCapabilities(overlay->hwdata->channel, select, &(overlay->hwdata->caps));
   1.462 -overlay->hwdata->props.format = overlay->hwdata->caps.format ;
   1.463 -
   1.464 -    overlay->hwdata->format = overlay->hwdata->props.format;  //to make easier for apps to use
   1.465 -
   1.466 -
   1.467 -	overlay->hwdata->props.size = sizeof (overlay->hwdata->props);
   1.468 +    overlay->hwdata->format = format;
   1.469 +    overlay->hwdata->props.format = format;
   1.470 +    overlay->hwdata->props.size = sizeof(PgScalerProps_t);
   1.471      overlay->hwdata->props.src_dim.w = width;   
   1.472      overlay->hwdata->props.src_dim.h = height;   
   1.473  	
   1.474 -	overlay->hwdata->chromakey = PgGetOverlayChromaColor();
   1.475 +    /* Don't use chromakey for now, blitting a surface will cover the window,
   1.476 +     * and therefore the chroma. */
   1.477 +    overlay->hwdata->chromakey = 0;
   1.478 +    PtSetResource(window, Pt_ARG_FILL_COLOR, overlay->hwdata->chromakey, 0);
   1.479  
   1.480 -	// Set chromakey in video widget so we can see overlay data
   1.481 -	/* I don't know where the container widget is!!!, I guess it is in hidden->window*/
   1.482 -	
   1.483 -	PtEnter(0);
   1.484 -	PtSetArg( &argt, Pt_ARG_FILL_COLOR, overlay->hwdata->chromakey, 0 );
   1.485 -	PtSetResources( window, 1, &argt ); 
   1.486 -	PtLeave(0);
   1.487 +    PhAreaToRect(&overlay->hwdata->CurrentWindow, &overlay->hwdata->props.viewport);
   1.488  
   1.489 +    overlay->hwdata->props.flags = Pg_SCALER_PROP_DOUBLE_BUFFER;
   1.490  
   1.491 -	fflush( stderr );
   1.492 +    if ((overlay->hwdata->ischromakey)&&(overlay->hwdata->chromakey))
   1.493 +    {
   1.494 +        overlay->hwdata->props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE;
   1.495 +        overlay->hwdata->props.color_key = overlay->hwdata->chromakey;
   1.496 +        overlay->hwdata->props.color_key_mask = 0x00FFFFFFUL;
   1.497 +    } 
   1.498 +    else
   1.499 +    {
   1.500 +        overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_CHROMA_ENABLE;
   1.501 +    }
   1.502  
   1.503 -	overlay->hwdata->props.viewport.ul.x = overlay->hwdata->CurrentWindow.x;
   1.504 -	overlay->hwdata->props.viewport.ul.y = overlay->hwdata->CurrentWindow.y;
   1.505 -	//Next line MIGHT have x and y reversed!!!!!!!!!!!!
   1.506 -	overlay->hwdata->props.viewport.lr.x = overlay->hwdata->CurrentWindow.x +overlay->hwdata->CurrentWindow.w;
   1.507 -	overlay->hwdata->props.viewport.lr.y = overlay->hwdata->CurrentWindow.y + overlay->hwdata->CurrentWindow.h;
   1.508 -		
   1.509 +    rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &overlay->hwdata->props);
   1.510  
   1.511 +    switch(rtncode)
   1.512 +    {
   1.513 +        case -1: SDL_SetError("PgConfigScalerChannel failed\n");
   1.514 +		 SDL_FreeYUVOverlay(overlay);
   1.515 +		 return(NULL);
   1.516 +   		 break;
   1.517 +        case 1:
   1.518 +        case 0:
   1.519 +        default:
   1.520 +                 break;
   1.521 +    }
   1.522  
   1.523 -	overlay->hwdata->props.flags =
   1.524 -	    ~Pg_SCALER_PROP_SCALER_ENABLE | Pg_SCALER_PROP_DOUBLE_BUFFER ;
   1.525 +    planes = grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
   1.526  
   1.527 -	if (overlay->hwdata->chromakey) {
   1.528 -		overlay->hwdata->props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE;
   1.529 -		overlay->hwdata->props.color_key = overlay->hwdata->chromakey;
   1.530 -		overlay->hwdata->props.color_key_mask = 0xffffff;
   1.531 -	} 
   1.532 -	else
   1.533 -	{
   1.534 -		overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_CHROMA_ENABLE;
   1.535 -	}
   1.536 +    if(overlay->hwdata->channel->yplane1 != NULL)			
   1.537 +        overlay->hwdata->YStride = overlay->hwdata->channel->yplane1->pitch;
   1.538 +    if(overlay->hwdata->channel->uplane1 != NULL)			
   1.539 +        overlay->hwdata->UStride = overlay->hwdata->channel->uplane1->pitch;
   1.540 +    if(overlay->hwdata->channel->vplane1 != NULL)			
   1.541 +        overlay->hwdata->VStride = overlay->hwdata->channel->vplane1->pitch;
   1.542  
   1.543 +    overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
   1.544  
   1.545 -	overlay->hwdata->scaler_on = FALSE;
   1.546 +    if(overlay->hwdata->current==0)
   1.547 +        overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
   1.548 +    else
   1.549 +        overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
   1.550  
   1.551 +    overlay->hwdata->locked = 1;
   1.552  
   1.553 +    /* Find the pitch and offset values for the overlay */
   1.554 +    overlay->planes = planes;
   1.555 +    overlay->pitches = calloc(overlay->planes, sizeof(Uint16));
   1.556 +    overlay->pixels  = calloc(overlay->planes, sizeof(Uint8*));
   1.557 +    if (!overlay->pitches || !overlay->pixels)
   1.558 +    {
   1.559 +        SDL_OutOfMemory();
   1.560 +        SDL_FreeYUVOverlay(overlay);
   1.561 +        return(NULL);
   1.562 +    }
   1.563  
   1.564 - rtncode =    PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));	
   1.565 -	switch(rtncode)
   1.566 -	{
   1.567 -	case -1:
   1.568 -		SDL_SetError("PgConfigScalerChannel failed\n");
   1.569 -		SDL_FreeYUVOverlay(overlay);
   1.570 -		return(NULL);
   1.571 -   		break;
   1.572 -	case 1:
   1.573 -		grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
   1.574 -		break;
   1.575 -	case 0:
   1.576 -	default:
   1.577 -   		break;
   1.578 -	}
   1.579 +    if (overlay->planes > 0)
   1.580 +    {
   1.581 +        overlay->pitches[0] = overlay->hwdata->channel->yplane1->pitch;
   1.582 +        overlay->pixels[0]  = overlay->hwdata->CurrentFrameData->Y;
   1.583 +    }
   1.584 +    if (overlay->planes > 1)
   1.585 +    {
   1.586 +        overlay->pitches[1] = overlay->hwdata->channel->uplane1->pitch;
   1.587 +        overlay->pixels[1]  = overlay->hwdata->CurrentFrameData->U;
   1.588 +    }
   1.589 +    if (overlay->planes > 2)
   1.590 +    {
   1.591 +        overlay->pitches[2] = overlay->hwdata->channel->vplane1->pitch;
   1.592 +        overlay->pixels[2]  = overlay->hwdata->CurrentFrameData->V;
   1.593 +    }
   1.594  
   1.595 +    overlay->hwdata->State = OVERLAY_STATE_ACTIVE;
   1.596 +    overlay->hwdata->scaler_on = 0;
   1.597 +    overlay->hw_overlay = 1;
   1.598  
   1.599 -	grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
   1.600 -
   1.601 -if(overlay->hwdata->channel->yplane1 != NULL)			
   1.602 -	overlay->hwdata->YStride = overlay->hwdata->channel->yplane1->pitch;
   1.603 -if(overlay->hwdata->channel->uplane1 != NULL)			
   1.604 -	overlay->hwdata->UStride = overlay->hwdata->channel->uplane1->pitch;
   1.605 -if(overlay->hwdata->channel->vplane1 != NULL)			
   1.606 -	overlay->hwdata->VStride = overlay->hwdata->channel->vplane1->pitch;
   1.607 -
   1.608 -
   1.609 -	overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
   1.610 -
   1.611 -
   1.612 -
   1.613 -	if (overlay->hwdata->current == -1)
   1.614 -	{
   1.615 -		SDL_SetError("PgNextFrame failed, bailing out\n");
   1.616 -		SDL_FreeYUVOverlay(overlay);
   1.617 -		return(NULL);
   1.618 -	}
   1.619 -        
   1.620 -        //set current frame for double buffering
   1.621 -	if(overlay->hwdata->current == 0)
   1.622 -	{
   1.623 -		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
   1.624 -	}
   1.625 -	else
   1.626 -	{
   1.627 -		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
   1.628 -	}
   1.629 -    
   1.630 -	overlay->hwdata->State = OVERLAY_STATE_ACTIVE;
   1.631 -
   1.632 -
   1.633 -	/* We're all done.. */
   1.634 -	return(overlay);
   1.635 +    return (overlay);
   1.636  }
   1.637  
   1.638  int ph_LockYUVOverlay(_THIS, SDL_Overlay *overlay)
   1.639  {
   1.640 -//int rtncode;
   1.641 +    if (overlay == NULL)
   1.642 +        return 0;
   1.643  
   1.644 -if(overlay == NULL)
   1.645 -   return 0;
   1.646 +    overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
   1.647 +    if (overlay->hwdata->current == -1)
   1.648 +    {
   1.649 +        SDL_SetError("PgNextFrame failed, bailing out\n");
   1.650 +        SDL_FreeYUVOverlay(overlay);
   1.651 +        return(NULL);
   1.652 +    }
   1.653  
   1.654 -//set current frame for double buffering
   1.655 -	if(overlay->hwdata->current == 0)
   1.656 -	{
   1.657 -		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
   1.658 -	}
   1.659 -	else
   1.660 -	{
   1.661 -		overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
   1.662 -	}
   1.663 +    overlay->hwdata->locked = 1;
   1.664  
   1.665 -	//Lock gets the pointer and passes it to the app. The app writes all yuv data into overlay->pixels
   1.666 -//Note this is defined as Uint8 **pixels;				/* Read-write */	
   1.667 -	overlay->pixels = &overlay->hwdata->CurrentFrameData->Y; 
   1.668 -	overlay->pitches = (Uint16*) &(overlay->hwdata->YStride);
   1.669 -		
   1.670 -	return(0);
   1.671 +    /* set current frame for double buffering */
   1.672 +    if (overlay->hwdata->current == 0)
   1.673 +        overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
   1.674 +    else
   1.675 +        overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
   1.676 +
   1.677 +    if (overlay->planes > 0)
   1.678 +    {
   1.679 +        overlay->pitches[0] = overlay->hwdata->channel->yplane1->pitch;
   1.680 +        overlay->pixels[0]  = overlay->hwdata->CurrentFrameData->Y;
   1.681 +    }
   1.682 +    if (overlay->planes > 1)
   1.683 +    {
   1.684 +        overlay->pitches[1] = overlay->hwdata->channel->uplane1->pitch;
   1.685 +        overlay->pixels[1]  = overlay->hwdata->CurrentFrameData->U;
   1.686 +    }
   1.687 +    if (overlay->planes > 2)
   1.688 +    {
   1.689 +        overlay->pitches[2] = overlay->hwdata->channel->vplane1->pitch;
   1.690 +        overlay->pixels[2]  = overlay->hwdata->CurrentFrameData->V;
   1.691 +    }
   1.692 +
   1.693 +    return(0);
   1.694  }
   1.695  
   1.696  void ph_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay)
   1.697  {
   1.698 -int rtncode;
   1.699 +    int rtncode;
   1.700  
   1.701 -if(overlay == NULL)
   1.702 -   return ;
   1.703 +    if(overlay == NULL)
   1.704 +         return;
   1.705  
   1.706 -		if(overlay->hwdata->scaler_on == FALSE) 
   1.707 -		{
   1.708 -			
   1.709 -		
   1.710 -		overlay->hwdata->props.flags |= Pg_SCALER_PROP_SCALER_ENABLE;
   1.711 +    if(overlay->hwdata->scaler_on == 1) 
   1.712 +    {
   1.713          rtncode =PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
   1.714 -        	switch(rtncode)
   1.715 -			{
   1.716 -				case -1:
   1.717 -					SDL_SetError("PgConfigScalerChannel failed\n");
   1.718 -					SDL_FreeYUVOverlay(overlay);
   1.719 -   					break;
   1.720 -				case 1:
   1.721 -					grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
   1.722 -					overlay->hwdata->scaler_on = TRUE;
   1.723 -					break;
   1.724 -				case 0:
   1.725 -					default:
   1.726 -					overlay->hwdata->scaler_on = TRUE;
   1.727 -   					break;
   1.728 -			}
   1.729 -//This would be the best place to draw chromakey but we do not have a SDL_Surface in the args
   1.730 -//This means we might see a chromakey flicker at startup
   1.731 -		}
   1.732 -		overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
   1.733 +        switch(rtncode)
   1.734 +        {
   1.735 +            case -1:
   1.736 +                     SDL_SetError("PgConfigScalerChannel failed\n");
   1.737 +                     SDL_FreeYUVOverlay(overlay);
   1.738 +                     break;
   1.739 +            case 1:
   1.740 +                     grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
   1.741 +                     break;
   1.742 +            case 0:
   1.743 +            default:
   1.744 +                     break;
   1.745 +        }
   1.746 +    }
   1.747  
   1.748 -
   1.749 -	if (overlay->hwdata->current == -1) {
   1.750 -		SDL_SetError("PgNextVideoFrame failed\n");
   1.751 -		SDL_FreeYUVOverlay(overlay);	
   1.752 -		return;	
   1.753 -	}
   1.754 -
   1.755 -	overlay->pixels = NULL;
   1.756 +    /* This would be the best place to draw chromakey but we do not have a SDL_Surface in the args
   1.757 +     * This means we might see a chromakey flicker at startup. */
   1.758  }
   1.759  
   1.760  int ph_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
   1.761  {
   1.762 -int rtncode;
   1.763 +    int rtncode;
   1.764 +    PhPoint_t pos;
   1.765  
   1.766 -if(overlay == NULL)
   1.767 -   return 0;
   1.768 +    if(overlay == NULL)
   1.769 +        return -1;
   1.770  
   1.771 +    /* If CurrentWindow has change, move the viewport */
   1.772 +    if((overlay->hwdata->CurrentWindow.pos.x != dstrect->x) ||
   1.773 +       (overlay->hwdata->CurrentWindow.pos.y != dstrect->y) ||
   1.774 +       (overlay->hwdata->CurrentWindow.size.w != dstrect->w) ||
   1.775 +       (overlay->hwdata->CurrentWindow.size.h != dstrect->h) ||
   1.776 +       (overlay->hwdata->scaler_on==0))
   1.777 +    {
   1.778 +        if(overlay->hwdata->State == OVERLAY_STATE_UNINIT)
   1.779 +            return -1;
   1.780  
   1.781 -	/*SDL_Rect CurrentWindow*/
   1.782 -//If CurrentWindow has change, move the viewport
   1.783 -if((overlay->hwdata->CurrentWindow.x != dstrect->x) ||
   1.784 -  (overlay->hwdata->CurrentWindow.y != dstrect->y) ||
   1.785 -  (overlay->hwdata->CurrentWindow.w != dstrect->w) ||
   1.786 -  (overlay->hwdata->CurrentWindow.h != dstrect->h))
   1.787 -{
   1.788 -		if(overlay->hwdata->State == OVERLAY_STATE_UNINIT)
   1.789 -		return -1;
   1.790 +        overlay->hwdata->props.flags |= Pg_SCALER_PROP_SCALER_ENABLE;
   1.791 +        overlay->hwdata->scaler_on = 1;
   1.792  
   1.793 -	overlay->hwdata->CurrentWindow.x = dstrect->x;
   1.794 -  	overlay->hwdata->CurrentWindow.y = dstrect->y;
   1.795 -  	overlay->hwdata->CurrentWindow.w = dstrect->w;
   1.796 -  	overlay->hwdata->CurrentWindow.h = dstrect->h;
   1.797 +        PtGetAbsPosition(window, &pos.x, &pos.y);
   1.798 +        overlay->hwdata->CurrentWindow.pos.x = pos.x + dstrect->x;
   1.799 +        overlay->hwdata->CurrentWindow.pos.y = pos.y + dstrect->y;
   1.800 +        overlay->hwdata->CurrentWindow.size.w = dstrect->w;
   1.801 +        overlay->hwdata->CurrentWindow.size.h = dstrect->h;
   1.802  
   1.803 -	overlay->hwdata->props.viewport.ul.x = overlay->hwdata->CurrentWindow.x;
   1.804 -	overlay->hwdata->props.viewport.ul.y = overlay->hwdata->CurrentWindow.y;
   1.805 -	//Next line MIGHT have x and y reversed!!!!!!!!!!!!
   1.806 -	overlay->hwdata->props.viewport.lr.x = overlay->hwdata->CurrentWindow.x +overlay->hwdata->CurrentWindow.w;
   1.807 -	overlay->hwdata->props.viewport.lr.y = overlay->hwdata->CurrentWindow.y + overlay->hwdata->CurrentWindow.h;
   1.808 +        PhAreaToRect(&overlay->hwdata->CurrentWindow, &overlay->hwdata->props.viewport);
   1.809  
   1.810 -	
   1.811 -     rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
   1.812 +        rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
   1.813  
   1.814 -	switch(rtncode)
   1.815 -	{
   1.816 -	case -1:
   1.817 -		SDL_SetError("PgConfigScalerChannel failed\n");
   1.818 -		SDL_FreeYUVOverlay(overlay);
   1.819 -		return(0);
   1.820 -   		break;
   1.821 -	case 1:
   1.822 -		grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
   1.823 -		break;
   1.824 -	case 0:
   1.825 -	default:
   1.826 -   		break;
   1.827 -	}
   1.828 -}
   1.829 +        switch(rtncode)
   1.830 +        {
   1.831 +            case -1:
   1.832 +                     SDL_SetError("PgConfigScalerChannel failed\n");
   1.833 +                     SDL_FreeYUVOverlay(overlay);
   1.834 +                     return (0);
   1.835 +            case 1:
   1.836 +                     grab_ptrs2(overlay->hwdata->channel, overlay->hwdata->FrameData0, overlay->hwdata->FrameData1);
   1.837 +                     break;
   1.838 +            case 0:
   1.839 +            default:
   1.840 +                     break;
   1.841 +        }
   1.842 +    }
   1.843  
   1.844 +    if (!overlay->hwdata->locked)
   1.845 +    {
   1.846 +        overlay->hwdata->current = PgNextVideoFrame(overlay->hwdata->channel);
   1.847 +        if (overlay->hwdata->current == -1)
   1.848 +        {
   1.849 +            SDL_SetError("PgNextVideoFrame failed\n");
   1.850 +            SDL_FreeYUVOverlay(overlay);
   1.851 +            return 0;
   1.852 +        }
   1.853 +        if (overlay->hwdata->current == 0)
   1.854 +            overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData0;
   1.855 +        else
   1.856 +            overlay->hwdata->CurrentFrameData = overlay->hwdata->FrameData1;
   1.857  
   1.858 -//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!
   1.859 -//	XvShmPutImage(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
   1.860 -//	              hwdata->image, 0, 0, overlay->w, overlay->h,
   1.861 -//	              dstrect->x, dstrect->y, dstrect->w, dstrect->h, False);	           
   1.862 -/*  This is what this call is
   1.863 -int XvShmPutImage (
   1.864 -   Display *dpy,
   1.865 -   XvPortID port,
   1.866 -   Drawable d,
   1.867 -   GC gc,
   1.868 -   XvImage *image,
   1.869 -   int src_x,
   1.870 -   int src_y,
   1.871 -   unsigned int src_w,
   1.872 -   unsigned int src_h,
   1.873 -   int dest_x, 
   1.874 -   int dest_y,
   1.875 -   unsigned int dest_w,
   1.876 -   unsigned int dest_h,
   1.877 -   Bool send_event
   1.878 -)
   1.879 -*/
   1.880 -
   1.881 -	return(0);
   1.882 +        if (overlay->planes > 0)
   1.883 +        {
   1.884 +            overlay->pitches[0] = overlay->hwdata->channel->yplane1->pitch;
   1.885 +            overlay->pixels[0]  = overlay->hwdata->CurrentFrameData->Y;
   1.886 +        }
   1.887 +        if (overlay->planes > 1)
   1.888 +        {
   1.889 +            overlay->pitches[1] = overlay->hwdata->channel->uplane1->pitch;
   1.890 +            overlay->pixels[1]  = overlay->hwdata->CurrentFrameData->U;
   1.891 +        }
   1.892 +        if (overlay->planes > 2)
   1.893 +        {
   1.894 +            overlay->pitches[2] = overlay->hwdata->channel->vplane1->pitch;
   1.895 +            overlay->pixels[2]  = overlay->hwdata->CurrentFrameData->V;
   1.896 +        }
   1.897 +    }
   1.898 +        
   1.899 +    return 0;
   1.900  }
   1.901  
   1.902  void ph_FreeYUVOverlay(_THIS, SDL_Overlay *overlay)
   1.903  {
   1.904 -	//struct private_yuvhwdata *hwdata;
   1.905 +    if (overlay == NULL)
   1.906 +        return;
   1.907  
   1.908 -	if(overlay == NULL)
   1.909 -		return;
   1.910 +    if (overlay->hwdata == NULL)
   1.911 +        return;
   1.912 +
   1.913 +    /* it is need for some buggy drivers, that can't hide overlay before */
   1.914 +    /* freeing buffer, so we got trash on the srceen                     */
   1.915 +    overlay->hwdata->props.flags &= ~Pg_SCALER_PROP_SCALER_ENABLE;
   1.916 +    PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
   1.917 +
   1.918 +    overlay->hwdata->scaler_on = 0;
   1.919 +    overlay->hwdata->State = OVERLAY_STATE_UNINIT;
   1.920 +
   1.921 +    if (overlay->hwdata->channel != NULL)
   1.922 +    {
   1.923 +        PgDestroyVideoChannel(overlay->hwdata->channel);
   1.924 +        overlay->hwdata->channel = NULL;
   1.925 +        return;
   1.926 +    }	
   1.927 +
   1.928 +    overlay->hwdata->CurrentFrameData = NULL;  
   1.929  	
   1.930 -	if(overlay->hwdata == NULL)
   1.931 -		return;
   1.932 -	
   1.933 -	overlay->hwdata->State = OVERLAY_STATE_UNINIT;
   1.934 -
   1.935 -	if( overlay->hwdata->channel == NULL )
   1.936 -	{
   1.937 -		return;
   1.938 -	}	
   1.939 -
   1.940 -	PgDestroyVideoChannel(overlay->hwdata->channel);
   1.941 -
   1.942 -	overlay->hwdata->channel = NULL;
   1.943 -	overlay->hwdata->CurrentFrameData = NULL;  
   1.944 -	
   1.945 -	free(overlay->hwdata->FrameData0);
   1.946 -	free(overlay->hwdata->FrameData1);
   1.947 -	overlay->hwdata->FrameData0 = NULL;
   1.948 -	overlay->hwdata->FrameData1 = NULL;
   1.949 -	free(overlay->hwdata);
   1.950 -
   1.951 +    free(overlay->hwdata->FrameData0);
   1.952 +    free(overlay->hwdata->FrameData1);
   1.953 +    overlay->hwdata->FrameData0 = NULL;
   1.954 +    overlay->hwdata->FrameData1 = NULL;
   1.955 +    free(overlay->hwdata);
   1.956  }