#ifndef COLOR_H #define COLOR_H #include #include #include "rtweekend.hpp" /* Writes color components as a space-delimited string of numbers in the range [0,255] */ void write_color(FILE *fp, color c, uint32_t samples_per_pixel) { double scale = 1.0 / samples_per_pixel; // Divide the color by the number of samples double r = c.x * scale; double g = c.y * scale; double b = c.z * scale; /* Write output */ fprintf(fp, "%d %d %d\n", (uint8_t) (255 * clamp(r, 0, 1)), (uint8_t) (255 * clamp(g, 0, 1)), (uint8_t) (255 * clamp(b, 0, 1))); } #endif