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 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 export_fonts(params, cfg, zip_file, graphics_chunks_handler, missing_char='?', texture_dimensions=(256, 256)): logger = logging.getLogger() logger.info('Exporting fonts') partitions_map = cfg.GRAPHICS_PARTITIONS_MAP palette = cfg.GRAPHICS_PALETTE_MAP[...] start, count = partitions_map['font'] font_manager = pywolf.graphics.FontManager(graphics_chunks_handler, palette, start, count) for i, font in enumerate(font_manager): height = font.height assert texture_dimensions == (256, 256) assert max(font.widths) * 16 <= texture_dimensions[0] assert height * 16 <= texture_dimensions[1] image_path = 'fonts/fontImage_0_{}.tga'.format(height) info_path = 'fonts/fontImage_{}.dat'.format(height) logger.info('Font [%d/%d]: %r, %r', (i + 1), count, image_path, info_path) image = Image.new('RGB', texture_dimensions) info_stream = io.BytesIO() image_path_ascii = image_path.encode('ascii') for j, glyph_image in enumerate(font.images): if glyph_image is None and missing_char is not None: glyph_image = font.images[ord(missing_char)] width = font.widths[ord(missing_char)] else: width = font.widths[j] origin = (((j % 16) * 16), ((j // 16) * 16)) if glyph_image is not None: image.paste(glyph_image, origin) stream_pack(info_stream, '<7l4fL32s', height, # height 0, # top height, # bottom width, # pitch width, # xSkip width, # imageWidth height, # imageHeight (origin[0] / texture_dimensions[0]), # s (origin[1] / texture_dimensions[1]), # t ((origin[0] + width) / texture_dimensions[0]), # s2 ((origin[1] + height) / texture_dimensions[1]), # t2 0, # glyph image_path_ascii) # shaderName stream_pack(info_stream, '<f64s', 1.0, # glyphScale info_path.encode('ascii')) # name zip_file.writestr(info_path, info_stream.getbuffer()) pixels_bgr = bytes(x for pixel in image.transpose(Image.FLIP_TOP_BOTTOM).getdata() for x in reversed(pixel)) font_stream = io.BytesIO() write_targa_bgrx(font_stream, texture_dimensions, 24, pixels_bgr) zip_file.writestr(image_path, font_stream.getbuffer()) logger.info('Done') _sep()
def to_stream(self, chunk_stream): stream_pack(chunk_stream, '<H', self.height) stream_pack_array(chunk_stream, '<H', self.locations) stream_pack_array(chunk_stream, '<B', self.widths)
def to_stream(self, stream): stream_pack(stream, '<HH', self.left, self.right) stream_pack_array(stream, '<H', self.offsets)
def to_stream(self, stream): stream_pack_array(stream, '<L', self.plane_offsets) stream_pack_array(stream, '<H', self.plane_sizes) stream_pack(stream, '<HH', *self.dimensions) stream_pack(stream, '<16s', self.name.encode('ascii'))
def to_stream(self, stream): stream_pack_array(stream, '<L', self.plane_offsets) stream_pack_array(stream, '<H', self.plane_sizes) stream_pack(stream, '<HH', *self.size) stream_pack(stream, '<16s', self.name.encode('ascii'))
def to_stream(self, stream): stream_pack(stream, '<H', len(self.events)) for event in self.events: stream_pack(stream, '<BBH', event)