Image rework for soundness and usability #748
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 correctImage::bytes
: returns an immutable slice of all bytes in the imageImage::width_mut
,Image::height_mut
,Image::bytes_mut
: unsafe methods that return a mutable reference to the respective field, allowing for unchecked manipulationImage::pixel_amount
: returns the amount of pixels this image has according to its dimensionsImage::from_color
: creates an image filled with one color, previously calledImage::gen_image_color
Breaking changes
Image.width
,Image.height
andImage.bytes
are private nowImage::width
andImage::height
isu16
now instead ofusize
Image::set_pixel
andImage::get_pixel
takeu16
instead ofu32
asx
andy
arguments nowBugfixes
Image::get_pixel
correctly panics nowImage::blend
andImage::overlay
panic now if the two images have the same amount of pixels, but differentwidth
andheight
Other non-breaking changes
Into
implementations forColor
are nowFrom
implementations (should giveInto
automatically)Image::from_color
/Image::gen_image_color
is 2-3 times faster nowImage::empty
,Image::width
,Image::height
areconst fn
s nowImage::gen_image_color
is a deprecated alias ofImage::from_color
nowTODO:
u16
,u32
orusize
?