diff options
author | Keuin <[email protected]> | 2022-04-14 15:03:16 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-04-14 15:03:16 +0800 |
commit | bbe3917ed18fa164dd31a0f3bfcc9d4362b8f545 (patch) | |
tree | 4e4124cc3916382fea5c5f04039c11246267b1f5 | |
parent | 92a1095ca8b9cd13f233e26a5e1f70518663806e (diff) |
Specialize pixel::gamma2 for small values.
-rw-r--r-- | bitmap.h | 29 |
1 files changed, 24 insertions, 5 deletions
@@ -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, |