diff options
Diffstat (limited to 'src/display')
-rw-r--r-- | src/display/image.rs | 6 | ||||
-rw-r--r-- | src/display/pixelflut.rs | 29 |
2 files changed, 22 insertions, 13 deletions
diff --git a/src/display/image.rs b/src/display/image.rs index 77d8c83..4b25cb2 100644 --- a/src/display/image.rs +++ b/src/display/image.rs @@ -1,7 +1,7 @@ use std::io::Write; -use crate::vec3::Color; use crate::display::{Display, Pixel}; +use crate::vec3::Color; pub struct Image { width: usize, @@ -39,7 +39,9 @@ impl Display for Image { } fn maybe_write(&self, output: &mut impl Write) { - output.write_fmt(format_args!("P3\n{} {}\n255\n", self.width, self.height)).unwrap(); + output + .write_fmt(format_args!("P3\n{} {}\n255\n", self.width, self.height)) + .unwrap(); for y in (0..self.height).rev() { for x in 0..self.width { let pixel = self.data.get((y * self.width) + x).unwrap(); diff --git a/src/display/pixelflut.rs b/src/display/pixelflut.rs index 3a62f8d..9b71c8e 100644 --- a/src/display/pixelflut.rs +++ b/src/display/pixelflut.rs @@ -1,8 +1,8 @@ use std::io::Write; -use std::net::{TcpStream}; +use std::net::TcpStream; +use crate::display::{Display, Pixel}; use crate::vec3::Color; -use crate::display::{Display, Pixel}; pub struct Pixelflut { socket: TcpStream, @@ -54,15 +54,22 @@ impl Display for Pixelflut { for x in 0..self.width { let pixel = self.data.get((y * self.width) + x).unwrap(); let scale = 1.0 / pixel.sample_count as f64; - let mut r = (pixel.color.x * scale).sqrt(); - let mut g = (pixel.color.y * scale).sqrt(); - let mut b = (pixel.color.z * scale).sqrt(); - self.socket.write(format!("PX {} {} {:02x}{:02x}{:02x}\n", - self.x + x, - self.y + self.height - y, - (256.0 * r.clamp(0.0, 0.999)) as u32, - (256.0 * g.clamp(0.0, 0.999)) as u32, - (256.0 * b.clamp(0.0, 0.999)) as u32).as_bytes()); + let r = (pixel.color.x * scale).sqrt(); + let g = (pixel.color.y * scale).sqrt(); + let b = (pixel.color.z * scale).sqrt(); + self.socket + .write( + format!( + "PX {} {} {:02x}{:02x}{:02x}\n", + self.x + x, + self.y + self.height - y, + (256.0 * r.clamp(0.0, 0.999)) as u32, + (256.0 * g.clamp(0.0, 0.999)) as u32, + (256.0 * b.clamp(0.0, 0.999)) as u32 + ) + .as_bytes(), + ) + .unwrap(); } } } |