Merge "Use PwriteFully and write image header last"