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 +++++++++++++++++ main_simple_scanner.cpp | 6 ++++++ 2 files changed, 23 insertions(+) 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 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 *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(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::from_normalized(1.0, 0.0, 0.0), -- cgit v1.2.3