summaryrefslogtreecommitdiff
path: root/bitmap.h
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-04-13 14:42:59 +0800
committerKeuin <[email protected]>2022-04-13 14:42:59 +0800
commit3caba9694f6e6f0f8b51dcffd7619fa04fbe6c29 (patch)
tree0975252facef9f71931dee7bbd526bcfccf49ad4 /bitmap.h
parent4ad345447384ae9327cab0977b95d0b67f8bde57 (diff)
Antialiasing. (not parallelized)
Diffstat (limited to 'bitmap.h')
-rw-r--r--bitmap.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/bitmap.h b/bitmap.h
index bc1205f..8906ec5 100644
--- a/bitmap.h
+++ b/bitmap.h
@@ -9,6 +9,7 @@
#include <cstdint>
#include <ostream>
#include <cassert>
+#include <vector>
#include "bitfont.h"
@@ -87,6 +88,26 @@ public:
content.resize(width * height, pixel<T>{});
}
+ static bitmap<T> average(const std::vector<bitmap<T>> &images) {
+ assert(!images.empty());
+ bitmap<T> 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>{(T) (acc_r / m), (T) (acc_g / m), (T) (acc_b / m)};
+ }
+ return result;
+ }
+
void set(unsigned x, unsigned y, const pixel<T> &pixel) {
image(x, y) = pixel;
}