1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-28 16:21:03 +00:00

move unpack of icon to display_loader()

This commit is contained in:
Pavol Rusnak 2016-05-11 22:09:03 +02:00
parent 01fb1dcbf2
commit 406f0c6783
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 15 additions and 10 deletions

View File

@ -13,6 +13,7 @@
#include "trezor-qrenc/qr_encode.h"
#include "display.h"
#include <string.h>
#if defined STM32_HAL_H
#include "display-stmhal.h"
@ -238,6 +239,12 @@ void display_qrcode(uint8_t x, uint8_t y, const char *data, int datalen, int sca
#include "loader.h"
static void inflate_callback_loader(uint8_t byte, uint32_t pos, void *userdata)
{
uint8_t *out = (uint8_t *)userdata;
out[pos] = byte;
}
void display_loader(uint16_t progress, uint16_t fgcolor, uint16_t bgcolor, const uint8_t *icon, uint16_t iconfgcolor)
{
uint16_t colortable[16], iconcolortable[16];
@ -246,6 +253,13 @@ void display_loader(uint16_t progress, uint16_t fgcolor, uint16_t bgcolor, const
set_color_table(iconcolortable, iconfgcolor, bgcolor);
}
display_set_window(RESX / 2 - img_loader_size, RESY * 2 / 5 - img_loader_size, img_loader_size * 2, img_loader_size * 2);
if (icon && memcmp(icon, "TOIg\x60\x00\x60\x00", 8) == 0) {
uint8_t icondata[96 * 96 / 2];
sinf_inflate(icon + 12, inflate_callback_loader, icondata);
icon = icondata;
} else {
icon = NULL;
}
for (int y = 0; y < img_loader_size * 2; y++) {
for (int x = 0; x < img_loader_size * 2; x++) {
int mx = x, my = y;

View File

@ -211,13 +211,6 @@ STATIC mp_obj_t mod_TrezorUi_Display_qrcode(size_t n_args, const mp_obj_t *args)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_qrcode_obj, 5, 5, mod_TrezorUi_Display_qrcode);
static void inflate_callback_loader(uint8_t byte, uint32_t pos, void *userdata)
{
uint8_t *out = (uint8_t *)userdata;
out[pos] = byte;
}
/// def trezor.ui.display.loader(progress: int, fgcolor: int, bgcolor: int, icon: bytes=None, iconfgcolor: int=None) -> None
///
/// Renders a rotating loader graphic.
@ -245,15 +238,13 @@ STATIC mp_obj_t mod_TrezorUi_Display_loader(size_t n_args, const mp_obj_t *args)
if (datalen != icon.len - 12) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid size of data"));
}
uint8_t icondata[96 * 96 /2];
sinf_inflate(data + 12, inflate_callback_loader, icondata);
uint16_t iconfgcolor;
if (n_args > 5) { // icon color provided
iconfgcolor = mp_obj_get_int(args[5]);
} else {
iconfgcolor = ~bgcolor; // invert
}
display_loader(progress, fgcolor, bgcolor, icondata, iconfgcolor);
display_loader(progress, fgcolor, bgcolor, data, iconfgcolor);
} else {
display_loader(progress, fgcolor, bgcolor, NULL, 0);
}