2022-10-14 22:59:41 -04:00
|
|
|
/*
|
|
|
|
* Created by Brett Terpstra 6920201 on 14/10/22.
|
|
|
|
* Copyright (c) Brett Terpstra 2022 All Rights Reserved
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef STEP_2_IMAGE_H
|
|
|
|
#define STEP_2_IMAGE_H
|
|
|
|
|
|
|
|
#include "util/std.h"
|
|
|
|
#include "math/vectors.h"
|
|
|
|
|
|
|
|
namespace Raytracing {
|
|
|
|
|
2022-10-19 19:08:22 -04:00
|
|
|
// glorified structure to store our image data.
|
2022-10-15 16:34:29 -04:00
|
|
|
class Image {
|
|
|
|
private:
|
|
|
|
int width;
|
|
|
|
int height;
|
2022-10-18 23:11:51 -04:00
|
|
|
Vec4 *pixelData;
|
2022-10-15 16:34:29 -04:00
|
|
|
public:
|
|
|
|
Image(int width, int height);
|
|
|
|
Image(const Image &image);
|
2022-10-16 17:53:33 -04:00
|
|
|
Image(const Image&& image) = delete;
|
2022-10-15 16:34:29 -04:00
|
|
|
|
2022-10-18 23:11:51 -04:00
|
|
|
inline void setPixelColor(int x, int y, const Vec4 &color) {
|
2022-10-15 16:34:29 -04:00
|
|
|
pixelData[(x * height) + y] = color;
|
|
|
|
}
|
|
|
|
|
2022-10-18 23:11:51 -04:00
|
|
|
[[nodiscard]] inline Vec4 getPixelColor(int x, int y) const {
|
2022-10-15 16:34:29 -04:00
|
|
|
return pixelData[(x * height) + y];
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] int getPixelR(int x, int y) const;
|
|
|
|
[[nodiscard]] int getPixelG(int x, int y) const;
|
|
|
|
[[nodiscard]] int getPixelB(int x, int y) const;
|
|
|
|
[[nodiscard]] int getPixelA(int x, int y) const;
|
|
|
|
|
|
|
|
[[nodiscard]] inline int getWidth() const { return width; }
|
|
|
|
|
|
|
|
[[nodiscard]] inline int getHeight() const { return height; }
|
|
|
|
|
|
|
|
~Image();
|
2022-10-14 22:59:41 -04:00
|
|
|
};
|
|
|
|
|
2022-10-19 19:08:22 -04:00
|
|
|
// image writer class used to output the image to a file.
|
2022-10-14 22:59:41 -04:00
|
|
|
class ImageOutput {
|
2022-10-15 16:34:29 -04:00
|
|
|
private:
|
2022-10-16 17:53:33 -04:00
|
|
|
Image image;
|
2022-10-15 16:34:29 -04:00
|
|
|
public:
|
|
|
|
explicit ImageOutput(const Image& image): image(image) {}
|
|
|
|
virtual void write(const std::string& file, const std::string& formatExtension);
|
2022-10-14 22:59:41 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //STEP_2_IMAGE_H
|