Skip to content

Commit

Permalink
load /mnt/extsd/resource/OSD/GOGGLE/wallpaper.bmp
Browse files Browse the repository at this point in the history
  • Loading branch information
ligenxxxx committed Jun 11, 2024
1 parent 7ad5d4c commit c539e50
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) {
Expand Down
75 changes: 75 additions & 0 deletions src/core/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/core/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

0 comments on commit c539e50

Please sign in to comment.