mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-02-06 09:02:20 +08:00
Some checks failed
ToolsCI / Tools (push) Has been cancelled
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :components/sal.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
Weekly CI Scheduler / Trigger and Monitor CIs (push) Has been cancelled
Weekly CI Scheduler / Create Discussion Report (push) Has been cancelled
1. 8250 serila family (OFW, PCI, DWC, early) 2. Virtual serial (by graphic and input) 3. HVC early serial 4. ARM PL011 serial Signed-off-by: GuEe-GUI <2991707448@qq.com>
106 lines
2.6 KiB
C
106 lines
2.6 KiB
C
/*
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Change Logs:
|
|
* Date Author Notes
|
|
* 2023-02-25 GuEe-GUI the first version
|
|
*/
|
|
|
|
#include "psf.h"
|
|
|
|
static void psf_read_header(struct psf_font *psf)
|
|
{
|
|
if (psf->header1->magic[0] == PSF1_MAGIC0 &&
|
|
psf->header1->magic[1] == PSF1_MAGIC1)
|
|
{
|
|
psf->font_map = (void *)&psf->header1[1];
|
|
psf->type = PSF_TYPE_1;
|
|
|
|
if (psf->header1->mode & PSF1_MODE512)
|
|
{
|
|
psf->count = 512;
|
|
}
|
|
else
|
|
{
|
|
psf->count = 256;
|
|
}
|
|
|
|
psf->size = psf->header1->charsize;
|
|
psf->height = psf->header1->charsize;
|
|
psf->width = 8;
|
|
}
|
|
else if (psf->header2->magic[0] == PSF2_MAGIC0 &&
|
|
psf->header2->magic[1] == PSF2_MAGIC1 &&
|
|
psf->header2->magic[2] == PSF2_MAGIC2 &&
|
|
psf->header2->magic[3] == PSF2_MAGIC3)
|
|
{
|
|
psf->font_map = (void *)&psf->header2[1];
|
|
psf->type = PSF_TYPE_2;
|
|
psf->count = psf->header2->length;
|
|
psf->size = psf->header2->charsize;
|
|
psf->height = psf->header2->height;
|
|
psf->width = psf->header2->width;
|
|
}
|
|
else
|
|
{
|
|
psf->type = PSF_TYPE_UNKNOW;
|
|
}
|
|
|
|
psf->glyph = psf->height * psf->width;
|
|
}
|
|
|
|
rt_err_t psf_initialize(const void *psf_data, struct psf_font *out_psf)
|
|
{
|
|
struct psf_font *psf = out_psf;
|
|
|
|
psf->raw_data = psf_data;
|
|
psf_read_header(psf);
|
|
|
|
if (psf->type == PSF_TYPE_UNKNOW)
|
|
{
|
|
return -RT_ENOSYS;
|
|
}
|
|
|
|
return RT_EOK;
|
|
}
|
|
|
|
rt_err_t psf_parse(struct psf_font *psf, const rt_uint8_t *font_data,
|
|
rt_uint8_t *tmpglyph, rt_uint32_t color_size,
|
|
rt_uint32_t foreground, rt_uint32_t background)
|
|
{
|
|
rt_uint8_t *font = (void *)font_data, *map = (void *)psf->font_map;
|
|
|
|
psf->font_data = font_data;
|
|
|
|
for (int n = 0; n < psf->count; ++n, map += psf->size)
|
|
{
|
|
rt_memcpy(tmpglyph, map, psf->size);
|
|
|
|
for (int i = 0; i < psf->size; ++i)
|
|
{
|
|
for (int j = 0; j < 8; ++j)
|
|
{
|
|
if (i % (psf->size / psf->height) * 8 + j < psf->width)
|
|
{
|
|
if (tmpglyph[i] & 0x80)
|
|
{
|
|
rt_memcpy(font, &foreground, color_size);
|
|
}
|
|
else
|
|
{
|
|
rt_memcpy(font, &background, color_size);
|
|
}
|
|
|
|
font += color_size;
|
|
}
|
|
|
|
tmpglyph[i] = tmpglyph[i] << 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
return RT_EOK;
|
|
}
|