Files
tactility/libs/lv_screenshot/src/lv_screenshot.c
T
Ken Van Hoeylandt a8a664703b Various updates (#60)
- update lvgl to v9.2.0
- update esp_lvgl_port to v2.3.3
- various code correctness improvements
2024-10-19 22:52:08 +02:00

71 lines
3.0 KiB
C

#include "lv_screenshot.h"
#include "save_bmp.h"
#include "save_png.h"
static void data_pre_processing(lv_draw_buf_t* snapshot, uint16_t bpp, lv_100ask_screenshot_sv_t screenshot_sv);
bool lv_screenshot_create(lv_obj_t* obj, lv_color_format_t cf, lv_100ask_screenshot_sv_t screenshot_sv, const char* filename) {
lv_draw_buf_t* snapshot = lv_snapshot_take(obj, cf);
int32_t width = lv_obj_get_width(obj);
int32_t height = lv_obj_get_height(obj);
if (snapshot) {
data_pre_processing(snapshot, LV_COLOR_DEPTH, screenshot_sv);
if (screenshot_sv == LV_100ASK_SCREENSHOT_SV_PNG) {
if (LV_COLOR_DEPTH == 16) {
lv_screenshot_save_png_file(snapshot->data, width, height, 24, filename);
} else if (LV_COLOR_DEPTH == 32) {
lv_screenshot_save_png_file(snapshot->data, width, height, 32, filename);
}
} else if (screenshot_sv == LV_100ASK_SCREENSHOT_SV_BMP) {
if (LV_COLOR_DEPTH == 16) {
lve_screenshot_save_bmp_file(snapshot->data, width, height, 24, filename);
} else if (LV_COLOR_DEPTH == 32) {
lve_screenshot_save_bmp_file(snapshot->data, width, height, 32, filename);
}
}
return true;
}
lv_draw_buf_destroy(snapshot);
return false;
}
static void data_pre_processing(lv_draw_buf_t* snapshot, uint16_t bpp, lv_100ask_screenshot_sv_t screenshot_sv) {
if (bpp == 16) {
uint16_t rgb565_data = 0;
uint32_t count = 0;
for (int w = 0; w < snapshot->header.w; w++) {
for (int h = 0; h < snapshot->header.h; h++) {
rgb565_data = (uint16_t)((*(uint8_t*)(snapshot->data + count + 1) << 8) | *(uint8_t*)(snapshot->data + count));
if (screenshot_sv == LV_100ASK_SCREENSHOT_SV_PNG) {
*(uint8_t*)(snapshot->data + count) = (uint8_t)(((rgb565_data) >> 11) << 3);
*(uint8_t*)(snapshot->data + count + 1) = (uint8_t)(((rgb565_data) >> 5) << 2);
*(uint8_t*)(snapshot->data + count + 2) = (uint8_t)(((rgb565_data) >> 0) << 3);
} else if (screenshot_sv == LV_100ASK_SCREENSHOT_SV_BMP) {
*(uint8_t*)(snapshot->data + count) = (uint8_t)(((rgb565_data) >> 0) << 3);
*(uint8_t*)(snapshot->data + count + 1) = (uint8_t)(((rgb565_data) >> 5) << 2);
*(uint8_t*)(snapshot->data + count + 2) = (uint8_t)(((rgb565_data) >> 11) << 3);
}
count += 3;
}
}
} else if ((screenshot_sv == LV_100ASK_SCREENSHOT_SV_PNG) && (bpp == 32)) {
uint8_t tmp_data = 0;
uint32_t count = 0;
for (int w = 0; w < snapshot->header.w; w++) {
for (int h = 0; h < snapshot->header.h; h++) {
tmp_data = *(snapshot->data + count);
*(uint8_t*)(snapshot->data + count) = *(snapshot->data + count + 2);
*(uint8_t*)(snapshot->data + count + 2) = tmp_data;
count += 4;
}
}
}
}