diff --git a/Rsconscript b/Rsconscript index 13a01ab..0332094 100644 --- a/Rsconscript +++ b/Rsconscript @@ -124,9 +124,9 @@ EOF env["LDFLAGS"] += %w[-ffreestanding -nostdlib -T src/link.ld] env["LIBS"] += %w[gcc] env["OBJDUMP"] = "i686-elf-objdump" - env.FontGen("^/fontgen/fontgen.c", "font/Hack-Regular.ttf") - env["CPPPATH"] += ["#{env.build_root}/fontgen"] - env.Program("^/hos.elf", glob("src/**/*.{S,c}") + ["^/fontgen/fontgen.c"]) + env.FontGen("^/kfont/kfont.c", "font/Hack-Regular.ttf") + env["CPPPATH"] += ["#{env.build_root}/kfont"] + env.Program("^/hos.elf", glob("src/**/*.{S,c}") + ["^/kfont/kfont.c"]) env.depends("#{env.build_root}/hos.elf", "src/link.ld") env.Disassemble("^/hos.elf.txt", "^/hos.elf") env.EfiImage("build/hos-efi.img", %w[^/hos.elf]) diff --git a/src/fb.c b/src/fb.c index 80dc0d2..fb2d60e 100644 --- a/src/fb.c +++ b/src/fb.c @@ -6,6 +6,16 @@ static uint32_t fb_width; static uint32_t fb_height; static uint32_t fb_pitch; +static inline uint32_t build_pixel(uint8_t r, uint8_t g, uint8_t b) +{ + return (r << 16u) | (g << 8u) | b; +} + +static inline void fb_set_pixel(int x, int y, uint8_t r, uint8_t g, uint8_t b) +{ + fb[fb_pitch * y / 4u + x] = build_pixel(r, g, b); +} + void fb_init(uint32_t * addr, uint32_t width, uint32_t height, uint32_t pitch) { fb = addr; @@ -34,3 +44,54 @@ bool fb_ready(void) { return fb != NULL; } + +void fb_blend_alpha8(const uint8_t * bitmap, int width, int height, int pitch, int x, int y, uint8_t r, uint8_t g, uint8_t b) +{ + if (((x + width) <= 0) || (x >= (int)fb_width) || ((y + height) <= 0) || (y >= (int)fb_height)) + { + return; + } + if (x < 0) + { + width += x; + bitmap += (-x); + x = 0; + } + if (y < 0) + { + height += y; + bitmap += ((-y) * pitch); + y = 0; + } + if ((x + width) > (int)fb_width) + { + width = (int)fb_width - x; + } + if ((y + height) > (int)fb_height) + { + height = (int)fb_height - y; + } + uint32_t * target = &fb[fb_pitch * y / 4u + x]; + for (int row = 0; row < height; row++) + { + for (int col = 0; col < width; col++) + { + uint32_t alpha = bitmap[col]; + uint32_t current_pixel = target[col]; + uint8_t cr = (current_pixel >> 16u) & 0xFFu; + uint8_t cg = (current_pixel >> 8u) & 0xFFu; + uint8_t cb = current_pixel & 0xFFu; + uint8_t pr = alpha * r / 255u; + uint8_t pg = alpha * g / 255u; + uint8_t pb = alpha * b / 255u; + uint32_t current_alpha = 255u - alpha; + uint32_t pixel = build_pixel( + pr + current_alpha * cr / 255u, + pg + current_alpha * cg / 255u, + pb + current_alpha * cb / 255u); + target[col] = pixel; + } + bitmap += pitch; + target += (fb_pitch / 4u); + } +} diff --git a/src/fb.h b/src/fb.h index e00f716..93c575c 100644 --- a/src/fb.h +++ b/src/fb.h @@ -6,5 +6,6 @@ void fb_init(uint32_t * addr, uint32_t width, uint32_t height, uint32_t pitch); bool fb_ready(void); +void fb_blend_alpha8(const uint8_t * bitmap, int width, int height, int pitch, int x, int y, uint8_t r, uint8_t g, uint8_t b); #endif diff --git a/src/hos_main.c b/src/hos_main.c index b35b115..dadb014 100644 --- a/src/hos_main.c +++ b/src/hos_main.c @@ -1,6 +1,7 @@ #include #include "fb.h" #include "mbinfo.h" +#include "kfont.h" void hos_main(uint32_t mbinfo_addr) { @@ -9,4 +10,6 @@ void hos_main(uint32_t mbinfo_addr) { return; } + const fontgen_char_info_t * char_info = kfont.char_infos['H']; + fb_blend_alpha8(char_info->bitmap, char_info->width, char_info->height, char_info->width, 10, 10, 0xFFu, 0x88u, 0u); }