Refactor common code in M3ToXYZTransformer

Change-Id: I1ac6cfeaca28d8e2c3b8e63701fd5f615ba900a4