def export_textures(params, cfg, zip_file, vswap_chunks_handler): logger = logging.getLogger() logger.info('Exporting textures') start = 0 count = vswap_chunks_handler.sprites_start - start texture_manager = pywolf.graphics.TextureManager(vswap_chunks_handler, cfg.GRAPHICS_PALETTE_MAP[...], cfg.SPRITE_DIMENSIONS, start, count) for i, texture in enumerate(texture_manager): name = cfg.TEXTURE_NAMES[i >> 1] path = 'textures/{}_wall/{}__{}.tga'.format(params.short_name, name, (i & 1)) logger.info('Texture [%d/%d]: %r', (i + 1), count, path) top_bottom_rgb_image = texture.image.transpose(Image.FLIP_TOP_BOTTOM).convert('RGB') pixels_bgr = bytes(x for pixel in top_bottom_rgb_image.getdata() for x in reversed(pixel)) texture_stream = io.BytesIO() write_targa_bgrx(texture_stream, cfg.TEXTURE_DIMENSIONS, 24, pixels_bgr) zip_file.writestr(path, texture_stream.getbuffer()) palette = cfg.GRAPHICS_PALETTE for i, color in enumerate(palette): path = 'textures/{}_palette/color_0x{:02x}.tga'.format(params.short_name, i) logger.info('Texture palette color [%d/%d]: %r, (0x%02X, 0x%02X, 0x%02X)', (i + 1), len(palette), path, *color) image = build_color_image(cfg.TEXTURE_DIMENSIONS, color) top_bottom_rgb_image = image.transpose(Image.FLIP_TOP_BOTTOM).convert('RGB') pixels_bgr = bytes(x for pixel in top_bottom_rgb_image.getdata() for x in reversed(pixel)) texture_stream = io.BytesIO() write_targa_bgrx(texture_stream, cfg.TEXTURE_DIMENSIONS, 24, pixels_bgr) zip_file.writestr(path, texture_stream.getbuffer()) logger.info('Done') _sep()
def export_tile8(params, cfg, zip_file, graphics_chunks_handler): logger = logging.getLogger() logger.info('Exporting tile8') partitions_map = cfg.GRAPHICS_PARTITIONS_MAP palette_map = cfg.GRAPHICS_PALETTE_MAP start, count = partitions_map['tile8'] tile8_manager = pywolf.graphics.Tile8Manager(graphics_chunks_handler, palette_map, start, count) for i, tile8 in enumerate(tile8_manager): path = 'gfx/{}/tile8__{}.tga'.format(params.short_name, cfg.TILE8_NAMES[i]) logger.info('Tile8 [%d/%d]: %r', (i + 1), count, path) top_bottom_rgb_image = tile8.image.transpose(Image.FLIP_TOP_BOTTOM).convert('RGB') pixels_bgr = bytes(x for pixel in top_bottom_rgb_image.getdata() for x in reversed(pixel)) tile8_stream = io.BytesIO() write_targa_bgrx(tile8_stream, tile8.dimensions, 24, pixels_bgr) zip_file.writestr(path, tile8_stream.getbuffer()) logger.info('Done') _sep()
def export_sprites(params, cfg, zip_file, vswap_chunks_handler): logger = logging.getLogger() logger.info('Exporting sprites') start = vswap_chunks_handler.sprites_start count = vswap_chunks_handler.sounds_start - start sprite_manager = pywolf.graphics.SpriteManager(vswap_chunks_handler, cfg.GRAPHICS_PALETTE_MAP[...], cfg.SPRITE_DIMENSIONS, start, count) for i, sprite in enumerate(sprite_manager): name = cfg.SPRITE_NAMES[i] path = 'sprites/{}/{}.tga'.format(params.short_name, name) logger.info('Sprite [%d/%d]: %r', (i + 1), count, path) top_bottom_rgba_image = sprite.image.transpose(Image.FLIP_TOP_BOTTOM).convert('RGBA') pixels_bgra = bytes(x for pixel in top_bottom_rgba_image.getdata() for x in [pixel[2], pixel[1], pixel[0], pixel[3]]) sprite_stream = io.BytesIO() write_targa_bgrx(sprite_stream, cfg.SPRITE_DIMENSIONS, 32, pixels_bgra) zip_file.writestr(path, sprite_stream.getbuffer()) logger.info('Done') _sep()
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()