2024-01-01 21:18:56 +01:00
|
|
|
pub mod read {
|
2024-01-01 07:30:04 +01:00
|
|
|
use image::{io::Reader as ImageReader, DynamicImage};
|
|
|
|
use rpl::instructions::read::{Read, SourceType};
|
|
|
|
|
2024-01-11 11:39:59 +01:00
|
|
|
pub fn read(Read { source, .. }: Read) -> DynamicImage {
|
2024-01-11 01:36:47 +01:00
|
|
|
// TODO: actual error handling
|
|
|
|
let img = ImageReader::open(match source {
|
2024-01-01 07:30:04 +01:00
|
|
|
SourceType::File(path) => path,
|
|
|
|
})
|
|
|
|
.expect("something went wrong :(((");
|
|
|
|
|
|
|
|
img.decode().expect("couldn't decode image")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-01 21:18:56 +01:00
|
|
|
pub mod write {
|
2024-01-11 01:36:47 +01:00
|
|
|
use image::{DynamicImage, ImageFormat};
|
2024-01-01 07:30:04 +01:00
|
|
|
use rpl::instructions::write::{TargetFormat, TargetType, Write};
|
|
|
|
|
2024-01-11 01:36:47 +01:00
|
|
|
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");
|
2024-01-01 07:30:04 +01:00
|
|
|
}
|
|
|
|
}
|
2024-01-01 21:18:56 +01:00
|
|
|
|
|
|
|
pub mod filters {
|
|
|
|
pub mod invert {
|
|
|
|
use image::DynamicImage;
|
|
|
|
|
|
|
|
pub fn invert(mut input_data: DynamicImage) -> DynamicImage {
|
|
|
|
input_data.invert();
|
|
|
|
input_data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|