Prior to multithreading rework
This commit is contained in:
parent
551d7df8be
commit
fb17ed2b7a
1
note.txt
1
note.txt
@ -12,6 +12,7 @@ Optimize:
|
||||
Find a tool for optimization
|
||||
GET RID OF THAT FUCKING CLONE (Doesn't matter much)
|
||||
Multithreading (thread # agnostic)
|
||||
Threads with HQ or set of designated frames ?
|
||||
u32 instructions
|
||||
Might still be not enough, idk
|
||||
Used for end-of-file pointers
|
||||
|
@ -355,7 +355,7 @@ fn etch_instructions(settings: &Settings, data: &Data)
|
||||
return Ok(source);
|
||||
}
|
||||
|
||||
fn read_instructions(source: &EmbedSource) -> anyhow::Result<(OutputMode, Settings)> {
|
||||
fn read_instructions(source: &EmbedSource, threads: usize) -> anyhow::Result<(OutputMode, Settings)> {
|
||||
// highgui::named_window("window", WINDOW_FULLSCREEN)?;
|
||||
// highgui::imshow("window", &source.image)?;
|
||||
// highgui::wait_key(10000000)?;
|
||||
@ -378,16 +378,35 @@ fn read_instructions(source: &EmbedSource) -> anyhow::Result<(OutputMode, Settin
|
||||
let height = source.frame_size.height;
|
||||
let width = source.frame_size.width;
|
||||
|
||||
let settings = Settings::new(size, fps, width, height);
|
||||
let settings = Settings::new(size, threads, fps, width, height);
|
||||
|
||||
// println!("Output mode is: {}\nsize is: {}\nfps is: {}", out_mode, size, fps);
|
||||
return Ok((out_mode, settings));
|
||||
}
|
||||
|
||||
fn summon_etch_thread() -> anyhow::Result<()> {
|
||||
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn etch(path: &str, data: Data, settings: Settings) -> anyhow::Result<()> {
|
||||
let mut frames = Vec::new();
|
||||
let mut index: usize = 0;
|
||||
|
||||
match data.out_mode {
|
||||
OutputMode::Color => {
|
||||
let length = data.bytes.len();
|
||||
let chunk_size = (length / settings.threads) + 1;
|
||||
|
||||
for chunk in data.bytes.chunks(chunk_size) {
|
||||
dbg!(chunk.len());
|
||||
}
|
||||
return Ok(());
|
||||
},
|
||||
OutputMode::Binary => {},
|
||||
}
|
||||
|
||||
let instructional_frame = etch_instructions(&settings, &data)?;
|
||||
frames.push(instructional_frame);
|
||||
|
||||
@ -424,7 +443,7 @@ pub fn etch(path: &str, data: Data, settings: Settings) -> anyhow::Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn read(path: &str) -> anyhow::Result<Vec<u8>> {
|
||||
pub fn read(path: &str, threads: usize) -> anyhow::Result<Vec<u8>> {
|
||||
let instruction_size = 5;
|
||||
|
||||
let mut video = VideoCapture::from_file(&path, CAP_ANY)
|
||||
@ -433,11 +452,8 @@ pub fn read(path: &str) -> anyhow::Result<Vec<u8>> {
|
||||
|
||||
//Could probably avoid cloning
|
||||
video.read(&mut frame)?;
|
||||
//TEMPORARY
|
||||
let instruction_source = EmbedSource::from(frame.clone(), instruction_size);
|
||||
let (out_mode, settings) = read_instructions(&instruction_source)?;
|
||||
// dbg!(&settings);
|
||||
// dbg!(&out_mode);
|
||||
let (out_mode, settings) = read_instructions(&instruction_source, threads)?;
|
||||
|
||||
let mut byte_data: Vec<u8> = Vec::new();
|
||||
loop {
|
||||
|
@ -10,6 +10,7 @@ pub struct Data {
|
||||
pub out_mode: OutputMode,
|
||||
}
|
||||
|
||||
//Get rid of possible empty spaces
|
||||
impl Data {
|
||||
pub fn new_out_mode(out_mode: OutputMode) -> Data {
|
||||
Data {
|
||||
@ -39,16 +40,18 @@ impl Data {
|
||||
#[derive(Debug)]
|
||||
pub struct Settings {
|
||||
pub size: i32,
|
||||
pub threads: usize,
|
||||
pub fps: f64,
|
||||
pub width: i32,
|
||||
pub height: i32,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
pub fn new(size: i32, fps: i32, width: i32, height: i32,)
|
||||
pub fn new(size: i32, threads: usize, fps: i32, width: i32, height: i32)
|
||||
-> Settings {
|
||||
Settings {
|
||||
size,
|
||||
threads,
|
||||
fps: fps as f64,
|
||||
height,
|
||||
width
|
||||
|
18
src/ui.rs
18
src/ui.rs
@ -53,6 +53,12 @@ fn embed_path() -> anyhow::Result<()> {
|
||||
.with_default(2)
|
||||
.prompt()?;
|
||||
|
||||
let threads = CustomType::<usize>::new("How many threads to dedicate for processing ?")
|
||||
.with_error_message("Please type a valid number")
|
||||
.with_help_message("The more threads, the merrier")
|
||||
.with_default(4)
|
||||
.prompt()?;
|
||||
|
||||
let out_mode = match out_mode {
|
||||
"Colored" => OutputMode::Color,
|
||||
"B/W (Binary)" => OutputMode::Binary,
|
||||
@ -90,7 +96,7 @@ fn embed_path() -> anyhow::Result<()> {
|
||||
let bytes = etcher::rip_bytes(&path)?;
|
||||
|
||||
let data = Data::from_color(bytes);
|
||||
let settings = Settings::new(size, fps, width, height);
|
||||
let settings = Settings::new(size, threads, fps, width, height);
|
||||
|
||||
etcher::etch("output.avi", data, settings)?;
|
||||
},
|
||||
@ -99,7 +105,7 @@ fn embed_path() -> anyhow::Result<()> {
|
||||
let binary = etcher::rip_binary(bytes)?;
|
||||
|
||||
let data = Data::from_binary(binary);
|
||||
let settings = Settings::new(size, fps, width, height);
|
||||
let settings = Settings::new(size, threads, fps, width, height);
|
||||
|
||||
etcher::etch("output.avi", data, settings)?;
|
||||
},
|
||||
@ -142,7 +148,13 @@ fn dislodge_path() -> anyhow::Result<()> {
|
||||
.with_help_message("Please include name of file and extension")
|
||||
.prompt().unwrap();
|
||||
|
||||
let out_data = etcher::read(&in_path)?;
|
||||
let threads = CustomType::<usize>::new("How many threads to dedicate for processing ?")
|
||||
.with_error_message("Please type a valid number")
|
||||
.with_help_message("The more threads, the merrier")
|
||||
.with_default(4)
|
||||
.prompt()?;
|
||||
|
||||
let out_data = etcher::read(&in_path, threads)?;
|
||||
etcher::write_bytes(&out_path, out_data)?;
|
||||
|
||||
return Ok(());
|
||||
|
Loading…
Reference in New Issue
Block a user