A three-image algorithm for hard x-ray grating interferometry