Density-functional theory investigation of energy gaps and optical properties of Hg1−xCdxTe and In1−xGaxAs