打印位图字体时出现问题

时间:2018-01-09 18:43:23

标签: c fonts bitmap

最近我试图在C中打印位图字体,只使用set_pixel函数(只在屏幕的确定坐标中设置像素的颜色)。
问题是,当我尝试我的代码时,这段代码根本不起作用。 我会写下代码,你知道为什么会失败吗? 我能找到的唯一原因是警告我的编译器(clang)报告:

x86_64-uefi/tty.c:67:11: warning: incompatible pointer to integer conversion passing 'char [2]' to parameter of type 'char' [-Wint-conversion]
        put_char("c", 1, 1, r | g | b);

我不知道如何解决。

涉及的文件:
 1:tty.c(打印的那个)

#include "font.h"
#include "tty.h"
KABI void put_char(char c, uint8_t x, uint8_t y, uint32_t rgb) 
{
    uint8_t i,j;

    // Convert the character to an index
    c = c & 0x7F;
    if (c < ' ') {
        c = 0;
    } else {
        c -= ' ';
    }

    // 'font' is a multidimensional array of [96][char_width]
    // which is really just a 1D array of size 96*char_width.
    const uint8_t* chr = font[c*CHAR_WIDTH];

    // Draw pixels
    for (j=0; j<CHAR_WIDTH; j++) {
        for (i=0; i<CHAR_HEIGHT; i++) {
            if (chr[j] & (1<<i)) {
                set_pixel(x+j, y+i, rgb);
            }
        }
    }
}

2:tty.h(tty.c的标题)

#pragma once

// Types (uint8_t, etc.)
#include "typedefs.h"

// tty_init: Cleans the screen and setup all.
KABI void tty_init(void);

KABI void put_char(char c, uint8_t x, uint8_t y, uint32_t rgb);

3:font.h(我把它缩短了一点)

// Our types (uint8_t, etc.)
#include "typedefs.h"
#define CHAR_WIDTH 6
#define CHAR_HEIGHT 8
const unsigned char font[96][6] = {
    {0x00,0x00,0x00,0x00,0x00,0x00}, //  
    {0x2e,0x00,0x00,0x00,0x00,0x00}, // !
    {0x03,0x00,0x03,0x00,0x00,0x00}, // "
    {0x0a,0x1f,0x0a,0x1f,0x0a,0x00}, // #
    {0x2e,0x2a,0x6b,0x2a,0x3a,0x00}, // $
    {0x0e,0x2a,0x1e,0x08,0x3c,0x2a}, // %
    {0x3e,0x2a,0x2a,0x22,0x38,0x08}, // &
    {0x03,0x00,0x00,0x00,0x00,0x00}, // '
...
    {0x3e,0x24,0x24,0x24,0x3c,0x00}, // b
    {0x3c,0x24,0x24,0x24,0x24,0x00}, // c
...
    {0x00,0x00,0x00,0x00,0x00,0x00}
};

调用tty_init函数输出以下内容: enter image description here 显然没什么,但如果你仔细看(字体很小),它只打印一个6像素的线, 提前谢谢!

我不知道它是否有事可做,但是......

注意:KABI代表__attribute__((sysv_abi))
并且像素行打印在“代表”字符串的顶部。

0 个答案:

没有答案