### 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)

terrain_meshes.clear();
	terrain_peering_bits_meshes.clear();
	per_terrain_pattern_tiles.clear();
	terrains_cache_dirty = true;
	
	navigation_layers.clear();
	custom_data_layers.clear();
	custom_data_layers_by_name.clear();
	
	source_level_proxies.clear();
	coords_level_proxies.clear();
	alternative_level_proxies.clear();
#ifndef DISABLE_DEPRECATED
	for (const KeyValue<int, CompatibilityTileData *> &E : compatibility_data) {
		memdelete(E.value);
	}
	compatibility_data.clear();
#endif 
	while (!source_ids.is_empty()) {
		remove_source(source_ids[0]);
	}
	tile_shape = TILE_SHAPE_SQUARE;
	tile_layout = TILE_LAYOUT_STACKED;
	tile_offset_axis = TILE_OFFSET_AXIS_HORIZONTAL;
	tile_size = Size2i(16, 16);
}
const Vector2i TileSetSource::INVALID_ATLAS_COORDS = Vector2i(-1, -1);
const int TileSetSource::INVALID_TILE_ALTERNATIVE = -1;
#ifndef DISABLE_DEPRECATED
void TileSet::_compatibility_conversion() {