The effect of charge trapping on the spectrometric performance of HgI2 gamma-ray detectors