add: image is now printable

This commit is contained in:
Starnakin 2024-12-10 16:26:00 +01:00
parent d39f708a51
commit d6a59da6d1
4 changed files with 75 additions and 10 deletions

9
headers/icon.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include <stdint.h>
struct icon {
uint32_t height;
uint32_t width;
uint32_t *pixels;
};

13
headers/icons/image.h Normal file

File diff suppressed because one or more lines are too long

37
script/icon_maker.py Normal file
View File

@ -0,0 +1,37 @@
from PIL import Image
import sys
import os
if (len(sys.argv) < 2):
print("Error: usage python icon_maker.py {img}")
image = Image.open(sys.argv[1])
width, height = image.size
pixels = list(image.getdata())
pixels = [r << 16 | g << 8 | b for r, g, b in pixels]
string = str(pixels).replace("(", "{").replace(")", "}").replace("[", "{").replace("]", "}")
filename: str = os.path.basename(sys.argv[1]).split(".")[0]
string = f"""\
#pragma once
#include <stdint.h>
#include "icon.h"
uint32_t {filename}_color_map[{width} * {height}] = {string};
struct icon {filename}_icon = {{
.height = {height},
.width = {width},
.pixels = {filename}_color_map
}};
"""
with open(f"./headers/icons/{filename}.h", "w") as f:
f.write(string)

View File

@ -2,6 +2,8 @@
#include "debug.h"
#include "drivers.h"
#include "gdt.h"
#include "icon.h"
#include "icons/image.h"
#include "idt.h"
#include "kprintf.h"
#include "memory.h"
@ -29,11 +31,22 @@
static void put_pixel(uint32_t color, uint32_t x, uint32_t y)
{
// / 4 cause display.buff is in 32bit instead of 8bit
const uint32_t coords = x + y*display.pitch / 4;
// /
// 4 cause display.buff is in 32bit instead of 8bit
const uint32_t coords = x + y * display.pitch / 4;
display.buff[coords] = color;
}
void draw_icon(uint32_t pos_x, uint32_t pos_y, struct icon *img)
{
for (uint32_t y = 0; y < img->height; y++) {
for (uint32_t x = 0; x < img->width; x++) {
put_pixel(img->pixels[y * img->width + x], pos_x + x,
pos_y + y);
}
}
}
void kernel_main(multiboot_info_t *mbd, uint32_t magic)
{
/* terminal_initialize(); */
@ -47,14 +60,7 @@ void kernel_main(multiboot_info_t *mbd, uint32_t magic)
/* "complex 8*unknown quantity -byte descriptor table. -- Troy "
*/
/* "Martin 03:50, 22 March 2009 (UTC)\n"); */
uint32_t color = 0 << 16 | 128 << 8 | 128;
for (size_t i = 0; i < 100; i++) {
put_pixel(color, 10, i);
put_pixel(color, 11, i);
put_pixel(color, 12, i);
put_pixel(color, 13, i);
put_pixel(color, 14, i);
}
draw_icon(0, 0, &image_icon);
/* memset(display.buff, 255, 1024 * 1024); */
/* shell_init(); */
}