Compare commits
4 commits
jxl-suppor
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
ccc2efc21a |
|||
|
32f5503ffc |
|||
|
d91a894b6c |
|||
|
bba0ec5682 |
1 changed files with 21 additions and 23 deletions
44
src/main.rs
44
src/main.rs
|
|
@ -1,19 +1,11 @@
|
||||||
use std::{
|
use std::{env, ffi::OsStr, fs, io::Write, path::Path};
|
||||||
env,
|
|
||||||
ffi::OsStr,
|
|
||||||
fs,
|
|
||||||
io::{Read, Write},
|
|
||||||
path::Path,
|
|
||||||
};
|
|
||||||
|
|
||||||
use iced::{
|
use iced::{
|
||||||
Alignment, Color, Element, Length, Renderer, Subscription, Task, Theme, color, event,
|
Alignment, Color, Element, Length, Renderer, Subscription, Task, Theme, color, event,
|
||||||
keyboard::{self, Key, key},
|
keyboard::{self, Key, key},
|
||||||
theme, widget, window,
|
theme, widget, window,
|
||||||
};
|
};
|
||||||
use image::{
|
use image::{DynamicImage, EncodableLayout, ImageDecoder, ImageReader, RgbaImage, imageops};
|
||||||
DynamicImage, EncodableLayout, ImageDecoder, ImageReader, RgbImage, RgbaImage, imageops,
|
|
||||||
};
|
|
||||||
use jpegxl_rs::image::ToDynamic;
|
use jpegxl_rs::image::ToDynamic;
|
||||||
use rfd::FileDialog;
|
use rfd::FileDialog;
|
||||||
|
|
||||||
|
|
@ -89,20 +81,24 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
Key::Character("r") => {
|
Key::Character("r") => {
|
||||||
let Some(image) = self.image.as_ref() else {
|
match self.image.as_ref() {
|
||||||
eprintln!("no image to rotate");
|
None => self.error = Some("no image to rotate".into()),
|
||||||
return Task::none();
|
Some(image) => {
|
||||||
|
self.error = None;
|
||||||
|
self.image = Some(imageops::rotate90(image));
|
||||||
|
return self.allocate_image();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
self.image = Some(imageops::rotate90(image));
|
|
||||||
return self.allocate_image();
|
|
||||||
}
|
}
|
||||||
Key::Character("i") => {
|
Key::Character("i") => {
|
||||||
let Some(image) = self.image.as_mut() else {
|
match self.image.as_mut() {
|
||||||
eprintln!("no image to invert");
|
None => self.error = Some("no image to invert".into()),
|
||||||
return Task::none();
|
Some(image) => {
|
||||||
|
self.error = None;
|
||||||
|
imageops::invert(image);
|
||||||
|
return self.allocate_image();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
imageops::invert(image);
|
|
||||||
return self.allocate_image();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Key::Character("s") => {
|
Key::Character("s") => {
|
||||||
|
|
@ -149,12 +145,14 @@ impl State {
|
||||||
path.display()
|
path.display()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Err(e) => return Some(format!("faled to decode '{}' {e}", path.display())),
|
Err(e) => {
|
||||||
|
return Some(format!("failed to decode jxl '{}': {e}", path.display()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
let reader = match ImageReader::open(&path) {
|
let reader = match ImageReader::open(path) {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return Some(format!(
|
return Some(format!(
|
||||||
|
|
@ -274,7 +272,7 @@ impl State {
|
||||||
widget::image::allocate(widget::image::Handle::from_rgba(
|
widget::image::allocate(widget::image::Handle::from_rgba(
|
||||||
image.width(),
|
image.width(),
|
||||||
image.height(),
|
image.height(),
|
||||||
unsafe { std::mem::transmute::<_, &'static [u8]>(image.as_bytes()) },
|
unsafe { std::mem::transmute::<&[u8], &'static [u8]>(image.as_bytes()) },
|
||||||
))
|
))
|
||||||
.map(Message::ImageDisplayReady)
|
.map(Message::ImageDisplayReady)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue