Kernel: VESA can now print 8x16 bitmaps
This commit is contained in:
parent
f51ca4b642
commit
9d9a6b2fec
|
@ -241,6 +241,8 @@ void TTY::HandleAnsiEscape(uint16_t ch)
|
||||||
|
|
||||||
void TTY::RenderFromBuffer(uint32_t x, uint32_t y)
|
void TTY::RenderFromBuffer(uint32_t x, uint32_t y)
|
||||||
{
|
{
|
||||||
|
if (x >= m_width || y >= m_height)
|
||||||
|
Kernel::panic("invalid render from buffer, {} {}", x, y);
|
||||||
const auto& cell = m_buffer[y * m_width + x];
|
const auto& cell = m_buffer[y * m_width + x];
|
||||||
VESA::PutCharAt(cell.character, x, y, cell.foreground, cell.background);
|
VESA::PutCharAt(cell.character, x, y, cell.foreground, cell.background);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <kernel/font.h>
|
||||||
#include <kernel/IO.h>
|
#include <kernel/IO.h>
|
||||||
#include <kernel/kmalloc.h>
|
#include <kernel/kmalloc.h>
|
||||||
#include <kernel/multiboot.h>
|
#include <kernel/multiboot.h>
|
||||||
|
@ -6,8 +7,6 @@
|
||||||
#include <kernel/Serial.h>
|
#include <kernel/Serial.h>
|
||||||
#include <kernel/VESA.h>
|
#include <kernel/VESA.h>
|
||||||
|
|
||||||
#include "font.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define MULTIBOOT_FLAGS_FRAMEBUFFER (1 << 12)
|
#define MULTIBOOT_FLAGS_FRAMEBUFFER (1 << 12)
|
||||||
|
@ -35,6 +34,8 @@ namespace VESA
|
||||||
static void (*ClearImpl)(Color) = nullptr;
|
static void (*ClearImpl)(Color) = nullptr;
|
||||||
static void (*SetCursorPositionImpl)(uint32_t, uint32_t, Color) = nullptr;
|
static void (*SetCursorPositionImpl)(uint32_t, uint32_t, Color) = nullptr;
|
||||||
|
|
||||||
|
static void GraphicsPutBitmapAt(const uint8_t* bitmap, uint32_t x, uint32_t y, Color fg);
|
||||||
|
static void GraphicsPutBitmapAt(const uint8_t* bitmap, uint32_t x, uint32_t y, Color fg, Color bg);
|
||||||
static void GraphicsPutCharAt(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg);
|
static void GraphicsPutCharAt(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg);
|
||||||
static void GraphicsClear(Color color);
|
static void GraphicsClear(Color color);
|
||||||
static void GraphicsSetCursorPosition(uint32_t x, uint32_t y, Color fg);
|
static void GraphicsSetCursorPosition(uint32_t x, uint32_t y, Color fg);
|
||||||
|
@ -43,6 +44,17 @@ namespace VESA
|
||||||
static void TextClear(Color color);
|
static void TextClear(Color color);
|
||||||
static void TextSetCursorPosition(uint32_t x, uint32_t y, Color fg);
|
static void TextSetCursorPosition(uint32_t x, uint32_t y, Color fg);
|
||||||
|
|
||||||
|
void PutBitmapAt(const uint8_t* bitmap, uint32_t x, uint32_t y, Color fg)
|
||||||
|
{
|
||||||
|
if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_GRAPHICS)
|
||||||
|
GraphicsPutBitmapAt(bitmap, x, y, fg);
|
||||||
|
}
|
||||||
|
void PutBitmapAt(const uint8_t* bitmap, uint32_t x, uint32_t y, Color fg, Color bg)
|
||||||
|
{
|
||||||
|
if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_GRAPHICS)
|
||||||
|
GraphicsPutBitmapAt(bitmap, x, y, fg, bg);
|
||||||
|
}
|
||||||
|
|
||||||
void PutCharAt(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg)
|
void PutCharAt(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg)
|
||||||
{
|
{
|
||||||
if (x >= s_width || y >= s_height)
|
if (x >= s_width || y >= s_height)
|
||||||
|
@ -154,6 +166,48 @@ namespace VESA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void GraphicsPutBitmapAt(const uint8_t* bitmap, uint32_t x, uint32_t y, Color fg)
|
||||||
|
{
|
||||||
|
uint32_t u32_fg = s_graphics_colors[(uint8_t)fg];
|
||||||
|
|
||||||
|
uint32_t fx = x * font.Width;
|
||||||
|
uint32_t fy = y * font.Height;
|
||||||
|
|
||||||
|
uint32_t row_offset = (fy * s_pitch) + (fx * (s_bpp / 8));
|
||||||
|
for (uint32_t gy = 0; gy < font.Height; gy++)
|
||||||
|
{
|
||||||
|
uint32_t pixel_offset = row_offset;
|
||||||
|
for (uint32_t gx = 0; gx < font.Width; gx++)
|
||||||
|
{
|
||||||
|
if (bitmap[gy] & (1 << (font.Width - gx - 1)))
|
||||||
|
GraphicsSetPixel(pixel_offset, u32_fg);
|
||||||
|
pixel_offset += s_bpp / 8;
|
||||||
|
}
|
||||||
|
row_offset += s_pitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GraphicsPutBitmapAt(const uint8_t* bitmap, uint32_t x, uint32_t y, Color fg, Color bg)
|
||||||
|
{
|
||||||
|
uint32_t u32_fg = s_graphics_colors[(uint8_t)fg];
|
||||||
|
uint32_t u32_bg = s_graphics_colors[(uint8_t)bg];
|
||||||
|
|
||||||
|
uint32_t fx = x * font.Width;
|
||||||
|
uint32_t fy = y * font.Height;
|
||||||
|
|
||||||
|
uint32_t row_offset = (fy * s_pitch) + (fx * (s_bpp / 8));
|
||||||
|
for (uint32_t gy = 0; gy < font.Height; gy++)
|
||||||
|
{
|
||||||
|
uint32_t pixel_offset = row_offset;
|
||||||
|
for (uint32_t gx = 0; gx < font.Width; gx++)
|
||||||
|
{
|
||||||
|
GraphicsSetPixel(pixel_offset, (bitmap[gy] & (1 << (font.Width - gx - 1))) ? u32_fg : u32_bg);
|
||||||
|
pixel_offset += s_bpp / 8;
|
||||||
|
}
|
||||||
|
row_offset += s_pitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void GraphicsPutCharAt(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg)
|
static void GraphicsPutCharAt(uint16_t ch, uint32_t x, uint32_t y, Color fg, Color bg)
|
||||||
{
|
{
|
||||||
// find correct bitmap
|
// find correct bitmap
|
||||||
|
@ -167,25 +221,9 @@ namespace VESA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned char* glyph = font.Bitmap + index * font.Height;
|
const uint8_t* glyph = font.Bitmap + index * font.Height;
|
||||||
|
|
||||||
uint32_t u32_fg = s_graphics_colors[(uint8_t)fg];
|
GraphicsPutBitmapAt(glyph, x, y, fg, bg);
|
||||||
uint32_t u32_bg = s_graphics_colors[(uint8_t)bg];
|
|
||||||
|
|
||||||
uint32_t fx = x * font.Width;
|
|
||||||
uint32_t fy = y * font.Height;
|
|
||||||
|
|
||||||
uint32_t row_offset = (fy * s_pitch) + (fx * (s_bpp / 8));
|
|
||||||
for (uint32_t gy = 0; gy < font.Height; gy++)
|
|
||||||
{
|
|
||||||
uint32_t pixel_offset = row_offset;
|
|
||||||
for (uint32_t gx = 0; gx < font.Width; gx++)
|
|
||||||
{
|
|
||||||
GraphicsSetPixel(pixel_offset, (glyph[gy] & (1 << (font.Width - gx - 1))) ? u32_fg : u32_bg);
|
|
||||||
pixel_offset += s_bpp / 8;
|
|
||||||
}
|
|
||||||
row_offset += s_pitch;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GraphicsClear(Color color)
|
static void GraphicsClear(Color color)
|
||||||
|
@ -237,23 +275,7 @@ namespace VESA
|
||||||
________,
|
________,
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32_t u32_fg = s_graphics_colors[(uint8_t)fg];
|
GraphicsPutBitmapAt(cursor, x, y, fg);
|
||||||
|
|
||||||
uint32_t fx = x * font.Width;
|
|
||||||
uint32_t fy = y * font.Height;
|
|
||||||
|
|
||||||
uint32_t row_offset = (fy * s_pitch) + (fx * (s_bpp / 8));
|
|
||||||
for (uint32_t gy = 0; gy < font.Height; gy++)
|
|
||||||
{
|
|
||||||
uint32_t pixel_offset = row_offset;
|
|
||||||
for (uint32_t gx = 0; gx < font.Width; gx++)
|
|
||||||
{
|
|
||||||
if (cursor[gy] & (1 << (font.Width - gx - 1)))
|
|
||||||
GraphicsSetPixel(pixel_offset, u32_fg);
|
|
||||||
pixel_offset += s_bpp / 8;
|
|
||||||
}
|
|
||||||
row_offset += s_pitch;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Created from bdf2c Version 3, (c) 2009, 2010 by Lutz Sammer
|
// Created from bdf2c Version 3, (c) 2009, 2010 by Lutz Sammer
|
||||||
// License AGPLv3: GNU Affero General Public License version 3
|
// License AGPLv3: GNU Affero General Public License version 3
|
||||||
|
|
||||||
#include "font.h"
|
#include <kernel/font.h>
|
||||||
|
|
||||||
/// character bitmap for each encoding
|
/// character bitmap for each encoding
|
||||||
static const unsigned char __font_bitmap__[] = {
|
static const unsigned char __font_bitmap__[] = {
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace VESA
|
||||||
};
|
};
|
||||||
|
|
||||||
bool Initialize();
|
bool Initialize();
|
||||||
|
void PutBitmapAt(const uint8_t*, uint32_t, uint32_t, Color);
|
||||||
|
void PutBitmapAt(const uint8_t*, uint32_t, uint32_t, Color, Color);
|
||||||
void PutCharAt(uint16_t, uint32_t, uint32_t, Color, Color);
|
void PutCharAt(uint16_t, uint32_t, uint32_t, Color, Color);
|
||||||
void Clear(Color);
|
void Clear(Color);
|
||||||
void SetCursorPosition(uint32_t, uint32_t, Color);
|
void SetCursorPosition(uint32_t, uint32_t, Color);
|
||||||
|
|
Loading…
Reference in New Issue