mirror of
https://forge.katzen.cafe/katzen-cafe/iowo.git
synced 2024-11-21 13:14:41 +01:00
implement invert instruction
This commit is contained in:
parent
2b3c74053e
commit
e7863402f3
|
@ -1,4 +1,4 @@
|
|||
pub mod Read {
|
||||
pub mod read {
|
||||
use image::{io::Reader as ImageReader, DynamicImage};
|
||||
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 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
use rpl::instructions::{FilterInstruction, Instruction};
|
||||
|
||||
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> {
|
||||
fn execute(instruction: Instruction, input: Option<DynamicValue>) -> Option<DynamicValue> {
|
||||
match instruction {
|
||||
rpl::instructions::Instruction::Read(read_instruction) => Some(DynamicValue::Image(
|
||||
instructions::Read::read(read_instruction),
|
||||
Instruction::Read(read_instruction) => Some(DynamicValue::Image(
|
||||
instructions::read::read(read_instruction),
|
||||
)),
|
||||
rpl::instructions::Instruction::Write(write_instruction) => {
|
||||
instructions::Write::write(
|
||||
Instruction::Write(write_instruction) => {
|
||||
instructions::write::write(
|
||||
write_instruction,
|
||||
match input {
|
||||
Some(DynamicValue::Image(img)) => img,
|
||||
|
@ -22,9 +21,17 @@ impl Executor for DebugExecutor {
|
|||
);
|
||||
None
|
||||
}
|
||||
rpl::instructions::Instruction::Math(_) => todo!(),
|
||||
rpl::instructions::Instruction::Blend(_) => todo!(),
|
||||
rpl::instructions::Instruction::Noise(_) => todo!(),
|
||||
Instruction::Math(_) => todo!(),
|
||||
Instruction::Blend(_) => 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"),
|
||||
}),
|
||||
)),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ pub enum Instruction {
|
|||
Math(MathInstruction),
|
||||
Blend(BlendInstruction),
|
||||
Noise(NoiseInstruction),
|
||||
Filter(FilterInstruction),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
|
||||
|
@ -39,3 +40,8 @@ pub enum NoiseInstruction {
|
|||
Simplex,
|
||||
Voronoi,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
|
||||
pub enum FilterInstruction {
|
||||
Invert,
|
||||
}
|
||||
|
|
13
testfiles/invert.rpl
Normal file
13
testfiles/invert.rpl
Normal 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
|
||||
))
|
||||
]
|
||||
)
|
Loading…
Reference in a new issue