8000 feat: create blank canvas by ZimboPro · Pull Request #1189 · ggez/ggez · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: create blank canvas #1189

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
merged 3 commits into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading 8000
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/graphics/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@ impl Image {
)
}

/// A little helper function that creates a blank [`Image`] that is of the given width and height and optional color.
///
/// The default color is [`Color::WHITE`].
/// Mainly useful for debugging.
pub fn new_blank_canvas_image(
gfx: &impl Has<GraphicsContext>,
width: u32,
height: u32,
color: Option<Color>,
) -> Self {
let pixels = (0..(width * height))
.flat_map(|_| {
let (r, g, b, a) = color.unwrap_or(Color::WHITE).to_rgba();
[r, g, b, a]
})
.collect::<Vec<_>>();
Self::from_pixels(
gfx,
&pixels,
wgpu::TextureFormat::Rgba8UnormSrgb,
width,
height,
)
}

/// Creates a new image initialized with given pixel data.
pub fn from_pixels(
gfx: &impl Has<GraphicsContext>,
Expand Down
0