From 35c105e796c0f4d08b5ea58d31d7eb4a37273755 Mon Sep 17 00:00:00 2001 From: Saracen Date: Mon, 6 Nov 2023 07:45:02 +0000 Subject: [PATCH] Fix generating terrain icon with certain image formats. --- scene/resources/tile_set.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 7b4080517f9d..422cd4fa2c06 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -1839,20 +1839,25 @@ Vector>> TileSet::generate_terrains_icons(Size2i p_size) { // Generate the icons. for (int terrain_set = 0; terrain_set < get_terrain_sets_count(); terrain_set++) { for (int terrain = 0; terrain < get_terrains_count(terrain_set); terrain++) { - Ref image; - image.instantiate(); + Ref dst_image; + dst_image.instantiate(); if (counts[terrain_set][terrain].count > 0) { // Get the best tile. - Ref texture = counts[terrain_set][terrain].texture; + Ref src_texture = counts[terrain_set][terrain].texture; + ERR_FAIL_COND_V(src_texture.is_null(), output); + Ref src_image = src_texture->get_image(); + ERR_FAIL_COND_V(src_image.is_null(), output); Rect2i region = counts[terrain_set][terrain].region; - image->initialize_data(region.size.x, region.size.y, false, Image::FORMAT_RGBA8); - image->blit_rect(texture->get_image(), region, Point2i()); - image->resize(p_size.x, p_size.y, Image::INTERPOLATE_NEAREST); + + dst_image->initialize_data(region.size.x, region.size.y, false, src_image->get_format()); + dst_image->blit_rect(src_image, region, Point2i()); + dst_image->convert(Image::FORMAT_RGBA8); + dst_image->resize(p_size.x, p_size.y, Image::INTERPOLATE_NEAREST); } else { - image->initialize_data(1, 1, false, Image::FORMAT_RGBA8); - image->set_pixel(0, 0, get_terrain_color(terrain_set, terrain)); + dst_image->initialize_data(1, 1, false, Image::FORMAT_RGBA8); + dst_image->set_pixel(0, 0, get_terrain_color(terrain_set, terrain)); } - Ref icon = ImageTexture::create_from_image(image); + Ref icon = ImageTexture::create_from_image(dst_image); icon->set_size_override(p_size); output.write[terrain_set].write[terrain] = icon; }