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

#ifndef DISABLE_DEPRECATED
	for (const KeyValue<int, CompatibilityTileData *> &E : compatibility_data) {
		memdelete(E.value);
	}
#endif 
	while (!source_ids.is_empty()) {
		remove_source(source_ids[0]);
	}
}
void TileSetSource::set_tile_set(const TileSet *p_tile_set) {
	tile_set = p_tile_set;
}
TileSet *TileSetSource::get_tile_set() const {
	return (TileSet *)tile_set;
}
void TileSetSource::reset_state() {
	tile_set = nullptr;
};
void TileSetSource::_bind_methods() {
	
	ClassDB::bind_method(D_METHOD("get_tiles_count"), &TileSetSource::get_tiles_count);
	ClassDB::bind_method(D_METHOD("get_tile_id", "index"), &TileSetSource::get_tile_id);
	ClassDB::bind_method(D_METHOD("has_tile", "atlas_coords"), &TileSetSource::has_tile);
	
	ClassDB::bind_method(D_METHOD("get_alternative_tiles_count", "atlas_coords"), &TileSetSource::get_alternative_tiles_count);
	ClassDB::bind_method(D_METHOD("get_alternative_tile_id", "atlas_coords", "index"), &TileSetSource::get_alternative_tile_id);
	ClassDB::bind_method(D_METHOD("has_alternative_tile", "atlas_coords", "alternative_tile"), &TileSetSource::has_alternative_tile);
}
void TileSetAtlasSource::set_tile_set(const TileSet *p_tile_set) {