C语言实现的在framebuff上面显示图片
2013-08-05 18:11
309 查看
/**************************************************
//初始化framebuffer,和在framebuffer上面显示图片数据
*************************************************/
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <errno.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/input.h>
#include <time.h>
#include <stdlib.h>
//framebuffer
char *fb_addr;
int screen_fbd = 0;
struct fb_fix_screeninfo fb_fix;//这两个用于获取framebuffer相关信息的
struct fb_var_screeninfo fb_var;
unsigned fb_size; //buffer的长度
char *env = NULL;//fb的路径
//初始化framebuffer函数
int initFramebuffer(void)
{
if(!(env = getenv("FRAMEBUFFER"))) //getenv()用来取得参数envvar环境变量的内容,如果没有这样的变量,默认framebuffer路径是下面的
{
env = "/dev/fb0";
}
screen_fbd = open(env, O_RDWR); //以可读可写的方式打fb0
if(screen_fbd < 0)
{
return 0;
}
//ioctl:控制I/O设备 ,提供了一种获得设备信息和向设备发送控制参数的手段
if(ioctl(screen_fbd, FBIOGET_FSCREENINFO, &fb_fix) == -1)
{//返回与Framebuffer有关的固定的信息,比如图形硬件上实际的帧缓存空间的大小、
close(screen_fbd);
return 0;
}
if(ioctl(screen_fbd, FBIOGET_VSCREENINFO, &fb_var) == -1)
{//而后者返回的是与Framebuffer有关的可变信息,可变的信息就是指Framebuffer的长度、宽度以及颜色深度等信息
close(screen_fbd);
return 0;
} //应该是位深度吧,用几位表示一个像素点
fb_size = fb_var.yres * fb_fix.line_length;
fb_addr = (char *)mmap(NULL, fb_size, PROT_READ|PROT_WRITE,MAP_SHARED, screen_fbd, 0);
return 1;
}
/*
写数据文件到LCD的freamebuffer中
参数1:解码后的图片数据的指针
参数2:要在LCD上显示的位置的X坐标
参数3:要在LCD上显示的位置的Y坐标
参数4:图片宽度
参数5:图片高度
*/
void write_buf_image(unsigned char *gimage,int x,int y,int width,int height)
{ short *buff = (short*)fb_addr;
short *buffer = buff;
int i = 0,j = 0,a = 0;
for(j = 0; (j < height)&&(y+j)<272; j++ )
{
buff = (buffer+x)+480*(j+y);
for(i = 0; ((i < width)&&((x+i)<480)); i++)
{
*buff++ = *(gimage+a+1)<<8|*(gimage+a);
a++;
a++;
}
a=width*2*j;
}
}
/*
int main(void)
{
int i;
initFramebuffer();
unsigned char *image=(char*)malloc(480*272*2);
for(i=0; i<480*272*2; i++)
image[i] = 0xff;
write_buf_image(image,0,0,480,272);
return 0;
}
*/
//初始化framebuffer,和在framebuffer上面显示图片数据
*************************************************/
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <errno.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/input.h>
#include <time.h>
#include <stdlib.h>
//framebuffer
char *fb_addr;
int screen_fbd = 0;
struct fb_fix_screeninfo fb_fix;//这两个用于获取framebuffer相关信息的
struct fb_var_screeninfo fb_var;
unsigned fb_size; //buffer的长度
char *env = NULL;//fb的路径
//初始化framebuffer函数
int initFramebuffer(void)
{
if(!(env = getenv("FRAMEBUFFER"))) //getenv()用来取得参数envvar环境变量的内容,如果没有这样的变量,默认framebuffer路径是下面的
{
env = "/dev/fb0";
}
screen_fbd = open(env, O_RDWR); //以可读可写的方式打fb0
if(screen_fbd < 0)
{
return 0;
}
//ioctl:控制I/O设备 ,提供了一种获得设备信息和向设备发送控制参数的手段
if(ioctl(screen_fbd, FBIOGET_FSCREENINFO, &fb_fix) == -1)
{//返回与Framebuffer有关的固定的信息,比如图形硬件上实际的帧缓存空间的大小、
close(screen_fbd);
return 0;
}
if(ioctl(screen_fbd, FBIOGET_VSCREENINFO, &fb_var) == -1)
{//而后者返回的是与Framebuffer有关的可变信息,可变的信息就是指Framebuffer的长度、宽度以及颜色深度等信息
close(screen_fbd);
return 0;
} //应该是位深度吧,用几位表示一个像素点
fb_size = fb_var.yres * fb_fix.line_length;
fb_addr = (char *)mmap(NULL, fb_size, PROT_READ|PROT_WRITE,MAP_SHARED, screen_fbd, 0);
return 1;
}
/*
写数据文件到LCD的freamebuffer中
参数1:解码后的图片数据的指针
参数2:要在LCD上显示的位置的X坐标
参数3:要在LCD上显示的位置的Y坐标
参数4:图片宽度
参数5:图片高度
*/
void write_buf_image(unsigned char *gimage,int x,int y,int width,int height)
{ short *buff = (short*)fb_addr;
short *buffer = buff;
int i = 0,j = 0,a = 0;
for(j = 0; (j < height)&&(y+j)<272; j++ )
{
buff = (buffer+x)+480*(j+y);
for(i = 0; ((i < width)&&((x+i)<480)); i++)
{
*buff++ = *(gimage+a+1)<<8|*(gimage+a);
a++;
a++;
}
a=width*2*j;
}
}
/*
int main(void)
{
int i;
initFramebuffer();
unsigned char *image=(char*)malloc(480*272*2);
for(i=0; i<480*272*2; i++)
image[i] = 0xff;
write_buf_image(image,0,0,480,272);
return 0;
}
*/
相关文章推荐
- Jquery实现鼠标放在图片上面显示大图效果
- (源码实例)通过层DIV实现,当鼠标放在链接上面,显示图片及文字
- (源码实例)通过层DIV实现,当鼠标放在链接上面,显示图片及文字 - 流星絮语 JAVA学习笔记 - CSDNBlog
- (源码实例)通过层DIV实现,当鼠标放在链接上面,显示图片及文字
- (源码实例)通过层DIV实现,当鼠标放在链接上面,显示图片及文字
- CSS实现Div透明,而显示在上面的文字不透明,但也可看到显示在下面的图片内容
- Android实现自适应图片和字体显示
- 写一个函数实现根据下拉列表的变化,更新图片显示
- VC++实现在图片上显示数字
- ASP.NET实现投票结果的图片进度条显示
- Asp.net 2.0 无刷新图片上传 显示缩略图 具体实现
- QT画图教程1:实现给label上面显示图并且让图自适应控件大小
- Linux framebuffer显示bmp图片【转】
- Discuz板块横排显示图片的实现方法
- dede5.7实现有缩略图则显示缩略图,无则不显示图片
- frameburrer显示bmp图片( 程序)
- Android中 在显示ImageView时图片上面和下面都出现一段空白区间的解决办法
- 用css来控制图片大小显示的实现方法与代码
- 在adapter中实现点击图片,显示dialog public HomeMsgAdapter(Context context,List<HomeMsgBean> list){