From 92a1095ca8b9cd13f233e26a5e1f70518663806e Mon Sep 17 00:00:00 2001 From: Keuin Date: Thu, 14 Apr 2022 14:31:58 +0800 Subject: Add gamma2 correction. --- bitmap.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'bitmap.h') diff --git a/bitmap.h b/bitmap.h index a5b05e6..58b9a25 100644 --- a/bitmap.h +++ b/bitmap.h @@ -71,6 +71,14 @@ struct pixel { static inline T max_value() { return mod; // FIXME } + + inline pixel gamma2() const { + const auto max = max_value(); + const double r_ = sqrt(1.0 * this->r / max); + const double g_ = sqrt(1.0 * this->g / max); + const double b_ = sqrt(1.0 * this->b / max); + return pixel::from_normalized(r_, g_, b_); + } }; template< @@ -215,6 +223,15 @@ public: return out; } + bitmap gamma2() const { + std::vector> out; + out.reserve(content.size()); + for (const auto &pix: content) { + out.push_back(pix.gamma2()); + } + return bitmap{width, height, std::move(out)}; + } + }; template -- cgit v1.2.3