Skip to content

Commit 777d47a

Browse files
committed
Port to embedded-graphics 0.9
1 parent 906afc7 commit 777d47a

3 files changed

Lines changed: 27 additions & 18 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ paste = "1.0"
2828
criterion = "0.3.5"
2929
clap = { version = "3.2.22", features = ["derive"] }
3030
embedded-graphics-simulator = { version = "0.5.0", default-features = false }
31+
32+
[patch.crates-io]
33+
embedded-graphics = { git = "https://github.com/embedded-graphics/embedded-graphics.git" }
34+
embedded-graphics-simulator = { git = "https://github.com/embedded-graphics/simulator.git" }

src/color_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{parse_error::ParseError, Bpp, TgaHeader};
22
use embedded_graphics::{
3-
iterator::raw::RawDataSlice, pixelcolor::raw::LittleEndian, prelude::PixelColor,
3+
iterator::raw::RawDataSlice, pixelcolor::raw::LittleEndianMsb0, prelude::PixelColor,
44
};
55
use nom::bytes::complete::take;
66

@@ -79,7 +79,7 @@ impl<'a> ColorMap<'a> {
7979
pub(crate) fn get<C>(&self, index: usize) -> Option<C>
8080
where
8181
C: PixelColor + From<C::Raw>,
82-
RawDataSlice<'a, C::Raw, LittleEndian>: IntoIterator<Item = C::Raw>,
82+
RawDataSlice<'a, C::Raw, LittleEndianMsb0>: IntoIterator<Item = C::Raw>,
8383
{
8484
RawDataSlice::new(self.data)
8585
.into_iter()

tests/logo.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use embedded_graphics::{
55
};
66
use tinytga::{Bpp, Compression, DataType, ImageOrigin, Tga};
77

8-
const WIDTH: usize = 240;
9-
const HEIGHT: usize = 320;
8+
const IMAGE_SIZE: Size = Size::new(240, 320);
109

1110
// TODO: use e-g framebuffer when it's added
1211
#[derive(Debug, PartialEq)]
@@ -19,7 +18,7 @@ impl<C: PixelColor + From<Rgb888> + std::fmt::Debug> Framebuffer<C> {
1918
let color = C::from(Rgb888::BLACK);
2019

2120
Self {
22-
pixels: [[color; WIDTH]; HEIGHT],
21+
pixels: [[color; IMAGE_SIZE.width as usize]; IMAGE_SIZE.height as usize],
2322
}
2423
}
2524

@@ -42,7 +41,16 @@ impl<C: PixelColor + From<Rgb888> + std::fmt::Debug> Framebuffer<C> {
4241
let first_error = zipped()
4342
.enumerate()
4443
.find(|(_, (a, b))| a != b)
45-
.map(|(i, (a, b))| (Point::new((i % WIDTH) as i32, (i / WIDTH) as i32), a, b));
44+
.map(|(i, (a, b))| {
45+
(
46+
Point::new(
47+
(i % IMAGE_SIZE.width as usize) as i32,
48+
(i / IMAGE_SIZE.width as usize) as i32,
49+
),
50+
a,
51+
b,
52+
)
53+
});
4654

4755
if self != expected {
4856
let first_error = first_error.unwrap();
@@ -80,24 +88,21 @@ impl<C> OriginDimensions for Framebuffer<C> {
8088
}
8189

8290
fn expected_rgb555() -> Framebuffer<Rgb555> {
83-
Framebuffer::from_image(ImageRawLE::<Rgb555>::new(
84-
include_bytes!("logo_rgb555.raw"),
85-
WIDTH as u32,
86-
))
91+
Framebuffer::from_image(
92+
ImageRawLE::<Rgb555>::new(include_bytes!("logo_rgb555.raw"), IMAGE_SIZE).unwrap(),
93+
)
8794
}
8895

8996
fn expected_rgb888() -> Framebuffer<Rgb888> {
90-
Framebuffer::from_image(ImageRawBE::<Rgb888>::new(
91-
include_bytes!("logo_rgb888.raw"),
92-
WIDTH as u32,
93-
))
97+
Framebuffer::from_image(
98+
ImageRawBE::<Rgb888>::new(include_bytes!("logo_rgb888.raw"), IMAGE_SIZE).unwrap(),
99+
)
94100
}
95101

96102
fn expected_gray8() -> Framebuffer<Gray8> {
97-
Framebuffer::from_image(ImageRawBE::<Gray8>::new(
98-
include_bytes!("logo_gray8.raw"),
99-
WIDTH as u32,
100-
))
103+
Framebuffer::from_image(
104+
ImageRawBE::<Gray8>::new(include_bytes!("logo_gray8.raw"), IMAGE_SIZE).unwrap(),
105+
)
101106
}
102107

103108
#[track_caller]

0 commit comments

Comments
 (0)