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

Make Image Safe #634

Open
sloganking opened this issue Aug 19, 2023 · 1 comment · May be fixed by #748
Open

Make Image Safe #634

sloganking opened this issue Aug 19, 2023 · 1 comment · May be fixed by #748
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@sloganking
Copy link
Contributor

Problem

Creating an image in Macroquad is verbose and unsafe. To create an image in macroquad I have to:

let mut image = Image::empty();
image.width = screen_width() as u16;
image.height = screen_height() as u16;
image.bytes = vec![0; image.width as usize * image.height as usize * 4];
  • Create an image object
  • Set it's width
  • Set it's height
  • Manually calculate the bytes necessary for it's dimensions and allocate them.
    • Look up the pixel format / size to determine needed bytes.

If you do ANY of this wrong. You'll get segfaults or unsafe and undefined behavior.

Feature request

Why can't we have a safe image abstraction like the Image crate does? This is not only safer but also more convenient as it lets you create an image in one line.

let mut img = RgbImage::new(32, 32);

See their docs for more.

@not-fl3 not-fl3 added enhancement New feature or request good first issue Good for newcomers labels Aug 19, 2023
@cyrgani cyrgani linked a pull request Jun 24, 2024 that will close this issue
@cyrgani
Copy link
Contributor

cyrgani commented Jun 25, 2024

Actually, there already is the Image::gen_image_color function, which creates a new image with the given dimensions filled with the given color. Therefore, one can simply call Image::gen_image_color(screen_width() as u16, screen_height() as u16, BLACK), so I don't see much value in adding a new constructor just for black images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants