From c539e50f1ef052d52dbc531acf22072f12da7781 Mon Sep 17 00:00:00 2001 From: ligenxxxx Date: Tue, 11 Jun 2024 18:57:29 +0800 Subject: [PATCH] load /mnt/extsd/resource/OSD/GOGGLE/wallpaper.bmp --- src/core/main.c | 6 ++++ src/core/osd.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ src/core/osd.h | 3 +- 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/src/core/main.c b/src/core/main.c index 55d4db49..2f8b9f9c 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -135,6 +135,12 @@ void lvgl_init() { false, LV_FONT_DEFAULT); lv_disp_set_theme(dispp, theme); lv_obj_set_style_bg_color(lv_scr_act(), lv_color_make(64, 64, 64), 0); + + // user wallpaper + if (load_wallpaper("/mnt/extsd/resource/OSD/GOGGLE/wallpaper.bmp")) { + lv_obj_t *img_obj = lv_img_create(lv_scr_act()); + lv_img_set_src(img_obj, &img_menu_bg); + } } int main(int argc, char *argv[]) { diff --git a/src/core/osd.c b/src/core/osd.c index 85719e3e..2269e141 100644 --- a/src/core/osd.c +++ b/src/core/osd.c @@ -992,6 +992,81 @@ void osd_shadow_clear(void) { } } +/////////////////////////////////////////////////////////////////////////////// +// load_bmp_file +int load_bmp_image(const char *file, uint32_t *obuf, int width, int height) { + char *buf; + struct stat stFile; + FILE *fd; + int size, rd; + int line_size; + + fd = fopen(file, "rb"); + if (fd == NULL) { + LOGE("%s cannot open", file); + return 0; + } + + // get file size + fseek(fd, 0, SEEK_END); + size = ftell(fd); + fseek(fd, 0, SEEK_SET); + + buf = (unsigned char *)malloc(size); + if (buf == NULL) { + LOGE("%s error 1", file); + return 0; + } + + rd = fread(buf, 1, size, fd); + if (rd != size) { + LOGE("%s error 2", file); + free(buf); + return 0; + } + + fclose(fd); + + // check image size + bmpFileHead *bmp = (bmpFileHead *)buf; + char *pb = buf + sizeof(bmpFileHead) + bmp->info.biClrUsed; + if (bmp->info.biWidth != width || bmp->info.biHeight != height) { + LOGE("%s error 3", file); + free(buf); + return 0; + } + + line_size = (width * 3 + 3) & 0xFFFC; // 4bytes align + + int x, y; + uint32_t addr; + + for (y = 0; y < height; y++) { + addr = y * line_size; + for (x = 0; x < width; x++) + obuf[(height - y - 1) * width + x] = (0xff << 24) + ((pb[addr + x * 3] & 0xff)) + ((pb[addr + x * 3 + 1] & 0xff) << 8) + ((pb[addr + x * 3 + 2] & 0xff) << 16); + } + + free(buf); + return 1; +} + +static uint32_t img_menu_bg_data[1920 * 1080]; // 0x00BBGGRR +lv_img_dsc_t img_menu_bg; +int load_wallpaper(char *file_path) { + if (load_bmp_image(file_path, img_menu_bg_data, 1920, 1080)) { + img_menu_bg.header.cf = LV_IMG_CF_TRUE_COLOR; + img_menu_bg.header.always_zero = 0; + img_menu_bg.header.reserved = 0; + img_menu_bg.header.w = 1920; + img_menu_bg.header.h = 1080; + img_menu_bg.data_size = 1920 * 1080 * LV_COLOR_SIZE / 8; + img_menu_bg.data = (uint8_t *)img_menu_bg_data; + return 1; + } else { + return 0; + } +} /////////////////////////////////////////////////////////////////////////////// // Threads for updating FC OSD diff --git a/src/core/osd.h b/src/core/osd.h index c5ef4dfe..21adc08b 100644 --- a/src/core/osd.h +++ b/src/core/osd.h @@ -87,6 +87,7 @@ typedef struct { } osd_font_t; extern uint8_t channel_osd_mode; +extern lv_img_dsc_t img_menu_bg; int osd_init(void); int osd_clear(void); @@ -101,7 +102,7 @@ void load_fc_osd_font(uint8_t); void *thread_osd(void *ptr); void osd_resource_path(char *buf, const char *fmt, osd_resource_t osd_resource_type, ...); void osd_toggle(); - +int load_wallpaper(char *file_path); #ifdef __cplusplus } #endif