/** * @file display_stage.c * @author nicolas.brulez@parrot.com * @date 2012/09/25 * * This stage is a naive example of how to display video using GTK2 + Cairo * In a complete application, all GTK handling (gtk main thread + widgets/window creation) * should NOT be handled by the video pipeline (see the Navigation linux example) * * The window will be resized according to the picture size, and should not be resized bu the user * as we do not handle any gtk event except the expose-event * * This example is not intended to be a GTK/Cairo tutorial, it is only an example of how to display * the AR.Drone live video feed. The GTK Thread is started here to improve the example readability * (we have all the gtk-related code in one file) */ // Self header file #include "display_stage.h" // GTK/Cairo headers #include #include //Opencv //#include #include #include IplImage* inCamera; // Funcs pointer definition const vp_api_stage_funcs_t display_stage_funcs = { NULL, (vp_api_stage_open_t) display_stage_open, (vp_api_stage_transform_t) display_stage_transform, (vp_api_stage_close_t) display_stage_close }; // Extern so we can make the ardrone_tool_exit() function (ardrone_testing_tool.c) // return TRUE when we close the video window extern int exit_program; C_RESULT display_stage_open (display_stage_cfg_t *cfg) { // Check that we use RGB565 if (2 != cfg->bpp) { // If that's not the case, then don't display anything cfg->paramsOK = FALSE; } else { // Else, start GTK thread and window cfg->paramsOK = TRUE; cfg->frameBuffer = NULL; cfg->fbSize = 0; //START_THREAD (gtk, cfg); } return C_OK; } IplImage *ipl_image_from_data(uint8_t* data) { IplImage *currframe; IplImage *dst; currframe = cvCreateImage(cvSize(640,360), IPL_DEPTH_8U, 3); dst = cvCreateImage(cvSize(640,360), IPL_DEPTH_8U, 3); currframe->imageData = data; cvCvtColor(currframe, dst, CV_BGR2RGB); cvReleaseImage(&currframe); return dst; } C_RESULT display_stage_transform (display_stage_cfg_t *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out) { inCamera=ipl_image_from_data((uint8_t*)in->buffers[0]); /* // Process only if we are using RGB565 if (FALSE == cfg->paramsOK) { return C_OK; } // Realloc frameBuffer if needed if (in->size != cfg->fbSize) { cfg->frameBuffer = vp_os_realloc (cfg->frameBuffer, in->size); cfg->fbSize = in->size; } // Copy last frame to frameBuffer vp_os_memcpy (cfg->frameBuffer, in->buffers[in->indexBuffer], cfg->fbSize); // Ask GTK to redraw the window uint32_t width = 0, height = 0; getPicSizeFromBufferSize (in->size, &width, &height); if (TRUE == gtkRunning) { gtk_widget_queue_draw_area (cfg->widget, 0, 0, width, height); } // Tell the pipeline that we don't have any output out->size = 0;*/ return C_OK; } C_RESULT display_stage_close (display_stage_cfg_t *cfg) { // Free all allocated memory if (NULL != cfg->frameBuffer) { vp_os_free (cfg->frameBuffer); cfg->frameBuffer = NULL; } return C_OK; }