Created
June 14, 2020 18:45
-
-
Save sajattack/4ba717ab157e8d96d399672bfbf576b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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