added mats, updated gradient, updated bmp.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include "vec3.hpp"
|
||||
|
||||
class BMPWriter {
|
||||
@@ -34,6 +35,18 @@ private:
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
// Helper function to create directory if it doesn't exist
|
||||
static bool createDirectoryIfNeeded(const std::string& filename) {
|
||||
std::filesystem::path filePath(filename);
|
||||
std::filesystem::path directory = filePath.parent_path();
|
||||
|
||||
// If there's a directory component and it doesn't exist, create it
|
||||
if (!directory.empty() && !std::filesystem::exists(directory)) {
|
||||
return std::filesystem::create_directories(directory);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
// Save a 2D vector of Vec3 (RGB) colors as BMP
|
||||
// Vec3 components: x = red, y = green, z = blue (values in range [0,1])
|
||||
@@ -78,6 +91,11 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create directory if needed
|
||||
if (!createDirectoryIfNeeded(filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BMPHeader header;
|
||||
BMPInfoHeader infoHeader;
|
||||
|
||||
@@ -121,6 +139,11 @@ public:
|
||||
|
||||
private:
|
||||
static bool saveBMP(const std::string& filename, const std::vector<std::vector<Vec3>>& pixels, int width, int height) {
|
||||
// Create directory if needed
|
||||
if (!createDirectoryIfNeeded(filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BMPHeader header;
|
||||
BMPInfoHeader infoHeader;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user