diff options
author | Keuin <[email protected]> | 2022-04-14 13:43:28 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-04-14 14:01:15 +0800 |
commit | 01f5ff46d222ee137a87a69cae430421e50c21b5 (patch) | |
tree | 4cfb490cfb0287c31234f7c2afef463e6926df02 /bitmap.h | |
parent | a41fbf75aff54f4d3bd88793cdf2bf281ea9ee01 (diff) |
Use flexible intermediate color depth when rendering.
Note: further debugging is needed. The output image quality won't be improved when using 16bit/32bit internal color depth.
Diffstat (limited to 'bitmap.h')
-rw-r--r-- | bitmap.h | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -136,11 +136,25 @@ public: width(width), height(height), content{data} {} static bitmap<T> average(const std::vector<bitmap<T>> &images) { + using Acc = typename std::conditional< + (sizeof(T) <= 1), + uint_fast16_t, + typename std::conditional< + (sizeof(T) <= 2), + uint_fast32_t, + typename std::conditional< + (sizeof(T) <= 4), + uint_fast64_t, + uintmax_t + >::type + >::type + >::type; // pick the smallest suitable type for accumulator + static_assert(sizeof(Acc) > sizeof(T), "accumulator may overflow"); assert(!images.empty()); bitmap<T> result{images[0].width, images[0].height}; const auto m = images.size(); const auto n = images[0].content.size(); - uint_fast32_t acc_r, acc_g, acc_b; + Acc acc_r, acc_g, acc_b; for (size_t i = 0; i < n; ++i) { acc_r = 0; acc_g = 0; @@ -197,7 +211,6 @@ public: bitmap<T> out{shape.first, shape.second}; for (size_t i = 0; i < sz; ++i) { out[i] = pixel<T>::from(src[i]); - std::cerr << (int) out[i].r << ' ' << (int) out[i].g << ' ' << (int) out[i].b << std::endl; } return out; } |