From ef8d04ba6e796245b40657472bd5c532f02023b1 Mon Sep 17 00:00:00 2001 From: Christoffer Sundbom Date: Sun, 20 Oct 2024 02:26:26 +0200 Subject: [PATCH 1/5] fixed the alpha rounde project icon --- editor/project_manager/project_list.cpp | 42 ++++++++++++++----------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/editor/project_manager/project_list.cpp b/editor/project_manager/project_list.cpp index 541ab01e6268..4bd6ff8e0328 100644 --- a/editor/project_manager/project_list.cpp +++ b/editor/project_manager/project_list.cpp @@ -495,24 +495,30 @@ void ProjectList::_update_icons_async() { } void ProjectList::_load_project_icon(int p_index) { - Item &item = _projects.write[p_index]; - - Ref default_icon = get_editor_theme_icon(SNAME("DefaultProjectIcon")); - Ref icon; - if (!item.icon.is_empty()) { - Ref img; - img.instantiate(); - Error err = img->load(item.icon.replace_first("res://", item.path + "/")); - if (err == OK) { - img->resize(default_icon->get_width(), default_icon->get_height(), Image::INTERPOLATE_LANCZOS); - icon = ImageTexture::create_from_image(img); - } - } - if (icon.is_null()) { - icon = default_icon; - } - - item.control->set_project_icon(icon); + Item &item = _projects.write[p_index]; + + Ref default_icon = get_editor_theme_icon(SNAME("DefaultProjectIcon")); + Ref icon; + if (!item.icon.is_empty()) { + Ref img; + img.instantiate(); + Error err = img->load(item.icon.replace_first("res://", item.path + "/")); + if (err == OK) { + // Ensure the image is in the correct format. + img->convert(Image::FORMAT_RGBA8); + // Premultiply alpha before resizing. + img->premultiply_alpha(); + img->resize(default_icon->get_width(), default_icon->get_height(), Image::INTERPOLATE_CUBIC); + // Unpremultiply alpha after resizing. + //img->unpremultiply_alpha(); + icon = ImageTexture::create_from_image(img); + } + } + if (icon.is_null()) { + icon = default_icon; + } + + item.control->set_project_icon(icon); } // Project list updates. From 830516b463b45f8599594dd602378c79c8f166e6 Mon Sep 17 00:00:00 2001 From: Christoffer Sundbom Date: Sun, 20 Oct 2024 02:27:18 +0200 Subject: [PATCH 2/5] cleaned up the code --- editor/project_manager/project_list.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/editor/project_manager/project_list.cpp b/editor/project_manager/project_list.cpp index 4bd6ff8e0328..92ccd3aeb157 100644 --- a/editor/project_manager/project_list.cpp +++ b/editor/project_manager/project_list.cpp @@ -504,13 +504,9 @@ void ProjectList::_load_project_icon(int p_index) { img.instantiate(); Error err = img->load(item.icon.replace_first("res://", item.path + "/")); if (err == OK) { - // Ensure the image is in the correct format. img->convert(Image::FORMAT_RGBA8); - // Premultiply alpha before resizing. img->premultiply_alpha(); img->resize(default_icon->get_width(), default_icon->get_height(), Image::INTERPOLATE_CUBIC); - // Unpremultiply alpha after resizing. - //img->unpremultiply_alpha(); icon = ImageTexture::create_from_image(img); } } From 7f1f828af679b745751a448d6da0da61fee39279 Mon Sep 17 00:00:00 2001 From: Christoffer Sundbom Date: Sun, 20 Oct 2024 02:37:25 +0200 Subject: [PATCH 3/5] got a better result with another function --- editor/project_manager/project_list.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editor/project_manager/project_list.cpp b/editor/project_manager/project_list.cpp index 92ccd3aeb157..ea0a426277ef 100644 --- a/editor/project_manager/project_list.cpp +++ b/editor/project_manager/project_list.cpp @@ -505,7 +505,7 @@ void ProjectList::_load_project_icon(int p_index) { Error err = img->load(item.icon.replace_first("res://", item.path + "/")); if (err == OK) { img->convert(Image::FORMAT_RGBA8); - img->premultiply_alpha(); + img->fix_alpha_edges(); img->resize(default_icon->get_width(), default_icon->get_height(), Image::INTERPOLATE_CUBIC); icon = ImageTexture::create_from_image(img); } From c1e070b9f6f7b78accb33612b0edfbb3d7b52401 Mon Sep 17 00:00:00 2001 From: Christoffer Sundbom Date: Sun, 20 Oct 2024 03:23:21 +0200 Subject: [PATCH 4/5] style fix --- editor/project_manager/project_list.cpp | 42 ++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/editor/project_manager/project_list.cpp b/editor/project_manager/project_list.cpp index ea0a426277ef..a5984db0471a 100644 --- a/editor/project_manager/project_list.cpp +++ b/editor/project_manager/project_list.cpp @@ -494,28 +494,28 @@ void ProjectList::_update_icons_async() { set_process(true); } -void ProjectList::_load_project_icon(int p_index) { - Item &item = _projects.write[p_index]; - - Ref default_icon = get_editor_theme_icon(SNAME("DefaultProjectIcon")); - Ref icon; - if (!item.icon.is_empty()) { - Ref img; - img.instantiate(); - Error err = img->load(item.icon.replace_first("res://", item.path + "/")); - if (err == OK) { - img->convert(Image::FORMAT_RGBA8); + void ProjectList::_load_project_icon(int p_index) { + Item &item = _projects.write[p_index]; + + Ref default_icon = get_editor_theme_icon(SNAME("DefaultProjectIcon")); + Ref icon; + if (!item.icon.is_empty()) { + Ref img; + img.instantiate(); + Error err = img->load(item.icon.replace_first("res://", item.path + "/")); + if (err == OK) { + img->convert(Image::FORMAT_RGBA8); img->fix_alpha_edges(); - img->resize(default_icon->get_width(), default_icon->get_height(), Image::INTERPOLATE_CUBIC); - icon = ImageTexture::create_from_image(img); - } - } - if (icon.is_null()) { - icon = default_icon; - } - - item.control->set_project_icon(icon); -} + img->resize(default_icon->get_width(), default_icon->get_height(), Image::INTERPOLATE_CUBIC); + icon = ImageTexture::create_from_image(img); + } + } + if (icon.is_null()) { + icon = default_icon; + } + + item.control->set_project_icon(icon); + } // Project list updates. From 8892b7e34d0aa119ebec1698767e3c37b97de93f Mon Sep 17 00:00:00 2001 From: Christoffer Sundbom Date: Sun, 20 Oct 2024 03:29:31 +0200 Subject: [PATCH 5/5] style fix --- editor/project_manager/project_list.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/editor/project_manager/project_list.cpp b/editor/project_manager/project_list.cpp index a5984db0471a..088444c09710 100644 --- a/editor/project_manager/project_list.cpp +++ b/editor/project_manager/project_list.cpp @@ -494,7 +494,7 @@ void ProjectList::_update_icons_async() { set_process(true); } - void ProjectList::_load_project_icon(int p_index) { +void ProjectList::_load_project_icon(int p_index) { Item &item = _projects.write[p_index]; Ref default_icon = get_editor_theme_icon(SNAME("DefaultProjectIcon")); @@ -515,7 +515,7 @@ void ProjectList::_update_icons_async() { } item.control->set_project_icon(icon); - } +} // Project list updates.