use image::Rgb;

use crate::{rtweekend::clamp, vec3::*};

pub fn get_scaled_color_components(c: Color, samples_per_pixel: i32) -> Rgb<u8> {
    let r = c.x();
    let g = c.y();
    let b = c.z();

    // Divide the color by the number of samples
    let scale = 1.0 / samples_per_pixel as f64;
    let r = (scale * r).sqrt();
    let g = (scale * g).sqrt();
    let b = (scale * b).sqrt();

    Rgb([
        (255.0 * clamp(r, 0.0, 1.0)) as u8,
        (255.0 * clamp(g, 0.0, 1.0)) as u8,
        (255.0 * clamp(b, 0.0, 1.0)) as u8,
    ])
}
