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

Image cleanup, no more public constructor, readImage is friend, raytrace is friend and takes scene

parent 1f6f9ab7
No related branches found
No related tags found
No related merge requests found
......@@ -16,28 +16,18 @@ Image::Image(int width, int height)
vec.insert(vec.end(), color);
}
}
/*
void Image::setPixels(std::shared_ptr<Sampler> sampler) {
Threadpool tp(4);
for (int x = 0; x != width; x++) {
for (int y = 0; y != height; y++) {
vec[width * y + x] = sampler->color(x, y);
}
}
} */
void Image::setPixel(int x, int y, Vec3 color) {
vec[width * y + x] = color;
}
void Image::setPixels(size_t threadcount, std::shared_ptr<Sampler> sampler) {
Threadpool tp(threadcount);
for (int x = 0; x != width; x++) {
for (int y = 0; y != height; y++) {
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
tp.queueTask(std::bind([this, x, y, sampler]() {
this->setPixelsTask(x, y, sampler);
}));
}
}
// std::cout << "Done queing" << std::endl;
}
void Image::setPixelsTask(int x, int y, std::shared_ptr<Sampler> sampler) {
......@@ -68,14 +58,12 @@ Vec3 Image::color(float x, float y) const {
Vec3 v = vec[width * yy + xx];
return v;
}
Image raytrace(size_t threadcount, const cam::CamObs& cam,
const std::shared_ptr<Sampler>& sampler, size_t n) {
Image result(cam.width, cam.height);
Image raytrace(size_t threadcount, const std::shared_ptr<Scene>& scene,
size_t n) {
Image result(scene->cam.width, scene->cam.height);
result.setPixels(threadcount, std::make_shared<StratifiedSampler>(
StratifiedSampler(sampler, n))
// sampler
);
StratifiedSampler(scene, n)));
result.gammaCorrect(2.2);
return result;
}
......@@ -144,10 +132,8 @@ void writeBmp(const char* filename, Image img) {
char bgr[3] = {blue, green, red};
for (int i = 0; i < 3; i++) {
char c0 = (bgr[i] & 0x00FF);
// char c8 = ((bgr[i] & (unsigned int)0xFF00) >> 8);
ofile.write(&c0, sizeof(c0));
// ofile.write (&c8, sizeof (c8));
}
}
// If needed add extra bytes after each row
......
......@@ -4,12 +4,11 @@
#include "../camera/CamObs.h"
#include "Sampler.h"
#include "Scene.h"
namespace util {
class Image : public Sampler {
public:
Image(int width, int height);
void setPixel(int x, int y, Vec3 color);
void setPixels(size_t threadcount, std::shared_ptr<Sampler> sampler);
......@@ -18,20 +17,24 @@ class Image : public Sampler {
Vec3 color(float x, float y) const override;
const int width;
const int height;
const int width, height;
bool halfed;
void gammaCorrect(float gamma);
friend Image raytrace(size_t threadcount,
const std::shared_ptr<Scene>& scene, size_t n);
friend Image readImage(const char* filename);
protected:
void setPixelsTask(int x, int y, std::shared_ptr<Sampler> sampler);
private:
std::vector<Vec3> vec;
Image(int width, int height);
};
Image raytrace(size_t threadcount, const cam::CamObs& cam,
const std::shared_ptr<Sampler>& sampler, size_t n);
Image raytrace(size_t threadcount, const std::shared_ptr<Scene>& scene,
size_t n);
void writeBmp(const char* filename, Image img);
Image readImage(const char* filename);
......
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