refactor: try to integrate jpegxl_rs with hooks

The problem is, libjxl_rs does not offer a way to get metadata
before decoding the entire image.

As such, there is no reasonable way to implement ImageDecoder here;
I think it's possible to make it decode the image on init,
but that would lead to unexpected behavior performance-wise.
This commit is contained in:
electria 2026-07-29 15:37:51 -07:00
commit 59ef65de70
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs
2 changed files with 23 additions and 0 deletions

22
src/jxl.rs Normal file
View file

@ -0,0 +1,22 @@
pub struct JxlDecoder<'a> {
metadata: jpegxl_rs::decode::Metadata,
inner: jpegxl_rs::decode::JxlDecoder<'a, 'a>,
}
impl<'a> image::ImageDecoder for JxlDecoder<'a> {
fn color_type(&self) -> image::ColorType {
image::ColorType::Rgba8
}
fn icc_profile(&mut self) -> image::ImageResult<Option<Vec<u8>>> {
Ok(self.metadata.icc_profile.clone())
}
fn dimensions(&self) -> (u32, u32) {}
fn read_image(self, buf: &mut [u8]) -> image::ImageResult<()>
where
Self: Sized,
{
}
fn read_image_boxed(self: Box<Self>, buf: &mut [u8]) -> image::ImageResult<()> {
self.read_image(buf)
}
}

View file

@ -7,6 +7,7 @@ use iced::{
}; };
use image::{EncodableLayout, RgbaImage, imageops}; use image::{EncodableLayout, RgbaImage, imageops};
mod jxl;
mod utils; mod utils;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]