Finish encode function for now

This commit is contained in:
Lncvrt committed 2026-03-13 20:59:45 -07:00
1 parent 88c00614f4
commit 78acb35b76
3 files changed
+52 -3

No files matched your search

+1
View File
@@ -6,6 +6,7 @@ edition = "2024"
[dependencies] [dependencies]
gtk4 = "0.11.0" gtk4 = "0.11.0"
image = "0.25.10" image = "0.25.10"
tempfile = "3.27.0"
[package.metadata.bundle] [package.metadata.bundle]
name = "VideoStore" name = "VideoStore"
+50 -2
View File
@@ -1,5 +1,53 @@
use image::{ImageBuffer, Rgb};
use std::path::PathBuf; use std::path::PathBuf;
use tempfile::TempDir;
pub async fn encode(path: PathBuf) { pub fn encode(path: PathBuf) {
println!("{}", path.display()); let temp_dir = TempDir::new().unwrap();
let temp_path = temp_dir.path();
let size = 300;
let file_data = std::fs::read(&path).unwrap();
let mut frame_num = 0;
let mut byte_index = 0;
let mut bit_index = 0;
loop {
let mut img = ImageBuffer::<Rgb<u8>, Vec<u8>>::new(size, size);
for pixel_idx in 0..(size * size) {
let x = (pixel_idx % size) as u32;
let y = (pixel_idx / size) as u32;
if byte_index < file_data.len() {
let byte = file_data[byte_index];
let bit = (byte >> (7 - bit_index)) & 1;
let color = if bit == 0 {
Rgb([255, 0, 0])
} else {
Rgb([0, 255, 0])
};
img.put_pixel(x, y, color);
bit_index += 1;
if bit_index == 8 {
bit_index = 0;
byte_index += 1;
}
} else {
img.put_pixel(x, y, Rgb([0, 0, 255]));
}
}
let frame_path = temp_path.join(format!("frame_{}.png", frame_num));
img.save(&frame_path).unwrap();
frame_num += 1;
if byte_index >= file_data.len() {
break;
}
}
} }
+1 -1
View File
@@ -43,7 +43,7 @@ fn main() {
move |_| { move |_| {
get_user_selected_file(&window, |file_path| { get_user_selected_file(&window, |file_path| {
if let Some(path) = file_path { if let Some(path) = file_path {
spawn_future_local(encode(path)); encode(path);
} }
}); });
} }