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
Add screenshot api #7163
Add screenshot api #7163
Changes from 23 commits
7311b14
539370c
ed06f12
a3208de
6707d19
6487690
bfcd473
6ba0228
90f5fed
baabde3
1941274
de6eb41
86798ad
ed31728
edb1e57
cfdb2c8
1267d52
6e0c39b
ef26a66
b49ff4b
d2d72cb
cf5fd04
1da0a8a
23bad7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,6 +174,7 @@ impl Image { | |
/// - `TextureFormat::R8Unorm` | ||
/// - `TextureFormat::Rg8Unorm` | ||
/// - `TextureFormat::Rgba8UnormSrgb` | ||
/// - `TextureFormat::Bgra8UnormSrgb` | ||
/// | ||
/// To convert [`Image`] to a different format see: [`Image::convert`]. | ||
pub fn try_into_dynamic(self) -> anyhow::Result<DynamicImage> { | ||
|
@@ -196,6 +197,20 @@ impl Image { | |
self.data, | ||
) | ||
.map(DynamicImage::ImageRgba8), | ||
// This format is commonly used as the format for the swapchain texture | ||
// This conversion is added here to support screenshots | ||
TextureFormat::Bgra8UnormSrgb => ImageBuffer::from_raw( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we introduce the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seconding the confusion about why this is part of this PR. I don't mind it, just a bit confused. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wgpu apparently quite likes this format for swapchain textures - this was necessary to get the save to disk functionality working on my machine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. Can you please leave a comment here to that effect then? |
||
self.texture_descriptor.size.width, | ||
self.texture_descriptor.size.height, | ||
{ | ||
let mut data = self.data; | ||
for bgra in data.chunks_exact_mut(4) { | ||
bgra.swap(0, 2); | ||
} | ||
data | ||
}, | ||
) | ||
.map(DynamicImage::ImageRgba8), | ||
// Throw and error if conversion isn't supported | ||
texture_format => { | ||
return Err(anyhow!( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why you didn't just import the screenshot module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, other than not wanting to pollute the namespace i guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, I don't mind either way. I'd prefer having the
screenshot
module in scope just to not havecrate::view
, but really it's up to you, really not a big deal.