Add at() method to Image

This commit is contained in:
cdo committed 2026-10-26 15:04:59 +00:00
1 parent c5f64b757f
commit 937b20bb87
1 file changed
+5 -3
+5 -3
View File
@@ -95,6 +95,10 @@ impl<P: Pixel> Image<P> {
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)
where
F: Fn(usize, usize, &mut P) + Send + Sync,
@@ -117,9 +121,7 @@ impl<P: Pixel> Image<P> {
Q: Pixel,
{
let mut img = Image::with_extent(self.extent);
img.for_each(|x, y, p| {
*p = f(self.pixels[self.extent.x * y + x]);
});
img.for_each(|x, y, p| *p = f(self.at(x, y)));
img
}