framebuff操作程序
来源:互联网 发布:telnet 端口不通 编辑:程序博客网 时间:2024/06/15 02:41
/*
* Usage:
*
*/
#include <unistd.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "s1d13521ioctl.h"
#include <linux/fb.h>
#define WF_MODE_INIT 0
#define WF_MODE_DU 1
#define WF_MODE_GC16 2
#define WF_MODE_GC4 3
int main(int argc,char*argv[])
{
int fbdev, i, j;
static unsignedshort*vram;
unsigned short*pdata;
unsigned short*pdata1;
unsigned char clr;
int choose = 0;
int fd;
int WIDTH = 600;
int HEIGHT = 800;
int PIC_WIDTH = 600;
int PIC_HEIGHT= 800;
unsigned char*data;
struct stat sb;
int xindex;
int yindex;
int retVal;
int update_mode = 0;
unsigned short mode;
unsigned short cmd[10];
struct fb_var_screeninfo info;
choose = atoi(argv[1]);
update_mode = atoi(argv[2]);
printf("choose = %d, update_mode = %d\n", choose, update_mode);
/*read a grayscale file from external*/
fd = open(argv[3], O_RDONLY);
if (fd < 0){
printf("Failed to open:%s\n", argv[3]);
exit(-1);
}
if (fstat(fd,&sb)== -1){
printf("stat test_fb error!\n");
return -1;
}
printf("file size = %d!\n", sb.st_size);
data = (unsignedchar*)malloc(sb.st_size+1);
if (data == NULL){
printf("Failed to malloc\n");
exit(-1);
}
retVal = read(fd, data, sb.st_size);
if (retVal< sb.st_size){
printf("read32read32: retVal < N, fd = %d ,retVal = %d\n", fd, retVal);
return -1;
}
fbdev = open("/dev/graphics/fb0", O_RDWR);
if ( fbdev< 0)
{
printf("Failed to open:fb");
exit(-1);
}
if (ioctl(fbdev, FBIOGET_VSCREENINFO,&info)== -1){
printf("FBIOGET_VSCREENINFO error\n");
exit(-1);
}
printf("yres = %d\n", info.yres);
printf("xres = %d\n", info.xres);
printf("yres_virtual = %d\n", info.yres_virtual);
printf("xres_virtual = %d\n", info.xres_virtual);
/* RGB16 */
vram = (unsignedshort*)mmap(NULL, info.xres_virtual* info.yres_virtual* 2,
PROT_READ | PROT_WRITE, MAP_SHARED, fbdev,0);
if(vram == MAP_FAILED){
printf("mmap OVERLAY2 error!\n");
goto out;
}
/*Clear the framebuffer, nor the screen*/
for(i = 0; i < info.yres_virtual; i++){
for(j = 0; j < info.xres_virtual; j++){
vram[i*info.xres_virtual+ j]= 0xFFFF;
}
}
pdata = (unsignedshort*)data;
xindex = 0;
yindex = 0;
for(i = 0; i < info.yres; i++){
xindex = 0;
for(j = 0; j < info.xres; j++){
vram[i*info.xres+j]= pdata[i*info.xres+ j];
xindex++;
if(xindex>= PIC_WIDTH)
break;
}
yindex++;
if (yindex>= PIC_HEIGHT)
break;
}
info.yoffset = 0;
info.activate = FB_ACTIVATE_VBL;
ioctl(fbdev,FBIOPUT_VSCREENINFO,&info);/*control the first frame buffer*/
bzero(cmd,sizeof(cmd));
switch (choose){
case 1:
cmd[0] = WF_MODE_DU;
break;
case 2:
cmd[0] = WF_MODE_GC16;
break;
case 3:
cmd[0] = WF_MODE_GC4;
break;
default:
printf("%s:input mode error! choose = %d\n",__func__, choose);
}
cmd[1] = 0;
cmd[2] = 0;
switch (update_mode){
case 1: //UPD_FULL
ioctl(fbdev,S1D13521_UPD_FULL, cmd);
break;
case 2://UPD_PART
ioctl(fbdev,S1D13521_UPD_PART, cmd);
break;
case 3://UPD_FULL_AREA
cmd[3] = 20; /*x*/
cmd[4] = 20; /*y*/
cmd[5] = 200;/*width*/
cmd[6] = 200;/*height*/
ioctl(fbdev,S1D13521_UPD_FULL_AREA, cmd);
break;
case 4:
cmd[3] = 100;/*x*/
cmd[4] = 300;/*y*/
cmd[5] = 400;/*width*/
cmd[6] = 100;/*height*/
ioctl(fbdev,S1D13521_UPD_PART_AREA, cmd);
break;
case 5:
for (i = 0; i < 600; i++){
cmd[3] = i + 50;
cmd[4] = 300;
cmd[5] = 10;
cmd[6] = 10;
usleep(1000* 10);
ioctl(fbdev,S1D13521_UPD_PART_AREA, cmd);
}
break;
default:
for(i = 0; i < info.yres_virtual; i++){
for(j = 0; j < info.xres_virtual; j++){
vram[i*info.xres_virtual+ j]= 0xFFFF;
}
}
cmd[0] = WF_MODE_GC16;
cmd[1] = 0;
cmd[2] = 0;
ioctl(fbdev,S1D13521_UPD_FULL, cmd);
printf("%s: input update_mode error! clear screen !\n",__func__);
}
void showbar(char*cmd)
{
int i = 0;
for (i = 0; i < 600; i++){
cmd[3] = i + 10;
cmd[4] = 300;
cmd[5] = 10;
cmd[6] = 10;
usleep(1000* 10);
}
}
out:
munmap(vram, info.xres_virtual* info.yres_virtual* 2);
close(fbdev);
close(fd);
free(data);
printf("end\n");
}
- framebuff操作程序
- Android Framebuff 分析
- Android Framebuff 分析
- 从printk到framebuff
- linux -- framebuff驱动总结
- Framebuff中pixclock是如何计算的?
- 交叉编译framebuff图片浏览工具fbv
- C语言实现的在framebuff上面显示图片
- 备料操作程序说明
- 文件操作程序
- java操作外部程序
- J2ME程序操作文件系统
- j2me程序操作文件系统
- J2ME程序操作文件系统
- J2ME程序操作文件系统
- J2ME程序操作文件系统
- J2ME程序操作文件系统
- 常用系统程序操作
- ListView与Button的共存问题解决
- linux内核层与应用层通讯方法
- ubuntu下运行等级设置以及引导加载程序路径问题
- implantisomd5和checkisomd5
- amoeba安装手册
- framebuff操作程序
- C++对象的直接初始化和复制初始化
- JAVA文本框格式化
- Tomcat6.0配置JNDI数据源完整例子
- 人人笔试 2011.10.11北航场
- 优化的冒泡排序C代码
- 学习junit和hamcrest的使用
- JS 移动层 div 精简示例
- PHP+IIS+Mysql+PHPmyadmin