From c8b8a23bff46959123527d421d57dd94e5b48d22 Mon Sep 17 00:00:00 2001 From: HistidineDwarf Date: Wed, 8 Feb 2023 22:10:39 -0800 Subject: [PATCH] Seperated etch_frame --- note.txt | 1 + src/etcher.rs | 79 +++++++++++++++++++++++++++++++++------------------ 2 files changed, 52 insertions(+), 28 deletions(-) diff --git a/note.txt b/note.txt index f130edb..3d144c4 100644 --- a/note.txt +++ b/note.txt @@ -13,6 +13,7 @@ Optimize: GET RID OF THAT FUCKING CLONE (Doesn't matter much) Multithreading (thread # agnostic) Threads with HQ or set of designated frames ? + Consider whether Data is still useful u32 instructions Might still be not enough, idk Used for end-of-file pointers diff --git a/src/etcher.rs b/src/etcher.rs index 3b4ee00..c9c2dea 100644 --- a/src/etcher.rs +++ b/src/etcher.rs @@ -150,6 +150,57 @@ fn etch_pixel(frame: &mut EmbedSource, rgb: Vec, x: i32, y: i32) -> anyhow:: return Ok(()); } +fn etch_bw(source: &mut EmbedSource, data: &[bool], global_index: &mut usize) { + let width = source.actual_size.width; + let height = source.actual_size.height; + let size = source.size as usize; + + for y in (0..height).step_by(size) { + for x in (0..width).step_by(size) { + let local_index = global_index.clone(); + + let brightness = if data[local_index] == true { + 255 // 1 + } else { + 0 // 0 + }; + let rgb = vec![ + brightness, + brightness, + brightness, + ]; + + //Increment index so we move along the data + *global_index += 1; + + etch_pixel(source, rgb, x, y).unwrap(); + } + } +} + +fn etch_color(source: &mut EmbedSource, data: &[u8], global_index: &mut usize) { + let width = source.actual_size.width; + let height = source.actual_size.height; + let size = source.size as usize; + + for y in (0..height).step_by(size) { + for x in (0..width).step_by(size) { + let local_index = global_index.clone(); + + let rgb = + vec![ + data[local_index], //Red + data[local_index+1],//Green + data[local_index+2] //Blue + ]; + //Increment index so we move along the data + *global_index += 3; + + etch_pixel(source, rgb, x, y).unwrap(); + } + } +} + fn etch_frame(source: &mut EmbedSource, data: &Data, global_index: &mut usize) -> anyhow::Result<()>{ @@ -216,34 +267,6 @@ fn etch_frame(source: &mut EmbedSource, data: &Data, global_index: &mut usize) return Ok(()); } -fn read_frame2(source: &EmbedSource, out_mode: &OutputMode) -> anyhow::Result> { - highgui::named_window("window", WINDOW_FULLSCREEN)?; - highgui::imshow("window", &source.image)?; - highgui::wait_key(10000000)?; - - imwrite("src/out/test1.png", &source.image, &Vector::new())?; - - let width = source.actual_size.width; - let height = source.actual_size.height; - let size = source.size as usize; - - let mut binary_data: Vec = Vec::new(); - for y in (0..height).step_by(size) { - for x in (0..width).step_by(size) { - let rgb = get_pixel(source, x, y).unwrap(); - // dbg!(&rgb); - if rgb[0] > 130 { - binary_data.push(true); - } else { - binary_data.push(false); - } - } - } - - let translated = translate_binary(binary_data)?; - return Ok(translated); -} - fn read_frame(source: &EmbedSource, out_mode: &OutputMode) -> anyhow::Result>{ // let _timer = Timer::new("Reading frame");