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

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

cyrgani
Copy link
Contributor

@cyrgani cyrgani commented Jun 24, 2024

This PR is a huge rework of the Image type to fix a soundness issue and other bugs, increase performance and improve ergonomics. It also adds deprecation warnings to prepare users for future breaking changes.
Fixes #634.
Fixes #746.
Fixes #637.
Fixes #544.

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, Image::bytes_mut: returns an immutable / mutable slice of all bytes in the image
  • Image::width_mut, Image::height_mut, Image::bytes_vec_mut: unsafe methods that return a mutable reference to the respective field, allowing for unchecked manipulation (mostly exist to support migration of strange usecases)
  • Image::pixel_amount: returns the amount of pixels this image has according to its dimensions
  • Image::filled_with_color: creates an image filled with one color, previously called Image::gen_image_color
  • Image::set_image_data: updates all of the image data given a &[[u8; 4]]

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::filled_with_color / Image::gen_image_color is 2-3 times faster now
  • Image::sub_image is 2 times faster now
  • Image::empty, Image::width, Image::height are const fns now (done in make all methods const that can be const on 1.70.0 #850)
  • Image::gen_image_color is a deprecated alias of Image::filled_with_color now
  • Accessing any of the Image fields directly gives a deprecation warning and suggests using the methods instead.

Planned breaking changes for version 0.5

  • Make Image.width, Image.height and Image.bytes private
  • Change return type of Image::width and Image::height from usize to u16
  • Change argument type of x and y in Image::set_pixel and Image::get_pixel from u32 to u16

@cyrgani cyrgani marked this pull request as ready for review July 27, 2024 21:47
@cyrgani
Copy link
Contributor Author

cyrgani commented Jul 28, 2024

@not-fl3 I think this is ready for reviewing now.

@cyrgani
Copy link
Contributor Author

cyrgani commented Sep 11, 2024

Also fixes #544.

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