From 9aa21001189c4658d8ae3c3fa2b182acedcf3175 Mon Sep 17 00:00:00 2001 From: HeroicKatora Date: Fri, 29 May 2020 19:55:19 +0000 Subject: [PATCH] Revert "Introduce bounds check pixel get/get_mut" --- src/buffer.rs | 16 ---------------- src/image.rs | 37 ------------------------------------- 2 files changed, 53 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 22a21a5814..0bcb2ff00a 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -833,14 +833,6 @@ where *self.get_pixel(x, y) } - fn opt_pixel(&self, x: u32, y: u32) -> Option

{ - 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 { @@ -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 } diff --git a/src/image.rs b/src/image.rs index 957f2fedd2..045f6a8328 100644 --- a/src/image.rs +++ b/src/image.rs @@ -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 { - 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. @@ -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