Advertisement
Guest User

Untitled

a guest
Apr 30th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdarg.h>
  4. #include <assert.h>
  5. #include <unistd.h>
  6. #include <sys/time.h>
  7.  
  8. #include "bcm_host.h"
  9.  
  10. #define WIDTH   480
  11. #define HEIGHT  640
  12.  
  13. #ifndef ALIGN_UP
  14. #define ALIGN_UP(x,y)  ((x + (y)-1) & ~((y)-1))
  15. #endif
  16.  
  17. int main(void)
  18. {    
  19.     uint32_t screen = 0;
  20.     int ret;
  21.    
  22.     DISPMANX_DISPLAY_HANDLE_T display;      // Esse display será aberto por vc_dispmanx_display_open()
  23.     DISPMANX_MODEINFO_T info;               // Esta estrutura será preenchida pelo comando vc_dispmanx_display_get_info()
  24.     DISPMANX_RESOURCE_HANDLE_T resource;    // Este handle é obtido pelo comando vc_dispmanx_resource_create()
  25.     DISPMANX_UPDATE_HANDLE_T update;        // Este handle é obtido pelo comando vc_dispmanx_update_start()
  26.     DISPMANX_ELEMENT_HANDLE_T element;      // Este handle é obtido pelo comando vc_dispmanx_element_add
  27.     VC_RECT_T src_rect;
  28.     VC_RECT_T dst_rect;
  29.    
  30.     FILE * fp;
  31.    
  32.     uint8_t  * img_yuv;
  33.     uint8_t * imgs;
  34.            
  35.     uint32_t vc_image_ptr;              // Este valor é preenchido (provavelmente) pela função vc_dispmanx_resource_create()
  36.     int width = WIDTH;                  // Tamanho do retângulo, definido em #define acima
  37.     int height = HEIGHT;                // Tamanho do retângulo, definido em #define acima
  38.     int pitch = ALIGN_UP(width, 16);
  39.  
  40.     imgs = calloc(460800, 1);
  41.     img_yuv = calloc(614400, 1);
  42.    
  43.     VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FROM_SOURCE | DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS, 255, 0 };
  44.  
  45.     bcm_host_init();
  46.    
  47.     fp = fopen("frame.yuv", "rb");
  48.     assert(fp);
  49.  
  50.     ret = fread(imgs, 1, 460800, fp);
  51.     assert(ret);
  52.    
  53.     fclose(fp);
  54.  
  55.     display = vc_dispmanx_display_open( screen );          
  56.     ret = vc_dispmanx_display_get_info( display, &info);   
  57.     assert(ret == 0);
  58.  
  59.     resource = vc_dispmanx_resource_create( VC_IMAGE_YUV420, width, height, &vc_image_ptr );
  60.     assert( resource );
  61.    
  62.     memcpy(img_yuv, imgs, 460800); 
  63.    
  64.     vc_dispmanx_rect_set( &dst_rect, 0, 0, width, height);
  65.     ret = vc_dispmanx_resource_write_data(resource, VC_IMAGE_YUV420, pitch * 2, img_yuv, &dst_rect );
  66.     assert( ret == 0 );
  67.    
  68.     update = vc_dispmanx_update_start( 10 );
  69.     assert( update );
  70.  
  71.     vc_dispmanx_rect_set( &src_rect, 0, 0, width << 16, height << 16 );
  72.     vc_dispmanx_rect_set( &dst_rect, 0, 0, width, height );
  73.  
  74.     element = vc_dispmanx_element_add( update, display, 2000, &dst_rect, resource, &src_rect, DISPMANX_PROTECTION_NONE, &alpha, NULL, VC_IMAGE_ROT0 );
  75.  
  76.     ret = vc_dispmanx_update_submit_sync(update);
  77.     assert( ret == 0 );
  78.    
  79.     sleep(5);
  80.    
  81.     update = vc_dispmanx_update_start( 10 );
  82.     assert(update);
  83.    
  84.     ret = vc_dispmanx_element_remove(update, element);
  85.     assert( ret == 0 );
  86.    
  87.     ret = vc_dispmanx_update_submit_sync(update);
  88.     assert( ret == 0 );
  89.    
  90.     ret = vc_dispmanx_resource_delete(resource);
  91.     assert( ret == 0 );
  92.    
  93.     ret = vc_dispmanx_display_close(display);
  94.     assert( ret == 0 );
  95.  
  96.     return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement