Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <assert.h>
- #include <unistd.h>
- #include <sys/time.h>
- #include "bcm_host.h"
- #define WIDTH 480
- #define HEIGHT 640
- #ifndef ALIGN_UP
- #define ALIGN_UP(x,y) ((x + (y)-1) & ~((y)-1))
- #endif
- int main(void)
- {
- uint32_t screen = 0;
- int ret;
- DISPMANX_DISPLAY_HANDLE_T display; // Esse display será aberto por vc_dispmanx_display_open()
- DISPMANX_MODEINFO_T info; // Esta estrutura será preenchida pelo comando vc_dispmanx_display_get_info()
- DISPMANX_RESOURCE_HANDLE_T resource; // Este handle é obtido pelo comando vc_dispmanx_resource_create()
- DISPMANX_UPDATE_HANDLE_T update; // Este handle é obtido pelo comando vc_dispmanx_update_start()
- DISPMANX_ELEMENT_HANDLE_T element; // Este handle é obtido pelo comando vc_dispmanx_element_add
- VC_RECT_T src_rect;
- VC_RECT_T dst_rect;
- FILE * fp;
- uint8_t * img_yuv;
- uint8_t * imgs;
- uint32_t vc_image_ptr; // Este valor é preenchido (provavelmente) pela função vc_dispmanx_resource_create()
- int width = WIDTH; // Tamanho do retângulo, definido em #define acima
- int height = HEIGHT; // Tamanho do retângulo, definido em #define acima
- int pitch = ALIGN_UP(width, 16);
- imgs = calloc(460800, 1);
- img_yuv = calloc(614400, 1);
- VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FROM_SOURCE | DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS, 255, 0 };
- bcm_host_init();
- fp = fopen("frame.yuv", "rb");
- assert(fp);
- ret = fread(imgs, 1, 460800, fp);
- assert(ret);
- fclose(fp);
- display = vc_dispmanx_display_open( screen );
- ret = vc_dispmanx_display_get_info( display, &info);
- assert(ret == 0);
- resource = vc_dispmanx_resource_create( VC_IMAGE_YUV420, width, height, &vc_image_ptr );
- assert( resource );
- memcpy(img_yuv, imgs, 460800);
- vc_dispmanx_rect_set( &dst_rect, 0, 0, width, height);
- ret = vc_dispmanx_resource_write_data(resource, VC_IMAGE_YUV420, pitch * 2, img_yuv, &dst_rect );
- assert( ret == 0 );
- update = vc_dispmanx_update_start( 10 );
- assert( update );
- vc_dispmanx_rect_set( &src_rect, 0, 0, width << 16, height << 16 );
- vc_dispmanx_rect_set( &dst_rect, 0, 0, width, height );
- element = vc_dispmanx_element_add( update, display, 2000, &dst_rect, resource, &src_rect, DISPMANX_PROTECTION_NONE, &alpha, NULL, VC_IMAGE_ROT0 );
- ret = vc_dispmanx_update_submit_sync(update);
- assert( ret == 0 );
- sleep(5);
- update = vc_dispmanx_update_start( 10 );
- assert(update);
- ret = vc_dispmanx_element_remove(update, element);
- assert( ret == 0 );
- ret = vc_dispmanx_update_submit_sync(update);
- assert( ret == 0 );
- ret = vc_dispmanx_resource_delete(resource);
- assert( ret == 0 );
- ret = vc_dispmanx_display_close(display);
- assert( ret == 0 );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement