diff options
-rw-r--r-- | bitmap.h | 17 | ||||
-rw-r--r-- | main_simple_scanner.cpp | 6 |
2 files changed, 23 insertions, 0 deletions
@@ -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> diff --git a/main_simple_scanner.cpp b/main_simple_scanner.cpp index 26518b1..91c036e 100644 --- a/main_simple_scanner.cpp +++ b/main_simple_scanner.cpp @@ -27,6 +27,7 @@ void generate_image(uint16_t image_width, uint16_t image_height, double viewport } else { std::cerr << "Antialiasing Samples: " << samples << std::endl; } + std::cerr << "Initializing context..." << std::endl; double r = 1.0 * image_width / image_height; viewport<T> *vp; if (samples == 1) { @@ -40,10 +41,15 @@ void generate_image(uint16_t image_width, uint16_t image_height, double viewport 100)); // the earth world.add_object(std::make_shared<sphere>(vec3d{0, 0, sphere_z}, sphere_r)); timer tm; + std::cerr << "Rendering..." << std::endl; tm.start_measure(); auto image = vp->render(world, vec3d::zero(), image_width, image_height); // camera position as the coordinate origin tm.stop_measure(); + std::cerr << "Applying gamma2..." << std::endl; + tm.start_measure(); + image = image.gamma2(); // gamma correction + tm.stop_measure(); if (!caption.empty()) { image.print(caption, pixel<T>::from_normalized(1.0, 0.0, 0.0), |