Refactor PngWriter._build_image_data() and its callers