/*
* SdlShow.h
*
* Created on: 2014-6-1
* Author: root
*/
#ifndef SDLSHOW_H_
#define SDLSHOW_H_
#include <SDL/SDL.h>
#include <SDL/SDL_thread.h>
class SdlShow
{
public:
SdlShow();
~SdlShow();
bool SdlInitlib(const int &iWidth ,const int &iHeigth);
bool SdlWindowsShow(unsigned char * pyuv422);
private:
SDL_Overlay *Overlay;
SDL_Surface *Surface;
SDL_Rect Rect;
SDL_Event Event;
int m_iWidth;
int m_iHeight;
};
#endif /* SDLSHOW_H_ */
/*
* SdlShow.cpp
*
* Created on: 2014-6-1
* Author: root
*/
#include"SdlShow.h"
SdlShow::SdlShow()
{
Overlay = NULL;
Surface = NULL;
memset(&Rect,0,sizeof(SDL_Rect));
memset(&Event,0,sizeof(SDL_Event));
m_iWidth = 0;
m_iHeight = 0;
}
SdlShow::~SdlShow()
{
}
bool SdlShow::SdlInitlib(const int &iWidth ,const int &iHeigth)
{
m_iWidth = iWidth;
m_iHeight = iHeigth;
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER))
{
fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
exit(1);
}
Surface = SDL_SetVideoMode(iWidth, iHeigth, 0, 0);
if(!Surface)
{
perror(" create vide omode error ! \n");
return -1;
}
Overlay = SDL_CreateYUVOverlay(iWidth,iHeigth,SDL_YUY2_OVERLAY,Surface);
Rect.x = 0;
Rect.y = 0;
Rect.w = iWidth;
Rect.h = iHeigth;
return true;
}
bool SdlShow::SdlWindowsShow(unsigned char * pyuv422)
{
SDL_LockYUVOverlay(Overlay);
memcpy(Overlay->pixels[0],pyuv422,2*m_iWidth*m_iHeight);
SDL_UnlockYUVOverlay(Overlay);
SDL_DisplayYUVOverlay(Overlay, &Rect);
return true;
}
mian.cpp
YUYV422bufer
SdlShow oSdlShow;
oSdlShow.SdlInitlib(Width,Height);
oSdlShow.SdlWindowsShow(YUYV422bufer);