⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdl_gapivideo.c

📁 SDL库 在进行视频显示程序spcaview安装时必须的库文件
💻 C
📖 第 1 页 / 共 3 页
字号:
		this->hidden->gxProperties.cbyPitch = g_RawFrameBufferInfo.cyStride;		this->hidden->gxProperties.cxWidth = g_RawFrameBufferInfo.cxPixels;		this->hidden->gxProperties.cyHeight = g_RawFrameBufferInfo.cyPixels;		this->hidden->videoMem = g_RawFrameBufferInfo.pFramePointer;		this->hidden->useVga = 1;		switch( g_RawFrameBufferInfo.wFormat )		{		case FORMAT_565:			this->hidden->gxProperties.ffFormat = kfDirect565;			break;		case FORMAT_555:			this->hidden->gxProperties.ffFormat = kfDirect555;			break;		default:			/* unknown pixel format, try define by BPP! */			switch( g_RawFrameBufferInfo.wBPP )			{			case 4:			case 8:				this->hidden->gxProperties.ffFormat = kfDirect;			case 16:				this->hidden->gxProperties.ffFormat = kfDirect565;			default:				this->hidden->gxProperties.ffFormat = kfDirect;				break;			}		}	}	if( this->hidden->gxProperties.cBPP != 16 )	{		this->hidden->gapiOrientation = SDL_ORIENTATION_UP;	} else	if( (this->hidden->gxProperties.cbxPitch > 0) && (this->hidden->gxProperties.cbyPitch > 0 ))	{		this->hidden->gapiOrientation = SDL_ORIENTATION_UP;	} else	if( (this->hidden->gxProperties.cbxPitch > 0) && (this->hidden->gxProperties.cbyPitch < 0 ))	{		this->hidden->gapiOrientation = SDL_ORIENTATION_RIGHT; // ipaq 3660	} else	if( (this->hidden->gxProperties.cbxPitch < 0) && (this->hidden->gxProperties.cbyPitch > 0 ))	{		this->hidden->gapiOrientation = SDL_ORIENTATION_LEFT; // ipaq 3800	}}static void GAPI_CreatePalette(int ncolors, SDL_Color *colors){  // Setup a custom color palette   BYTE buffer[ sizeof(LOGPALETTE) + 255 * sizeof(PALETTEENTRY) ];   int i;   LOGPALETTE*   pLogical = (LOGPALETTE*)buffer;   PALETTEENTRY* entries  = pLogical->palPalEntry;   HPALETTE hPalette;   HDC hdc;   for (i = 0; i < ncolors; ++i)   {      // Find intensity by replicating the bit patterns over a byte      entries[i].peRed   = colors[i].r;      entries[i].peGreen = colors[i].g;      entries[i].peBlue  = colors[i].b;      entries[i].peFlags = 0;   }   // Create the GDI palette object   pLogical->palVersion    = 0x0300;   pLogical->palNumEntries = ncolors;   hPalette = CreatePalette( pLogical );   ASSERT(hPalette);	   // Realize the palette   hdc = GetDC(0);   SelectPalette( hdc, hPalette, FALSE );   RealizePalette( hdc );   ReleaseDC( 0, hdc );   DeleteObject( hPalette );}int GAPI_VideoInit(_THIS, SDL_PixelFormat *vformat){	int i,bpp;	/* Create the window */	if ( DIB_CreateWindow(this) < 0 ) {		return(-1);	}	if( g_hGapiLib )	{		FillStructs(this, 0);		// SDL does not supports 2/4bpp mode, so use 16 bpp		bpp = gapi->gxProperties.cBPP < 8 ? 16 : gapi->gxProperties.cBPP;				/* set up normal and landscape mode */		GAPI_AddMode(this, bpp, gapi->gxProperties.cyHeight, gapi->gxProperties.cxWidth);			GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth, gapi->gxProperties.cyHeight);		}	/* add hi-res mode */	if( g_bRawBufferAvailable && 		!((gapi->gxProperties.cxWidth == (unsigned)g_RawFrameBufferInfo.cxPixels) && (gapi->gxProperties.cyHeight == (unsigned)g_RawFrameBufferInfo.cyPixels)))	{		FillStructs(this, 1);		// SDL does not supports 2/4bpp mode, so use 16 bpp		bpp = gapi->gxProperties.cBPP < 8 ? 16 : gapi->gxProperties.cBPP;		/* set up normal and landscape mode */		GAPI_AddMode(this, bpp, gapi->gxProperties.cyHeight, gapi->gxProperties.cxWidth);			GAPI_AddMode(this, bpp, gapi->gxProperties.cxWidth, gapi->gxProperties.cyHeight);		}	/* Determine the current screen size */	this->info.current_w = gapi->gxProperties.cxWidth;	this->info.current_h = gapi->gxProperties.cyHeight;	/* Sort the mode lists */	for ( i=0; i<NUM_MODELISTS; ++i ) {		if ( gapi->SDL_nummodes[i] > 0 ) {			SDL_qsort(gapi->SDL_modelist[i], gapi->SDL_nummodes[i], sizeof *gapi->SDL_modelist[i], cmpmodes);		}	}	vformat->BitsPerPixel = this->hidden->gxProperties.cBPP < 8 ? 16 : (unsigned char)this->hidden->gxProperties.cBPP;	// Get color mask	if (this->hidden->gxProperties.ffFormat & kfDirect565) {		vformat->BitsPerPixel = 16;		vformat->Rmask = 0x0000f800;		vformat->Gmask = 0x000007e0;		vformat->Bmask = 0x0000001f;		this->hidden->videoMode = GAPI_DIRECT_565;	}	else	if (this->hidden->gxProperties.ffFormat & kfDirect555) {		vformat->BitsPerPixel = 16;		vformat->Rmask = 0x00007c00;		vformat->Gmask = 0x000003e0;		vformat->Bmask = 0x0000001f;		this->hidden->videoMode = GAPI_DIRECT_555;	}	else	if ((this->hidden->gxProperties.ffFormat & kfDirect) && (this->hidden->gxProperties.cBPP < 8)) {		// We'll perform the conversion		vformat->BitsPerPixel = 16;		vformat->Rmask = 0x0000f800; // 16 bit 565		vformat->Gmask = 0x000007e0;		vformat->Bmask = 0x0000001f;		if (this->hidden->gxProperties.ffFormat & kfDirectInverted)			this->hidden->invert = (1 << this->hidden->gxProperties.cBPP) - 1;		this->hidden->colorscale = this->hidden->gxProperties.cBPP < 8 ? 8 - this->hidden->gxProperties.cBPP : 0;		this->hidden->videoMode = GAPI_MONO;	}	else	if (this->hidden->gxProperties.ffFormat & kfPalette) {		this->hidden->videoMode = GAPI_PALETTE;	} 	/* We're done! */	return(0);}SDL_Rect **GAPI_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags){	return(this->hidden->SDL_modelist[((format->BitsPerPixel+7)/8)-1]);//  	 return (SDL_Rect **) -1;}SDL_Surface *GAPI_SetVideoMode(_THIS, SDL_Surface *current,				int width, int height, int bpp, Uint32 flags){	SDL_Surface *video; 	Uint32 Rmask, Gmask, Bmask; 	DWORD style; 	SDL_Rect allScreen;	if( bpp < 4 )	{		SDL_SetError("1 bpp and 2 bpp modes is not implemented yet!");		return 0;	}	/* Recalculate bitmasks if necessary */	if (bpp == current->format->BitsPerPixel) {		video = current;	}	else {		switch(bpp) {			case 8:				Rmask = 0;				Gmask = 0;				Bmask = 0;				break;			case 15:							case 16:				/* Default is 565 unless the display is specifically 555 */				if (this->hidden->gxProperties.ffFormat & kfDirect555) {					Rmask = 0x00007c00;					Gmask = 0x000003e0;					Bmask = 0x0000001f;				}				else {					Rmask = 0x0000f800;					Gmask = 0x000007e0;					Bmask = 0x0000001f;				}				break;			case 24:			case 32:				Rmask = 0x00ff0000;				Gmask = 0x0000ff00;				Bmask = 0x000000ff;				break;			default:				SDL_SetError("Unsupported Bits Per Pixel format requested");				return NULL;		}		video = SDL_CreateRGBSurface(SDL_SWSURFACE,					0, 0, bpp, Rmask, Gmask, Bmask, 0);		if ( video == NULL ) {			SDL_OutOfMemory();			return(NULL);		}	}	gapi->userOrientation = SDL_ORIENTATION_UP;	video->flags = SDL_FULLSCREEN;	/* Clear flags, GAPI supports fullscreen only */	/* GAPI or VGA? */	if( g_hGapiLib )	{		FillStructs(this, 0);		if( (((unsigned)width != gapi->gxProperties.cxWidth) || ((unsigned)height != gapi->gxProperties.cyHeight))			&& (((unsigned)width != gapi->gxProperties.cyHeight) || ((unsigned)height != gapi->gxProperties.cxWidth)))			FillStructs(this, 1); // gapi is found but we use VGA resolution				} else		FillStructs(this, 1);	if ( !this->hidden->needUpdate && !this->hidden->videoMem) {		SDL_SetError("Couldn't get address of video memory, may be unsupported device or bug");		return(NULL);	}	/* detect user landscape mode */	if( (width > height) && (GetSystemMetrics(SM_CXSCREEN) < GetSystemMetrics(SM_CYSCREEN))) 		gapi->userOrientation = SDL_ORIENTATION_RIGHT;	/* shall we apply hires fix? for example when we do not use hires resource */	gapi->hiresFix = 0;	if( gapi->userOrientation == SDL_ORIENTATION_RIGHT )	{		if( (width > GetSystemMetrics(SM_CYSCREEN)) || (height > GetSystemMetrics(SM_CXSCREEN)))			gapi->hiresFix = 1;	} else		if( (width > GetSystemMetrics(SM_CXSCREEN)) || (height > GetSystemMetrics(SM_CYSCREEN)))			if( !((width == GetSystemMetrics(SM_CYSCREEN)) && (height == GetSystemMetrics(SM_CXSCREEN)))) // user portrait, device landscape				gapi->hiresFix = 1;	switch( gapi->userOrientation )	{	case SDL_ORIENTATION_UP:		gapi->startOffset = 0;		gapi->dstLineStep = gapi->gxProperties.cbyPitch;		gapi->dstPixelStep = gapi->gxProperties.cbxPitch;		break;	case SDL_ORIENTATION_RIGHT:		switch( gapi->gapiOrientation )		{		case SDL_ORIENTATION_UP:		case SDL_ORIENTATION_RIGHT:		case SDL_ORIENTATION_LEFT:			if( (this->hidden->videoMode == GAPI_MONO) )				gapi->startOffset = -gapi->gxProperties.cbxPitch + 1; // monochrome mode			else				gapi->startOffset = gapi->gxProperties.cbyPitch * (gapi->gxProperties.cyHeight - 1);							gapi->dstLineStep = gapi->gxProperties.cbxPitch;			gapi->dstPixelStep = -gapi->gxProperties.cbyPitch;			break;		}	}	video->w = this->hidden->w = width;	video->h = this->hidden->h = height;	video->pitch = SDL_CalculatePitch(video); 	/* Small fix for WinCE/Win32 - when activating window	   SDL_VideoSurface is equal to zero, so activating code	   is not called properly for fullscreen windows because	   macros WINDIB_FULLSCREEN uses SDL_VideoSurface	*/	SDL_VideoSurface = video;	/* GAPI is always fullscreen, title bar is useless */	style = 0;	if (!SDL_windowid)		SetWindowLong(SDL_Window, GWL_STYLE, style);	/* Allocate bitmap */	if(gapiBuffer) 	{		SDL_free(gapiBuffer);		gapiBuffer = NULL;	}	gapiBuffer = SDL_malloc(video->h * video->pitch);	video->pixels = gapiBuffer; 	if ( ! this->hidden->buffer ) {		SDL_SetError("Couldn't allocate buffer for requested mode");		return(NULL);	}	SDL_memset(gapiBuffer, 255, video->h * video->pitch);	MoveWindow(SDL_Window, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), FALSE);	ShowWindow(SDL_Window, SW_SHOW);	SetForegroundWindow(SDL_Window);	/* JC 14 Mar 2006		Flush the message loop or this can cause big problems later		Especially if the user decides to use dialog boxes or assert()!	*/	WIN_FlushMessageQueue();	/* Open GAPI display */	if( !gapi->useVga && this->hidden->useGXOpenDisplay )		if( !gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN) )		{			SDL_SetError("Couldn't initialize GAPI");			return(NULL);		}#if REPORT_VIDEO_INFO	printf("Video properties:\n");	printf("display bpp: %d\n", gapi->gxProperties.cBPP);	printf("display width: %d\n", gapi->gxProperties.cxWidth);	printf("display height: %d\n", gapi->gxProperties.cyHeight);	printf("x pitch: %d\n", gapi->gxProperties.cbxPitch);	printf("y pitch: %d\n", gapi->gxProperties.cbyPitch);	printf("gapi flags: 0x%x\n", gapi->gxProperties.ffFormat);	if( !gapi->useVga && this->hidden->useGXOpenDisplay && gapi->needUpdate)	{		gapi->videoMem = gapi->gxFunc.GXBeginDraw(); 		gapi->gxFunc.GXEndDraw();	}	printf("video memory: 0x%x\n", gapi->videoMem);	printf("need update: %d\n", gapi->needUpdate);	printf("hi-res fix: %d\n", gapi->hiresFix);	printf("VGA is available on the device: %d\n", g_bRawBufferAvailable);	printf("use raw framebuffer: %d\n", gapi->useVga);	printf("video surface bpp: %d\n", video->format->BitsPerPixel);	printf("video surface width: %d\n", video->w);	printf("video surface height: %d\n", video->h);#endif	/* Blank screen */	allScreen.x = allScreen.y = 0;	allScreen.w = video->w - 1;	allScreen.h = video->h - 1;	GAPI_UpdateRects(this, 1, &allScreen);	/* We're done */	return(video);}/* We don't actually allow hardware surfaces other than the main one */static int GAPI_AllocHWSurface(_THIS, SDL_Surface *surface){	return(-1);}static void GAPI_FreeHWSurface(_THIS, SDL_Surface *surface){	return;}/* We need to wait for vertical retrace on page flipped displays */static int GAPI_LockHWSurface(_THIS, SDL_Surface *surface){	return(0);}static void GAPI_UnlockHWSurface(_THIS, SDL_Surface *surface){	return;}static int updateLine8to8(_THIS, unsigned char *srcPointer, unsigned char *destPointer, int width, int height, int lines){	if( gapi->dstPixelStep == 1) /* optimized blitting on most devices */	{		SDL_memcpy(destPointer, srcPointer, width);		return 1;	} else	{		// TODO: read 4 pixels, write DWORD		int step = gapi->dstPixelStep;		while(width--)		{			*destPointer = *srcPointer++;			destPointer += step;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -