Skip to content

Commit

Permalink
remove font converting; too many edge cases to code around
Browse files Browse the repository at this point in the history
  • Loading branch information
benlumley committed May 13, 2024
1 parent f23bb25 commit c1398ac
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 107 deletions.
2 changes: 1 addition & 1 deletion ipk/goggle/control/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: msp-osd
Version: 0.12.0
Version: 0.12.1
Maintainer: bri3d
Description: MSP OSD service for the DJI HD FPV goggles.
Architecture: pigeon-glasses
Expand Down
104 changes: 0 additions & 104 deletions jni/font/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,107 +224,3 @@ void close_font(display_info_t *display_info) {
}
}

void convert_bin_fonts(const char *file_location)
{
display_info_t sd_display_info = {
.char_width = 30,
.char_height = 15,
.font_width = 36,
.font_height = 54,
.x_offset = 180,
.y_offset = 0,
.fonts = {NULL, NULL, NULL, NULL},
};

static display_info_t hd_display_info = {
.char_width = 50,
.char_height = 18,
.font_width = 24,
.font_height = 36,
.x_offset = 120,
.y_offset = 80,
.fonts = {NULL, NULL, NULL, NULL},
};

char *legacy_fcs[6] = {"", "bf", "inav", "ardu", "ultra", "quic"};

for (int is_hd = 0; is_hd < 2; is_hd++)
{
for (int i = 0; i < 6; i++)
{
int page_count = 1;
char file_path[255];
get_font_path_with_extension(file_path, file_location, ".bin", 255, is_hd, legacy_fcs[i]);
char page_2_file_path[255];
get_font_path_with_extension(page_2_file_path, file_location, "_2.bin", 255, is_hd, legacy_fcs[i]);
char *file_paths[2] = {file_path, page_2_file_path};
struct stat st;
memset(&st, 0, sizeof(st));
stat(file_path, &st);
size_t page_1_filesize = st.st_size;
stat(page_2_file_path, &st);
size_t page_2_filesize = st.st_size;
display_info_t display_info = is_hd ? hd_display_info : sd_display_info;
size_t desired_filesize = display_info.font_height * display_info.font_width * NUM_CHARS * BYTES_PER_PIXEL;
DEBUG_PRINT("Found a font candidate to convert: %s %d\n", file_path, page_1_filesize);
if(page_1_filesize == desired_filesize) {
DEBUG_PRINT("Found a font to convert: %s %d\n", file_path, desired_filesize);
} else {
DEBUG_PRINT("Font %s is not the right size, skipping\n", file_path);
continue;
}
if(page_2_filesize == desired_filesize) {
page_count = 2;
}
void *image_buf = malloc(desired_filesize * page_count);
for(int page = 0; page < page_count; page++) {
int fd = open(file_paths[page], O_RDONLY, 0);
if (!fd) {
DEBUG_PRINT("Could not open file %s\n", file_path);
continue;
}
void* mmappedData = mmap(NULL, desired_filesize, PROT_READ, MAP_PRIVATE, fd, 0);
if (mmappedData != MAP_FAILED) {
for(int char_num = 0; char_num < NUM_CHARS; char_num++) {
for(int y = 0; y < display_info.font_height; y++) {
// Copy each character line at a time into the correct font buffer
int char_width_bytes = display_info.font_width * BYTES_PER_PIXEL;
int char_size_bytes_src = (display_info.font_width * display_info.font_height * BYTES_PER_PIXEL);
int char_size_bytes_dest = (display_info.font_width * page_count * display_info.font_height * BYTES_PER_PIXEL);
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);
}
}
} else {
DEBUG_PRINT("Could not map font %s\n", file_path);
free(image_buf);
continue;
}
close(fd);
munmap(mmappedData, desired_filesize);
}
char out_file_path[255];
get_font_path_with_extension(out_file_path, file_location, ".png", 255, is_hd, legacy_fcs[i]);
FILE* out_fd = fopen(out_file_path, "wb");
if(out_fd == NULL) {
DEBUG_PRINT("Could not open output %s\n", out_file_path);
continue;
}
spng_ctx *enc = spng_ctx_new(SPNG_CTX_ENCODER);
struct spng_ihdr ihdr =
{
.width = display_info.font_width * page_count,
.height = display_info.font_height * NUM_CHARS,
.bit_depth = 8,
.color_type = SPNG_COLOR_TYPE_TRUECOLOR_ALPHA
};
spng_set_ihdr(enc, &ihdr);
spng_set_png_file(enc, out_fd);
spng_encode_image(enc, image_buf, desired_filesize * page_count, SPNG_FMT_PNG, SPNG_ENCODE_FINALIZE);
spng_ctx_free(enc);
free(image_buf);
fclose(out_fd);
DEBUG_PRINT("Converted font %s to %s\n", file_path, out_file_path);
}
}
}

1 change: 0 additions & 1 deletion jni/font/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ typedef enum
FONT_VARIANT_COUNT
} font_variant_e;

void convert_bin_fonts(const char *file_location);
void load_font(display_info_t *display_info, char *font_variant);
void close_font(display_info_t *display_info);
void get_font_path_with_extension(char *font_path_dest, const char *font_path, const char *extension, uint8_t len, uint8_t is_hd, char *font_variant);
1 change: 0 additions & 1 deletion jni/osd_dji_overlay_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ void osd_directfb(duss_disp_instance_handle_t *disp, duss_hal_obj_handle_t ion_h
rec_load_config();
rec_pb_load_config();
check_is_au_overlay_enabled();
convert_bin_fonts(SDCARD_FONT_PATH);

uint8_t is_v2_goggles = dji_goggles_are_v2();
DEBUG_PRINT("Detected DJI goggles %s\n", is_v2_goggles ? "V2" : "V1");
Expand Down

0 comments on commit c1398ac

Please sign in to comment.