feat: graph-ir (continueing #6) #10

Merged
schrottkatze merged 37 commits from schrottkatze/iowo:graph-ir into main 2024-01-23 12:55:01 +00:00
5 changed files with 15 additions and 15 deletions
Showing only changes of commit ccbccfb11b - Show all commits

View file

@ -1,4 +1,4 @@
use rpl::instructions::{FilterInstruction, Instruction}; use rpl::instructions::{Filter, Instruction};
use crate::value::Dynamic; use crate::value::Dynamic;
mod instructions; mod instructions;
@ -25,12 +25,12 @@ impl crate::Executor for Executor {
Instruction::Blend(_) => todo!(), Instruction::Blend(_) => todo!(),
Instruction::Noise(_) => todo!(), Instruction::Noise(_) => todo!(),
Instruction::Filter(filter_instruction) => match filter_instruction { Instruction::Filter(filter_instruction) => match filter_instruction {
FilterInstruction::Invert => Some(Dynamic::Image( Filter::Invert => Some(Dynamic::Image(instructions::filters::invert::invert(
instructions::filters::invert::invert(match input { match input {
Some(Dynamic::Image(img)) => img, Some(Dynamic::Image(img)) => img,
_ => panic!("invalid value type for invert"), _ => panic!("invalid value type for invert"),
}), },
)), ))),
}, },
} }
} }

View file

@ -7,14 +7,14 @@ pub mod write;
pub enum Instruction { pub enum Instruction {
Read(read::Read), Read(read::Read),
Write(write::Write), Write(write::Write),
Math(MathInstruction), Math(Math),
Blend(BlendInstruction), Blend(Blend),
Noise(NoiseInstruction), Noise(Noise),
Filter(FilterInstruction), Filter(Filter),
} }
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
pub enum MathInstruction { pub enum Math {
Add, Add,
Subtract, Subtract,
Multiply, Multiply,
@ -22,7 +22,7 @@ pub enum MathInstruction {
} }
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
pub enum BlendInstruction { pub enum Blend {
Normal, Normal,
Multiply, Multiply,
Additive, Additive,
@ -35,13 +35,13 @@ pub enum BlendInstruction {
} }
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
pub enum NoiseInstruction { pub enum Noise {
Perlin, Perlin,
Simplex, Simplex,
Voronoi, Voronoi,
} }
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
pub enum FilterInstruction { pub enum Filter {
Invert, Invert,
} }

View file

@ -20,7 +20,7 @@ mod tests {
use crate::instructions::{ use crate::instructions::{
read::{SourceFormat, SourceType}, read::{SourceFormat, SourceType},
write::{TargetFormat, TargetType}, write::{TargetFormat, TargetType},
MathInstruction, Math,
}; };
#[test] #[test]
@ -40,7 +40,7 @@ mod tests {
source: SourceType::File("~/example/file.png".into()), source: SourceType::File("~/example/file.png".into()),
format: SourceFormat::Png format: SourceFormat::Png
}), }),
Instruction::Math(MathInstruction::Add), Instruction::Math(Math::Add),
Instruction::Write(instructions::write::Write { Instruction::Write(instructions::write::Write {
target: TargetType::File("~/example/out.jpg".into()), target: TargetType::File("~/example/out.jpg".into()),
format: TargetFormat::Jpeg format: TargetFormat::Jpeg