sdl_layer.cpp

来自「ARM交叉编译工具链」· C++ 代码 · 共 56 行

CPP
56
字号
/*
  * this src is used for testing the v4l and the sdl .
  * Beside this,it provides a simple wrap of v4l and sdl .
  * You can use it any where,but should keep this header.
  * Any suggestion is appreicated.
  *
  *	Tianjin University , China.
  *	
  *	vinqosky@gmail.com
  */

#include "sdl_layer.h"

int CSDLDisplay::init(int width, int height)
{
	if(SDL_Init(SDL_INIT_VIDEO)<0)
	{
		//ERROR
		return -1;
	}

	m_video_info = SDL_GetVideoInfo();
	m_screen = SDL_SetVideoMode(width,height,32,SDL_SWSURFACE|SDL_ASYNCBLIT);
	m_width = width;
	m_height = height;
	m_dst_rect.x = 0;
	m_dst_rect.y = 0;
	m_dst_rect.w = m_screen->w;
	m_dst_rect.h = m_screen->h;
	m_image = SDL_CreateYUVOverlay(width,height,SDL_YV12_OVERLAY,m_screen);

	return 1;
}

void CSDLDisplay::closeIt()
{
	SDL_FreeYUVOverlay(m_image);
	SDL_FreeSurface(m_screen);
	SDL_Quit();
}

void CSDLDisplay::display(unsigned char * ybuf, unsigned char * ubuf, unsigned char * vbuf)
{
	int ysize = m_width*m_height;
	int uvsize = ysize/4;

	SDL_LockYUVOverlay(m_image);
	memcpy(m_image->pixels[0],ybuf,ysize);
	memcpy(m_image->pixels[1],vbuf,uvsize);
	memcpy(m_image->pixels[2],ubuf,uvsize);
	SDL_DisplayYUVOverlay(m_image,&m_dst_rect);
	SDL_UnlockYUVOverlay(m_image);
}


⌨️ 快捷键说明

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