Fix convertToFormat function (more templates + fix unpremult)