Lossless WebP? #88
-
Hi! Thanks for your absolutely amazing library. I am investigating whether this is feasible to use in a radiology viewer application, so my investigation is restricted to using lossless formats. For my investigation, I am creating benchmarks that try out the various image formats and analyze:
I also have some unit tests that go through a single encode + decode and verify the pixel data is the same, which hopefully confirms that the encoding and decoding process is lossless. You can follow my progress here: https://github.com/amoerie/lossless-codec-benchmarks For now, it looks like WebP and AVIF are not lossless yet, so I am presuming I'm configuring them wrong. This is my question: is it already possible to pass in WebP and AVIF encoder options so it can be set to lossless? I found a folder "Webp" under "NativeCodecs" but this only seems to implement a decoder, and is nowhere on NuGet yet. Furthermore, if you have advice on the best parameters to use per file format for my benchmarks, I would be very eager to hear them. Thanks and have a nice day! P.S. Feel free to (re)use the benchmarks and tests in any way if they can be of any use to you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Howdy! I can fill in a few gaps for you. First thing to know is that not all mime types known to MagicScaler have codec support presently. AVIF is not supported at all yet, and although it does have a spec for lossless encoding, it's not good -- as in it's less efficient than PNG which is much much older. If we add AVIF, it will probably be lossy only. HEIF is supported only for decode, mostly because Apple is the only major user of that format, and we're only concerned with being able to process HEIC images from Apple devices and get them converted to something more widely used. WebP support is in progress. As you've seen, the decoder is done but not yet published to NuGet. I'll put out a public package when the encoder is working too, and it will support lossless mode. That's tracking under #19 I'm curious about your use case, though. Radiology images are typically 16-bit greyscale, and you'd need to preserve the full bit depth. MagicScaler currently only supports 8-bit output, so even the lossless formats will reduce the bit depth during transcode. The primary use for MagicScaler so far is processing for web output, where 16-bit doesn't make much sense. There is a longer-term plan to allow higher bit-depths through the pipeline -- as HDR becomes more commonly supported, we'll need at least 10- or 12-bit output even for web. I'd like to consider supporting medical imaging use cases as well but haven't put a lot of thought into it. If you can share a bit more about your workflow, that would be helpful for planning purposes. |
Beta Was this translation helpful? Give feedback.
Howdy! I can fill in a few gaps for you.
First thing to know is that not all mime types known to MagicScaler have codec support presently.
TrySetEncoderFormat
returns a bool to tell you whether an encoder for the requested format was found, so you would need to check that result.AVIF is not supported at all yet, and although it does have a spec for lossless encoding, it's not good -- as in it's less efficient than PNG which is much much older. If we add AVIF, it will probably be lossy only.
HEIF is supported only for decode, mostly because Apple is the only major user of that format, and we're only concerned with being able to process HEIC images from Apple devices and get them converted…