1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 06:48:16 +00:00

feat(core/rust): implement interpolate color and color table functions in rust

This commit is contained in:
tychovrahe 2022-06-07 12:49:58 +02:00 committed by TychoVrahe
parent 7f2a995c54
commit 29a5b0a770

View File

@ -3,6 +3,7 @@ use crate::{
error::Error,
time::Duration,
trezorhal::{display, qr, time},
ui::lerp::Lerp,
};
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)]
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 {
fn from(val: u16) -> Self {
Self(val)