summaryrefslogtreecommitdiff
path: root/bitmap.h
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-04-14 14:31:58 +0800
committerKeuin <[email protected]>2022-04-14 14:31:58 +0800
commit92a1095ca8b9cd13f233e26a5e1f70518663806e (patch)
treeb29bf86817fbe8beb5893d453397c3bbf9f82efb /bitmap.h
parent977490e2b3a181796348ab1853a87cde7c92f676 (diff)
Add gamma2 correction.
Diffstat (limited to 'bitmap.h')
-rw-r--r--bitmap.h17
1 files changed, 17 insertions, 0 deletions
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<T> 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<T>::from_normalized(r_, g_, b_);
+ }
};
template<
@@ -215,6 +223,15 @@ public:
return out;
}
+ bitmap<T> gamma2() const {
+ std::vector<pixel<T>> out;
+ out.reserve(content.size());
+ for (const auto &pix: content) {
+ out.push_back(pix.gamma2());
+ }
+ return bitmap<T>{width, height, std::move(out)};
+ }
+
};
template<typename T>