Seperated etch_frame

This commit is contained in:
HistidineDwarf 2023-02-08 22:10:39 -08:00
parent fb17ed2b7a
commit c8b8a23bff
2 changed files with 52 additions and 28 deletions

View File

@ -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

View File

@ -150,6 +150,57 @@ fn etch_pixel(frame: &mut EmbedSource, rgb: Vec<u8>, 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<Vec<u8>> {
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<bool> = 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<Vec<u8>>{
// let _timer = Timer::new("Reading frame");