Avoid some repeated code for PNG->YUV and YUV->PNG.