Replace tga with bmp for code size reduction
Saved almost 100K just because the TGA parsing code was getting duplicated for each draw target. Compression may still be helpful later but it needs to reuse/share the decompression code and not duplicate it extra times.
This commit is contained in:
parent
4d4d39c7a1
commit
3e1245260d
7 changed files with 38 additions and 29 deletions
25
Cargo.lock
generated
25
Cargo.lock
generated
|
|
@ -768,7 +768,7 @@ dependencies = [
|
|||
"mipidsi",
|
||||
"rgb",
|
||||
"smart-leds",
|
||||
"tinytga",
|
||||
"tinybmp",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -810,12 +810,6 @@ version = "2.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3c8dda44ff03a2f238717214da50f65d5a53b45cd213a7370424ffdb6fae815"
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "mipidsi"
|
||||
version = "0.9.0"
|
||||
|
|
@ -849,16 +843,6 @@ version = "1.0.6"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
|
|
@ -1280,13 +1264,12 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinytga"
|
||||
version = "0.5.0"
|
||||
name = "tinybmp"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "477839bd612acb4d0551915eaf6eef8cc1b3a9dd58e18e9c2b746c78614a25d5"
|
||||
checksum = "df43af2cb7b369009aa14144959bb4f2720ab62034c9073242f2d3a186c2edb6"
|
||||
dependencies = [
|
||||
"embedded-graphics",
|
||||
"nom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
|||
|
|
@ -47,6 +47,6 @@ embedded-hal-bus = "0.3.0"
|
|||
embassy-futures = "0.1.2"
|
||||
heapless = "0.8.0"
|
||||
rgb = "0.8.52"
|
||||
tinytga = "0.5.0"
|
||||
smart-leds = "0.4.0"
|
||||
fixed = "1.29.0"
|
||||
tinybmp = "0.6.0"
|
||||
|
|
|
|||
|
|
@ -1,17 +1,16 @@
|
|||
use embassy_time::Duration;
|
||||
use embedded_graphics::{image::Image, pixelcolor::Rgb888, prelude::*, primitives::Rectangle};
|
||||
use fixed::types::U0F8;
|
||||
use embedded_graphics::{pixelcolor::Rgb888, prelude::*, primitives::Rectangle};
|
||||
use smart_leds::hsv::{Hsv, hsv2rgb};
|
||||
use tinytga::Tga;
|
||||
use tinybmp::Bmp;
|
||||
|
||||
pub struct Hal {
|
||||
image_data: Tga<'static, Rgb888>,
|
||||
image_data: Bmp<'static, Rgb888>,
|
||||
}
|
||||
|
||||
impl Hal {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
image_data: Tga::from_slice(include_bytes!("assets/hal.tga")).unwrap(),
|
||||
image_data: Bmp::from_slice(include_bytes!("assets/hal.bmp")).unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -29,13 +28,13 @@ impl Drawable for Hal {
|
|||
}
|
||||
|
||||
pub struct HappyEyes {
|
||||
image_data: Tga<'static, Rgb888>,
|
||||
image_data: Bmp<'static, Rgb888>,
|
||||
}
|
||||
|
||||
impl HappyEyes {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
image_data: Tga::from_slice(include_bytes!("assets/eye1.tga")).unwrap(),
|
||||
image_data: Bmp::from_slice(include_bytes!("assets/eye1.bmp")).unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -123,6 +122,33 @@ impl<'a, D: Dimensions> Dimensions for RainbowFilter<'a, D> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct ColorMapFilter<'a, D> {
|
||||
pub inner_target: &'a mut D,
|
||||
pub filter: fn(Rgb888) -> Rgb888,
|
||||
}
|
||||
|
||||
impl<'a, D: DrawTarget<Color = Rgb888>> DrawTarget for ColorMapFilter<'a, D> {
|
||||
type Color = D::Color;
|
||||
type Error = D::Error;
|
||||
|
||||
fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
|
||||
where
|
||||
I: IntoIterator<Item = Pixel<Self::Color>>,
|
||||
{
|
||||
self.inner_target.draw_iter(
|
||||
pixels
|
||||
.into_iter()
|
||||
.map(|Pixel(point, color)| Pixel(point, (self.filter)(color))),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, D: Dimensions> Dimensions for ColorMapFilter<'a, D> {
|
||||
fn bounding_box(&self) -> Rectangle {
|
||||
self.inner_target.bounding_box()
|
||||
}
|
||||
}
|
||||
|
||||
fn mix_u8(a: u8, b: u8) -> u8 {
|
||||
(a as u16 * b as u16 / 255) as u8
|
||||
}
|
||||
|
|
|
|||
BIN
firmware/src/assets/eye1.bmp
Normal file
BIN
firmware/src/assets/eye1.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
BIN
firmware/src/assets/hal.bmp
Normal file
BIN
firmware/src/assets/hal.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
Loading…
Add table
Reference in a new issue