hard-rewrite #1

Merged
schrottkatze merged 6 commits from :hard-rewrite into main 2024-01-01 22:36:43 +00:00
4 changed files with 50 additions and 13 deletions
Showing only changes of commit e7863402f3 - Show all commits

View file

@ -1,4 +1,4 @@
pub mod Read { pub mod read {
use image::{io::Reader as ImageReader, DynamicImage}; use image::{io::Reader as ImageReader, DynamicImage};
use rpl::instructions::read::{Read, SourceType}; use rpl::instructions::read::{Read, SourceType};
@ -12,7 +12,7 @@ pub mod Read {
} }
} }
pub mod Write { pub mod write {
use image::{io::Reader as ImageReader, DynamicImage, ImageFormat}; use image::{io::Reader as ImageReader, DynamicImage, ImageFormat};
use rpl::instructions::write::{TargetFormat, TargetType, Write}; use rpl::instructions::write::{TargetFormat, TargetType, Write};
@ -28,3 +28,14 @@ pub mod Write {
); );
} }
} }
pub mod filters {
pub mod invert {
use image::DynamicImage;
pub fn invert(mut input_data: DynamicImage) -> DynamicImage {
input_data.invert();
input_data
}
}
}

View file

@ -1,19 +1,18 @@
use rpl::instructions::{FilterInstruction, Instruction};
use crate::{value::DynamicValue, Executor}; use crate::{value::DynamicValue, Executor};
mod instructions; mod instructions;
pub struct DebugExecutor; pub struct DebugExecutor;
impl Executor for DebugExecutor { impl Executor for DebugExecutor {
fn execute( fn execute(instruction: Instruction, input: Option<DynamicValue>) -> Option<DynamicValue> {
instruction: rpl::instructions::Instruction,
input: Option<DynamicValue>,
) -> Option<DynamicValue> {
match instruction { match instruction {
rpl::instructions::Instruction::Read(read_instruction) => Some(DynamicValue::Image( Instruction::Read(read_instruction) => Some(DynamicValue::Image(
instructions::Read::read(read_instruction), instructions::read::read(read_instruction),
)), )),
rpl::instructions::Instruction::Write(write_instruction) => { Instruction::Write(write_instruction) => {
instructions::Write::write( instructions::write::write(
write_instruction, write_instruction,
match input { match input {
Some(DynamicValue::Image(img)) => img, Some(DynamicValue::Image(img)) => img,
@ -22,9 +21,17 @@ impl Executor for DebugExecutor {
); );
None None
} }
rpl::instructions::Instruction::Math(_) => todo!(), Instruction::Math(_) => todo!(),
rpl::instructions::Instruction::Blend(_) => todo!(), Instruction::Blend(_) => todo!(),
rpl::instructions::Instruction::Noise(_) => todo!(), Instruction::Noise(_) => todo!(),
Instruction::Filter(filter_instruction) => match filter_instruction {
FilterInstruction::Invert => Some(DynamicValue::Image(
instructions::filters::invert::invert(match input {
Some(DynamicValue::Image(img)) => img,
_ => panic!("invalid value type for invert"),
}),
)),
},
} }
} }
} }

View file

@ -10,6 +10,7 @@ pub enum Instruction {
Math(MathInstruction), Math(MathInstruction),
Blend(BlendInstruction), Blend(BlendInstruction),
Noise(NoiseInstruction), Noise(NoiseInstruction),
Filter(FilterInstruction),
} }
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
@ -39,3 +40,8 @@ pub enum NoiseInstruction {
Simplex, Simplex,
Voronoi, Voronoi,
} }
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
pub enum FilterInstruction {
Invert,
}

13
testfiles/invert.rpl Normal file
View file

@ -0,0 +1,13 @@
(
[
Read((
source: File("/home/jade/example/file.png"),
format: Png
)),
Filter(Invert),
Write((
target: File("/home/jade/example/inverted.jpg"),
format: Jpeg
))
]
)