forked from katzen-cafe/iowo
basic conversion thing do worky!!!
This commit is contained in:
parent
f046393af8
commit
b92977d8f1
13 changed files with 680 additions and 14 deletions
30
crates/executor/src/debug/instructions/mod.rs
Normal file
30
crates/executor/src/debug/instructions/mod.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
pub mod Read {
|
||||
use image::{io::Reader as ImageReader, DynamicImage};
|
||||
use rpl::instructions::read::{Read, SourceType};
|
||||
|
||||
pub fn read(Read { source, format }: Read) -> DynamicImage {
|
||||
let mut img = ImageReader::open(match source {
|
||||
SourceType::File(path) => path,
|
||||
})
|
||||
.expect("something went wrong :(((");
|
||||
|
||||
img.decode().expect("couldn't decode image")
|
||||
}
|
||||
}
|
||||
|
||||
pub mod Write {
|
||||
use image::{io::Reader as ImageReader, DynamicImage, ImageFormat};
|
||||
use rpl::instructions::write::{TargetFormat, TargetType, Write};
|
||||
|
||||
pub fn write(Write { target, format }: Write, input_data: DynamicImage) {
|
||||
input_data.save_with_format(
|
||||
match target {
|
||||
TargetType::File(path) => path,
|
||||
},
|
||||
match format {
|
||||
TargetFormat::Jpeg => ImageFormat::Jpeg,
|
||||
TargetFormat::Png => ImageFormat::Png,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
30
crates/executor/src/debug/mod.rs
Normal file
30
crates/executor/src/debug/mod.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
use crate::{value::DynamicValue, Executor};
|
||||
mod instructions;
|
||||
|
||||
pub struct DebugExecutor;
|
||||
|
||||
impl Executor for DebugExecutor {
|
||||
fn execute(
|
||||
instruction: rpl::instructions::Instruction,
|
||||
input: Option<DynamicValue>,
|
||||
) -> Option<DynamicValue> {
|
||||
match instruction {
|
||||
rpl::instructions::Instruction::Read(read_instruction) => Some(DynamicValue::Image(
|
||||
instructions::Read::read(read_instruction),
|
||||
)),
|
||||
rpl::instructions::Instruction::Write(write_instruction) => {
|
||||
instructions::Write::write(
|
||||
write_instruction,
|
||||
match input {
|
||||
Some(DynamicValue::Image(img)) => img,
|
||||
_ => panic!("awawwawwa"),
|
||||
},
|
||||
);
|
||||
None
|
||||
}
|
||||
rpl::instructions::Instruction::Math(_) => todo!(),
|
||||
rpl::instructions::Instruction::Blend(_) => todo!(),
|
||||
rpl::instructions::Instruction::Noise(_) => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue