Skip to content

Commit

Permalink
Merge pull request #1245 from image-rs/revert-1229-get-pixel-opt
Browse files Browse the repository at this point in the history
Revert "Introduce bounds check pixel get/get_mut"
  • Loading branch information
HeroicKatora committed May 29, 2020
2 parents d39f89d + 9aa2100 commit ce53607
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 53 deletions.
16 changes: 0 additions & 16 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,14 +833,6 @@ where
*self.get_pixel(x, y)
}

fn opt_pixel(&self, x: u32, y: u32) -> Option<P> {
if let Some(idx) = self.pixel_indices(x, y) {
Some(*P::from_slice(&self.data[idx]))
} else {
None
}
}

/// Returns the pixel located at (x, y), ignoring bounds checking.
#[inline(always)]
unsafe fn unsafe_get_pixel(&self, x: u32, y: u32) -> P {
Expand All @@ -865,14 +857,6 @@ where
self.get_pixel_mut(x, y)
}

fn opt_pixel_mut(&mut self, x: u32, y: u32) -> Option<&mut P> {
if let Some(idx) = self.pixel_indices(x, y) {
Some(P::from_slice_mut(&mut self.data[idx]))
} else {
None
}
}

fn put_pixel(&mut self, x: u32, y: u32, pixel: P) {
*self.get_pixel_mut(x, y) = pixel
}
Expand Down
37 changes: 0 additions & 37 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,25 +583,6 @@ pub trait GenericImageView {
/// TODO: change this signature to &P
fn get_pixel(&self, x: u32, y: u32) -> Self::Pixel;

/// Get the pixel value at (x, y) when in bounds.
///
/// Return `Some(_)` with the pixel value if the coordinates are [`in_bounds`] and otherwise
/// returns `None`.
///
/// This method can be overridden by image implementations to be more efficient than the manual
/// bounds check. In particular, `get_pixel` will often do its own bounds check and would
/// duplicate this prior step. The optimizer may not detect all of them.
///
/// [`in_bounds`]: #method.in_bounds
// TODO: swap the default implementation to `get_pixel`.
fn opt_pixel(&self, x: u32, y: u32) -> Option<Self::Pixel> {
if self.in_bounds(x, y) {
Some(self.get_pixel(x, y))
} else {
None
}
}

/// Returns the pixel located at (x, y)
///
/// This function can be implemented in a way that ignores bounds checking.
Expand Down Expand Up @@ -648,24 +629,6 @@ pub trait GenericImage: GenericImageView {
/// Panics if `(x, y)` is out of bounds.
fn get_pixel_mut(&mut self, x: u32, y: u32) -> &mut Self::Pixel;

/// Gets a reference to the mutable pixel when location `(x, y)` is in bounds.
///
/// Return `Some(_)` with the pixel value if the coordinates are [`in_bounds`] and otherwise
/// returns `None`.
///
/// This method can be overridden by image implementations to be more efficient than the manual
/// bounds check. In particular, `get_pixel` will often do its own bounds check and would
/// duplicate this prior step. The optimizer may not detect all of them.
///
/// [`in_bounds`]: trait.GenericImageView.html#method.in_bounds
fn opt_pixel_mut(&mut self, x: u32, y: u32) -> Option<&mut Self::Pixel> {
if self.in_bounds(x, y) {
Some(self.get_pixel_mut(x, y))
} else {
None
}
}

/// Put a pixel at location (x, y)
///
/// # Panics
Expand Down

0 comments on commit ce53607

Please sign in to comment.