### Godot version

5ee983188de97ae027f9b9c1443438063f708a7e

### System information

Windows 11

### Issue description

Godot editor will throw an error and fail to generate preview icons for terrain tiles which use a base image which is not RGBA8 format.
`core\io\image.cpp:2788 - Condition "format != p_src->format" is true.`

### Steps to reproduce

- Import a non-RGBA8 image into Godot.
- Create a TileMap
- Create an associated TileSet
- Create a terrain for this tileset
- Add the image as an atlas
- Go to the paint tab
- Paint the terrain on the TileSet
- An error will occur any time terrains are edited in the TileSet editor or selected in the TileMap editor terrain tab.

### Minimal reproduction project

[tileset_terrain_bug.zip](https://github.com/godotengine/godot/files/13264213/tileset_terrain_bug.zip)

ClassDB::bind_method(D_METHOD("remove_coords_level_tile_proxy", "source_from", "coords_from"), &TileSet::remove_coords_level_tile_proxy);
	ClassDB::bind_method(D_METHOD("set_alternative_level_tile_proxy", "source_from", "coords_from", "alternative_from", "source_to", "coords_to", "alternative_to"), &TileSet::set_alternative_level_tile_proxy);
	ClassDB::bind_method(D_METHOD("get_alternative_level_tile_proxy", "source_from", "coords_from", "alternative_from"), &TileSet::get_alternative_level_tile_proxy);
	ClassDB::bind_method(D_METHOD("has_alternative_level_tile_proxy", "source_from", "coords_from", "alternative_from"), &TileSet::has_alternative_level_tile_proxy);
	ClassDB::bind_method(D_METHOD("remove_alternative_level_tile_proxy", "source_from", "coords_from", "alternative_from"), &TileSet::remove_alternative_level_tile_proxy);
	ClassDB::bind_method(D_METHOD("map_tile_proxy", "source_from", "coords_from", "alternative_from"), &TileSet::map_tile_proxy);
	ClassDB::bind_method(D_METHOD("cleanup_invalid_tile_proxies"), &TileSet::cleanup_invalid_tile_proxies);
	ClassDB::bind_method(D_METHOD("clear_tile_proxies"), &TileSet::clear_tile_proxies);
	
	ClassDB::bind_method(D_METHOD("add_pattern", "pattern", "index"), &TileSet::add_pattern, DEFVAL(-1));
	ClassDB::bind_method(D_METHOD("get_pattern", "index"), &TileSet::get_pattern, DEFVAL(-1));
	ClassDB::bind_method(D_METHOD("remove_pattern", "index"), &TileSet::remove_pattern);
	ClassDB::bind_method(D_METHOD("get_patterns_count"), &TileSet::get_patterns_count);
	ADD_GROUP("Rendering", "");
	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "uv_clipping"), "set_uv_clipping", "is_uv_clipping");
	ADD_ARRAY("occlusion_layers", "occlusion_layer_");
	ADD_GROUP("", "");
	ADD_ARRAY("physics_layers", "physics_layer_");
	ADD_ARRAY("terrain_sets", "terrain_set_");
	ADD_ARRAY("navigation_layers", "navigation_layer_");
	ADD_ARRAY("custom_data_layers", "custom_data_layer_");
	
	BIND_ENUM_CONSTANT(TILE_SHAPE_SQUARE);
	BIND_ENUM_CONSTANT(TILE_SHAPE_ISOMETRIC);
	BIND_ENUM_CONSTANT(TILE_SHAPE_HALF_OFFSET_SQUARE);
	BIND_ENUM_CONSTANT(TILE_SHAPE_HEXAGON);
	BIND_ENUM_CONSTANT(TILE_LAYOUT_STACKED);
	BIND_ENUM_CONSTANT(TILE_LAYOUT_STACKED_OFFSET);
	BIND_ENUM_CONSTANT(TILE_LAYOUT_STAIRS_RIGHT);
	BIND_ENUM_CONSTANT(TILE_LAYOUT_STAIRS_DOWN);