-
-
Notifications
You must be signed in to change notification settings - Fork 12
Fix incorrect RLE4 padding checking #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
68c9a56
fix: incorrect padding behaviour
Ddystopia ee87e09
chore: CHANGELOG.md entry
Ddystopia 69cc777
chore: add test
Ddystopia db425f0
chore: reformat changelog entry a bit
Ddystopia acb6cec
Update CHANGELOG.md
Ddystopia 59e5198
chore: improve readability of `has_padding` calculation for 4bit rle
Ddystopia e743cac
chore: tidy up tests
Ddystopia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
Binary file not shown.
Binary file not shown.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| use embedded_graphics::{ | ||
|
Ddystopia marked this conversation as resolved.
Outdated
|
||
| image::{Image, ImageRaw}, | ||
| iterator::raw::RawDataSlice, | ||
| pixelcolor::{raw::LittleEndian, Bgr888, Rgb555, Rgb565, Rgb888}, | ||
| prelude::*, | ||
| }; | ||
| use tinybmp::Bmp; | ||
|
|
||
| const WIDTH: usize = 20; | ||
| const HEIGHT: usize = 20; | ||
|
|
||
| // TODO: use e-g framebuffer when it's added | ||
| #[derive(Debug, PartialEq)] | ||
| struct Framebuffer<C> { | ||
| pixels: [[C; WIDTH]; HEIGHT], | ||
| } | ||
|
|
||
| impl<C: PixelColor + From<Rgb888> + std::fmt::Debug> Framebuffer<C> { | ||
| pub fn new() -> Self { | ||
| let color = C::from(Rgb888::BLACK); | ||
|
|
||
| Self { | ||
| pixels: [[color; WIDTH]; HEIGHT], | ||
| } | ||
| } | ||
|
|
||
| pub fn from_image(image: impl ImageDrawable<Color = C>) -> Self { | ||
| let mut framebuffer = Framebuffer::<C>::new(); | ||
| Image::new(&image, Point::zero()) | ||
| .draw(&mut framebuffer) | ||
| .unwrap(); | ||
| framebuffer | ||
| } | ||
|
|
||
| pub fn pixels(&self) -> impl Iterator<Item = C> + '_ { | ||
| self.pixels.iter().flatten().copied() | ||
| } | ||
|
|
||
| pub fn assert_eq(&self, expected: &Self) { | ||
| let zipped = || self.pixels().zip(expected.pixels()); | ||
|
|
||
| let errors = zipped().filter(|(a, b)| a != b).count(); | ||
| let first_error = zipped() | ||
| .enumerate() | ||
| .find(|(_, (a, b))| a != b) | ||
| .map(|(i, (a, b))| (Point::new((i % WIDTH) as i32, (i / WIDTH) as i32), a, b)); | ||
|
|
||
| //let first_error = self.pixels() | ||
|
|
||
| if self != expected { | ||
| let first_error = first_error.unwrap(); | ||
| panic!( | ||
| "framebuffer differs from expected\n{} errors\nfirst error at ({}): {:?} (expected {:?})", | ||
| errors, | ||
| first_error.0, | ||
| first_error.1, | ||
| first_error.2, | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<C: PixelColor> DrawTarget for Framebuffer<C> { | ||
| type Color = C; | ||
| type Error = std::convert::Infallible; | ||
|
|
||
| fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error> | ||
| where | ||
| I: IntoIterator<Item = embedded_graphics::Pixel<Self::Color>>, | ||
| { | ||
| for Pixel(p, c) in pixels { | ||
| self.pixels[p.y as usize][p.x as usize] = c; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl<C> OriginDimensions for Framebuffer<C> { | ||
| fn size(&self) -> embedded_graphics::prelude::Size { | ||
| Size::new(WIDTH as u32, HEIGHT as u32) | ||
| } | ||
| } | ||
|
|
||
| fn draw_raw<C>(data: &[u8]) -> Framebuffer<C> | ||
| where | ||
| C: PixelColor + From<C::Raw> + From<Rgb888> + std::fmt::Debug, | ||
| for<'a> RawDataSlice<'a, C::Raw, LittleEndian>: IntoIterator<Item = C::Raw>, | ||
| { | ||
| let raw = ImageRaw::<C, LittleEndian>::new(data, WIDTH as u32); | ||
|
|
||
| Framebuffer::from_image(raw) | ||
| } | ||
|
|
||
| fn draw_bmp<C>(data: &[u8]) -> Framebuffer<C> | ||
| where | ||
| C: PixelColor + From<Rgb555> + From<Rgb565> + From<Rgb888> + std::fmt::Debug, | ||
| { | ||
| let bmp = Bmp::<C>::from_slice(data).unwrap(); | ||
|
|
||
| Framebuffer::from_image(bmp) | ||
| } | ||
|
|
||
| #[test] | ||
| fn ethernet_port() { | ||
| let raw = draw_raw::<Bgr888>(include_bytes!("ethernet_port.raw")); | ||
| let bmp = draw_bmp::<Bgr888>(include_bytes!("ethernet_port.bmp")); | ||
|
|
||
| bmp.assert_eq(&raw); | ||
| } | ||
|
Ddystopia marked this conversation as resolved.
Outdated
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.