Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JXL: initial support #1945

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

JXL: initial support #1945

wants to merge 3 commits into from

Conversation

Quackdoc
Copy link

The work done here was entirely @EugeneVert, I just cleaned it up a bit and intend to implement missing features at some point, this is a draft because it needs cleaned up and is missing a few features

  • Animation
  • CMYK (this may be handled internally by jxl-oxide in the future)

jxl-oxide also has some issues decoding large image's often running into OOM issues if the image is large enough.

currently it's usable enough for a good chunk of images out there. decided to post it both to get comments on the current state as well since I'm using it in it's current state, it may as well be in the open

I license past and future contributions under the dual MIT/Apache-2.0 license,
allowing licensees to choose either at their option.

@EugeneVert
Copy link

I license past and future contributions to image-rs under the dual MIT/Apache-2.0 license,
allowing licensees to choose either at their option.

}

fn icc_profile(&mut self) -> Option<Vec<u8>> {
self.image.embedded_icc().map(Vec::from)
Copy link

@tirr-c tirr-c Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decoded images are in rendered_icc() profile, but it seems like JxlImage lacks the method. I'll fix that in the next release of jxl-oxide.

Copy link
Contributor

@fintelia fintelia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening this PR, it is off to a good start!

I left some minor comments, but the one big thing I'd really like to see before we enable jxl by default is to implement ImageDecoder::set_limits. Supporting resource limits for decoding can be rather tricky to implement if you don't have it right from the start (as we're unfortunately finding with some of our other decoders) but we can't really do fuzzing without it.

src/lib.rs Outdated
/// | PNM | PBM, PGM, PPM, standard PAM | Yes |
/// | DDS | DXT1, DXT3, DXT5 | No |
/// | TGA | Yes | Rgb8, Rgba8, Bgr8, Bgra8, Gray8, GrayA8 |
/// | OpenEXR | Rgb32F, Rgba32F (no dwa compression) | Rgb32F, Rgba32F (no dwa compression) |
/// | farbfeld | Yes | Yes |
/// | JPEG XL | Yes | No |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, aren't JXL and JPEG XL the same thing?

Comment on lines 49 to 75
let pixfmt = renderer.pixel_format();
let metadata = &image.image_header().metadata;
let bits_per_sample = metadata.bit_depth.bits_per_sample();
let bitdepth = BitDepth::new(bits_per_sample);


let colortype = match (pixfmt, bitdepth) {
(PixelFormat::Gray, BitDepth::Eight) => ColorType::L8,
(PixelFormat::Gray, BitDepth::Sixteen) => ColorType::L16,
//
(PixelFormat::Graya, BitDepth::Eight) => ColorType::La8,
(PixelFormat::Graya, BitDepth::Sixteen) => ColorType::La16,
//
(PixelFormat::Rgb, BitDepth::Eight) => ColorType::Rgb8,
(PixelFormat::Rgb, BitDepth::Sixteen) => ColorType::Rgb16,
(PixelFormat::Rgb, BitDepth::ThirtyTwo) => ColorType::Rgb32F,
//
(PixelFormat::Rgba, BitDepth::Eight) => ColorType::Rgba8,
(PixelFormat::Rgba, BitDepth::Sixteen) => ColorType::Rgba16,
(PixelFormat::Rgba, BitDepth::ThirtyTwo) => ColorType::Rgba32F,
//
_ => {
return Err(unsupported_color(ExtendedColorType::Unknown(
bits_per_sample as u8,
)))
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this also need to check whether samples are integer or float?

Comment on lines +158 to +160
17.. => Self::ThirtyTwo,
9.. => Self::Sixteen,
_ => Self::Eight,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me nervous that it will silently fail if passed images with other numbers of bits per sample

Self::with_limits(r, Limits::default())
}
/// Creates a new decoder that decodes from the stream ```r```
pub fn with_limits(r: R, limits: Limits) -> ImageResult<JxlDecoder<R>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, implementing set_limits should be preferred over with_limits

@Quackdoc
Copy link
Author

sorry haven't had a lot of time to work on this, ill try to make an update soon if I get the time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants