File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Unreleased
22
3+ - Added ` Buffer::pixels() ` for accessing the buffer's pixel data.
34- Added ` Buffer::pixel_rows() ` for iterating over rows of the buffer data.
45- Added ` Buffer::pixels_iter() ` for iterating over each pixel with its associated ` x ` /` y ` coordinate.
56- ** Breaking:** Removed generic type parameters ` D ` and ` W ` from ` Buffer<'_> ` struct.
Original file line number Diff line number Diff line change @@ -272,8 +272,24 @@ impl Buffer<'_> {
272272 }
273273}
274274
275- /// Pixel helper accessors.
275+ /// Helper accessors for viewing the buffer's data as RGBA pixel data .
276276impl Buffer < ' _ > {
277+ /// Access the buffer's pixels.
278+ ///
279+ /// The size of the returned slice is `buffer.width() * buffer.height()`.
280+ ///
281+ /// # Examples
282+ ///
283+ /// Clear the buffer with red.
284+ ///
285+ /// ```no_run
286+ /// # let buffer: softbuffer::Buffer<'_> = unimplemented!();
287+ /// buffer.pixels().fill(0x00ff0000);
288+ /// ```
289+ pub fn pixels ( & mut self ) -> & mut [ u32 ] {
290+ self . buffer_impl . pixels_mut ( )
291+ }
292+
277293 /// Iterate over each row of pixels.
278294 ///
279295 /// Each slice returned from the iterator has a length of `buffer.width()`.
@@ -327,7 +343,7 @@ impl Buffer<'_> {
327343 & mut self ,
328344 ) -> impl DoubleEndedIterator < Item = & mut [ u32 ] > + ExactSizeIterator {
329345 let width = self . width ( ) . get ( ) as usize ;
330- let pixels = self . buffer_impl . pixels_mut ( ) ;
346+ let pixels = self . pixels ( ) ;
331347 assert_eq ! ( pixels. len( ) % width, 0 , "buffer must be multiple of width" ) ;
332348 // NOTE: This won't panic because `width` is `NonZeroU32`
333349 pixels. chunks_mut ( width)
You can’t perform that action at this time.
0 commit comments