summaryrefslogtreecommitdiff
path: root/libraries/daguerre/include/daguerre.hpp
diff options
context:
space:
mode:
authorBenji Dial <benji@benjidial.net>2024-05-19 11:39:07 -0400
committerBenji Dial <benji@benjidial.net>2024-05-19 11:39:07 -0400
commitd2448d151edad03fb2ca2274cb02426f5fb69582 (patch)
treef5e92bf96fe3a87068a9365d693456d258c22180 /libraries/daguerre/include/daguerre.hpp
parent17c1bd441de115720d7c6758550c49c1b4689900 (diff)
downloadhilbert-os-d2448d151edad03fb2ca2274cb02426f5fb69582.tar.gz
add font loading and rendering to daguerre
Diffstat (limited to 'libraries/daguerre/include/daguerre.hpp')
-rw-r--r--libraries/daguerre/include/daguerre.hpp68
1 files changed, 63 insertions, 5 deletions
diff --git a/libraries/daguerre/include/daguerre.hpp b/libraries/daguerre/include/daguerre.hpp
index 62d10f0..c236cb9 100644
--- a/libraries/daguerre/include/daguerre.hpp
+++ b/libraries/daguerre/include/daguerre.hpp
@@ -14,6 +14,16 @@ namespace daguerre {
uint8_t b;
};
+ static inline void default_overlay(hilbert_color &dest, const rgb24 &src) {
+ dest = __euler_encode_color(src.r, src.g, src.b);
+ }
+
+ static inline void default_overlay(rgb24 &dest, const bool &src) {
+ dest.r = src ? 255 : 0;
+ dest.g = src ? 255 : 0;
+ dest.b = src ? 255 : 0;
+ }
+
template <class color_t>
class image {
@@ -100,7 +110,7 @@ namespace daguerre {
//from [from_x, from_x + width) x [from_y, from_y + height).
template <
class to_color_t, class from_color_t,
- void overlay(to_color_t &dest, const from_color_t &src)>
+ void overlay(to_color_t &dest, const from_color_t &src) = default_overlay>
void overlay_region(
image<to_color_t> &to, unsigned to_x, unsigned to_y,
const image<from_color_t> &from, unsigned from_x, unsigned from_y,
@@ -116,12 +126,60 @@ namespace daguerre {
}
- static inline void encode(hilbert_color &dest, const rgb24 &src) {
- dest = __euler_encode_color(src.r, src.g, src.b);
- }
-
image<hilbert_color> get_hilbert_framebuffer();
bool try_load_ppm(std::FILE *input, image<rgb24> &into);
+ static inline bool try_load_ppm(const char *path, image<rgb24> &into) {
+ std::FILE *f = std::fopen(path, "r");
+ if (!f)
+ return false;
+ bool success = try_load_ppm(f, into);
+ std::fclose(f);
+ return success;
+ }
+
+ //TODO: unicode
+ template <class color_t>
+ class fixed_bitmap_font {
+
+ public:
+ unsigned width;
+ unsigned height;
+ image<color_t> glyphs[128];
+
+ template <class target_color_t,
+ void overlay(target_color_t &dest, const color_t &src) = default_overlay>
+ void overlay_text(
+ image<target_color_t> &target, unsigned x,
+ unsigned y, const char *text) const {
+
+ while (1) {
+ uint8_t ch = (uint8_t)*text;
+ if (ch == 0)
+ return;
+ if (ch < 128) {
+ overlay_region<target_color_t, color_t, overlay>(
+ target, x, y, glyphs[ch], 0, 0, width, height);
+ x += width;
+ }
+ ++text;
+ }
+
+ }
+
+ };
+
+ bool try_load_psf(std::FILE *input, fixed_bitmap_font<bool> &into);
+
+ static inline bool try_load_psf(
+ const char *path, fixed_bitmap_font<bool> &into) {
+ std::FILE *f = std::fopen(path, "r");
+ if (!f)
+ return false;
+ bool success = try_load_psf(f, into);
+ std::fclose(f);
+ return success;
+ }
+
}