1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// use eframe::{egui};
//
// /// Immediate mode texture manager that supports at most one texture at the time :)
// #[derive(Default)]
// pub struct TexMngr {
// loaded_url: String,
// texture_id: Option<egui::TextureId>,
// }
//
// impl TexMngr {
// pub(crate) fn texture(
// &mut self,
// frame: &mut eframe::Frame,
// url: &str,
// image: &Image,
// ) -> Option<egui::TextureId> {
// if self.loaded_url != url {
// if let Some(texture_id) = self.texture_id.take() {
// frame.tex_allocator().free(texture_id);
// }
//
// self.texture_id = Some(
// frame
// .tex_allocator()
// .alloc_srgba_premultiplied(image.size, &image.pixels),
// );
// self.loaded_url = url.to_owned();
// }
// self.texture_id
// }
// }
//
// pub struct Image {
// pub size: (usize, usize),
// pub pixels: Vec<egui::Color32>,
// }
//
// // https://github.com/LedgerHQ/ledger-sample-apps/blob/master/blue-app-samplesign/demo.py
// // https://github.com/LedgerHQ/rust-app
// //https://github.com/LedgerHQ/ledger-nanos-sdk
// impl Image {
// pub fn decode(bytes: &[u8]) -> Option<Image> {
// use image::GenericImageView;
// let image = image::load_from_memory(bytes).ok()?;
// let image_buffer = image.to_rgba8();
// let size = (image.width() as usize, image.height() as usize);
// let pixels = image_buffer.into_vec();
// assert_eq!(size.0 * size.1 * 4, pixels.len());
// let pixels = pixels
// .chunks(4)
// .map(|p| egui::Color32::from_rgba_unmultiplied(p[0], p[1], p[2], p[3]))
// .collect();
//
// Some(Image { size, pixels })
// }
// }