summaryrefslogtreecommitdiff
path: root/bitmap.h
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-04-14 15:03:16 +0800
committerKeuin <[email protected]>2022-04-14 15:03:16 +0800
commitbbe3917ed18fa164dd31a0f3bfcc9d4362b8f545 (patch)
tree4e4124cc3916382fea5c5f04039c11246267b1f5 /bitmap.h
parent92a1095ca8b9cd13f233e26a5e1f70518663806e (diff)
Specialize pixel::gamma2 for small values.
Diffstat (limited to 'bitmap.h')
-rw-r--r--bitmap.h29
1 files changed, 24 insertions, 5 deletions
diff --git a/bitmap.h b/bitmap.h
index 58b9a25..c955803 100644
--- a/bitmap.h
+++ b/bitmap.h
@@ -72,15 +72,34 @@ struct pixel {
return mod; // FIXME
}
- inline pixel<T> gamma2() const {
+ 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_);
+ if (sizeof(T) <= 2) {
+ // 26% faster than using double
+ const auto r_ = sqrtf((float) (this->r) / (float) max);
+ const auto g_ = sqrtf((float) (this->g) / (float) max);
+ const auto b_ = sqrtf((float) (this->b) / (float) max);
+ return pixel<T>::from_normalized(r_, g_, b_);
+ } else {
+ const auto r_ = sqrt(1.0 * this->r / max);
+ const auto g_ = sqrt(1.0 * this->g / max);
+ const auto b_ = sqrt(1.0 * this->b / max);
+ return pixel<T>::from_normalized(r_, g_, b_);
+ }
}
+
};
+//template<>
+//pixel<uint16_t> pixel<uint16_t>::gamma2() const {
+// // 26% faster than using double
+// const auto max = max_value();
+// const auto r_ = sqrtf((float) (this->r) / (float) (max));
+// const auto g_ = sqrtf((float) (this->g) / (float) (max));
+// const auto b_ = sqrtf((float) (this->b) / (float) (max));
+// return pixel<uint16_t>::from_normalized(r_, g_, b_);
+//}
+
template<
typename T,
typename S,