Store `x` and `y` in `Region` as u16
diff --git a/sparse_strips/vello_cpu/src/fine/mod.rs b/sparse_strips/vello_cpu/src/fine/mod.rs index 25294bc..05f6bf8 100644 --- a/sparse_strips/vello_cpu/src/fine/mod.rs +++ b/sparse_strips/vello_cpu/src/fine/mod.rs
@@ -91,13 +91,13 @@ pub fn pack(&mut self, region: &mut Region<'_>) { let blend_buf = self.blend_buf.last().unwrap(); - for y in 0..Tile::HEIGHT as usize { + for y in 0..Tile::HEIGHT { for (x, pixel) in region .row_mut(y) .chunks_exact_mut(COLOR_COMPONENTS) .enumerate() { - let idx = COLOR_COMPONENTS * (Tile::HEIGHT as usize * x + y); + let idx = COLOR_COMPONENTS * (usize::from(Tile::HEIGHT) * x + usize::from(y)); pixel.copy_from_slice(&F::to_rgba8(&blend_buf[idx..][..COLOR_COMPONENTS])); } }
diff --git a/sparse_strips/vello_cpu/src/region.rs b/sparse_strips/vello_cpu/src/region.rs index 9772ec3..6dd6cab 100644 --- a/sparse_strips/vello_cpu/src/region.rs +++ b/sparse_strips/vello_cpu/src/region.rs
@@ -51,7 +51,11 @@ next_lines[h] = tail; } - regions.push(Region::new(areas, x, y)); + regions.push(Region::new( + areas, + u16::try_from(x).unwrap(), + u16::try_from(y).unwrap(), + )); } } @@ -73,25 +77,25 @@ } /// A rectangular region containing the pixels from one wide tile. -/// +/// /// For wide tiles at the right/bottom edge, it might contain less pixels /// than the actual wide tile, if the pixmap width/height isn't a multiple of the /// tile width/height. #[derive(Default, Debug)] pub struct Region<'a> { /// The x coordinate of the wide tile this region covers. - pub(crate) x: usize, + pub(crate) x: u16, /// The y coordinate of the wide tile this region covers. - pub(crate) y: usize, + pub(crate) y: u16, areas: [&'a mut [u8]; Tile::HEIGHT as usize], } impl<'a> Region<'a> { - pub(crate) fn new(areas: [&'a mut [u8]; Tile::HEIGHT as usize], x: usize, y: usize) -> Self { + pub(crate) fn new(areas: [&'a mut [u8]; Tile::HEIGHT as usize], x: u16, y: u16) -> Self { Self { areas, x, y } } - pub(crate) fn row_mut(&mut self, y: usize) -> &mut [u8] { - self.areas[y] + pub(crate) fn row_mut(&mut self, y: u16) -> &mut [u8] { + self.areas[usize::from(y)] } }
diff --git a/sparse_strips/vello_cpu/src/render.rs b/sparse_strips/vello_cpu/src/render.rs index 812470e..943053c 100644 --- a/sparse_strips/vello_cpu/src/render.rs +++ b/sparse_strips/vello_cpu/src/render.rs
@@ -340,8 +340,8 @@ .get_or(|| core::cell::RefCell::new(Fine::new())) .borrow_mut(); - let wtile = self.wide.get(x as u16, y as u16); - fine.set_coords(x as u16, y as u16); + let wtile = self.wide.get(x, y); + fine.set_coords(x, y); fine.clear(F::extract_color(&wtile.bg)); for cmd in &wtile.cmds {