summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
Diffstat (limited to 'libraries')
-rw-r--r--libraries/daguerre/include/daguerre.hpp34
-rw-r--r--libraries/daguerre/source/daguerre.cpp15
2 files changed, 26 insertions, 23 deletions
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 <stdint.h>
+#include <cstring>
#include <cstdio>
namespace daguerre {
@@ -13,14 +14,6 @@ namespace daguerre {
uint8_t b;
};
- template <class to_type, class from_type>
- to_type convert_color(const from_type &from);
-
- template <>
- inline hilbert_color convert_color<hilbert_color, rgb24>(const rgb24 &from) {
- return __euler_encode_color(from.r, from.g, from.b);
- }
-
template <class color_t>
class image {
@@ -88,15 +81,15 @@ namespace daguerre {
//from [from_x, from_x + width) x [from_y, from_y + height).
template <class color_t>
void copy_region(
- image<color_t> &to, const image<color_t> &from, unsigned from_x,
- unsigned from_y, unsigned to_x, unsigned to_y, unsigned width,
- unsigned height) {
+ image<color_t> &to, unsigned to_x, unsigned to_y,
+ const image<color_t> &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<to_color_t, from_color_t>>
- void copy_region(
- image<to_color_t> &to, const image<from_color_t> &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_color_t> &to, unsigned to_x, unsigned to_y,
+ const image<from_color_t> &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<hilbert_color> 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<hilbert_color>(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<rgb24> &into) {