@@ -224,107 +224,3 @@ void close_font(display_info_t *display_info) {
224224 }
225225}
226226
227- void convert_bin_fonts (const char * file_location )
228- {
229- display_info_t sd_display_info = {
230- .char_width = 30 ,
231- .char_height = 15 ,
232- .font_width = 36 ,
233- .font_height = 54 ,
234- .x_offset = 180 ,
235- .y_offset = 0 ,
236- .fonts = {NULL , NULL , NULL , NULL },
237- };
238-
239- static display_info_t hd_display_info = {
240- .char_width = 50 ,
241- .char_height = 18 ,
242- .font_width = 24 ,
243- .font_height = 36 ,
244- .x_offset = 120 ,
245- .y_offset = 80 ,
246- .fonts = {NULL , NULL , NULL , NULL },
247- };
248-
249- char * legacy_fcs [6 ] = {"" , "bf" , "inav" , "ardu" , "ultra" , "quic" };
250-
251- for (int is_hd = 0 ; is_hd < 2 ; is_hd ++ )
252- {
253- for (int i = 0 ; i < 6 ; i ++ )
254- {
255- int page_count = 1 ;
256- char file_path [255 ];
257- get_font_path_with_extension (file_path , file_location , ".bin" , 255 , is_hd , legacy_fcs [i ]);
258- char page_2_file_path [255 ];
259- get_font_path_with_extension (page_2_file_path , file_location , "_2.bin" , 255 , is_hd , legacy_fcs [i ]);
260- char * file_paths [2 ] = {file_path , page_2_file_path };
261- struct stat st ;
262- memset (& st , 0 , sizeof (st ));
263- stat (file_path , & st );
264- size_t page_1_filesize = st .st_size ;
265- stat (page_2_file_path , & st );
266- size_t page_2_filesize = st .st_size ;
267- display_info_t display_info = is_hd ? hd_display_info : sd_display_info ;
268- size_t desired_filesize = display_info .font_height * display_info .font_width * NUM_CHARS * BYTES_PER_PIXEL ;
269- DEBUG_PRINT ("Found a font candidate to convert: %s %d\n" , file_path , page_1_filesize );
270- if (page_1_filesize == desired_filesize ) {
271- DEBUG_PRINT ("Found a font to convert: %s %d\n" , file_path , desired_filesize );
272- } else {
273- DEBUG_PRINT ("Font %s is not the right size, skipping\n" , file_path );
274- continue ;
275- }
276- if (page_2_filesize == desired_filesize ) {
277- page_count = 2 ;
278- }
279- void * image_buf = malloc (desired_filesize * page_count );
280- for (int page = 0 ; page < page_count ; page ++ ) {
281- int fd = open (file_paths [page ], O_RDONLY , 0 );
282- if (!fd ) {
283- DEBUG_PRINT ("Could not open file %s\n" , file_path );
284- continue ;
285- }
286- void * mmappedData = mmap (NULL , desired_filesize , PROT_READ , MAP_PRIVATE , fd , 0 );
287- if (mmappedData != MAP_FAILED ) {
288- for (int char_num = 0 ; char_num < NUM_CHARS ; char_num ++ ) {
289- for (int y = 0 ; y < display_info .font_height ; y ++ ) {
290- // Copy each character line at a time into the correct font buffer
291- int char_width_bytes = display_info .font_width * BYTES_PER_PIXEL ;
292- int char_size_bytes_src = (display_info .font_width * display_info .font_height * BYTES_PER_PIXEL );
293- int char_size_bytes_dest = (display_info .font_width * page_count * display_info .font_height * BYTES_PER_PIXEL );
294- memcpy ((uint8_t * )image_buf + (char_num * char_size_bytes_dest ) + (display_info .font_width * page_count * y * BYTES_PER_PIXEL ) + (page * char_width_bytes ), (uint8_t * )mmappedData + (char_num * char_size_bytes_src ) + (y * char_width_bytes ), char_width_bytes );
295- }
296- }
297- } else {
298- DEBUG_PRINT ("Could not map font %s\n" , file_path );
299- free (image_buf );
300- continue ;
301- }
302- close (fd );
303- munmap (mmappedData , desired_filesize );
304- }
305- char out_file_path [255 ];
306- get_font_path_with_extension (out_file_path , file_location , ".png" , 255 , is_hd , legacy_fcs [i ]);
307- FILE * out_fd = fopen (out_file_path , "wb" );
308- if (out_fd == NULL ) {
309- DEBUG_PRINT ("Could not open output %s\n" , out_file_path );
310- continue ;
311- }
312- spng_ctx * enc = spng_ctx_new (SPNG_CTX_ENCODER );
313- struct spng_ihdr ihdr =
314- {
315- .width = display_info .font_width * page_count ,
316- .height = display_info .font_height * NUM_CHARS ,
317- .bit_depth = 8 ,
318- .color_type = SPNG_COLOR_TYPE_TRUECOLOR_ALPHA
319- };
320- spng_set_ihdr (enc , & ihdr );
321- spng_set_png_file (enc , out_fd );
322- spng_encode_image (enc , image_buf , desired_filesize * page_count , SPNG_FMT_PNG , SPNG_ENCODE_FINALIZE );
323- spng_ctx_free (enc );
324- free (image_buf );
325- fclose (out_fd );
326- DEBUG_PRINT ("Converted font %s to %s\n" , file_path , out_file_path );
327- }
328- }
329- }
330-
0 commit comments