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

ERR_FAIL_COND(p_new_source_id < 0);
	ERR_FAIL_COND_MSG(!sources.has(p_source_id), vformat("Cannot change TileSet atlas source ID. No tileset atlas source with id %d.", p_source_id));
	if (p_source_id == p_new_source_id) {
		return;
	}
	ERR_FAIL_COND_MSG(sources.has(p_new_source_id), vformat("Cannot change TileSet atlas source ID. Another atlas source exists with id %d.", p_new_source_id));
	sources[p_new_source_id] = sources[p_source_id];
	sources.erase(p_source_id);
	source_ids.erase(p_source_id);
	source_ids.push_back(p_new_source_id);
	source_ids.sort();
	_compute_next_source_id();
	terrains_cache_dirty = true;
	emit_changed();
}
bool TileSet::has_source(int p_source_id) const {
	return sources.has(p_source_id);
}
Ref<TileSetSource> TileSet::get_source(int p_source_id) const {
	ERR_FAIL_COND_V_MSG(!sources.has(p_source_id), nullptr, vformat("No TileSet atlas source with id %d.", p_source_id));
	return sources[p_source_id];
}
int TileSet::get_source_count() const {
	return source_ids.size();
}
int TileSet::get_source_id(int p_index) const {