Skip to content

Commit 1e67d8d

Browse files
authored
Merge pull request #287 from LedgerHQ/y333/nano_nbgl_icon_management
Update include_gif for Nano NBGL
2 parents 3fe8966 + d93b4e4 commit 1e67d8d

File tree

4 files changed

+9
-33
lines changed

4 files changed

+9
-33
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

include_gif/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "include_gif"
3-
version = "1.2.3"
3+
version = "1.2.4"
44
edition = "2021"
55
license.workspace = true
66
repository.workspace = true

include_gif/src/lib.rs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,6 @@ enum Input {
2121
FileNameAndType(LitStr, GlyphType),
2222
}
2323

24-
const MASK: [u8; 196] = [
25-
0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF,
26-
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
27-
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
28-
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
29-
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
30-
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
31-
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
32-
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
33-
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
34-
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
35-
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
36-
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
37-
0xFF, 0x00, 0x00, 0x00,
38-
];
39-
4024
impl syn::parse::Parse for Input {
4125
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
4226
// Parse the filename
@@ -153,7 +137,7 @@ fn generate_bagl_glyph(frame: &GrayImage) -> Vec<u8> {
153137
packed
154138
}
155139

156-
fn image_to_packed_buffer(frame: &mut GrayImage) -> (Vec<u8>, u8) {
140+
fn image_to_packed_buffer(frame: &mut GrayImage, invert: bool) -> (Vec<u8>, u8) {
157141
// Count the number of colors in the image (max 16 supported)
158142
let mut color_count = std::collections::HashSet::new();
159143
for pixel in frame.pixels() {
@@ -172,7 +156,7 @@ fn image_to_packed_buffer(frame: &mut GrayImage) -> (Vec<u8>, u8) {
172156
}
173157

174158
// Invert if bpp is 1
175-
if bits_per_pixel == 1 {
159+
if bits_per_pixel == 1 && invert {
176160
for pixel in frame.pixels_mut() {
177161
pixel.0[0] = 255 - pixel.0[0];
178162
}
@@ -211,18 +195,10 @@ fn image_to_packed_buffer(frame: &mut GrayImage) -> (Vec<u8>, u8) {
211195
fn generate_nbgl_glyph(frame: &mut GrayImage) -> (Vec<u8>, u8, bool) {
212196
// Special case for 14x14 images (Nano S+ and Nano X)
213197
if frame.width() == 14 && frame.height() == 14 {
214-
frame.enumerate_pixels_mut().for_each(|(x, y, pixel)| {
215-
let luma = pixel[0];
216-
if MASK[(y * 14 + x) as usize] == 0xFF && luma == 0 {
217-
*pixel = Luma([255; 1]);
218-
} else {
219-
*pixel = Luma([0; 1]);
220-
}
221-
});
222-
let (packed, bpp) = image_to_packed_buffer(frame);
198+
let (packed, bpp) = image_to_packed_buffer(frame, false);
223199
return (packed, bpp, false);
224200
}
225-
let (packed, bpp) = image_to_packed_buffer(frame);
201+
let (packed, bpp) = image_to_packed_buffer(frame, true);
226202
let mut compressed_image: Vec<u8> = Vec::new();
227203
let mut full_uncompressed_size = packed.len();
228204
let mut i = 0;

ledger_device_sdk/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ledger_device_sdk"
3-
version = "1.24.6"
3+
version = "1.24.7"
44
authors = ["yhql", "yogh333", "agrojean-ledger", "kingofpayne"]
55
edition = "2021"
66
license.workspace = true
@@ -15,7 +15,7 @@ ledger_device_sdk = { path = ".", features = ["speculos"] }
1515
testmacro = { path = "../testmacro", version = "0.1.0"}
1616

1717
[dependencies]
18-
include_gif = {path = "../include_gif", version = "1.2.3"}
18+
include_gif = {path = "../include_gif", version = "1.2.4"}
1919
num-traits = { version = "0.2.14", default-features = false }
2020
rand_core = { version = "0.6.3", default-features = false }
2121
zeroize = { version = "1.6.0", default-features = false }

0 commit comments

Comments
 (0)