u32 instructions with final byte work ?
This commit is contained in:
parent
d74e03e91f
commit
52438cb2f0
|
@ -73,11 +73,12 @@ fn translate_binary(binary_data: Vec<bool>) -> anyhow::Result<Vec<u8>>{
|
||||||
}
|
}
|
||||||
|
|
||||||
//Bit of a waste
|
//Bit of a waste
|
||||||
pub fn rip_binary_u64(byte: u64) -> anyhow::Result<Vec<bool>> {
|
pub fn rip_binary_u32(bytes: Vec<u32>) -> anyhow::Result<Vec<bool>> {
|
||||||
let mut binary_data: Vec<bool> = Vec::new();
|
let mut binary_data: Vec<bool> = Vec::new();
|
||||||
|
|
||||||
|
for byte in bytes {
|
||||||
let mut bits = format!("{:b}", byte);
|
let mut bits = format!("{:b}", byte);
|
||||||
let missing_0 = 64 - bits.len();
|
let missing_0 = 32 - bits.len();
|
||||||
|
|
||||||
//Adding the missing 0's, could be faster
|
//Adding the missing 0's, could be faster
|
||||||
for _ in 0..missing_0 {
|
for _ in 0..missing_0 {
|
||||||
|
@ -91,6 +92,8 @@ pub fn rip_binary_u64(byte: u64) -> anyhow::Result<Vec<bool>> {
|
||||||
binary_data.push(false);
|
binary_data.push(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Ok(binary_data);
|
return Ok(binary_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,33 +291,53 @@ fn etch_instructions(settings: &Settings, data: &Data)
|
||||||
-> anyhow::Result<EmbedSource> {
|
-> anyhow::Result<EmbedSource> {
|
||||||
let instruction_size = 5;
|
let instruction_size = 5;
|
||||||
|
|
||||||
let mut u8_instructions: Vec<u8> = Vec::new();
|
let mut u32_instructions: Vec<u32> = Vec::new();
|
||||||
|
|
||||||
//Both adds the output mode to instructions and finds last byte
|
//calculating at what frame and pixel the file ends
|
||||||
let last_byte_pointer = match data.out_mode {
|
let frame_size = (settings.height * settings.width) as usize;
|
||||||
|
|
||||||
|
//Adds the output mode to instructions
|
||||||
|
//Instead of putting entire size of file, add at which frame and pixel file ends
|
||||||
|
//Saves space on instruction frame
|
||||||
|
match data.out_mode {
|
||||||
OutputMode::Color => {
|
OutputMode::Color => {
|
||||||
u8_instructions.push(255);
|
u32_instructions.push(u32::MAX);
|
||||||
rip_binary_u64(data.bytes.len() as u64)?
|
|
||||||
|
let final_byte = data.bytes.len() % frame_size;
|
||||||
|
let pixel_length = (data.bytes.len() as f64 / 3.).ceil() as i32;
|
||||||
|
let pixel_length = (pixel_length * settings.size.pow(2)) as usize;
|
||||||
|
let mut final_frame = pixel_length / frame_size;
|
||||||
|
|
||||||
|
if pixel_length % frame_size != 0 {
|
||||||
|
final_frame += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dbg!(final_frame, final_byte);
|
||||||
|
|
||||||
|
u32_instructions.push(final_frame as u32);
|
||||||
|
u32_instructions.push(final_byte as u32);
|
||||||
},
|
},
|
||||||
OutputMode::Binary => {
|
OutputMode::Binary => {
|
||||||
u8_instructions.push(0);
|
u32_instructions.push(u32::MIN);
|
||||||
rip_binary_u64(data.binary.len() as u64)?
|
|
||||||
|
let final_byte = data.binary.len() % frame_size;
|
||||||
|
let pixel_length = (data.binary.len() as i32 * settings.size.pow(2)) as usize;
|
||||||
|
let mut final_frame = pixel_length / frame_size;
|
||||||
|
|
||||||
|
if pixel_length % frame_size != 0 {
|
||||||
|
final_frame += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dbg!(final_frame, final_byte);
|
||||||
|
|
||||||
|
u32_instructions.push(final_frame as u32);
|
||||||
|
u32_instructions.push(final_byte as u32);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
//Could choke and die
|
u32_instructions.push(settings.size as u32);
|
||||||
u8_instructions.push(settings.size as u8);
|
|
||||||
u8_instructions.push(settings.fps as u8);
|
|
||||||
let mut instruction_data = rip_binary(u8_instructions)?;
|
|
||||||
//Instead of putting entire size of file, add at which frame and pixel file ends
|
|
||||||
//Saves space on instruction frame
|
|
||||||
instruction_data.extend(last_byte_pointer);
|
|
||||||
|
|
||||||
//Here to make sure instruction frame and the rest are of the same size
|
let instruction_data = rip_binary_u32(u32_instructions)?;
|
||||||
//Using EmbedSource::new() in case it changes and this code becomes disconnected from the rest
|
|
||||||
// let dummy = EmbedSource::new(settings.size, settings.width, settings.height);
|
|
||||||
// let width = dummy.width;
|
|
||||||
// let height = dummy.height;
|
|
||||||
|
|
||||||
let mut source = EmbedSource::new(instruction_size, settings.width, settings.height);
|
let mut source = EmbedSource::new(instruction_size, settings.width, settings.height);
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
|
@ -323,11 +346,11 @@ fn etch_instructions(settings: &Settings, data: &Data)
|
||||||
Err(_) => {println!("Instructions written")}
|
Err(_) => {println!("Instructions written")}
|
||||||
}
|
}
|
||||||
|
|
||||||
// highgui::named_window("window", WINDOW_FULLSCREEN)?;
|
highgui::named_window("window", WINDOW_FULLSCREEN)?;
|
||||||
// highgui::imshow("window", &source.image)?;
|
highgui::imshow("window", &source.image)?;
|
||||||
// highgui::wait_key(10000000)?;
|
highgui::wait_key(10000000)?;
|
||||||
|
|
||||||
// imwrite("src/out/test1.png", &source.image, &Vector::new())?;
|
imwrite("src/out/test1.png", &source.image, &Vector::new())?;
|
||||||
|
|
||||||
return Ok(source);
|
return Ok(source);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue