Esempio n. 1
0
static int GetBPP(void)
{
	DDPIXELFORMAT ddpix;

	memset(&ddpix,0,sizeof(ddpix));
	ddpix.dwSize=sizeof(ddpix);

	ddrval=IDirectDrawSurface7_GetPixelFormat(lpDDSPrimary,&ddpix);
	if (ddrval != DD_OK)
	{
		//ShowDDErr("Error getting primary surface pixel format.");
		FCEU_printf("Error getting primary surface pixel format.\n");
		return 0;
	}

	if(ddpix.dwFlags&DDPF_RGB)
	{
		//mbg merge 7/17/06 removed silly dummy union stuff now that we have c++
		bpp=ddpix.dwRGBBitCount;
		CBM[0]=ddpix.dwRBitMask;
		CBM[1]=ddpix.dwGBitMask;
		CBM[2]=ddpix.dwBBitMask;
	}
	else
	{
		//ShowDDErr("RGB data not valid.");
		FCEU_printf("RGB data not valid.\n");
		return 0;
	}
	if(bpp==15) bpp=16;

	return 1;
}
Esempio n. 2
0
boolean Overlay( LPDIRECTDRAWSURFACE7 src_surface, RECT * src_rect,
			 LPDIRECTDRAWSURFACE7 dst_surface, RECT * dst_rect,
			 COLORREF color_key )
{
    DWORD					dw_color_key;
    DDPIXELFORMAT			ddpf;
	DDOVERLAYFX				ddofx;	
	int						flags;
	HRESULT					result;

	// compute the colorkey pixel value from the RGB value we've got/
	// NOTE : based on videolan colorkey code

    memset( &ddpf, 0, sizeof( DDPIXELFORMAT ));
    ddpf.dwSize = sizeof( DDPIXELFORMAT );
    result = IDirectDrawSurface7_GetPixelFormat( dst_surface, &ddpf );
	if( result != DD_OK )
	{
		Error( 0, "IDirectDrawSurface7_GetPixelFormat : could not get surface pixel format" );
		return FALSE;
	}

    dw_color_key = ( DWORD ) color_key;
    dw_color_key = ( DWORD ) ( ( ( dw_color_key * ddpf.dwRBitMask ) / 255 ) & ddpf.dwRBitMask );

    memset( &ddofx, 0, sizeof( DDOVERLAYFX ) );
    ddofx.dwSize = sizeof( DDOVERLAYFX );
    ddofx.dckDestColorkey.dwColorSpaceLowValue = dw_color_key;
    ddofx.dckDestColorkey.dwColorSpaceHighValue = dw_color_key;

	// set our overlay flags

    flags = DDOVER_SHOW | DDOVER_KEYDESTOVERRIDE;

	// attempt to overlay the surface

	result = IDirectDrawSurface7_UpdateOverlay( src_surface, src_rect, dst_surface, dst_rect, flags, &ddofx );
	if( result != DD_OK )
	{
		if( result == DDERR_SURFACELOST )
	    {
			IDirectDrawSurface7_Restore( src_surface );
			IDirectDrawSurface7_Restore( dst_surface );

			IDirectDrawSurface7_UpdateOverlay( src_surface, src_rect, dst_surface, dst_rect, flags, &ddofx );
		}
		else
		{
			Error( 0, "IDirectDrawSurface7_UpdateOverlay : error %i", result );
			return FALSE;
		}
	}

	return TRUE;
}
Esempio n. 3
0
boolean CheckPixelFormat( win32_driver_t * win32_driver )
{
	DDPIXELFORMAT	ddpf;
	HRESULT			result;

	// get the pixel format of our primary surface

    memset( &ddpf, 0, sizeof( DDPIXELFORMAT ));
    ddpf.dwSize = sizeof( DDPIXELFORMAT );
	result = IDirectDrawSurface7_GetPixelFormat( win32_driver->primary, &ddpf );
	if( result != DD_OK )
	{
		Error( 0, "IDirectDrawSurface7_GetPixelFormat ( CheckPixelFormat ) : error %u", result );
		return 0;
	}

	// TODO : support paletized video modes

	if( ( ddpf.dwFlags & DDPF_PALETTEINDEXED1 ) ||
		( ddpf.dwFlags & DDPF_PALETTEINDEXED2 ) ||
		( ddpf.dwFlags & DDPF_PALETTEINDEXED4 ) ||
		( ddpf.dwFlags & DDPF_PALETTEINDEXED8 ) ||
		( ddpf.dwFlags & DDPF_PALETTEINDEXEDTO8 ) )
		return FALSE;

	// store bytes per pixel

	win32_driver->bytespp = ddpf.dwRGBBitCount / 8;

	// find the rgb mode for software
	// colorspace conversion

	if( ddpf.dwRGBBitCount == 32 )
	{
		if( ddpf.dwRBitMask == 0xff0000 )
			win32_driver->mode = MODE_32_RGB;
		else
			win32_driver->mode = MODE_32_BGR;
	}

	if( ddpf.dwRGBBitCount == 24 )
	{
		if( ddpf.dwRBitMask == 0xff0000 )
			win32_driver->mode = MODE_24_RGB;
		else
			win32_driver->mode = MODE_24_BGR;
	}

	if( ddpf.dwRGBBitCount == 16 )
	{
		if( ddpf.dwRBitMask == 0xf800 )
			win32_driver->mode = MODE_16_RGB;
		else
			win32_driver->mode = MODE_16_BGR;
	}

	if( ddpf.dwRGBBitCount == 15 )
	{
		if( ddpf.dwRBitMask == 0x7C00 )
			win32_driver->mode = MODE_15_RGB;
		else
			win32_driver->mode = MODE_15_BGR;
	}

	return TRUE;
}
Esempio n. 4
0
static int
_directdraw_init (HWND                 window,
		  LPDIRECTDRAW        *object,
		  LPDIRECTDRAWSURFACE *surface_primary,
		  LPDIRECTDRAWSURFACE *surface_back,
		  int                 *depth,
		  int width,
		  int height)
{
   DDSURFACEDESC2      surface_desc;
   DDPIXELFORMAT       pixel_format;
   LPDIRECTDRAWCLIPPER clipper;
   LPDIRECTDRAW        o;
   DDSURFACEDESC2     *sd;
   HRESULT             res;

   res = DirectDrawCreateEx (NULL, (void **)&o, &IID_IDirectDraw7, NULL);
   if (FAILED(res))
     return 0;

   res = IDirectDraw7_SetCooperativeLevel (o, window, DDSCL_NORMAL);
   if (FAILED(res))
     {
	IDirectDraw7_Release (o);
	return 0;
     }

   res = IDirectDraw7_CreateClipper (o, 0, &clipper, NULL);
   if (FAILED(res))
     {
	IDirectDraw7_Release (o);
	return 0;
     }

   res = IDirectDrawClipper_SetHWnd (clipper, 0, window);
   if (FAILED(res))
     {
	IDirectDrawClipper_Release (clipper);
	IDirectDraw7_Release (o);
	return 0;
     }

   memset(&surface_desc, 0, sizeof(surface_desc));
   surface_desc.dwSize = sizeof(surface_desc);
   surface_desc.dwFlags = DDSD_CAPS;
   surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

   sd=&surface_desc;
   res = IDirectDraw7_CreateSurface (o, &surface_desc,
				     surface_primary, NULL);
   if (FAILED(res))
     {
	IDirectDrawClipper_Release (clipper);
	IDirectDraw7_Release (o);
	return 0;
     }

   res = IDirectDrawSurface7_SetClipper (*surface_primary, clipper);
   if (FAILED(res))
     {
	IDirectDrawClipper_Release (clipper);
	IDirectDrawSurface7_Release (*surface_primary);
	IDirectDraw7_Release (o);
	return 0;
     }

   memset (&surface_desc, 0, sizeof(surface_desc));
   surface_desc.dwSize = sizeof(surface_desc);
   surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
   surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
   surface_desc.dwWidth = width;
   surface_desc.dwHeight = height;

   sd=&surface_desc;
   res = IDirectDraw7_CreateSurface (o, (DDSURFACEDESC *)sd,
				     surface_back, NULL);
   if (FAILED(res))
     {
	IDirectDrawClipper_Release (clipper);
	IDirectDrawSurface7_Release (*surface_primary);
	IDirectDraw7_Release (o);
	return 0;
     }

   ZeroMemory(&pixel_format, sizeof(pixel_format));
   pixel_format.dwSize = sizeof(pixel_format);
   IDirectDrawSurface7_GetPixelFormat(*surface_primary, &pixel_format);

   *object = o;
   *depth = pixel_format.dwRGBBitCount;

   return 1;
}