Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Expose Image conversion functions (fixes #5452) #5527

Closed
wants to merge 2 commits into from

Conversation

micron-mushroom
Copy link
Contributor

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 to Image::from_dynamic
Rename texture_to_image to Image::try_into_dynamic
Image::try_into_dynamic now returns a Result (this is to make it easier for users who didn't read that only a few conversions are supported to figure it out.)

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Aug 1, 2022
@nicopap
Copy link
Contributor

nicopap commented Aug 1, 2022

@nicopap nicopap self-requested a review August 1, 2022 15:27
@nicopap
Copy link
Contributor

nicopap commented Aug 1, 2022

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.

@micron-mushroom
Copy link
Contributor Author

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.

@nicopap
Copy link
Contributor

nicopap commented Aug 1, 2022

I'll try the changes with some code that would benefit from this change and drop a review tomorrow.

Copy link
Contributor

@nicopap nicopap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think once the doc link is fixed, this is good to go.

The API is still very limited due to the limited number of supported formats, but it's a step toward the right direction, and can be improved later on.

crates/bevy_render/src/texture/image_texture_conversion.rs Outdated Show resolved Hide resolved
@micron-mushroom
Copy link
Contributor Author

@IceSentry is it good to merge now?

@IceSentry IceSentry added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Aug 4, 2022
@IceSentry
Copy link
Contributor

🤔 actually, the old function was pub(crate) so I guess it isn't a breaking change

@IceSentry IceSentry removed the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Aug 4, 2022
@rparrett rparrett added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Sep 1, 2022
@alice-i-cecile
Copy link
Member

Change makes sense to me, and is well-documented and has basic tests.

bors r+

bors bot pushed a commit that referenced this pull request Sep 3, 2022
## 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` to `Image::from_dynamic`
> Rename `texture_to_image` to `Image::try_into_dynamic`
> `Image::try_into_dynamic` now returns a `Result` (this is to make it easier for users who didn't read that only a few conversions are supported to figure it out.)
@bors bors bot changed the title Expose Image conversion functions (fixes #5452) [Merged by Bors] - Expose Image conversion functions (fixes #5452) Sep 3, 2022
@bors bors bot closed this Sep 3, 2022
@ickk ickk added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Oct 27, 2022
james7132 pushed a commit to james7132/bevy that referenced this pull request Oct 28, 2022
…ne#5527)

## 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` to `Image::from_dynamic`
> Rename `texture_to_image` to `Image::try_into_dynamic`
> `Image::try_into_dynamic` now returns a `Result` (this is to make it easier for users who didn't read that only a few conversions are supported to figure it out.)
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
…ne#5527)

## 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` to `Image::from_dynamic`
> Rename `texture_to_image` to `Image::try_into_dynamic`
> `Image::try_into_dynamic` now returns a `Result` (this is to make it easier for users who didn't read that only a few conversions are supported to figure it out.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants