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
40
src/main.rs
40
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::{
|
||||
Alignment, Color, Element, Length, Renderer, Subscription, Task, Theme, color, event,
|
||||
keyboard::{self, Key, key},
|
||||
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 rfd::FileDialog;
|
||||
|
||||
|
|
@ -81,25 +89,21 @@ impl State {
|
|||
}
|
||||
|
||||
Key::Character("r") => {
|
||||
match self.image.as_ref() {
|
||||
None => self.error = Some("no image to rotate".into()),
|
||||
Some(image) => {
|
||||
self.error = None;
|
||||
let Some(image) = self.image.as_ref() else {
|
||||
eprintln!("no image to rotate");
|
||||
return Task::none();
|
||||
};
|
||||
self.image = Some(imageops::rotate90(image));
|
||||
return self.allocate_image();
|
||||
}
|
||||
};
|
||||
}
|
||||
Key::Character("i") => {
|
||||
match self.image.as_mut() {
|
||||
None => self.error = Some("no image to invert".into()),
|
||||
Some(image) => {
|
||||
self.error = None;
|
||||
let Some(image) = self.image.as_mut() else {
|
||||
eprintln!("no image to invert");
|
||||
return Task::none();
|
||||
};
|
||||
imageops::invert(image);
|
||||
return self.allocate_image();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Key::Character("s") => {
|
||||
self.error = self.save_image();
|
||||
|
|
@ -145,14 +149,12 @@ impl State {
|
|||
path.display()
|
||||
));
|
||||
}
|
||||
Err(e) => {
|
||||
return Some(format!("failed to decode jxl '{}': {e}", path.display()));
|
||||
}
|
||||
Err(e) => return Some(format!("faled to decode '{}' {e}", path.display())),
|
||||
}
|
||||
}
|
||||
|
||||
_ => {
|
||||
let reader = match ImageReader::open(path) {
|
||||
let reader = match ImageReader::open(&path) {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
return Some(format!(
|
||||
|
|
@ -272,7 +274,7 @@ impl State {
|
|||
widget::image::allocate(widget::image::Handle::from_rgba(
|
||||
image.width(),
|
||||
image.height(),
|
||||
unsafe { std::mem::transmute::<&[u8], &'static [u8]>(image.as_bytes()) },
|
||||
unsafe { std::mem::transmute::<_, &'static [u8]>(image.as_bytes()) },
|
||||
))
|
||||
.map(Message::ImageDisplayReady)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue