added png writing routine used in SM