在开发板上显示字母,汉字,方框,宋体等。 我这里大部分都是参考韦东山老师讲的。
这里只是为了测试lcd驱动并且从新总结下。
英文字母和汉字: 利用点阵画点。
画线和画框: 调用画线函数
宋体: 利用freetype 库
图片: 利用libjpeg 压缩jpeg 图片显示。
代码如下:
// lcd_test.c
// 显示 横线 竖线 框 字符 汉字 字体 图像等
#include <sys/mman.h>
#include <stdio.h>
#include "ascii 8_16.h"
#include <linux/fb.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <wchar.h>
#include <string.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include "jpeglib.h"
#include <setjmp.h>
int fb_fd;
int hzk_fd;
struct stat hzk_stat;
unsigned char *hzk_mem;
unsigned char *fb_mem;
struct fb_var_screeninfo var; /* Current var */
struct fb_fix_screeninfo fix; /* Current fix */
int x_res, y_res;
int line_length;
int screen_size;
int pixel_length;
// freetype relattived parameters
FT_Library library;
FT_Face face;
FT_GlyphSlot slot;
FT_Matrix matrix; /* transformation matrix */
FT_Vector pen; /* untransformed origin */
FT_Error error;
wchar_t *wtext = L"中国neo";
unsigned int n ;
/* 显示 jpeg 图片相关参数*/
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
FILE * infile; /* source file */
unsigned char *buffer; /* Output row buffer */
int row_stride; /* physical row width in output buffer */
struct my_error_mgr {
struct jpeg_error_mgr pub; /* "public" fields */
};
void lcd_clear_display(unsigned int c)
{
memset(fb_mem , 0 , screen_size);
}
void show_put_pixel(int x ,int y , unsigned int color)
{
unsigned int *pen_32 = (unsigned int *)(fb_mem + y*line_length + x*pixel_length);
if(var.bits_per_pixel != 32)
{
printf(" sorry ! only support 32 bit\n");
return ;
}
*pen_32 = color ;
}
void lcd_put_line(int x1, int y1 , int x2, int y2 , unsigned int color)
{
int dx,dy,e;
dx=x2-x1;
dy=y2-y1;
if(dx>=0)
{
if(dy >= 0) // dy>&