Conversation
|
We can kick the tires of this API by splitting PCX into a separate crate and using these hooks to wire it up. Also, jxl-oxide has shipped |
|
@HeroicKatora how would you feel about moving forward with this PR and then spinning out a single |
|
That sounds like a good way to dogfood the hooks. IMHO there's also value in segregating the formats with weird licenses. PCX is under WTFPL, we probably don't want to have that as a dependency in the main crate. And all the RAW crates are under LGPL, it would be nice to signpost that as well. There's precedent in GStreamer, where decoders with weird licenses are segregated as gstreamer-plugins-ugly. Although the PCX author is still around, let me ask them to relicense and see what comes of it. |
|
|
|
The biggest concern being solved with an extra crate is the licensing / static dependency tree situation. However, I can also see users expecting formats to 'just be available' when depending on crates, similar to the discover mechanism of the traditional c libraries. We can't introduce life-before-main in Rust however. This combination of requirements is not possible to resolve right now when moving to a separate crate, afaik. To automatically register the decoders from I think the hooks can address the needs for users to substitute some formats, but they do not appropriately solve our internal needs. And in this implementation, the substitution does not work in all situations as intended as the feature selection is always given priority. |
|
On the plus side, splitting out But now I think the licensing argument is not as strong as I made it out to be. AFAIU bundling a bunch of formats into -extra isn't really an improvement from the licensing standpoint, and the licensing motivation for PCX is gone regardless. |
|
Addressing the use-case of substituting the builtin decoder with a personal one is quite valid. I'd be glad to approve on the PR and registry design if the registered hooks ran with higher priority than the builtin format dispatch. The trait boxing of |
|
If all you want is to substitute the decoder a known format with a custom implementation you don't need the hook machinery at all. You can simply disable the support for this format in |
|
My top-level goal is finding a way to spend less time thinking about, reviewing, and supporting obscure formats. IMO most of the effort around obscure formats is preparing/preventing them from causing issues for the rest of the crate. Any PR that touches the crate's Cargo.toml or lib.rs might accidentally (or maliciously) break them. Test images bloat the size of the repository. If some dependency yanks their crate, we may have to fork and publish our own copy. Some codec changes like swapping the backend decoder implementation might require a semver break. Separating out less common formats into a different crate provides a much nicer boundary to be more lax about reviews and concerns like those. If a codec breaks, we can drop support in a new major version. If CI is broken, it doesn't block PRs to the main image crate. If a decoder uses unsafe code, it doesn't prevent the main crate from eventually having |
97fb13c to
7b887b6
Compare
|
I created https://github.com/image-rs/image-extras to test out the usage of this API. In my view, there isn't much point in having hooks if they're going going to be for overriding the handling of built-in formats. That's because the Thus the question: Are we OK with merging this and then going ahead with publishing *We've been saying both |
|
One of the motivating use cases is Bevy where devs want to load custom formats through the standard asset loader. https://docs.rs/bevy/latest/bevy/image/struct.ImageLoader.html |
|
Haven't had much time to work on decoding hooks, but wanted to at least update where things stand... While trying to use this API from |
|
Ok, I've switched over the hooks to operate on file extensions rather than |
|
I think it's great that hooks can be specified in terms of patterns now. But that is somehow at odds with use cases and evolvability.
I really don't see the use case addressed here. If user code is being ran, one could as well construct the decoder by-hand directly. And with that change not even the provided format detection mechanism provides much of a help. Running of your code depends on a feature flag not being unified through third-party sibling dependencies. That seems … odd? Meanwhile that other use-case is much clearer:
The standard path is something you can not currently customize; but Bevy wants to customize. In another use case we actually had they wanted to load lossless jpeg, a functionality we had to cut in Also consider what happens if an extension crate (not I think in total, hooks must override the default behavior. That's the only consistent way to address both the uses cases and the failure modes. (Of course the internal dispatch still requires a newtype like |
197g
left a comment
There was a problem hiding this comment.
LGTM. We still maintain a split between format detections internal and external but since they are explicit we have room to refine everything in the future (e.g. adding a hook against an ImageFormat). This covers everything for image-extras and the jpeg example by registering a separate jpeg detection hook, which should be good for now.
This is an attempt at implementing the format decoding hooks registry described in #2368. It works out to be less code than I was expecting.
At the moment the hooks aren't especially useful because the only image formats that hooks can be registered for already have built-in decoders, but that could be changed in followup PRs