1.利用framebuffer绘制图像
宏定义
1.#define RGB888_FMT 32
2.#define RGB565_FMT 16
3.#include"utf.h"
函数接口主体
void draw_bmp(int x, int y, char *picname, int w, int h)
{int fd = open(picname, O_RDONLY);if (-1 == fd){perror("fail open bmp");return ;}lseek(fd, 54, SEEK_SET);unsigned char r, g, b;unsigned char *buff = malloc(w*h*3);read(fd, buff, w*h*3);unsigned char *p = buff;for (int j = h-1; j >= 0; j--){for (int i = 0; i < w; i++){b = *p; p++;g = *p; p++;r = *p; p++;if (vinf.bits_per_pixel == RGB888_FMT){unsigned int col = (r << 16) | (g << 8) | (b << 0);draw_point(i+x, j+y, col);}else if (vinf.bits_per_pixel == RGB565_FMT){unsigned short col = ((r >> 3) << 11) | ((g >> 2) << 5) | ((b >> 3) << 0);draw_point(i+x, j+y, col);}}}free(buff);close(fd);
}
内部调用的函数接口
void draw_point(int x,int y,unsigned int col)
{
if(x >= vinf.xres || y >= vinf.yres)
{
return;
}
if(vinf.bits_per_pixel == RGB888_FMT)
{
unsigned int *p = pmem;
*(p + y* vinf.xres_virtual + x)= col;
}
else if(vinf.bits_per_pixel == RGB565_FMT)
{
unsigned short *p = pmem;
*(p + y *vinf.xres_virtual + x)= col;
}
return;
}
2.利用framebuffer实现输出一个字
函数主体
void draw_word(int x,int y,unsigned char *word,int w,int h,unsigned int col)
{
for(int j =0;j<h;++j)
{
for(int i=0;i<w;++i)
{
unsigned char tmp = word[i+j*w];
for(int k =0;k<8;++k)
{
if(tmp & 0x80)
{
draw_point(i*8+k+x,j+y,col);
}
else
{
//文字背景色
}
tmp = tmp << 1;
}
}
}
}