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

max_size = kv.key;
			max_count = kv.value;
		}
	}
	set_tile_size(max_size);
	
	for (const KeyValue<int, CompatibilityTileData *> &E : compatibility_data) {
		memdelete(E.value);
	}
	compatibility_data = HashMap<int, CompatibilityTileData *>();
}
Array TileSet::compatibility_tilemap_map(int p_tile_id, Vector2i p_coords, bool p_flip_h, bool p_flip_v, bool p_transpose) {
	Array cannot_convert_array;
	cannot_convert_array.push_back(TileSet::INVALID_SOURCE);
	cannot_convert_array.push_back(TileSetAtlasSource::INVALID_ATLAS_COORDS);
	cannot_convert_array.push_back(TileSetAtlasSource::INVALID_TILE_ALTERNATIVE);
	if (!compatibility_tilemap_mapping.has(p_tile_id)) {
		return cannot_convert_array;
	}
	int tile_mode = compatibility_tilemap_mapping_tile_modes[p_tile_id];
	switch (tile_mode) {
		case COMPATIBILITY_TILE_MODE_SINGLE_TILE: {
			Array a;
			a.push_back(p_flip_h);
			a.push_back(p_flip_v);
			a.push_back(p_transpose);
			return compatibility_tilemap_mapping[p_tile_id][a];
		}
		case COMPATIBILITY_TILE_MODE_AUTO_TILE:
			return cannot_convert_array;