@@ -15,6 +15,12 @@ OttoEmojiDisplay::OttoEmojiDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_p
1515 : SpiLcdDisplay(panel_io, panel, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
1616 InitializeOttoEmojis ();
1717 SetupChatLabel ();
18+ SetupPreviewImage ();
19+ }
20+
21+ void OttoEmojiDisplay::SetupPreviewImage () {
22+ DisplayLockGuard lock (this );
23+ lv_obj_set_size (preview_image_, width_ , height_ );
1824}
1925
2026void OttoEmojiDisplay::InitializeOttoEmojis () {
@@ -135,4 +141,42 @@ void OttoEmojiDisplay::SetStatus(const char* status) {
135141 lv_obj_clear_flag (status_label_, LV_OBJ_FLAG_HIDDEN);
136142 lv_obj_clear_flag (network_label_, LV_OBJ_FLAG_HIDDEN);
137143 lv_obj_clear_flag (battery_label_, LV_OBJ_FLAG_HIDDEN);
144+ }
145+
146+ void OttoEmojiDisplay::SetPreviewImage (std::unique_ptr<LvglImage> image) {
147+ DisplayLockGuard lock (this );
148+ if (preview_image_ == nullptr ) {
149+ ESP_LOGE (TAG, " Preview image is not initialized" );
150+ return ;
151+ }
152+
153+ if (image == nullptr ) {
154+ esp_timer_stop (preview_timer_);
155+ lv_obj_remove_flag (emoji_box_, LV_OBJ_FLAG_HIDDEN);
156+ lv_obj_add_flag (preview_image_, LV_OBJ_FLAG_HIDDEN);
157+ preview_image_cached_.reset ();
158+ if (gif_controller_) {
159+ gif_controller_->Start ();
160+ }
161+ return ;
162+ }
163+
164+ preview_image_cached_ = std::move (image);
165+ auto img_dsc = preview_image_cached_->image_dsc ();
166+ // 设置图片源并显示预览图片
167+ lv_image_set_src (preview_image_, img_dsc);
168+ lv_image_set_rotation (preview_image_, -900 );
169+ if (img_dsc->header .w > 0 && img_dsc->header .h > 0 ) {
170+ // zoom factor 1.0
171+ lv_image_set_scale (preview_image_, 256 * width_ / img_dsc->header .w );
172+ }
173+
174+ // Hide emoji_box_
175+ if (gif_controller_) {
176+ gif_controller_->Stop ();
177+ }
178+ lv_obj_add_flag (emoji_box_, LV_OBJ_FLAG_HIDDEN);
179+ lv_obj_remove_flag (preview_image_, LV_OBJ_FLAG_HIDDEN);
180+ esp_timer_stop (preview_timer_);
181+ ESP_ERROR_CHECK (esp_timer_start_once (preview_timer_, PREVIEW_IMAGE_DURATION_MS * 1000 ));
138182}
0 commit comments