#!/usr/bin/env python import os import OIL import shutil import time import multiprocessing indir = "/home/achin/tmp/test_output" #outdir = "/storage/home/achin/devel/Minecraft-Overviewer/output_earth/world-smooth_lighting_indexed" #indir = "/storage/home/achin/devel/Minecraft-Overviewer/output_dir/" outdir = "/home/achin/tmp/test_ouput_index" def getPngs(): for (dirpath, dirnames, filenames) in os.walk(indir): for file in filenames: if file.endswith(".png"): yield os.path.join(dirpath, file) def convert_image(png): outpng = png.replace(indir, outdir) dirname = os.path.dirname(outpng) if not os.path.exists(dirname): try: os.makedirs(dirname) except OSError: pass OIL.Image.load(png).save(outpng, indexed=True, palette_size=256) convert_image(next(getPngs())) count = 0 total = 8278.0 start = time.time() last_count = 0 pool = multiprocessing.Pool(processes=4) results = pool.imap_unordered(convert_image, getPngs()) for _ in results: count += 1 if count % 1000 == 0: cd = count - last_count td = time.time() - start print("Progress: %f. Converted %d tiles in %f seconds, or %f T/s" % ((count/total), cd, td, (cd/td))) last_count = count start = time.time() #for png in getPngs(): # convert_image(png) # #print("Converting %r to %r" % (png, outpng)) # count += 1 # if count % 100 == 0: # cd = count - last_count # td = time.time() - start # print("Progress: %f. Converted %d tiles in %f seconds, or %f T/s" % ((count/total), cd, td, (cd/td))) # last_count = count # start = time.time()