def write_targa_bgrx(stream, dimensions, depth_bits, pixels_bgrx): stream_pack(stream, '<BBBHHBHHHHBB', 0, # id_length 0, # colormap_type 2, # image_type: BGR(A) 0, # colormap_index 0, # colormap_length 0, # colormap_size 0, # x_origin 0, # y_origin dimensions[0], # width dimensions[1], # height depth_bits, # pixel_size: 24 (BGR) | 32 (BGRA) 0x00) # attributes stream_write(stream, pixels_bgrx)
def write_targa_bgrx(stream, size, depth_bits, pixels_bgrx): stream_pack(stream, '<BBBHHBHHHHBB', 0, # id_length 0, # colormap_type 2, # image_type: BGR(A) 0, # colormap_index 0, # colormap_length 0, # colormap_size 0, # x_origin 0, # y_origin size[0], # width size[1], # height depth_bits, # pixel_size: 24 (BGR) | 32 (BGRA) 0x00) # attributes stream_write(stream, pixels_bgrx)
def jascpal_write(stream, palette): assert palette stream_write(stream, 'JASC-PAL\n') stream_write(stream, '0100\n') stream_write(stream, '{:d}\n'.format(len(palette))) for r, g, b in palette: assert 0x00 <= r <= 0xFF assert 0x00 <= g <= 0xFF assert 0x00 <= b <= 0xFF stream_write(stream, '{:d} {:d} {:d}\n'.format(r, g, b))
def to_stream(self, stream): self.header.to_stream(stream) stream_write(stream, self.events)
def to_stream(self, stream): stream_write(stream, self.to_bytes())