FIX: do not show the background bitmap when model is white.

Jira: STUDIO-5620

Signed-off-by: wenjie.guo <wenjie.guo@bambulab.com>
Change-Id: Ic61ba2ca53d071c815323b980abf79c067770b58
(cherry picked from commit cc55e02e753e3ae88d1a0bd0d9fc51aab9ab7fd8)
This commit is contained in:
wenjie.guo 2023-12-20 11:59:26 +08:00 committed by Lane.Wei
parent 7c99f28d16
commit eeaf7170e0
5 changed files with 46 additions and 10 deletions

View File

@ -34,6 +34,7 @@
#define TIMEOUT_RESPONSE 15 #define TIMEOUT_RESPONSE 15
#define BE_UNACTED_ON 0x00200001 #define BE_UNACTED_ON 0x00200001
#define SHOW_BACKGROUND_BITMAP_PIXEL_THRESHOLD 80
#ifndef _MSW_DARK_MODE #ifndef _MSW_DARK_MODE
#define _MSW_DARK_MODE 1 #define _MSW_DARK_MODE 1
#endif // _MSW_DARK_MODE #endif // _MSW_DARK_MODE

View File

@ -45,7 +45,6 @@ wxDEFINE_EVENT(EVT_CLEAR_IPADDRESS, wxCommandEvent);
static wxString task_canceled_text = _L("Task canceled"); static wxString task_canceled_text = _L("Task canceled");
std::string get_print_status_info(PrintDialogStatus status) std::string get_print_status_info(PrintDialogStatus status)
{ {
switch(status) { switch(status) {
@ -4447,9 +4446,10 @@ void EditDevNameDialog::on_edit_name(wxCommandEvent &e)
Fit(); Fit();
} }
void ThumbnailPanel::set_thumbnail(wxImage img) void ThumbnailPanel::set_thumbnail(wxImage &img)
{ {
m_bitmap = img; m_brightness_value = get_brightness_value(img);
m_bitmap = img;
//Paint the background bitmap to the thumbnail bitmap with wxMemoryDC //Paint the background bitmap to the thumbnail bitmap with wxMemoryDC
wxMemoryDC dc; wxMemoryDC dc;
bitmap_with_background.Create(wxSize(m_bitmap.GetWidth(), m_bitmap.GetHeight())); bitmap_with_background.Create(wxSize(m_bitmap.GetWidth(), m_bitmap.GetHeight()));
@ -4468,7 +4468,7 @@ void EditDevNameDialog::on_edit_name(wxCommandEvent &e)
void ThumbnailPanel::render(wxDC& dc) { void ThumbnailPanel::render(wxDC& dc) {
if (wxGetApp().dark_mode()) { if (wxGetApp().dark_mode() && m_brightness_value < SHOW_BACKGROUND_BITMAP_PIXEL_THRESHOLD) {
#ifdef __WXMSW__ #ifdef __WXMSW__
wxMemoryDC memdc; wxMemoryDC memdc;
wxBitmap bmp(GetSize()); wxBitmap bmp(GetSize());

View File

@ -62,6 +62,30 @@ enum PrintFromType {
FROM_SDCARD_VIEW, FROM_SDCARD_VIEW,
}; };
static int get_brightness_value(wxImage image) {
wxImage grayImage = image.ConvertToGreyscale();
int width = grayImage.GetWidth();
int height = grayImage.GetHeight();
int totalLuminance = 0;
unsigned char alpha;
int num_none_transparent = 0;
for (int y = 0; y < height; y+=2) {
for (int x = 0; x < width; x+=2) {
alpha = image.GetAlpha(x, y);
if (alpha != 0) {
wxColour pixelColor = grayImage.GetRed(x, y);
totalLuminance += pixelColor.Red();
num_none_transparent = num_none_transparent + 1;
}
}
}
return totalLuminance / num_none_transparent;
}
class Material class Material
{ {
public: public:
@ -513,12 +537,12 @@ public:
void OnPaint(wxPaintEvent &event); void OnPaint(wxPaintEvent &event);
void PaintBackground(wxDC &dc); void PaintBackground(wxDC &dc);
void OnEraseBackground(wxEraseEvent &event); void OnEraseBackground(wxEraseEvent &event);
void set_thumbnail(wxImage img); void set_thumbnail(wxImage &img);
void render(wxDC &dc); void render(wxDC &dc);
private: private:
ScalableBitmap m_background_bitmap; ScalableBitmap m_background_bitmap;
wxBitmap bitmap_with_background; wxBitmap bitmap_with_background;
int m_brightness_value{ -1 };
}; };
}} // namespace Slic3r::GUI }} // namespace Slic3r::GUI

View File

@ -547,11 +547,19 @@ void PrintingTaskPanel::create_panel(wxWindow* parent)
void PrintingTaskPanel::paint(wxPaintEvent&) void PrintingTaskPanel::paint(wxPaintEvent&)
{ {
wxPaintDC dc(m_bitmap_thumbnail); wxPaintDC dc(m_bitmap_thumbnail);
if (wxGetApp().dark_mode()) if (wxGetApp().dark_mode()) {
dc.DrawBitmap(m_bitmap_background.bmp(), 0, 0); if (m_brightness_value > 0 && m_brightness_value < SHOW_BACKGROUND_BITMAP_PIXEL_THRESHOLD) {
dc.DrawBitmap(m_bitmap_background.bmp(), 0, 0);
dc.SetTextForeground(*wxBLACK);
}
else
dc.SetTextForeground(*wxWHITE);
}
else
dc.SetTextForeground(*wxBLACK);
dc.DrawBitmap(m_thumbnail_bmp_display, wxPoint(0, 0)); dc.DrawBitmap(m_thumbnail_bmp_display, wxPoint(0, 0));
dc.SetTextForeground(*wxBLACK);
dc.SetFont(Label::Body_12); dc.SetFont(Label::Body_12);
if (m_plate_index >= 0) { if (m_plate_index >= 0) {
wxString plate_id_str = wxString::Format("%d", m_plate_index); wxString plate_id_str = wxString::Format("%d", m_plate_index);
dc.DrawText(plate_id_str, wxPoint(4, 4)); dc.DrawText(plate_id_str, wxPoint(4, 4));
@ -1876,6 +1884,7 @@ void StatusPanel::on_webrequest_state(wxWebRequestEvent &evt)
img_list.insert(std::make_pair(m_request_url, img)); img_list.insert(std::make_pair(m_request_url, img));
wxImage resize_img = img.Scale(m_project_task_panel->get_bitmap_thumbnail()->GetSize().x, m_project_task_panel->get_bitmap_thumbnail()->GetSize().y, wxIMAGE_QUALITY_HIGH); wxImage resize_img = img.Scale(m_project_task_panel->get_bitmap_thumbnail()->GetSize().x, m_project_task_panel->get_bitmap_thumbnail()->GetSize().y, wxIMAGE_QUALITY_HIGH);
m_project_task_panel->set_thumbnail_img(resize_img); m_project_task_panel->set_thumbnail_img(resize_img);
m_project_task_panel->set_brightness_value(get_brightness_value(resize_img));
} }
if (obj) { if (obj) {
m_project_task_panel->set_plate_index(obj->m_plate_index); m_project_task_panel->set_plate_index(obj->m_plate_index);
@ -3021,6 +3030,7 @@ void StatusPanel::update_cloud_subtask(MachineObject *obj)
img = it->second; img = it->second;
wxImage resize_img = img.Scale(m_project_task_panel->get_bitmap_thumbnail()->GetSize().x, m_project_task_panel->get_bitmap_thumbnail()->GetSize().y); wxImage resize_img = img.Scale(m_project_task_panel->get_bitmap_thumbnail()->GetSize().x, m_project_task_panel->get_bitmap_thumbnail()->GetSize().y);
m_project_task_panel->set_thumbnail_img(resize_img); m_project_task_panel->set_thumbnail_img(resize_img);
m_project_task_panel->set_brightness_value(get_brightness_value(resize_img));
} }
if (this->obj) { if (this->obj) {
m_project_task_panel->set_plate_index(obj->m_plate_index); m_project_task_panel->set_plate_index(obj->m_plate_index);

View File

@ -204,6 +204,7 @@ private:
ProgressBar* m_gauge_progress; ProgressBar* m_gauge_progress;
Label* m_error_text; Label* m_error_text;
PrintingTaskType m_type; PrintingTaskType m_type;
int m_brightness_value{ -1 };
public: public:
void init_bitmaps(); void init_bitmaps();
@ -225,6 +226,7 @@ public:
void show_priting_use_info(bool show, wxString time = wxEmptyString, wxString weight = wxEmptyString); void show_priting_use_info(bool show, wxString time = wxEmptyString, wxString weight = wxEmptyString);
void show_profile_info(bool show, wxString profile = wxEmptyString); void show_profile_info(bool show, wxString profile = wxEmptyString);
void set_thumbnail_img(const wxBitmap& bmp); void set_thumbnail_img(const wxBitmap& bmp);
void set_brightness_value(int value) { m_brightness_value = value; }
void set_plate_index(int plate_idx = -1); void set_plate_index(int plate_idx = -1);
void market_scoring_show(); void market_scoring_show();
void market_scoring_hide(); void market_scoring_hide();
@ -244,7 +246,6 @@ public:
void set_star_count_dirty(bool dirty) { m_star_count_dirty = dirty; } void set_star_count_dirty(bool dirty) { m_star_count_dirty = dirty; }
void set_has_reted_text(bool has_rated); void set_has_reted_text(bool has_rated);
void paint(wxPaintEvent&); void paint(wxPaintEvent&);
}; };
class StatusBasePanel : public wxScrolledWindow class StatusBasePanel : public wxScrolledWindow