From 05498860e8f7b1e8bb27880bc7526de026694804 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 26 Mar 2021 21:55:50 +0100 Subject: Renamed libs Cleaner and more flexible. --- libs/libgui/bmp.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 libs/libgui/bmp.c (limited to 'libs/libgui/bmp.c') diff --git a/libs/libgui/bmp.c b/libs/libgui/bmp.c new file mode 100644 index 0000000..5576d16 --- /dev/null +++ b/libs/libgui/bmp.c @@ -0,0 +1,29 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + +#include +#include +#include +#include +#include + +struct bmp *bmp_load(const char *path) +{ + void *buf = sread(path); + if (!buf) + return NULL; + + struct bmp_header *h = buf; + if (h->signature[0] != 'B' || h->signature[1] != 'M') + return NULL; + + // TODO: Support padding with odd widths + struct bmp_info *info = (struct bmp_info *)((u32)buf + sizeof(*h)); + struct bmp *bmp = malloc(sizeof(*bmp)); + bmp->size.x = info->width; + bmp->size.y = info->height; + bmp->data = (u8 *)((u32)buf + h->offset); + bmp->bpp = info->bpp; + bmp->pitch = bmp->size.x * (bmp->bpp >> 3); + + return bmp; +} -- cgit v1.2.3