aboutsummaryrefslogtreecommitdiff
path: root/src/conversion/czi/convertJxrs.py
blob: d19a59af39e1730b471e62de5879a98d48f6d0ab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from concurrent.futures import ThreadPoolExecutor
from subprocess import check_call
from glob import glob
from sys import argv

totalFiles = 0
coutner = 0


def convertjxrs(filename):
    global counter
    global totalFiles
    asTif = filename.rsplit('.',1)[0] + ".tif"
    check_call(['./JxrDecApp', "-i", filename, "-o", asTif])
    check_call(['convert', asTif, filename.rsplit('.',1)[0] + ".png"])
    check_call(['rm', filename, asTif])
    counter += 1
    print (f"> Processed File: {counter}/{totalFiles}   :   {filename}  -->  {filename.rsplit('.',1)[0]}.png")


if __name__ == "__main__":

	if (len(argv) != 2):
		print("\nMissing Argument!\n\nUsage:\npython3 convertJxrs.py <DirectoryContainingJxrs>")
		exit(0)
	else:
	    print("=========== BEGIN JXR CONVERSION ===========")
	    print ('Files Dir: ' + argv[1] + '\n')

	    filenames = glob(argv[1] + 'data-*.jxr')
	    counter = 0
	    totalFiles = len(filenames)

	    pool = ThreadPoolExecutor(5)
	    for f in pool.map(convertjxrs, filenames):
	        pass
	    pool.shutdown(True)
	    print("=========== FINISH JXR CONVERSION ===========")