24 #include <core/exception.h> 25 #include <fvutils/color/conversions.h> 26 #include <fvutils/color/yuv.h> 27 #include <fvwidgets/image_display.h> 28 #include <fvwidgets/sdl_keeper.h> 34 namespace firevision {
48 ImageDisplay::ImageDisplay(
unsigned int width,
unsigned int height,
const char *title)
50 SDLKeeper::init(SDL_INIT_VIDEO);
52 SDL_WM_SetCaption(title, NULL);
57 int bpp = SDL_VideoModeOK(_width, _height, 16, SDL_ANYFORMAT);
58 _surface = SDL_SetVideoMode(width, height, bpp, SDL_HWSURFACE | SDL_ANYFORMAT);
60 throw Exception(
"SDL: cannot create surface");
64 _overlay = SDL_CreateYUVOverlay(width, height, SDL_UYVY_OVERLAY, _surface);
78 ImageDisplay::~ImageDisplay()
82 SDL_FreeYUVOverlay(_overlay);
83 SDL_FreeSurface(_surface);
93 ImageDisplay::show(colorspace_t colorspace,
unsigned char *buffer)
95 SDL_LockYUVOverlay(_overlay);
96 convert(colorspace, YUV422_PACKED, buffer, _overlay->pixels[0], _width, _height);
97 SDL_UnlockYUVOverlay(_overlay);
98 SDL_DisplayYUVOverlay(_overlay, _rect);
105 ImageDisplay::show(
unsigned char *yuv422_planar_buffer)
107 SDL_LockYUVOverlay(_overlay);
109 yuv422planar_to_yuv422packed(yuv422_planar_buffer, _overlay->pixels[0], _width, _height);
111 SDL_UnlockYUVOverlay(_overlay);
112 SDL_DisplayYUVOverlay(_overlay, _rect);
119 ImageDisplay::process_events(
unsigned int max_num_events)
121 unsigned int proc = 0;
123 while ((proc++ < max_num_events) && (SDL_PollEvent(&event))) {
133 ImageDisplay::loop_until_quit()
138 if (SDL_WaitEvent(&event)) {
139 switch (event.type) {
140 case SDL_QUIT: quit =
true;
break;
142 if ((event.key.keysym.sym == SDLK_ESCAPE) || (event.key.keysym.sym == SDLK_q)) {
Fawkes library namespace.
Base class for exceptions in Fawkes.