Add at() method to Image
This commit is contained in:
1 parent
c5f64b757f
commit
937b20bb87
1 file changed
+5
-3
+5
-3
@@ -95,6 +95,10 @@ impl<P: Pixel> Image<P> {
|
|||||||
Self { extent, pixels }
|
Self { extent, pixels }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn at(&self, x: usize, y: usize) -> P {
|
||||||
|
self.pixels[y * self.extent.x + x]
|
||||||
|
}
|
||||||
|
|
||||||
pub fn for_each<F>(&mut self, f: F)
|
pub fn for_each<F>(&mut self, f: F)
|
||||||
where
|
where
|
||||||
F: Fn(usize, usize, &mut P) + Send + Sync,
|
F: Fn(usize, usize, &mut P) + Send + Sync,
|
||||||
@@ -117,9 +121,7 @@ impl<P: Pixel> Image<P> {
|
|||||||
Q: Pixel,
|
Q: Pixel,
|
||||||
{
|
{
|
||||||
let mut img = Image::with_extent(self.extent);
|
let mut img = Image::with_extent(self.extent);
|
||||||
img.for_each(|x, y, p| {
|
img.for_each(|x, y, p| *p = f(self.at(x, y)));
|
||||||
*p = f(self.pixels[self.extent.x * y + x]);
|
|
||||||
});
|
|
||||||
img
|
img
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user