1
- use std:: io:: { Stdout , Write } ;
1
+ use std:: io:: Write ;
2
2
3
3
use crate :: { interval:: Interval , vec3:: Vec3 } ;
4
4
5
5
pub type Color = Vec3 ;
6
6
7
- pub fn write_color ( out : & mut Stdout , pixel_color : Color ) {
8
- let r = pixel_color. x ( ) ;
9
- let g = pixel_color. y ( ) ;
10
- let b = pixel_color. z ( ) ;
7
+ pub fn write_color < W : Write > ( mut out : W , pixel_color : Color ) {
8
+ let r = pixel_color. x ( ) ;
9
+ let g = pixel_color. y ( ) ;
10
+ let b = pixel_color. z ( ) ;
11
11
12
- let r = linear_to_gamma ( r) ;
13
- let g = linear_to_gamma ( g) ;
14
- let b = linear_to_gamma ( b) ;
12
+ let r = linear_to_gamma ( r) ;
13
+ let g = linear_to_gamma ( g) ;
14
+ let b = linear_to_gamma ( b) ;
15
15
16
- let intensity = Interval :: new ( 0.0 , 0.999 ) ;
17
- let rbyte = ( 256.0 * intensity. clamp ( r) ) as i32 ;
18
- let gbyte = ( 256.0 * intensity. clamp ( g) ) as i32 ;
19
- let bbyte = ( 256.0 * intensity. clamp ( b) ) as i32 ;
20
- out. write_all ( format ! ( "{rbyte} {gbyte} {bbyte}\n " ) . as_bytes ( ) ) . unwrap ( ) ;
16
+ let intensity = Interval :: new ( 0.0 , 0.999 ) ;
17
+ let rbyte = ( 256.0 * intensity. clamp ( r) ) as i32 ;
18
+ let gbyte = ( 256.0 * intensity. clamp ( g) ) as i32 ;
19
+ let bbyte = ( 256.0 * intensity. clamp ( b) ) as i32 ;
20
+ out. write_all ( format ! ( "{rbyte} {gbyte} {bbyte}\n " ) . as_bytes ( ) )
21
+ . unwrap ( ) ;
21
22
}
22
23
pub fn linear_to_gamma ( linear_component : f64 ) -> f64 {
23
- if linear_component > 0.0 {
24
- return linear_component. sqrt ( )
25
- }
26
- 0.0
27
- }
24
+ if linear_component > 0.0 {
25
+ return linear_component. sqrt ( ) ;
26
+ }
27
+ 0.0
28
+ }
29
+
0 commit comments