#ifndef COLOR_H #define COLOR_H #include #include #include #include #include "vec3.h" #include "util.h" void write_color(std::ostream &out, Color pixel_color, int sample_per_pixel) { auto r = pixel_color.x(); auto g = pixel_color.y(); auto b = pixel_color.z(); auto scale = 1.0 / sample_per_pixel; r = std::sqrt(scale * r); g = std::sqrt(scale * g); b = std::sqrt(scale * b); out << static_cast(256 * clamp(r, 0.0, 0.999)) << " " << static_cast(256 * clamp(g, 0.0, 0.999)) << " " << static_cast(256 * clamp(b, 0.0, 0.999)) << "\n"; } void write_color_vec(std::vector& vec, std::size_t i, Color pixel_color, int sample_per_pixel) { auto r = pixel_color.x(); auto g = pixel_color.y(); auto b = pixel_color.z(); auto scale = 1.0 / sample_per_pixel; r = std::sqrt(scale * r); g = std::sqrt(scale * g); b = std::sqrt(scale * b); vec[i+0] = static_cast(256 * clamp(r, 0.0, 0.999)); vec[i+1] = static_cast(256 * clamp(g, 0.0, 0.999)); vec[i+2] = static_cast(256 * clamp(b, 0.0, 0.999)); } #endif // COLOR_H