Closed vuhe closed 6 months ago
Some of the decoders in zune-image use a try_new
method because they rely on external crates for decoding. For example jpeg-xl
decoder has this method https://docs.rs/zune-image/latest/zune_image/codecs/jpeg_xl/struct.JxlDecoder.html#impl-JxlDecoder%3CR%3E. These crates might not be fully compatible with zune-image's design. If you have a better way to handle this, we welcome your contributions!
Thank you for your reply.
Or simply wrapper it with rimage trait, as I need to use a decoder selected based on the image type, I need to repeat the following code:
let mut decoder = AvifDecoder::try_new(reader).unwrap();
let img = <AvifDecoder<ZByteReader<Vec<u8>>> as DecoderTrait<Vec<u8>>>::decode(&mut decoder).unwrap();
I just want decode, but this seems too complicated. If you don't plan to design it to be fully compatible with zune-image, can you provide a more concise API?
There is no new method, so I cannot use macro_rules either.
Latest pre-release of zune-image
has a from_decoder
method that simplifies this.
https://docs.rs/zune-image/0.5.0-rc0/zune_image/image/struct.Image.html#method.from_decoder
After merge of #208, support for this release will be added. So decoding will be as easy as this:
let decoder = AvifDecoder::try_new(file)?;
return Image::from_decoder(decoder);
This looks great, I will replace it after PR merge.
Update, support for latest pre-relase of zune-image
is added in version 0.11.0-next.1
Description
The decoder method should be consistent with zune, as I use the decoder to decode the&[u8] read from the compressed file, and the try_new method will cause unnecessary additional overhead.
I used translation software, please understand if my language is a bit strange.
Problem or Motivation
No response
Expected behavior
No response
Alternatives Considered
No response
Anything else?
No response