mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-08-01 11:28:20 +00:00
feat(core/rust): implement interpolate color and color table functions in rust
This commit is contained in:
parent
7f2a995c54
commit
29a5b0a770
@ -3,6 +3,7 @@ use crate::{
|
|||||||
error::Error,
|
error::Error,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
trezorhal::{display, qr, time},
|
trezorhal::{display, qr, time},
|
||||||
|
ui::lerp::Lerp,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::geometry::{Offset, Point, Rect};
|
use super::geometry::{Offset, Point, Rect};
|
||||||
@ -237,6 +238,16 @@ pub fn set_window(window: Rect) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_color_table(fg_color: Color, bg_color: Color) -> [Color; 16] {
|
||||||
|
let mut table: [Color; 16] = [Color::from_u16(0); 16];
|
||||||
|
|
||||||
|
for (i, item) in table.iter_mut().enumerate() {
|
||||||
|
*item = Color::lerp(bg_color, fg_color, i as f32 / 15_f32);
|
||||||
|
}
|
||||||
|
|
||||||
|
table
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
pub struct Font(i32);
|
pub struct Font(i32);
|
||||||
|
|
||||||
@ -298,6 +309,15 @@ impl Color {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Lerp for Color {
|
||||||
|
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
||||||
|
let r = u8::lerp(a.r(), b.r(), t);
|
||||||
|
let g = u8::lerp(a.g(), b.g(), t);
|
||||||
|
let b = u8::lerp(a.b(), b.b(), t);
|
||||||
|
Color::rgb(r, g, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<u16> for Color {
|
impl From<u16> for Color {
|
||||||
fn from(val: u16) -> Self {
|
fn from(val: u16) -> Self {
|
||||||
Self(val)
|
Self(val)
|
||||||
|
Loading…
Reference in New Issue
Block a user