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

modtrezorui: update qrcode to draw 1px border

This commit is contained in:
Pavol Rusnak 2017-03-28 14:24:29 +02:00
parent 5cc87ecdce
commit f6747b9556
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 12 additions and 7 deletions

View File

@ -372,16 +372,21 @@ void display_qrcode(int x, int y, const char *data, int datalen, uint8_t scale)
if (scale < 1 || scale > 10) return; if (scale < 1 || scale > 10) return;
uint8_t bitdata[QR_MAX_BITDATA]; uint8_t bitdata[QR_MAX_BITDATA];
int side = qr_encode(QR_LEVEL_M, 0, data, datalen, bitdata); int side = qr_encode(QR_LEVEL_M, 0, data, datalen, bitdata);
x += DISPLAY_OFFSET[0]; x += DISPLAY_OFFSET[0] - (side + 2) * scale / 2;
y += DISPLAY_OFFSET[1]; y += DISPLAY_OFFSET[1] - (side + 2) * scale / 2;
int x0, y0, x1, y1; int x0, y0, x1, y1;
clamp_coords(x, y, side * scale, side * scale, &x0, &y0, &x1, &y1); clamp_coords(x, y, (side + 2) * scale, (side + 2) * scale, &x0, &y0, &x1, &y1);
display_set_window(x0, y0, x1, y1); display_set_window(x0, y0, x1, y1);
for (int j = y0; j <= y1; j++) { for (int j = y0; j <= y1; j++) {
for (int i = x0; i <= x1; i++) { for (int i = x0; i <= x1; i++) {
int rx = i - x; int rx = (i - x) / scale - 1;
int ry = j - y; int ry = (j - y) / scale - 1;
int a = (rx / scale) * side + (ry / scale); // 1px border
if (rx < 0 || ry < 0 || rx >= side || ry >= side) {
DATA(0xFF); DATA(0xFF);
continue;
}
int a = rx * side + ry;
if (bitdata[a / 8] & (1 << (7 - a % 8))) { if (bitdata[a / 8] & (1 << (7 - a % 8))) {
DATA(0x00); DATA(0x00); DATA(0x00); DATA(0x00);
} else { } else {

View File

@ -221,7 +221,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUi_Display_text_width_obj, mod_Trezor
/// def trezor.ui.display.qrcode(x: int, y: int, data: bytes, scale: int) -> None: /// def trezor.ui.display.qrcode(x: int, y: int, data: bytes, scale: int) -> None:
/// ''' /// '''
/// Renders data encoded as a QR code at position (x,y). /// Renders data encoded as a QR code centered at position (x,y).
/// Scale determines a zoom factor. /// Scale determines a zoom factor.
/// ''' /// '''
STATIC mp_obj_t mod_TrezorUi_Display_qrcode(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t mod_TrezorUi_Display_qrcode(size_t n_args, const mp_obj_t *args) {