Advertisement
Guest User

Untitled

a guest
May 10th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.82 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 * img1;
  33.     uint8_t * img2;
  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.     img1 = calloc((WIDTH*HEIGHT*3)>>1, 1);
  41.     img2 = calloc((WIDTH*HEIGHT*3)>>1, 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.    
  48.     // Carrega imagens para memória
  49.     fp = fopen("f1.yuv", "rb");
  50.     assert(fp);
  51.  
  52.     ret = fread(img1, 1, (WIDTH*HEIGHT*3)>>1, fp);
  53.     assert(ret);
  54.  
  55.     fclose(fp);
  56.    
  57.     fp = fopen("f2.yuv", "rb");
  58.     assert(fp);
  59.  
  60.     ret = fread(img2, 1, (WIDTH*HEIGHT*3)>>1, fp);
  61.     assert(ret);
  62.  
  63.     fclose(fp);
  64.    
  65.    
  66.     // Mostra imagens na tela
  67.     display = vc_dispmanx_display_open( screen );          
  68.     ret = vc_dispmanx_display_get_info( display, &info);   
  69.     assert(ret == 0);
  70.  
  71.     resource = vc_dispmanx_resource_create( VC_IMAGE_YUV420, width, height, &vc_image_ptr );
  72.     assert( resource );
  73.  
  74.     update = vc_dispmanx_update_start( 10 );
  75.     assert( update );
  76.    
  77.     vc_dispmanx_rect_set( &src_rect, 0, 0, width << 16, height << 16 );
  78.     vc_dispmanx_rect_set( &dst_rect, 0, 0, width, height );
  79.    
  80.     element = vc_dispmanx_element_add( update, display, 2000, &dst_rect, resource, &src_rect, DISPMANX_PROTECTION_NONE, &alpha, NULL, VC_IMAGE_ROT0 );
  81.  
  82.     // Coloca primeiro frame na tela
  83.     ret = vc_dispmanx_resource_write_data(resource, VC_IMAGE_YUV420, (pitch * 3)>>1, img1, &dst_rect );
  84.     assert( ret == 0 );
  85.    
  86.     ret = vc_dispmanx_update_submit_sync(update);
  87.     assert( ret == 0 );
  88.    
  89.     sleep(1);
  90.    
  91.     for(int n = 0; n < 5; n++)
  92.     {  
  93.         // Coloca segundo frame na tela
  94.         update = vc_dispmanx_update_start( 10 );
  95.         assert( update );
  96.        
  97.         ret = vc_dispmanx_resource_write_data(resource, VC_IMAGE_YUV420, (pitch * 3)>>1, img2, &dst_rect );
  98.         assert( ret == 0 );
  99.        
  100.         ret = vc_dispmanx_update_submit_sync(update);
  101.         assert( ret == 0 );
  102.        
  103.         sleep(1);
  104.        
  105.         update = vc_dispmanx_update_start( 10 );
  106.         assert( update );
  107.        
  108.         ret = vc_dispmanx_resource_write_data(resource, VC_IMAGE_YUV420, (pitch * 3)>>1, img1, &dst_rect );
  109.         assert( ret == 0 );
  110.        
  111.         ret = vc_dispmanx_update_submit_sync(update);
  112.         assert( ret == 0 );
  113.        
  114.         sleep(1);
  115.     }
  116.    
  117.     // Encerra display
  118.     printf("Desligando\n");
  119.    
  120.     update = vc_dispmanx_update_start( 10 );
  121.     assert(update);
  122.  
  123.     ret = vc_dispmanx_element_remove(update, element);
  124.     assert( ret == 0 );
  125.  
  126.     ret = vc_dispmanx_update_submit_sync(update);
  127.     assert( ret == 0 );
  128.  
  129.     ret = vc_dispmanx_resource_delete(resource);
  130.     assert( ret == 0 );
  131.  
  132.     ret = vc_dispmanx_display_close(display);
  133.     assert( ret == 0 );
  134.  
  135.     printf("Fim\n");
  136.    
  137.     return 0;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement