2024年9月11日嵌入式学习

今日继续学习framebuffer

利用framebuffer画图

找到一张图然后将图片显示在终端上

#define RGB888_FMT 32
#define RGB565_FMT 16
#include"utf.h"
void draw_bmp(int x , int y , char *picname , int w ,int h)
{
    int fd = open(picname , O_RDONLY);
    if(fd == -1)
    {
        perror("fail open");
        return;
    }

    lseek(fd , 54 , SEEK_SET);

    unsigned char r , b , g ;

    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  , y + j , col);
            }
            if(vinf.bits_per_pixel == RGB565_FMT)
            {
                unsigned int col = ((r >> 3) << 11) | ((g >> 2) << 5) | ((b >> 3) << 0);
                draw_point(i + x , j + i , col);
            }
        }
    }
    free(buff);
    close(fd);
}

tmp图片格式前54个字节时图片信息

显示一个字体,基于一个字库

int display_show_utf8(UTF8_INFO *info, int x, int y, char* zi, u32 col, u32 col1)
{
    unsigned long  out = 0 ;
    int ret = enc_utf8_to_unicode_one((unsigned char*)zi,&out);

    unsigned char* data = get_utf_data(info,out);
    unsigned char temp = 0 ;
    unsigned int i,j,k;
    unsigned int num = 0;
    for(i=0;i<info->height;i++)
    {
        for(j=0;j<info->width/8;j++)
        {
            temp = data[num++];
            for(k=0;k<8;k++)
            {
                if(0x80&temp)
                {
                    draw_point( x+k+j*8, y+i, col);
                }
                else
                {

                    draw_point( x+k+j*8, y+i, col1);
                }
                temp= temp<<1;
            }
        }

    }
    return ret;
}

显示一行字

int display_show_utf8_str(UTF8_INFO *info, int arg_x, int arg_y,  char* zi, u32 col, u32 col1)
{
    char* temp = zi;
    unsigned int x = arg_x ;
    unsigned int y =  arg_y;

    while(*temp != '\0')
    {
        int ret = display_show_utf8(info, x, y, temp, col, col1);
        x += info->width;
        if(x > vinf.xres_virtual)
        {
            x = 0;
            y += info->height;
            if(y > vinf.yres_virtual)
            {
                y = 0;
            }
        }

        temp += ret;
    }
    return 0;
}

继续去写了日志模块

创建日志文件

char filename[100] = {0};
int init_log()
{
    time_t now = time(NULL);
    struct tm *localtm = localtime(&now);
    sprintf(filename ,"%d年%d月%d日.txt" ,  localtm->tm_year + 1900 , localtm->tm_mon + 1, localtm->tm_mday);
    int fd = open(filename , O_RDWR | O_CREAT , 0666);
    if(fd == -1)
    {
        perror("fail open");
        return -1;
    }
    return fd;
}

日志的记录

#define LOG_INFO 1
#define LOG_WARNING 2
#define LOG_ERROR 3
int write_log(int type , char *info , int fd)
{
    time_t now = time(NULL);
    struct tm *localtm = localtime(&now);
    char loginfo[100] = {0};
    char typenum[100] = {0};
    if(type = 1)
    {
        strcpy(typenum , "INFO");
    }else if(type = 2)
    {
        strcpy(typenum , "WARNING");
    }else if(type = 3)
    {
        strcpy(typenum , "ERROR");
    }
    sprintf(loginfo , "[%d-%d-%d %d:%d:%d][%s]%s\n",localtm->tm_year + 1900 , localtm->tm_mon + 1 , localtm->tm_mday , localtm->tm_hour , localtm->tm_min , localtm->tm_sec , typenum , info);
    write(fd , loginfo , strlen(loginfo));
    return 0;
}

void uninit_log(int fd)
{
    close(fd);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值