1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

feat(core): support differently sized homescreen

[no changelog]
This commit is contained in:
tychovrahe 2023-04-03 14:21:49 +02:00 committed by TychoVrahe
parent 2b71a44fd3
commit 44178514f3
2 changed files with 24 additions and 20 deletions

View File

@ -17,6 +17,7 @@ use crate::{
use crate::{ use crate::{
trezorhal::{display::ToifFormat, uzlib::UZLIB_WINDOW_SIZE}, trezorhal::{display::ToifFormat, uzlib::UZLIB_WINDOW_SIZE},
ui::{ ui::{
constant::HEIGHT,
display::{tjpgd::BufferInput, toif::Toif}, display::{tjpgd::BufferInput, toif::Toif},
model_tt::component::homescreen::render::{ model_tt::component::homescreen::render::{
HomescreenJpeg, HomescreenToif, HOMESCREEN_TOIF_SIZE, HomescreenJpeg, HomescreenToif, HOMESCREEN_TOIF_SIZE,
@ -24,16 +25,17 @@ use crate::{
}, },
}; };
use render::{ use render::{
homescreen, homescreen_blurred, HomescreenNotification, HomescreenText, HOMESCREEN_IMAGE_SIZE, homescreen, homescreen_blurred, HomescreenNotification, HomescreenText,
HOMESCREEN_IMAGE_HEIGHT, HOMESCREEN_IMAGE_WIDTH,
}; };
use super::{theme, Loader, LoaderMsg}; use super::{theme, Loader, LoaderMsg};
const AREA: Rect = constant::screen(); const AREA: Rect = constant::screen();
const TOP_CENTER: Point = AREA.top_center(); const TOP_CENTER: Point = AREA.top_center();
const LABEL_Y: i16 = 222; const LABEL_Y: i16 = HEIGHT - 18;
const LOCKED_Y: i16 = 107; const LOCKED_Y: i16 = HEIGHT / 2 - 13;
const TAP_Y: i16 = 134; const TAP_Y: i16 = HEIGHT / 2 + 14;
const HOLD_Y: i16 = 35; const HOLD_Y: i16 = 35;
const LOADER_OFFSET: Offset = Offset::y(-10); const LOADER_OFFSET: Offset = Offset::y(-10);
const LOADER_DELAY: Duration = Duration::from_millis(500); const LOADER_DELAY: Duration = Duration::from_millis(500);
@ -363,7 +365,8 @@ fn get_image() -> Result<Gc<[u8]>, ()> {
fn is_image_jpeg(buffer: &[u8]) -> bool { fn is_image_jpeg(buffer: &[u8]) -> bool {
let jpeg = jpeg_info(buffer); let jpeg = jpeg_info(buffer);
if let Some((size, mcu_height)) = jpeg { if let Some((size, mcu_height)) = jpeg {
if size.x == HOMESCREEN_IMAGE_SIZE && size.y == HOMESCREEN_IMAGE_SIZE && mcu_height <= 16 { if size.x == HOMESCREEN_IMAGE_WIDTH && size.y == HOMESCREEN_IMAGE_HEIGHT && mcu_height <= 16
{
return true; return true;
} }
} }

View File

@ -51,7 +51,8 @@ struct HomescreenTextInfo {
pub icon_area: Option<Rect>, pub icon_area: Option<Rect>,
} }
pub const HOMESCREEN_IMAGE_SIZE: i16 = 240; pub const HOMESCREEN_IMAGE_WIDTH: i16 = WIDTH;
pub const HOMESCREEN_IMAGE_HEIGHT: i16 = HEIGHT;
pub const HOMESCREEN_TOIF_SIZE: i16 = 144; pub const HOMESCREEN_TOIF_SIZE: i16 = 144;
pub const HOMESCREEN_TOIF_Y_OFFSET: i16 = 27; pub const HOMESCREEN_TOIF_Y_OFFSET: i16 = 27;
pub const HOMESCREEN_TOIF_X_OFFSET: usize = ((WIDTH - HOMESCREEN_TOIF_SIZE) / 2) as usize; pub const HOMESCREEN_TOIF_X_OFFSET: usize = ((WIDTH - HOMESCREEN_TOIF_SIZE) / 2) as usize;
@ -64,7 +65,7 @@ const NOTIFICATION_TEXT_OFFSET: Offset = Offset::new(1, -2);
const TEXT_ICON_SPACE: i16 = 2; const TEXT_ICON_SPACE: i16 = 2;
const HOMESCREEN_DIM_HEIGHT: i16 = 35; const HOMESCREEN_DIM_HEIGHT: i16 = 35;
const HOMESCREEN_DIM_START: i16 = 198; const HOMESCREEN_DIM_START: i16 = HOMESCREEN_IMAGE_HEIGHT - 22;
const HOMESCREEN_DIM: f32 = 0.65; const HOMESCREEN_DIM: f32 = 0.65;
const HOMESCREEN_DIM_BORDER: i16 = theme::BUTTON_SPACING; const HOMESCREEN_DIM_BORDER: i16 = theme::BUTTON_SPACING;
@ -297,7 +298,7 @@ fn homescreen_line_blurred(
let t_buffer = unsafe { get_buffer_4bpp((y & 0x1) as u16, true) }; let t_buffer = unsafe { get_buffer_4bpp((y & 0x1) as u16, true) };
let mut img_buffer = unsafe { get_buffer_16bpp((y & 0x1) as u16, false) }; let mut img_buffer = unsafe { get_buffer_16bpp((y & 0x1) as u16, false) };
for x in 0..HOMESCREEN_IMAGE_SIZE { for x in 0..HOMESCREEN_IMAGE_WIDTH {
let c = if LOCKSCREEN_DIM_ALL { let c = if LOCKSCREEN_DIM_ALL {
let x = x as usize; let x = x as usize;
@ -349,7 +350,7 @@ fn homescreen_line(
let image_data = get_data(data_buffer, y, mcu_height); let image_data = get_data(data_buffer, y, mcu_height);
for x in 0..HOMESCREEN_IMAGE_SIZE { for x in 0..HOMESCREEN_IMAGE_WIDTH {
let d = image_data[x as usize]; let d = image_data[x as usize];
let c = if homescreen_dim_area(x, y) { let c = if homescreen_dim_area(x, y) {
@ -427,7 +428,7 @@ fn update_accs_sub(data: &[u16], idx: usize, acc_r: &mut u16, acc_g: &mut u16, a
struct BlurringContext { struct BlurringContext {
pub lines: &'static mut [[[u16; 240usize]; 3usize]], pub lines: &'static mut [[[u16; 240usize]; 3usize]],
pub totals: [[u16; HOMESCREEN_IMAGE_SIZE as usize]; COLORS], pub totals: [[u16; HOMESCREEN_IMAGE_WIDTH as usize]; COLORS],
line_num: i16, line_num: i16,
add_idx: usize, add_idx: usize,
rem_idx: usize, rem_idx: usize,
@ -438,7 +439,7 @@ impl BlurringContext {
let mem = unsafe { get_blurring_buffer(0, true) }; let mem = unsafe { get_blurring_buffer(0, true) };
Self { Self {
lines: &mut mem.buffer[0..DECOMP_LINES], lines: &mut mem.buffer[0..DECOMP_LINES],
totals: [[0; HOMESCREEN_IMAGE_SIZE as usize]; COLORS], totals: [[0; HOMESCREEN_IMAGE_WIDTH as usize]; COLORS],
line_num: 0, line_num: 0,
add_idx: 0, add_idx: 0,
rem_idx: 0, rem_idx: 0,
@ -462,19 +463,19 @@ impl BlurringContext {
let data = get_data(buffer, self.line_num, mcu_height); let data = get_data(buffer, self.line_num, mcu_height);
for i in -BLUR_RADIUS..=BLUR_RADIUS { for i in -BLUR_RADIUS..=BLUR_RADIUS {
let ic = i.clamp(0, HOMESCREEN_IMAGE_SIZE as i16 - 1) as usize; let ic = i.clamp(0, HOMESCREEN_IMAGE_WIDTH as i16 - 1) as usize;
update_accs_add(data, ic, &mut acc_r, &mut acc_g, &mut acc_b); update_accs_add(data, ic, &mut acc_r, &mut acc_g, &mut acc_b);
} }
for i in 0..HOMESCREEN_IMAGE_SIZE { for i in 0..HOMESCREEN_IMAGE_WIDTH {
self.lines[self.add_idx][RED_IDX][i as usize] = acc_r; self.lines[self.add_idx][RED_IDX][i as usize] = acc_r;
self.lines[self.add_idx][GREEN_IDX][i as usize] = acc_g; self.lines[self.add_idx][GREEN_IDX][i as usize] = acc_g;
self.lines[self.add_idx][BLUE_IDX][i as usize] = acc_b; self.lines[self.add_idx][BLUE_IDX][i as usize] = acc_b;
// clamping handles left and right edges // clamping handles left and right edges
let ic = (i - BLUR_RADIUS).clamp(0, HOMESCREEN_IMAGE_SIZE as i16 - 1) as usize; let ic = (i - BLUR_RADIUS).clamp(0, HOMESCREEN_IMAGE_WIDTH as i16 - 1) as usize;
let ic2 = (i + BLUR_SIZE as i16 - BLUR_RADIUS) let ic2 = (i + BLUR_SIZE as i16 - BLUR_RADIUS)
.clamp(0, HOMESCREEN_IMAGE_SIZE as i16 - 1) as usize; .clamp(0, HOMESCREEN_IMAGE_WIDTH as i16 - 1) as usize;
update_accs_add(data, ic2, &mut acc_r, &mut acc_g, &mut acc_b); update_accs_add(data, ic2, &mut acc_r, &mut acc_g, &mut acc_b);
update_accs_sub(data, ic, &mut acc_r, &mut acc_g, &mut acc_b); update_accs_sub(data, ic, &mut acc_r, &mut acc_g, &mut acc_b);
} }
@ -483,7 +484,7 @@ impl BlurringContext {
// adds one line of averages to sliding total averages // adds one line of averages to sliding total averages
fn vertical_avg_add(&mut self) { fn vertical_avg_add(&mut self) {
for i in 0..HOMESCREEN_IMAGE_SIZE as usize { for i in 0..HOMESCREEN_IMAGE_WIDTH as usize {
self.totals[RED_IDX][i] += self.lines[self.add_idx][RED_IDX][i]; self.totals[RED_IDX][i] += self.lines[self.add_idx][RED_IDX][i];
self.totals[GREEN_IDX][i] += self.lines[self.add_idx][GREEN_IDX][i]; self.totals[GREEN_IDX][i] += self.lines[self.add_idx][GREEN_IDX][i];
self.totals[BLUE_IDX][i] += self.lines[self.add_idx][BLUE_IDX][i]; self.totals[BLUE_IDX][i] += self.lines[self.add_idx][BLUE_IDX][i];
@ -492,7 +493,7 @@ impl BlurringContext {
// adds one line and removes one line of averages to/from sliding total averages // adds one line and removes one line of averages to/from sliding total averages
fn vertical_avg(&mut self) { fn vertical_avg(&mut self) {
for i in 0..HOMESCREEN_IMAGE_SIZE as usize { for i in 0..HOMESCREEN_IMAGE_WIDTH as usize {
self.totals[RED_IDX][i] += self.totals[RED_IDX][i] +=
self.lines[self.add_idx][RED_IDX][i] - self.lines[self.rem_idx][RED_IDX][i]; self.lines[self.add_idx][RED_IDX][i] - self.lines[self.rem_idx][RED_IDX][i];
self.totals[GREEN_IDX][i] += self.totals[GREEN_IDX][i] +=
@ -566,7 +567,7 @@ pub fn homescreen_blurred(data: &mut dyn HomescreenDecompressor, texts: &[Homesc
for y in 0..HEIGHT { for y in 0..HEIGHT {
// several lines have been already decompressed before this loop, adjust for // several lines have been already decompressed before this loop, adjust for
// that // that
if y < HOMESCREEN_IMAGE_SIZE - (BLUR_RADIUS + 1) { if y < HOMESCREEN_IMAGE_HEIGHT - (BLUR_RADIUS + 1) {
blurring.compute_line_avgs(data.get_data(), mcu_height); blurring.compute_line_avgs(data.get_data(), mcu_height);
} }
@ -583,11 +584,11 @@ pub fn homescreen_blurred(data: &mut dyn HomescreenDecompressor, texts: &[Homesc
// for the rest of image // for the rest of image
// the extra -1 is to indicate that this was the last decompressed line, // the extra -1 is to indicate that this was the last decompressed line,
// in the next pass the docompression and compute_line_avgs won't happen // in the next pass the docompression and compute_line_avgs won't happen
if y < HOMESCREEN_IMAGE_SIZE - (BLUR_RADIUS + 1) - 1 { if y < HOMESCREEN_IMAGE_HEIGHT - (BLUR_RADIUS + 1) - 1 {
blurring.inc_add(); blurring.inc_add();
} }
if y == HOMESCREEN_IMAGE_SIZE { if y == HOMESCREEN_IMAGE_HEIGHT {
// reached end of image, clear avgs (display black) // reached end of image, clear avgs (display black)
blurring.clear(); blurring.clear();
} }