Skip to content

Commit 57c2c64

Browse files
authored
feat: Add gif support (#1183)
* feat: Add gif support * fix: compiling errors * fix remove bg image
1 parent 4048647 commit 57c2c64

34 files changed

+1688
-325
lines changed

main/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ set(SOURCES "audio/audio_codec.cc"
5555
"display/lvgl_display/lvgl_theme.cc"
5656
"display/lvgl_display/lvgl_font.cc"
5757
"display/lvgl_display/lvgl_image.cc"
58+
"display/lvgl_display/gif/lvgl_gif.cc"
59+
"display/lvgl_display/gif/gifdec.c"
5860
"protocols/protocol.cc"
5961
"protocols/mqtt_protocol.cc"
6062
"protocols/websocket_protocol.cc"

main/assets.cc

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,6 @@ bool Assets::InitializePartition() {
106106
return checksum_valid_;
107107
}
108108

109-
lv_color_t Assets::ParseColor(const std::string& color) {
110-
if (color.find("#") == 0) {
111-
// Convert #112233 to lv_color_t
112-
uint8_t r = strtol(color.substr(1, 2).c_str(), nullptr, 16);
113-
uint8_t g = strtol(color.substr(3, 2).c_str(), nullptr, 16);
114-
uint8_t b = strtol(color.substr(5, 2).c_str(), nullptr, 16);
115-
return lv_color_make(r, g, b);
116-
}
117-
return lv_color_black();
118-
}
119-
120109
bool Assets::Apply() {
121110
void* ptr = nullptr;
122111
size_t size = 0;
@@ -158,6 +147,7 @@ bool Assets::Apply() {
158147
}
159148
}
160149

150+
#ifdef HAVE_LVGL
161151
auto& theme_manager = LvglThemeManager::GetInstance();
162152
auto light_theme = theme_manager.GetTheme("light");
163153
auto dark_theme = theme_manager.GetTheme("dark");
@@ -180,7 +170,7 @@ bool Assets::Apply() {
180170

181171
cJSON* emoji_collection = cJSON_GetObjectItem(root, "emoji_collection");
182172
if (cJSON_IsArray(emoji_collection)) {
183-
auto custom_emoji_collection = std::make_shared<CustomEmojiCollection>();
173+
auto custom_emoji_collection = std::make_shared<EmojiCollection>();
184174
int emoji_count = cJSON_GetArraySize(emoji_collection);
185175
for (int i = 0; i < emoji_count; i++) {
186176
cJSON* emoji = cJSON_GetArrayItem(emoji_collection, i);
@@ -208,11 +198,11 @@ bool Assets::Apply() {
208198
cJSON* background_color = cJSON_GetObjectItem(light_skin, "background_color");
209199
cJSON* background_image = cJSON_GetObjectItem(light_skin, "background_image");
210200
if (cJSON_IsString(text_color)) {
211-
light_theme->set_text_color(ParseColor(text_color->valuestring));
201+
light_theme->set_text_color(LvglTheme::ParseColor(text_color->valuestring));
212202
}
213203
if (cJSON_IsString(background_color)) {
214-
light_theme->set_background_color(ParseColor(background_color->valuestring));
215-
light_theme->set_chat_background_color(ParseColor(background_color->valuestring));
204+
light_theme->set_background_color(LvglTheme::ParseColor(background_color->valuestring));
205+
light_theme->set_chat_background_color(LvglTheme::ParseColor(background_color->valuestring));
216206
}
217207
if (cJSON_IsString(background_image)) {
218208
if (!GetAssetData(background_image->valuestring, ptr, size)) {
@@ -229,11 +219,11 @@ bool Assets::Apply() {
229219
cJSON* background_color = cJSON_GetObjectItem(dark_skin, "background_color");
230220
cJSON* background_image = cJSON_GetObjectItem(dark_skin, "background_image");
231221
if (cJSON_IsString(text_color)) {
232-
dark_theme->set_text_color(ParseColor(text_color->valuestring));
222+
dark_theme->set_text_color(LvglTheme::ParseColor(text_color->valuestring));
233223
}
234224
if (cJSON_IsString(background_color)) {
235-
dark_theme->set_background_color(ParseColor(background_color->valuestring));
236-
dark_theme->set_chat_background_color(ParseColor(background_color->valuestring));
225+
dark_theme->set_background_color(LvglTheme::ParseColor(background_color->valuestring));
226+
dark_theme->set_chat_background_color(LvglTheme::ParseColor(background_color->valuestring));
237227
}
238228
if (cJSON_IsString(background_image)) {
239229
if (!GetAssetData(background_image->valuestring, ptr, size)) {
@@ -245,7 +235,8 @@ bool Assets::Apply() {
245235
}
246236
}
247237
}
248-
238+
#endif
239+
249240
auto display = Board::GetInstance().GetDisplay();
250241
ESP_LOGI(TAG, "Refreshing display theme...");
251242
display->SetTheme(display->GetTheme());

main/assets.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
#ifndef ASSETS_H
22
#define ASSETS_H
33

4-
#include "emoji_collection.h"
5-
64
#include <map>
75
#include <string>
86
#include <functional>
97

108
#include <cJSON.h>
119
#include <esp_partition.h>
12-
#include <lvgl.h>
1310
#include <model_path.h>
1411

1512

@@ -54,7 +51,6 @@ class Assets {
5451
bool InitializePartition();
5552
uint32_t CalculateChecksum(const char* data, uint32_t length);
5653
bool GetAssetData(const std::string& name, void*& ptr, size_t& size);
57-
lv_color_t ParseColor(const std::string& color);
5854

5955
const esp_partition_t* partition_ = nullptr;
6056
esp_partition_mmap_handle_t mmap_handle_ = 0;

main/boards/common/esp32_camera.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "display.h"
44
#include "board.h"
55
#include "system_info.h"
6+
#include "lvgl_display.h"
67

78
#include <esp_log.h>
89
#include <esp_heap_caps.h>
@@ -60,7 +61,7 @@ bool Esp32Camera::Capture() {
6061
ESP_LOGI(TAG, "Camera captured %d frames in %d ms", frames_to_get, int((end_time - start_time) / 1000));
6162

6263
// 显示预览图片
63-
auto display = Board::GetInstance().GetDisplay();
64+
auto display = dynamic_cast<LvglDisplay*>(Board::GetInstance().GetDisplay());
6465
if (display != nullptr) {
6566
// Create a new preview image
6667
auto img_dsc = (lv_img_dsc_t*)heap_caps_calloc(1, sizeof(lv_img_dsc_t), MALLOC_CAP_8BIT);

main/boards/electron-bot/electron_emoji_display.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ ElectronEmojiDisplay::ElectronEmojiDisplay(esp_lcd_panel_io_handle_t panel_io,
6060
void ElectronEmojiDisplay::SetupGifContainer() {
6161
DisplayLockGuard lock(this);
6262

63-
if (emotion_label_) {
64-
lv_obj_del(emotion_label_);
63+
if (emoji_label_) {
64+
lv_obj_del(emoji_label_);
6565
}
6666
if (chat_message_label_) {
6767
lv_obj_del(chat_message_label_);
@@ -78,11 +78,11 @@ void ElectronEmojiDisplay::SetupGifContainer() {
7878
lv_obj_set_flex_grow(content_, 1);
7979
lv_obj_center(content_);
8080

81-
emotion_label_ = lv_label_create(content_);
82-
lv_label_set_text(emotion_label_, "");
83-
lv_obj_set_width(emotion_label_, 0);
84-
lv_obj_set_style_border_width(emotion_label_, 0, 0);
85-
lv_obj_add_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
81+
emoji_label_ = lv_label_create(content_);
82+
lv_label_set_text(emoji_label_, "");
83+
lv_obj_set_width(emoji_label_, 0);
84+
lv_obj_set_style_border_width(emoji_label_, 0, 0);
85+
lv_obj_add_flag(emoji_label_, LV_OBJ_FLAG_HIDDEN);
8686

8787
emotion_gif_ = lv_gif_create(content_);
8888
int gif_size = LV_HOR_RES;

main/boards/magiclick-2p4/magiclick_2p4_board.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class NV3023Display : public SpiLcdDisplay {
4444
// 设置内容区背景色和文本颜色
4545
lv_obj_set_style_bg_color(content_, lv_color_black(), 0);
4646
lv_obj_set_style_border_width(content_, 0, 0);
47-
lv_obj_set_style_text_color(emotion_label_, lv_color_white(), 0);
47+
lv_obj_set_style_text_color(emoji_label_, lv_color_white(), 0);
4848
lv_obj_set_style_text_color(chat_message_label_, lv_color_white(), 0);
4949
}
5050
};

main/boards/magiclick-c3-v2/magiclick_c3_v2_board.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class GC9107Display : public SpiLcdDisplay {
4444
// 设置内容区背景色和文本颜色
4545
lv_obj_set_style_bg_color(content_, lv_color_black(), 0);
4646
lv_obj_set_style_border_width(content_, 0, 0);
47-
lv_obj_set_style_text_color(emotion_label_, lv_color_white(), 0);
47+
lv_obj_set_style_text_color(emoji_label_, lv_color_white(), 0);
4848
lv_obj_set_style_text_color(chat_message_label_, lv_color_white(), 0);
4949
}
5050
};

main/boards/magiclick-c3/magiclick_c3_board.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class NV3023Display : public SpiLcdDisplay {
4242
// 设置内容区背景色和文本颜色
4343
lv_obj_set_style_bg_color(content_, lv_color_black(), 0);
4444
lv_obj_set_style_border_width(content_, 0, 0);
45-
lv_obj_set_style_text_color(emotion_label_, lv_color_white(), 0);
45+
lv_obj_set_style_text_color(emoji_label_, lv_color_white(), 0);
4646
lv_obj_set_style_text_color(chat_message_label_, lv_color_white(), 0);
4747
}
4848
};

main/boards/otto-robot/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
{
55
"name": "otto-robot",
66
"sdkconfig_append": [
7-
"CONFIG_PARTITION_TABLE_CUSTOM_FILENAME=\"partitions/v1/16m.csv\""
7+
"CONFIG_PARTITION_TABLE_CUSTOM_FILENAME=\"partitions/v1/16m.csv\"",
8+
"CONFIG_LVGL_USE_GIF=y"
89
]
910
}
1011
]

main/boards/otto-robot/otto_emoji_display.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ OttoEmojiDisplay::OttoEmojiDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_p
6161
void OttoEmojiDisplay::SetupGifContainer() {
6262
DisplayLockGuard lock(this);
6363

64-
if (emotion_label_) {
65-
lv_obj_del(emotion_label_);
64+
if (emoji_label_) {
65+
lv_obj_del(emoji_label_);
6666
}
6767

6868
if (chat_message_label_) {
@@ -80,11 +80,11 @@ void OttoEmojiDisplay::SetupGifContainer() {
8080
lv_obj_set_flex_grow(content_, 1);
8181
lv_obj_center(content_);
8282

83-
emotion_label_ = lv_label_create(content_);
84-
lv_label_set_text(emotion_label_, "");
85-
lv_obj_set_width(emotion_label_, 0);
86-
lv_obj_set_style_border_width(emotion_label_, 0, 0);
87-
lv_obj_add_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
83+
emoji_label_ = lv_label_create(content_);
84+
lv_label_set_text(emoji_label_, "");
85+
lv_obj_set_width(emoji_label_, 0);
86+
lv_obj_set_style_border_width(emoji_label_, 0, 0);
87+
lv_obj_add_flag(emoji_label_, LV_OBJ_FLAG_HIDDEN);
8888

8989
emotion_gif_ = lv_gif_create(content_);
9090
int gif_size = LV_HOR_RES;

0 commit comments

Comments
 (0)