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

Image rework for soundness and usability #748

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

cyrgani
Copy link
Contributor

@cyrgani cyrgani commented Jun 24, 2024

Fixes #634 and fixes #746 by making the fields of Image private, adding the safe constructor from #637 (EDIT: Image::gen_image_color already does that) and adding unsafe functions to modify the fields.

This is still work in progress and a breaking change.

New methods

  • Image::from_raw_parts: method for creating an image from width, height and bytes while checking if the amount of bytes is correct
  • Image::bytes: returns an immutable slice of all bytes in the image
  • Image::width_mut, Image::height_mut, Image::bytes_mut: unsafe methods that return a mutable reference to the respective field, allowing for unchecked manipulation
  • Image::pixel_amount: returns the amount of pixels this image has according to its dimensions
  • Image::from_color: creates an image filled with one color, previously called Image::gen_image_color

Breaking changes

  • Image.width, Image.height and Image.bytes are private now
  • Return type of Image::width and Image::height is u16 now instead of usize
  • Image::set_pixel and Image::get_pixel take u16 instead of u32 as x and y arguments now

Bugfixes

  • Reading an out-of-bounds pixel with Image::get_pixel correctly panics now
  • Image::blend and Image::overlay panic now if the two images have the same amount of pixels, but different width and height

Other non-breaking changes

  • Some Into implementations for Color are now From implementations (should give Into automatically)
  • Image::from_color / Image::gen_image_color is 2-3 times faster now
  • Image::empty, Image::width, Image::height are const fns now
  • Image::gen_image_color is a deprecated alias of Image::from_color now

TODO:

  • Should the width and height be u16, u32 or usize?
  • How large is the impact of this breakage?
  • Should this be split into breaking and non-breaking changes, to merge the non-breaking changes now and the breaking changes in 0.5?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Image fields should be private for soundness Make Image Safe
1 participant