#include <linux/fb.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
#include "xiyangyang-bitmap.inc" // 包含喜洋洋黑白点阵数据
static char luther_gliethttp_xiyangyang[];
int fb;
unsigned char *fb_mem;
int main(void)
{
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
int gliethttp_screensize;
int luther_mmap_size;
int screen_line_bytes;
int bitmap_x_size, bitmap_y_size;
int i, j, m, k;
int bit_value;
int xorg, yorg;
int screen_bytes_per_pixel;
fb = open("/dev/fb0", O_RDWR);
ioctl(fb, FBIOGET_FSCREENINFO, &finfo);
ioctl(fb, FBIOGET_VSCREENINFO, &vinfo);
// 计算整个屏幕占用字节数[luther.gliethttp]
screen_bytes_per_pixel = vinfo.bits_per_pixel / 8;
screen_line_bytes = vinfo.xres * screen_bytes_per_pixel;
gliethttp_screensize = vinfo.yres * screen_line_bytes;
printf("vinfo.xres=%d\n"
"vinfo.yres=%d\n"
"vinfo.bits_per_pixel=%d\n"
"gliethttp_screensize=%d\n",
vinfo.xres, vinfo.yres,
vinfo.bits_per_pixel,
gliethttp_screensize);
luther_mmap_size = gliethttp_screensize;
fb_mem = mmap(NULL, luther_mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0);
memset(fb_mem, 0, gliethttp_screensize); // 屏幕填充为黑色
bitmap_x_size = 800;
bitmap_y_size = 600;
xorg = (vinfo.xres - bitmap_x_size) >> 1; // 将图像放在x轴中间
yorg = 0;
// 显示黑白二色的喜洋洋[luther.gliethttp]
for ( i = 0; i < bitmap_y_size; i++)
for ( j = 0; j < (bitmap_x_size>>3); j++)
for ( m = 0; m < 8; m++) {
bit_value = luther_gliethttp_xiyangyang[i*(bitmap_x_size >> 3)+ j] & (0x80 >> m);
bit_value = bit_value ? 0xff:0x00;
// bit_value = 0xff;
for ( k = 0; k < screen_bytes_per_pixel; k++) {
fb_mem[(yorg+i)*screen_line_bytes + (xorg+(j<<3)+m)*screen_bytes_per_pixel + k] = bit_value;
// usleep(5);
}
}
munmap(fb_mem, luther_mmap_size);
close(fb);
return 0;
}
|
文件: | xiyangyang-bitmap.inc.tar.bz2 |
大小: | 16KB |
下载: | 下载 |
|
|