Measurement of branching fractions and mass spectra of B -> K pi pi gamma