Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/images/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,15 +574,16 @@ where
/// This is guaranteed to contain exactly `width * height * channels` subpixels.
#[doc(alias = "channels")]
pub fn subpixels(&self) -> &[P::Subpixel] {
let len = Self::image_buffer_len(self.width, self.height).unwrap();
// All constructors check that w*h*c <= data.len(), so this can't overflow
let len = self.width as usize * self.height as usize * <P as Pixel>::CHANNEL_COUNT as usize;
&self.data[..len]
}

/// Returns a slice for the pixels of this image.
///
/// The index order is x = 0 to width then y = 0 to height.
///
/// This is guaranteed to contain exactly `width * height` subpixels.
/// This is guaranteed to contain exactly `width * height` pixels.
pub fn pixels(&self) -> &[P] {
let subpixels = self.subpixels();
<P as Pixel>::pixels_from_channels(subpixels)
Expand Down Expand Up @@ -742,7 +743,8 @@ where
///
/// This is guaranteed to contain exactly `width * height * channels` subpixels.
pub fn subpixels_mut(&mut self) -> &mut [P::Subpixel] {
let len = Self::image_buffer_len(self.width, self.height).unwrap();
// All constructors check that w*h*c <= data.len(), so this can't overflow
let len = self.width as usize * self.height as usize * <P as Pixel>::CHANNEL_COUNT as usize;
&mut self.data[..len]
}

Expand Down
Loading