write createHDR function