Transforming complex space: a general strategy to compensate loss of transformation optical media