Skip to main content

gamma/
gamma.rs

1use tiny_skia::*;
2
3fn main() {
4    let mut paint = Paint {
5        shader: Shader::SolidColor(Color::from_rgba8(255, 100, 20, 255)),
6        anti_alias: true,
7        ..Default::default()
8    };
9    let stroke = Stroke::default();
10
11    let mut pixmap = Pixmap::new(1000, 1000).unwrap();
12    pixmap.fill(Color::BLACK);
13
14    let mut pb = PathBuilder::new();
15    for i in 0..10 {
16        pb.move_to(50.0, 45.0 + i as f32 * 20.0);
17        pb.line_to(450.0, 45.0 + i as f32 * 21.0);
18    }
19    let path = pb.finish().unwrap();
20
21    let colors = [
22        ColorSpace::Linear,
23        ColorSpace::Gamma2,
24        ColorSpace::SimpleSRGB,
25        ColorSpace::FullSRGBGamma,
26    ];
27
28    for (i, color) in colors.iter().enumerate() {
29        paint.colorspace = *color;
30
31        let mut xf = Transform::identity();
32        xf = xf.pre_translate(0.0, 240.0 * i as f32);
33
34        pixmap.stroke_path(&path, &paint, &stroke, xf, None);
35
36        // Move down 0.5 pixel so lines start in the middle of the pixel, not the edge
37        xf = xf.pre_translate(500.0, 0.5);
38
39        pixmap.stroke_path(&path, &paint, &stroke, xf, None);
40    }
41
42    pixmap.save_png("image.png").unwrap();
43}