@@ -21,22 +21,6 @@ enum Input {
21
21
FileNameAndType ( LitStr , GlyphType ) ,
22
22
}
23
23
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
-
40
24
impl syn:: parse:: Parse for Input {
41
25
fn parse ( input : syn:: parse:: ParseStream ) -> syn:: Result < Self > {
42
26
// Parse the filename
@@ -153,7 +137,7 @@ fn generate_bagl_glyph(frame: &GrayImage) -> Vec<u8> {
153
137
packed
154
138
}
155
139
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 ) {
157
141
// Count the number of colors in the image (max 16 supported)
158
142
let mut color_count = std:: collections:: HashSet :: new ( ) ;
159
143
for pixel in frame. pixels ( ) {
@@ -172,7 +156,7 @@ fn image_to_packed_buffer(frame: &mut GrayImage) -> (Vec<u8>, u8) {
172
156
}
173
157
174
158
// Invert if bpp is 1
175
- if bits_per_pixel == 1 {
159
+ if bits_per_pixel == 1 && invert {
176
160
for pixel in frame. pixels_mut ( ) {
177
161
pixel. 0 [ 0 ] = 255 - pixel. 0 [ 0 ] ;
178
162
}
@@ -211,18 +195,10 @@ fn image_to_packed_buffer(frame: &mut GrayImage) -> (Vec<u8>, u8) {
211
195
fn generate_nbgl_glyph ( frame : & mut GrayImage ) -> ( Vec < u8 > , u8 , bool ) {
212
196
// Special case for 14x14 images (Nano S+ and Nano X)
213
197
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 ) ;
223
199
return ( packed, bpp, false ) ;
224
200
}
225
- let ( packed, bpp) = image_to_packed_buffer ( frame) ;
201
+ let ( packed, bpp) = image_to_packed_buffer ( frame, true ) ;
226
202
let mut compressed_image: Vec < u8 > = Vec :: new ( ) ;
227
203
let mut full_uncompressed_size = packed. len ( ) ;
228
204
let mut i = 0 ;
0 commit comments