fix off-by-one error when calculating color values