diff --git a/crates/executor/src/debug/instructions/mod.rs b/crates/executor/src/debug/instructions/mod.rs index 0c4b611..0bbbfaa 100644 --- a/crates/executor/src/debug/instructions/mod.rs +++ b/crates/executor/src/debug/instructions/mod.rs @@ -2,8 +2,9 @@ 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 { + pub fn read(Read { source, format: _ }: Read) -> DynamicImage { + // TODO: actual error handling + let img = ImageReader::open(match source { SourceType::File(path) => path, }) .expect("something went wrong :((("); @@ -13,19 +14,21 @@ pub mod read { } pub mod write { - use image::{io::Reader as ImageReader, DynamicImage, ImageFormat}; + use image::{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, - }, - ); + 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, + }, + ) + .expect("couldn't save file — come back later and handle me properly please uwu"); } } diff --git a/crates/executor/src/debug/mod.rs b/crates/executor/src/debug/mod.rs index d56f546..8cde85b 100644 --- a/crates/executor/src/debug/mod.rs +++ b/crates/executor/src/debug/mod.rs @@ -1,21 +1,21 @@ use rpl::instructions::{FilterInstruction, Instruction}; -use crate::{value::DynamicValue, Executor}; +use crate::value::Dynamic; mod instructions; -pub struct DebugExecutor; +pub struct Executor; -impl Executor for DebugExecutor { - fn execute(instruction: Instruction, input: Option) -> Option { +impl crate::Executor for Executor { + fn execute(instruction: Instruction, input: Option) -> Option { match instruction { - Instruction::Read(read_instruction) => Some(DynamicValue::Image( - instructions::read::read(read_instruction), - )), + Instruction::Read(read_instruction) => { + Some(Dynamic::Image(instructions::read::read(read_instruction))) + } Instruction::Write(write_instruction) => { instructions::write::write( write_instruction, match input { - Some(DynamicValue::Image(img)) => img, + Some(Dynamic::Image(ref img)) => img, _ => panic!("awawwawwa"), }, ); @@ -25,9 +25,9 @@ impl Executor for DebugExecutor { Instruction::Blend(_) => todo!(), Instruction::Noise(_) => todo!(), Instruction::Filter(filter_instruction) => match filter_instruction { - FilterInstruction::Invert => Some(DynamicValue::Image( + FilterInstruction::Invert => Some(Dynamic::Image( instructions::filters::invert::invert(match input { - Some(DynamicValue::Image(img)) => img, + Some(Dynamic::Image(img)) => img, _ => panic!("invalid value type for invert"), }), )), diff --git a/crates/executor/src/lib.rs b/crates/executor/src/lib.rs index fb55029..9e4da44 100644 --- a/crates/executor/src/lib.rs +++ b/crates/executor/src/lib.rs @@ -1,5 +1,5 @@ use rpl::instructions::Instruction; -use value::DynamicValue; +use value::Dynamic; mod debug; mod value; @@ -17,14 +17,14 @@ pub enum Executors { } trait Executor { - fn execute(instruction: Instruction, input: Option) -> Option; + fn execute(instruction: Instruction, input: Option) -> Option; } pub fn execute_all(instructions: Vec) { let mut tmp = None; for instruction in instructions { - tmp = debug::DebugExecutor::execute(instruction, tmp); + tmp = debug::Executor::execute(instruction, tmp); } } diff --git a/crates/executor/src/value/mod.rs b/crates/executor/src/value/mod.rs index daf0dd2..f3595d0 100644 --- a/crates/executor/src/value/mod.rs +++ b/crates/executor/src/value/mod.rs @@ -1,5 +1,5 @@ use image::DynamicImage; -pub enum DynamicValue { +pub enum Dynamic { Image(DynamicImage), } diff --git a/crates/rpl/src/lib.rs b/crates/rpl/src/lib.rs index dbecd0a..91180c1 100644 --- a/crates/rpl/src/lib.rs +++ b/crates/rpl/src/lib.rs @@ -1,16 +1,14 @@ use instructions::Instruction; use serde::{Deserialize, Serialize}; -use crate::instructions::{ - read::{SourceFormat, SourceType}, - write::{TargetFormat, TargetType}, - MathInstruction, -}; - pub mod instructions; +/// # Panics +/// +/// Panics if deserialization fails. lol. +#[must_use] pub fn from_ron(raw: &str) -> Rpl { - ron::from_str(raw).unwrap() + ron::from_str(raw).expect("come back later and handle me correctly") } #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] diff --git a/testfiles/invert.rpl b/testfiles/invert.rpl index d17fe1a..5f235a9 100644 --- a/testfiles/invert.rpl +++ b/testfiles/invert.rpl @@ -1,12 +1,12 @@ ( [ Read(( - source: File("/home/jade/example/file.png"), + source: File("testfiles/juan.jpg"), format: Png )), Filter(Invert), Write(( - target: File("/home/jade/example/inverted.jpg"), + target: File("testfiles/inverted.jpg"), format: Jpeg )) ] diff --git a/testfiles/juan.jpg b/testfiles/juan.jpg new file mode 100644 index 0000000..2c4399f Binary files /dev/null and b/testfiles/juan.jpg differ