22 lines
634 B
Rust
22 lines
634 B
Rust
use super::{utility, Color, Rgb, RgbImage};
|
|
|
|
pub fn put_color(img: &mut RgbImage, pixel_color: &Color, x: u32, y: u32, samples_per_pixel: u32) {
|
|
let mut r = pixel_color.x();
|
|
let mut g = pixel_color.y();
|
|
let mut b = pixel_color.z();
|
|
|
|
let scale = 1.0;// / samples_per_pixel as f64;
|
|
r = (scale * r).sqrt();
|
|
g = (scale * g).sqrt();
|
|
b = (scale * b).sqrt();
|
|
|
|
img.put_pixel(
|
|
x,
|
|
y,
|
|
Rgb([
|
|
(256.0 * utility::clamp(r, 0.0, 0.999)) as u8,
|
|
(256.0 * utility::clamp(g, 0.0, 0.999)) as u8,
|
|
(256.0 * utility::clamp(b, 0.0, 0.999)) as u8,
|
|
]),
|
|
);
|
|
}
|