From 3caba9694f6e6f0f8b51dcffd7619fa04fbe6c29 Mon Sep 17 00:00:00 2001 From: Keuin Date: Wed, 13 Apr 2022 14:42:59 +0800 Subject: Antialiasing. (not parallelized) --- bitmap.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'bitmap.h') diff --git a/bitmap.h b/bitmap.h index bc1205f..8906ec5 100644 --- a/bitmap.h +++ b/bitmap.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "bitfont.h" @@ -87,6 +88,26 @@ public: content.resize(width * height, pixel{}); } + static bitmap average(const std::vector> &images) { + assert(!images.empty()); + bitmap result{images[0].width, images[0].height}; + const auto m = images.size(); + const auto n = images[0].content.size(); + uintmax_t acc_r, acc_g, acc_b; + for (size_t i = 0; i < n; ++i) { + acc_r = 0; + acc_g = 0; + acc_b = 0; + for (size_t j = 0; j < m; ++j) { + acc_r += images[j].content[i].r; + acc_g += images[j].content[i].g; + acc_b += images[j].content[i].b; + } + result.content[i] = pixel{(T) (acc_r / m), (T) (acc_g / m), (T) (acc_b / m)}; + } + return result; + } + void set(unsigned x, unsigned y, const pixel &pixel) { image(x, y) = pixel; } -- cgit v1.2.3