Skip to content

Instantly share code, notes, and snippets.

@sajattack
Created June 14, 2020 18:45
Show Gist options
  • Select an option

  • Save sajattack/4ba717ab157e8d96d399672bfbf576b9 to your computer and use it in GitHub Desktop.

Select an option

Save sajattack/4ba717ab157e8d96d399672bfbf576b9 to your computer and use it in GitHub Desktop.
fn draw_iter<T>(&mut self, pixels: T) -> Result<(), Self::Error>
where T: IntoIterator<Item = Pixel<Rgb888>> {
let mut ptr = self.vram_base as *mut u32;
let mut iter = pixels.into_iter();
let Pixel(coord, _color) = iter.next().unwrap();
unsafe {
if let Ok((x @ 0..=SCREEN_WIDTH, y @ 0..=SCREEN_HEIGHT)) = coord.try_into() {
ptr = (self.vram_base as *mut u32)
.offset(x as isize)
.offset((y * BUF_WIDTH) as isize);
}
for pixel in iter {
let Pixel(_coord, color) = pixel;
*ptr = (color.r() as u32)
| ((color.g() as u32) << 8)
| ((color.b() as u32) << 16);
ptr = ptr.add(1);
}
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment