Skip to content
Snippets Groups Projects
Commit f5fcf0b0 authored by Yoel's avatar Yoel
Browse files

Added new function to gammaCorrect the whole image vector

parent 562839f7
No related branches found
No related tags found
No related merge requests found
...@@ -35,7 +35,18 @@ void Image::setPixels(size_t threadcount, std::shared_ptr<Sampler> sampler) { ...@@ -35,7 +35,18 @@ void Image::setPixels(size_t threadcount, std::shared_ptr<Sampler> sampler) {
} }
void Image::setPixelsTask(int x, int y, std::shared_ptr<Sampler> sampler) { void Image::setPixelsTask(int x, int y, std::shared_ptr<Sampler> sampler) {
setPixel(x, y, sampler->color(x, y)); Vec3 v = sampler->color(x, y);
setPixel(x, y, v);
}
void Image::gammaCorrect(float gamma) {
// correct the whole data-array with the given gamma
std::transform(vec.begin(), vec.end(), vec.begin(),
[gamma](util::Vec3 v) -> util::Vec3 {
return util::Vec3(std::powf(v.x(), 1 / gamma),
std::powf(v.y(), 1 / gamma),
std::powf(v.z(), 1 / gamma));
});
} }
Vec3 Image::operator[](const std::array<int, 2>& i) const { Vec3 Image::operator[](const std::array<int, 2>& i) const {
return vec[width * i[1] + i[0]]; return vec[width * i[1] + i[0]];
...@@ -51,6 +62,7 @@ Image raytrace(size_t threadcount, const cam::CamObs& cam, ...@@ -51,6 +62,7 @@ Image raytrace(size_t threadcount, const cam::CamObs& cam,
StratifiedSampler(sampler, n)) StratifiedSampler(sampler, n))
// sampler // sampler
); );
result.gammaCorrect(2.2);
return result; return result;
} }
} // namespace util } // namespace util
\ No newline at end of file
...@@ -18,6 +18,7 @@ class Image { ...@@ -18,6 +18,7 @@ class Image {
const int width; const int width;
const int height; const int height;
void gammaCorrect(float gamma);
protected: protected:
void setPixelsTask(int x, int y, std::shared_ptr<Sampler> sampler); void setPixelsTask(int x, int y, std::shared_ptr<Sampler> sampler);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment