From e60fa7740cd7d245d1b22a25fea9df0768d32668 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 19 May 2024 04:34:40 -0400 Subject: mouse support (working in qemu, semi-working in virtualbox) --- libraries/daguerre/include/daguerre.hpp | 34 +++++++++++++++------------------ libraries/daguerre/source/daguerre.cpp | 15 +++++++++++---- 2 files changed, 26 insertions(+), 23 deletions(-) (limited to 'libraries/daguerre') diff --git a/libraries/daguerre/include/daguerre.hpp b/libraries/daguerre/include/daguerre.hpp index 274e257..62d10f0 100644 --- a/libraries/daguerre/include/daguerre.hpp +++ b/libraries/daguerre/include/daguerre.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include namespace daguerre { @@ -13,14 +14,6 @@ namespace daguerre { uint8_t b; }; - template - to_type convert_color(const from_type &from); - - template <> - inline hilbert_color convert_color(const rgb24 &from) { - return __euler_encode_color(from.r, from.g, from.b); - } - template class image { @@ -88,15 +81,15 @@ namespace daguerre { //from [from_x, from_x + width) x [from_y, from_y + height). template void copy_region( - image &to, const image &from, unsigned from_x, - unsigned from_y, unsigned to_x, unsigned to_y, unsigned width, - unsigned height) { + image &to, unsigned to_x, unsigned to_y, + const image &from, unsigned from_x, unsigned from_y, + unsigned width, unsigned height) { color_t *to_start = to.buffer + to.pitch * to_y + to_x; const color_t *from_start = from.buffer + from.pitch * from_y + from_x; for (unsigned y = 0; y < height; ++y) - memcpy( + std::memcpy( to_start + to.pitch * y, from_start + from.pitch * y, width * sizeof(color_t)); @@ -107,12 +100,11 @@ namespace daguerre { //from [from_x, from_x + width) x [from_y, from_y + height). template < class to_color_t, class from_color_t, - to_color_t converter(const from_color_t &) = - convert_color> - void copy_region( - image &to, const image &from, unsigned from_x, - unsigned from_y, unsigned to_x, unsigned to_y, unsigned width, - unsigned height) { + void overlay(to_color_t &dest, const from_color_t &src)> + void overlay_region( + image &to, unsigned to_x, unsigned to_y, + const image &from, unsigned from_x, unsigned from_y, + unsigned width, unsigned height) { to_color_t *to_start = to.buffer + to.pitch * to_y + to_x; const from_color_t *from_start = @@ -120,8 +112,12 @@ namespace daguerre { for (unsigned y = 0; y < height; ++y) for (unsigned x = 0; x < width; ++x) - to_start[to.pitch * y + x] = converter(from_start[from.pitch * y + x]); + overlay(to_start[to.pitch * y + x], from_start[from.pitch * y + x]); + + } + static inline void encode(hilbert_color &dest, const rgb24 &src) { + dest = __euler_encode_color(src.r, src.g, src.b); } image get_hilbert_framebuffer(); diff --git a/libraries/daguerre/source/daguerre.cpp b/libraries/daguerre/source/daguerre.cpp index fb3ddc7..7c13a88 100644 --- a/libraries/daguerre/source/daguerre.cpp +++ b/libraries/daguerre/source/daguerre.cpp @@ -8,15 +8,22 @@ namespace daguerre { return image(ptr, width, height, pitch, false); } + //TODO: make this more robust unsigned read_text_int(std::FILE *input) { unsigned n = 0; char ch; - while (true) { + std::fread(&ch, 1, 1, input); + if (ch == '#') { + do + std::fread(&ch, 1, 1, input); + while (ch != '\n'); std::fread(&ch, 1, 1, input); - if (ch < '0' || ch > '9') - return n; - n = n * 10 + ch - '0'; } + do { + n = n * 10 + ch - '0'; + std::fread(&ch, 1, 1, input); + } while (ch >= '0' && ch <= '9'); + return n; } bool try_load_ppm(std::FILE *input, image &into) { -- cgit v1.2.3