bevy icon indicating copy to clipboard operation
bevy copied to clipboard

guess image formats

Open robtfm opened this issue 1 year ago • 7 comments

Objective

provide an option to use image::guess_format to determine the image format, and make it the default.

useful when loading images of unknown format (eg from urls without extension/mimetype), and more robust when loading mislabelled files.

robtfm avatar Feb 20 '24 13:02 robtfm

4. On some level I'd like to check and warn if the extension does not match the inferred type. However I'm not sure if this is the right spot for it: it will slow down loading in the happy path.

we could do that here, i don't think the perf impact would be noticeable (when compared to loading the binary data, converting internally, pushing it to gpu, etc) .

if so i'd like to add another extension (say .image) which would never trigger the warning. i'm downloading files with no extension where all i know is that they are images, so i have to hack some recognised extension onto the "path" (which is acually a urn plus base url encoded into a path) to get the loader to pick up the asset, and the warning would be noisy and useless for me in that case.

robtfm avatar Feb 21 '24 10:02 robtfm

@robtfm that makes sense! Let's add that check and this special extension type here.

alice-i-cecile avatar Feb 21 '24 15:02 alice-i-cecile

so i have to hack some recognised extension onto the "path"

That is still necessary after #10153?

rparrett avatar Feb 21 '24 17:02 rparrett

That is still necessary after #10153?

Nice, I hadn’t seen that - I’ll check there’s no issues with using extensionless and then remove the “.image” extension

robtfm avatar Feb 21 '24 17:02 robtfm

Since there are multiple asset loaders registered which can handle an extensionless path for an Image. But that's beyond the scope for this PR.

right ... the built-in ones could probably be unified, but users might want to register other image loaders. i guess we may want a "default" loader for a given asset type (or possibly to try all the loaders?), but for now i'll leave the magic extension.

edit: probably asset_server.load_with::<ImageLoader>("bevy_bird") would be easiest.

robtfm avatar Feb 22 '24 00:02 robtfm

@robtfm once merge conflicts are resolved I'll merge this in for you.

alice-i-cecile avatar Jun 25 '24 22:06 alice-i-cecile

@robtfm I'll merge this ASAP once merge conflicts are fixed.

alice-i-cecile avatar Jul 01 '24 13:07 alice-i-cecile

Completed in #13575

alice-i-cecile avatar Aug 12 '24 13:08 alice-i-cecile