bevy
bevy copied to clipboard
Expose `Image` conversion functions (fixes #5452)
Solution
Exposes the image <-> "texture" as methods on Image
.
Extra
I'm wondering if image_texture_conversion.rs
should be renamed to image_conversion.rs
. That or the file be deleted altogether in favour of putting the code alongside the rest of the Image
impl. Its kind-of weird to refer to the Image
as a texture.
Also Image::convert
is a public method so I didn't want to edit its signature, but it might be nice to have the function consume the image instead of just passing a reference to it because it would eliminate a clone.
Changelog
Rename
image_to_texture
toImage::from_dynamic
Renametexture_to_image
toImage::try_into_dynamic
Image::try_into_dynamic
now returns aResult
(this is to make it easier for users who didn't read that only a few conversions are supported to figure it out.)
- related: #5452
Is this still WIP? I see commented code and builds fail.
Makes sense I think. There is a few more image formats that can be supported, I've a branch of bevy that adds four more compatible image formats. I'll upload them later and let you copy the code.
The idea of exposing the DynamicImage
conversion functions is OK for me, it's already a great ergonomic win compared to the current situation, but it's not as optimal as implementing the GenericImage
trait on Image
(or a wrapper type): it would allow ability to modify a wider variety of Image
(described in #5452) Still, we can merge this change and impl GenericImage
later.
Sorry about the messiness, I'm a hobbyist and it's the first time I've ever tried submitting code to a public repo. I tried implementing GenericImage
on Image, but I got the sense I was rewriting code that has already been written. I'll go remove the commented code and run cargo fmt
.
I'll try the changes with some code that would benefit from this change and drop a review tomorrow.
@IceSentry is it good to merge now?
🤔 actually, the old function was pub(crate) so I guess it isn't a breaking change
Change makes sense to me, and is well-documented and has basic tests.
bors r+
Pull request successfully merged into main.
Build succeeded: