Formation of color centers in lead iodide perovskites: Self-trapping and defects in the bulk and surfaces