Compare commits
No commits in common. "main" and "jxl-support" have entirely different histories.
main
...
jxl-suppor
1 changed files with 23 additions and 21 deletions
44
src/main.rs
44
src/main.rs
|
|
@ -1,11 +1,19 @@
|
||||||
use std::{env, ffi::OsStr, fs, io::Write, path::Path};
|
use std::{
|
||||||
|
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::{DynamicImage, EncodableLayout, ImageDecoder, ImageReader, RgbaImage, imageops};
|
use image::{
|
||||||
|
DynamicImage, EncodableLayout, ImageDecoder, ImageReader, RgbImage, RgbaImage, imageops,
|
||||||
|
};
|
||||||
use jpegxl_rs::image::ToDynamic;
|
use jpegxl_rs::image::ToDynamic;
|
||||||
use rfd::FileDialog;
|
use rfd::FileDialog;
|
||||||
|
|
||||||
|
|
@ -81,24 +89,20 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
Key::Character("r") => {
|
Key::Character("r") => {
|
||||||
match self.image.as_ref() {
|
let Some(image) = self.image.as_ref() else {
|
||||||
None => self.error = Some("no image to rotate".into()),
|
eprintln!("no image to rotate");
|
||||||
Some(image) => {
|
return Task::none();
|
||||||
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") => {
|
||||||
match self.image.as_mut() {
|
let Some(image) = self.image.as_mut() else {
|
||||||
None => self.error = Some("no image to invert".into()),
|
eprintln!("no image to invert");
|
||||||
Some(image) => {
|
return Task::none();
|
||||||
self.error = None;
|
|
||||||
imageops::invert(image);
|
|
||||||
return self.allocate_image();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
imageops::invert(image);
|
||||||
|
return self.allocate_image();
|
||||||
}
|
}
|
||||||
|
|
||||||
Key::Character("s") => {
|
Key::Character("s") => {
|
||||||
|
|
@ -145,14 +149,12 @@ impl State {
|
||||||
path.display()
|
path.display()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => return Some(format!("faled to decode '{}' {e}", path.display())),
|
||||||
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!(
|
||||||
|
|
@ -272,7 +274,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::<&[u8], &'static [u8]>(image.as_bytes()) },
|
unsafe { std::mem::transmute::<_, &'static [u8]>(image.as_bytes()) },
|
||||||
))
|
))
|
||||||
.map(Message::ImageDisplayReady)
|
.map(Message::ImageDisplayReady)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue