The different star formation histories of blue and red spiral and elliptical galaxies