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 * img1;
- uint8_t * img2;
- 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);
- img1 = calloc((WIDTH*HEIGHT*3)>>1, 1);
- img2 = calloc((WIDTH*HEIGHT*3)>>1, 1);
- VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FROM_SOURCE | DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS, 255, 0 };
- bcm_host_init();
- // Carrega imagens para memória
- fp = fopen("f1.yuv", "rb");
- assert(fp);
- ret = fread(img1, 1, (WIDTH*HEIGHT*3)>>1, fp);
- assert(ret);
- fclose(fp);
- fp = fopen("f2.yuv", "rb");
- assert(fp);
- ret = fread(img2, 1, (WIDTH*HEIGHT*3)>>1, fp);
- assert(ret);
- fclose(fp);
- // Mostra imagens na tela
- 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 );
- 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 );
- // Coloca primeiro frame na tela
- ret = vc_dispmanx_resource_write_data(resource, VC_IMAGE_YUV420, (pitch * 3)>>1, img1, &dst_rect );
- assert( ret == 0 );
- ret = vc_dispmanx_update_submit_sync(update);
- assert( ret == 0 );
- sleep(1);
- for(int n = 0; n < 5; n++)
- {
- // Coloca segundo frame na tela
- update = vc_dispmanx_update_start( 10 );
- assert( update );
- ret = vc_dispmanx_resource_write_data(resource, VC_IMAGE_YUV420, (pitch * 3)>>1, img2, &dst_rect );
- assert( ret == 0 );
- ret = vc_dispmanx_update_submit_sync(update);
- assert( ret == 0 );
- sleep(1);
- update = vc_dispmanx_update_start( 10 );
- assert( update );
- ret = vc_dispmanx_resource_write_data(resource, VC_IMAGE_YUV420, (pitch * 3)>>1, img1, &dst_rect );
- assert( ret == 0 );
- ret = vc_dispmanx_update_submit_sync(update);
- assert( ret == 0 );
- sleep(1);
- }
- // Encerra display
- printf("Desligando\n");
- 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 );
- printf("Fim\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement