Dipole- and charge transfer contributions to the work function change of semiconducting thin films: experiment and theory