-
Notifications
You must be signed in to change notification settings - Fork 69
Add Buffer::pixel_rows and Buffer::pixels_iter iterators
#312
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
Conversation
| let width = self.width().get() as usize; | ||
| let pixels = self.buffer_impl.pixels_mut(); | ||
| assert_eq!(pixels.len() % width, 0, "buffer must be multiple of width"); | ||
| // NOTE: This won't panic because `width` is `NonZeroU32` | ||
| pixels.chunks_mut(width) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope that we can soon drive this from the buffer instead, taking a stride into account.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working on it ;)
README.md
Outdated
| for index in 0..(buffer.width().get() * buffer.height().get()) { | ||
| let y = index / buffer.width().get(); | ||
| let x = index % buffer.width().get(); | ||
| for (x, y, pixel) in buffer.iter_pixels() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great way to get rid of the NonZero::get() API instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really gone though, people will wanna use it in larger examples, see e.g. examples/rectangle.rs (if you want to calculate distance a given pixel is from the right or bottom edge).
8afefda to
cc2d5e7
Compare
Buffer::pixel_rows and Buffer::iter_pixels iteratorsBuffer::pixel_rows and Buffer::pixels_iter iterators
cc2d5e7 to
540b3b8
Compare
|
I renamed |
Add:
pixel_rowsis a prerequisite for #291, as using a buffer with stride will be quite cumbersome without them. It currently chunks on the width, but should chunk on the stride once we add that.pixels_iteris more of a useful shorthand, it's not as critical, but still be nice to have.I decided to return opaque
impl Iterator<...>, we can add an explicitBufferRows<'_>iterator type later if desirable.