diff --git a/core/embed/lib/toif.c b/core/embed/lib/toif.c deleted file mode 100644 index 8221f45f2..000000000 --- a/core/embed/lib/toif.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is part of the Trezor project, https://trezor.io/ - * - * Copyright (c) SatoshiLabs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "toif.h" -#include -#include - -// see docs/misc/toif.md for definition of the TOIF format -bool toif_header_parse(const uint8_t *data, uint32_t len, uint16_t *out_w, - uint16_t *out_h, toif_format_t *out_format) { - if (len < 12 || memcmp(data, "TOI", 3) != 0) { - return false; - } - toif_format_t format = false; - if (data[3] == 'f') { - format = TOIF_FULL_COLOR_BE; - } else if (data[3] == 'g') { - format = TOIF_GRAYSCALE_OH; - } else if (data[3] == 'F') { - format = TOIF_FULL_COLOR_LE; - } else if (data[3] == 'G') { - format = TOIF_GRAYSCALE_EH; - } else { - return false; - } - - uint16_t w = *(uint16_t *)(data + 4); - uint16_t h = *(uint16_t *)(data + 6); - - uint32_t datalen = *(uint32_t *)(data + 8); - if (datalen != len - 12) { - return false; - } - - if (out_w != NULL && out_h != NULL && out_format != NULL) { - *out_w = w; - *out_h = h; - *out_format = format; - } - return true; -} diff --git a/core/embed/lib/toif.h b/core/embed/lib/toif.h deleted file mode 100644 index ccea6125c..000000000 --- a/core/embed/lib/toif.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the Trezor project, https://trezor.io/ - * - * Copyright (c) SatoshiLabs - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LIB_TOIF_H -#define LIB_TOIF_H - -#include -#include - -typedef enum { - TOIF_FULL_COLOR_BE = 0, // big endian - TOIF_GRAYSCALE_OH = 1, // odd hi - TOIF_FULL_COLOR_LE = 2, // little endian - TOIF_GRAYSCALE_EH = 3, // even hi -} toif_format_t; - -bool toif_header_parse(const uint8_t *buf, uint32_t len, uint16_t *out_w, - uint16_t *out_h, toif_format_t *out_format); - -#endif // LIB_TOIF_H diff --git a/core/embed/rust/src/trezorhal/display.rs b/core/embed/rust/src/trezorhal/display.rs index 3f4db098f..124d96d1e 100644 --- a/core/embed/rust/src/trezorhal/display.rs +++ b/core/embed/rust/src/trezorhal/display.rs @@ -20,14 +20,6 @@ pub struct FrameBuffer(*mut u16); #[derive(Copy, Clone)] pub struct FrameBuffer(*mut u32); -#[derive(PartialEq, Debug, Eq, FromPrimitive, Clone, Copy)] -pub enum ToifFormat { - FullColorBE = ffi::toif_format_t_TOIF_FULL_COLOR_BE as _, - GrayScaleOH = ffi::toif_format_t_TOIF_GRAYSCALE_OH as _, - FullColorLE = ffi::toif_format_t_TOIF_FULL_COLOR_LE as _, - GrayScaleEH = ffi::toif_format_t_TOIF_GRAYSCALE_EH as _, -} - pub fn backlight(val: i32) -> i32 { unsafe { ffi::display_backlight(val) } } diff --git a/core/embed/rust/src/ui/component/image.rs b/core/embed/rust/src/ui/component/image.rs index 7a5b9d46f..41c1a6883 100644 --- a/core/embed/rust/src/ui/component/image.rs +++ b/core/embed/rust/src/ui/component/image.rs @@ -1,14 +1,11 @@ -use crate::{ - trezorhal::display::ToifFormat, - ui::{ - component::{Component, Event, EventCtx, Never}, - display, - display::{ - toif::{image, Toif}, - Color, Icon, - }, - geometry::{Alignment2D, Offset, Point, Rect}, +use crate::ui::{ + component::{Component, Event, EventCtx, Never}, + display, + display::{ + toif::{image, Toif, ToifFormat}, + Color, Icon, }, + geometry::{Alignment2D, Offset, Point, Rect}, }; #[derive(PartialEq, Eq, Clone, Copy)] diff --git a/core/embed/rust/src/ui/display/toif.rs b/core/embed/rust/src/ui/display/toif.rs index 89a40a2eb..4e1db49b8 100644 --- a/core/embed/rust/src/ui/display/toif.rs +++ b/core/embed/rust/src/ui/display/toif.rs @@ -1,9 +1,6 @@ use crate::{ error::Error, - trezorhal::{ - display::ToifFormat, - uzlib::{UzlibContext, UZLIB_WINDOW_SIZE}, - }, + trezorhal::uzlib::{UzlibContext, UZLIB_WINDOW_SIZE}, ui::{ component::image::Image, constant, @@ -32,6 +29,14 @@ use super::Color; const TOIF_HEADER_LENGTH: usize = 12; +#[derive(PartialEq, Debug, Eq, FromPrimitive, Clone, Copy)] +pub enum ToifFormat { + FullColorBE = 0, // big endian + GrayScaleOH = 1, // odd hi + FullColorLE = 2, // little endian + GrayScaleEH = 3, // even hi +} + pub fn render_icon(icon: &Icon, center: Point, fg_color: Color, bg_color: Color) { render_toif(&icon.toif, center, fg_color, bg_color); } diff --git a/core/embed/rust/src/ui/model_tr/component/homescreen.rs b/core/embed/rust/src/ui/model_tr/component/homescreen.rs index bac39440e..dfa46da8a 100644 --- a/core/embed/rust/src/ui/model_tr/component/homescreen.rs +++ b/core/embed/rust/src/ui/model_tr/component/homescreen.rs @@ -1,10 +1,14 @@ use crate::{ strutil::StringType, - trezorhal::{display::ToifFormat, usb::usb_configured}, + trezorhal::usb::usb_configured, ui::{ component::{Child, Component, Event, EventCtx, Label}, constant::{HEIGHT, WIDTH}, - display::{rect_fill, toif::Toif, Font, Icon}, + display::{ + rect_fill, + toif::{Toif, ToifFormat}, + Font, Icon, + }, event::USBEvent, geometry::{Alignment2D, Insets, Offset, Point, Rect}, layout::util::get_user_custom_image, diff --git a/core/embed/rust/src/ui/model_tt/component/homescreen/mod.rs b/core/embed/rust/src/ui/model_tt/component/homescreen/mod.rs index dad943255..a89345fef 100644 --- a/core/embed/rust/src/ui/model_tt/component/homescreen/mod.rs +++ b/core/embed/rust/src/ui/model_tt/component/homescreen/mod.rs @@ -14,12 +14,12 @@ use crate::{ }; use crate::{ - trezorhal::{buffers::BufferJpegWork, display::ToifFormat, uzlib::UZLIB_WINDOW_SIZE}, + trezorhal::{buffers::BufferJpegWork, uzlib::UZLIB_WINDOW_SIZE}, ui::{ constant::HEIGHT, display::{ tjpgd::{jpeg_test, BufferInput}, - toif::Toif, + toif::{Toif, ToifFormat}, }, model_tt::component::homescreen::render::{ HomescreenJpeg, HomescreenToif, HOMESCREEN_TOIF_SIZE, diff --git a/core/embed/rust/trezorhal.h b/core/embed/rust/trezorhal.h index aa12b3763..e34711d70 100644 --- a/core/embed/rust/trezorhal.h +++ b/core/embed/rust/trezorhal.h @@ -11,7 +11,6 @@ #include "rgb_led.h" #include "secbool.h" #include "storage.h" -#include "toif.h" #include "touch.h" #include "usb.h"