def write(self, fptr):
self._validate(writing=True)<EOL>bytes_per_row = sum(self.bits_per_component) / <NUM_LIT:8><EOL>bytes_per_palette = bytes_per_row * self.palette.shape[<NUM_LIT:0>]<EOL>box_length = <NUM_LIT:8> + <NUM_LIT:3> + self.palette.shape[<NUM_LIT:1>] + bytes_per_palette<EOL>write_buffer = struct.pack('<STR_LIT>', int(box_length), b'<STR_LIT>')<EOL>fptr.write(write_buffer)<EOL>write_buffer = struct.pack('<STR_LIT>', self.palette.shape[<NUM_LIT:0>],<EOL>self.palette.shape[<NUM_LIT:1>])<EOL>fptr.write(write_buffer)<EOL>bps_signed = [x - <NUM_LIT:1> for x in self.bits_per_component]<EOL>write_buffer = struct.pack('<STR_LIT:>>' + '<STR_LIT:B>' * self.palette.shape[<NUM_LIT:1>],<EOL>*bps_signed)<EOL>fptr.write(write_buffer)<EOL>fptr.write(memoryview(self.palette))<EOL>
Write a Palette box to file.