cvkg_cli/
raster_export.rs1use std::path::PathBuf;
7
8pub struct RasterExport {
10 pub format: String,
12 pub output: PathBuf,
14 pub frames: u16,
16 pub fps: u16,
18}
19
20impl RasterExport {
21 pub fn new(format: String, output: PathBuf, frames: u16, fps: u16) -> Self {
23 Self {
24 format,
25 output,
26 frames,
27 fps,
28 }
29 }
30
31 pub fn execute(&self) -> Result<(), String> {
33 println!(
34 "Raster export: format={}, output={}, frames={}, fps={}",
35 self.format,
36 self.output.display(),
37 self.frames,
38 self.fps
39 );
40
41 if self.format == "png" {
42 self.export_png()
43 } else if self.format == "gif" {
44 self.export_gif()
45 } else {
46 Err(format!("Unsupported format: {}", self.format))
47 }
48 }
49
50 fn export_png(&self) -> Result<(), String> {
51 let frame = cvkg_export_raster::CapturedFrame {
53 width: 200,
54 height: 200,
55 rgba: vec![128u8; 200 * 200 * 4],
56 };
57 let png_bytes = cvkg_export_raster::encode_png(&frame)?;
58 std::fs::write(&self.output, png_bytes)
59 .map_err(|e| format!("Failed to write PNG: {}", e))?;
60 println!("Wrote test PNG to {}", self.output.display());
61 Ok(())
62 }
63
64 fn export_gif(&self) -> Result<(), String> {
65 let frames: Vec<cvkg_export_raster::CapturedFrame> = (0..self.frames)
66 .map(|_| cvkg_export_raster::CapturedFrame {
67 width: 200,
68 height: 200,
69 rgba: vec![128u8; 200 * 200 * 4],
70 })
71 .collect();
72 let gif_bytes = cvkg_export_raster::encode_gif(&frames, self.fps)?;
73 std::fs::write(&self.output, gif_bytes)
74 .map_err(|e| format!("Failed to write GIF: {}", e))?;
75 println!(
76 "Wrote test GIF ({} frames) to {}",
77 self.frames,
78 self.output.display()
79 );
80 Ok(())
81 }
82}