create_raw_image/
create_raw_image.rs1use vsf::builders::*;
2use vsf::types::BitPackedTensor;
3
4fn main() -> Result<(), String> {
5 println!("=== VSF RAW Image Example ===\n");
6
7 let width = 17;
9 let height = 163;
10 let planes = 1;
11 let bits = 11;
12 let cfa = vec![b'R', b'G', b'C', b'Y']; let blackpoint = 499;
14 let whitepoint = 8047;
15
16 println!("Sensor specs:");
17 println!(" Resolution: {}×{} (single plane)", width, height);
18 println!(" Bit depth: {} bits per sample", bits);
19 println!(" CFA pattern: RGCY (Red, Green, Cyan, Yellow)");
20 println!(" Black level: {}", blackpoint);
21 println!(" White level: {}\n", whitepoint);
22
23 let total_samples = width * height * planes;
25 let mut samples = Vec::with_capacity(total_samples);
26 let mut rng = 0usize;
27 for sample in 0..total_samples {
28 rng ^= rng.rotate_left(13).wrapping_add(sample);
29 let value = rng as u8 as u16 + blackpoint; samples.push(value);
31 }
32
33 let image = BitPackedTensor::pack(bits, vec![width, height], &samples);
35 println!(
36 "Packed {} samples into {} bytes\n",
37 total_samples,
38 image.data.len()
39 );
40
41 println!("Building VSF RAW image with metadata...");
43
44 let mut raw = RawImageBuilder::new(image);
45
46 raw.raw.cfa_pattern = Some(cfa);
48 raw.raw.black_level = Some(blackpoint as f32);
49 raw.raw.white_level = Some(whitepoint as f32);
50 raw.raw.magic_9 = Some(vec![
51 1.5, -0.3, -0.2, -0.4, 1.6, -0.2, -0.1, -0.5, 1.6,
53 ]);
54
55 raw.camera.make = Some("Sony".to_string());
57 raw.camera.model = Some("α7 IV".to_string());
58 raw.camera.serial_number = Some("87654321".to_string());
59 raw.camera.iso_speed = Some(800.);
60 raw.camera.shutter_time_s = Some(1. / 60.); raw.camera.aperture_f_number = Some(2.8);
62 raw.camera.focal_length_m = Some(0.024); raw.camera.exposure_compensation = Some(0.);
64 raw.camera.focus_distance_m = Some(5.);
65 raw.camera.flash_fired = Some(false);
66 raw.camera.metering_mode = Some("matrix".to_string());
67
68 raw.lens.make = Some("Sony".to_string());
70 raw.lens.model = Some("FE 24mm F2.8 G".to_string());
71 raw.lens.serial_number = Some("12345678".to_string());
72 raw.lens.min_focal_length_m = Some(0.024); raw.lens.max_focal_length_m = Some(0.024);
74 raw.lens.min_aperture_f = Some(2.8);
75 raw.lens.max_aperture_f = Some(22.);
76
77 let raw_bytes = raw.build()?;
79
80 println!("✓ Built VSF RAW image: {} bytes", raw_bytes.len());
81 println!(" (Includes mandatory BLAKE3 hash for integrity)\n");
82
83 std::fs::write("example_raw.vsf", &raw_bytes).expect("Failed to write file");
85 println!("✓ Saved to example_raw.vsf");
86
87 println!("\n=== Complete! ===");
88 println!("The RAW image includes:");
89 println!(" • Bitpacked sensor data ({}-bit samples)", bits);
90 println!(" • CFA pattern (RGCY Bayer)");
91 println!(" • Black/white levels");
92 println!(" • Colour transformation matrix (Magic 9)");
93 println!(" • Camera information (make, model, S/N, ISO, shutter, aperture, etc.)");
94 println!(" • Lens information (make, model, S/N, focal length range, etc.)");
95 println!(" • Mandatory BLAKE3 file hash (automatic)");
96 println!("\nAll metadata is validated and type-checked at compile time.");
97 println!("Try changing a value to something invalid - the compiler will catch it!");
98
99 Ok(())
100}