hi3531的hifb显示1080p60Hz 分类: HI3531 arm-linux-Ubuntu 2014-03-22 10:43 1061人阅读 评论(2) 收藏
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include <sys/mman.h> //mmap
#include "hifb.h"
#include "sample_comm.h"
#define IMAGE_WIDTH 1920
#define IMAGE_HEIGHT 1080
#define IMAGE_SIZE (1920*1080*3)
#define IMAGE_NUM 14
#define IMAGE_PATH "./res/%d.bits"
struct fb_bitfield a16 = {15, 1, 0}, a32 = {24, 8, 0};
struct fb_bitfield r16 = {10, 5, 0}, r32 = {16, 8, 0};
struct fb_bitfield g16 = {5, 5, 0}, g32 = {8, 8, 0};
struct fb_bitfield b16 = {0, 5, 0}, b32 = {0, 8, 0};
HIFB_ALPHA_S stAlpha;
HIFB_COLORKEY_S stColorKey;
FILE *fp1,*fp2,*fp3;
char bmp_buf[1920*1080*3*4];
int main()
{
int fd;
int i;
struct fb_fix_screeninfo fix;
struct fb_var_screeninfo var;
unsigned char *pShowScreen;
unsigned char *pHideScreen;
HIFB_POINT_S stPoint = {0, 0};
FILE *fp;
VO_PUB_ATTR_S stPubAttr = {0};
char image_name[128];
/*0. open VO device 0 */
/* …… initialize the attributes for stPubAttr */
HI_MPI_VO_SetPubAttr(0, &stPubAttr);
HI_MPI_VO_Enable(0);
/*1. open Framebuffer device overlay 0*/
fd = open("/dev/fb0", O_RDWR);
if(fd < 0)
{
printf("open fb0 failed!\n");
return -1;
}
HI_BOOL bShow = HI_FALSE;
/*2. set the screen original position*/
if (ioctl(fd, FBIOPUT_SCREEN_ORIGIN_HIFB, &stPoint) < 0)
{
printf("set screen original show position failed!\n");
return -1;
}
/*3. get the variable screen info*/
if (ioctl(fd, FBIOGET_VSCREENINFO, &var) < 0)
{
printf("Get variable screen info failed!\n");
close(fd);
return -1;
}
/*4. modify the variable screen info
the screen size: IMAGE_WIDTH*IMAGE_HEIGHT
the virtual screen size: IMAGE_WIDTH*(IMAGE_HEIGHT*2)
the pixel format: ARGB1555
*/
printf("%d,%d,%d,%d,%d,%d,%d\n", var.xres_virtual,var.yres_virtual,var.xres,var.yres,var.xoffset,var.yoffset,var.bits_per_pixel);
var.xres = var.xres_virtual = IMAGE_WIDTH;
var.yres = IMAGE_HEIGHT;
var.yres_virtual = IMAGE_HEIGHT*2;
var.bits_per_pixel = 32;
var.xoffset = 0;
var.yoffset = 0;
var.red = r32;
var.green = g32;
var.blue = b32;
var.transp = a32;
/*5. set the variable screeninfo*/
if (ioctl(fd, FBIOPUT_VSCREENINFO, &var) < 0)
{
printf("Put variable screen info failed!\n");
close(fd);
return -1;
}
printf("%d,%d,%d,%d,%d,%d,%d\n", var.xres_virtual,var.yres_virtual,var.xres,var.yres,var.xoffset,var.yoffset,var.bits_per_pixel);
/*6. get the fix screen info*/
if (ioctl(fd, FBIOGET_FSCREENINFO, &fix) < 0)
{
printf("Get fix screen info failed!\n");
close(fd);
return -1;
}
/*7. map the physical video memory for user use*/
pShowScreen = mmap(NULL, fix.smem_len, PROT_READ|PROT_WRITE,MAP_SHARED, fd, 0);
//pHideScreen = pShowScreen + (1920*1080*3;
memset(pShowScreen, 0, 1920*1080*8);
printf("fix.smem_len: %d\n", fix.smem_len);
/*8. load the bitmaps from file to hide screen and set pan display the
hide screen*/
unsigned int h,w,u32Height = 1080;
unsigned int u32Width = 1920;
bShow = HI_TRUE;
if (ioctl(fd, FBIOPUT_SHOW_HIFB, &bShow) < 0)
{
printf("FBIOPUT_SHOW_HIFB failed!\n");
close(fd);
return -1;
}
fp1 = fopen("1080P1.bmp", "rb");
if(fp1==NULL) printf("fp1 not open\n");
fread(bmp_buf, 54, 1, fp1);
fread(bmp_buf, u32Width*u32Height*3, 1, fp1);
fclose(fp1);
fp2 = fopen("2.bmp", "rb");
if(fp2==NULL) printf("fp1 not open\n");
fread(bmp_buf+u32Width*u32Height*3, 54, 1, fp2);
fread(bmp_buf+u32Width*u32Height*3, u32Width*u32Height*3, 1, fp2);
fclose(fp2);
fp3 = fopen("3.bmp", "rb");
if(fp3==NULL) printf("fp1 not open\n");
fread(bmp_buf+u32Width*u32Height*6, 54, 1, fp3);
fread(bmp_buf+u32Width*u32Height*6, u32Width*u32Height*3, 1, fp3);
fclose(fp3);
printf("ok open file\n");
int index=0;
for( index=0;index<100;index++)
{
////////////////////////////////////////////////////////////////////////////////////
for(h=0;h<u32Height;h++)
{
for(w=0;w<u32Width;w++)
{
*(unsigned char *)(pShowScreen+(1-index%2)*u32Width*u32Height*4+h*u32Width*4+w*4+0) = bmp_buf[(u32Height-1-h)*u32Width*3+w*3+0+(index%3)*u32Width*u32Height*3]; //b
*(unsigned char *)(pShowScreen+(1-index%2)*u32Width*u32Height*4+h*u32Width*4+w*4+1) = bmp_buf[(u32Height-1-h)*u32Width*3+w*3+1+(index%3)*u32Width*u32Height*3]; //g
*(unsigned char *)(pShowScreen+(1-index%2)*u32Width*u32Height*4+h*u32Width*4+w*4+2) = bmp_buf[(u32Height-1-h)*u32Width*3+w*3+2+(index%3)*u32Width*u32Height*3]; //r
*(unsigned char *)(pShowScreen+(1-index%2)*u32Width*u32Height*4+h*u32Width*4+w*4+3) = 0xff; //a
}
}
////////////////////////////////////////////////////////////////////////////////////
if(index%2==0)
{
var.yoffset = u32Height;
}
else
{
var.yoffset = 0;
}
if (ioctl(fd, FBIOPAN_DISPLAY, &var) < 0)
{
printf("FBIOPAN_DISPLAY failed!\n");
close(fd);
return -1;
}
sleep(3);
}
printf("Enter to quit!\n");
getchar();
/*9. close the devices*/
close(fd);
HI_MPI_VO_Disable(0);
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。