This repository has been archived by the owner on Sep 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
183 lines (179 loc) · 8.45 KB
/
test.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#! /usr/bin/env python3
import os
import sys
import subprocess
argv = sys.argv
pixels = 4
psi = 1. / 3.
rot = 0
if(len(argv) < 4 and (argv[2] != "move")):
print("no much argments.")
elif(argv[2] == "match"):
root0, ext0 = os.path.splitext(argv[3])
root1, ext1 = os.path.splitext(argv[4])
vboxd = vboxs = nsub = nemph = 4
if(len(argv) > 5):
vboxd = int(argv[5])
if(len(argv) > 6):
vboxs = int(argv[6])
if(len(argv) > 7):
nsub = int(argv[7])
if(len(argv) > 8):
nemph = int(argv[8])
subprocess.call([argv[1], argv[2], str(nsub), str(nemph), str(vboxd), str(vboxs), root0 + ".ppm", root1 + ".ppm", root0 + "-bump.ppm", root1 + "-bump.ppm", "match-" + root0 + "-" + root1])
subprocess.call(["ffmpeg", "-loop", "1", "-i", "match-" + root0 + "-" + root1 + "-%d-" + str(nemph) + ".ppm", "-framerate", "6", "-an", "-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2", "-vcodec", "libx264", "-pix_fmt", "yuv420p", "-t", "12", root0 + "-" + root1 + ".mp4"])
elif(argv[2] == "cat" or argv[2] == "catr" or argv[2] == "catb" or argv[2] == "catbr"):
cmd = [argv[1], argv[2]]
if(argv[2] == "cat" or argv[2] == "catb"):
cmd[1] = "catr"
elif(argv[2] == "catr" or argv[2] == "catbr"):
cmd[1] = "cat"
for s in argv[3:]:
r, e = os.path.splitext(s)
if(e != ".ppm"):
subprocess.call(["convert", s, "-compress", "none", r + ".ppm"])
if(argv[2] == "catb"):
cmd.append(r + "-bump.ppm")
elif(argv[2] == "catr"):
cmd.append(r + "-represent.ppm")
elif(argv[2] == "catbr"):
cmd.append(r + "-bump-represent.ppm")
else:
cmd.append(r + ".ppm")
subprocess.call(cmd)
elif(argv[2] == "seinsq" or argv[2] == "seinpdf"):
files = []
if(argv[2] == "seinsq"):
exts = argv[4:]
else:
exts = ["pdf"]
for root, dirs, filesw in os.walk(argv[3]):
for f in filesw:
r, e = os.path.splitext(f)
for s in exts:
if(e.lower() == "." + s.lower()):
files.append(os.path.join(root, f))
break
ex0 = len(files)
try:
ex0 = min(ex0, int(argv[- 1]))
except:
pass
ex = len(str(ex0))
pixels = int(pow(float(ex0), 2. / 3.))
if(argv[2] == "seinsq"):
for t in range(0, ex0):
subprocess.call(["convert", files[t], "-resize", str(pixels) + "x" + str(pixels) + "!", "-compress", "none", "sein-" + str(t).zfill(ex) + ".ppm"])
else:
for t in range(0, ex0):
subprocess.call(["pdftopng", files[t], "seinpdf-" + str(t).zfill(ex)])
elif(argv[2] == "move"):
curdir = os.path.basename(os.getcwd())
subprocess.call(["mv", "predg.ppm", curdir + ".ppm"])
s = 0
while(True):
f = subprocess.call(["mv", "predg-" + str(s) + ".ppm", curdir + "-" + str(s) + ".ppm"])
s += 1
if(f != 0):
break
elif(argv[2] == "mprep"):
for line in argv[4:]:
subprocess.call(["sh", "-c", argv[1] + " - " + line + " < " + argv[3]])
elif(argv[2] == "mapply"):
for line in argv[4:]:
subprocess.call(["sh", "-c", argv[1] + " i " + line + " < " + argv[3]])
elif(argv[2] == "tilecat" or argv[2] == "tilecatb" or argv[2] == "tilecatr" or argv[2] == "tilecatbr"):
pixels = int(argv[3])
cmd = ["montage"]
t = 0
for line in sys.stdin:
if(len(line) <= 2):
cmd.extend(["-tile", str(pixels) + "x" + str(pixels), "-geometry", "+0+0", "tilecat-" + str(t) + ".png"])
subprocess.call(cmd)
cmd = ["montage"]
t += 1
elif(argv[2] == "tilecatb"):
cmd.append(line[:- 1 - len("-bump.ppm")] + ".ppm")
elif(argv[2] == "tilecatr"):
cmd.append(line[:- 1 - len("-represent.ppm")] + ".ppm")
elif(argv[2] == "tilecatbr"):
cmd.append(line[:- 1 - len("-bump-represent.ppm")] + ".ppm")
else:
cmd.append(line[:- 1])
cmd.extend(["-tile", str(pixels) + "x" + str(pixels), "-geometry", "+0+0", "tilecat-" + str(t) + ".png"])
subprocess.call(cmd)
elif(argv[2] == "tile"):
idx = 3
try:
pixels = argv[3]
idx += 1
except:
pass
cmd = ["montage"]
cmd.extend(argv[idx:])
cmd.extend(["-tile", pixels, "-geometry", "+0+0", "tile.png"])
subprocess.call(cmd)
elif(argv[2] == "i2i"):
idx = 3
try:
pixels = int(argv[3])
idx += 1
except:
pass
for line in argv[idx:]:
root, ext = os.path.splitext(line)
if(ext != ".ppm" and argv[2] != "prep" and argv[2] != "prepsq"):
subprocess.call(["convert", line, "-compress", "none", root + ".ppm"])
for linex in argv[idx:]:
rootx, extx = os.path.splitext(linex)
for liney in argv[idx:]:
if(linex == liney): continue
rooty, exty = os.path.splitext(liney)
subprocess.call([argv[1], "recolor3", str(pixels), rooty + ".ppm", rootx + ".ppm", rooty + "-" + rootx + "-i2i0.ppm"])
subprocess.call([argv[1], "recolor", str(pixels), rootx + ".ppm", rooty + ".ppm", rooty + "-" + rootx + "-i2i1.ppm", "2.5"])
subprocess.call([argv[1], "recolor3", str(pixels), rooty + "-" + rootx + "-i2i1.ppm", rooty + "-" + rootx + "-i2i0.ppm", rooty + "-" + rootx + "-i2i.ppm"])
subprocess.call([argv[1], "recolor2", str(pixels), rooty + "-" + rootx + "-i2i.ppm", rooty + "-" + rootx + "-i2i--02.ppm", "-.02"])
else:
for line in argv[3:]:
try:
pixels = int(line)
continue
except:
root, ext = os.path.splitext(line)
if(ext != ".ppm" and argv[2] != "prep" and argv[2] != "prepsq"):
subprocess.call(["convert", line, "-compress", "none", root + ".ppm"])
if(argv[2] == "represent" or argv[2] == "flarge" or argv[2] == "blink" or argv[2] == "enlarge" or argv[2] == "shrink" or argv[2] == "sharpen" or argv[2] == "limit" or argv[2] == "bit" or argv[2] == "rgb2xyz" or argv[2] == "xyz2rgb"):
subprocess.call([argv[1], argv[2], root + ".ppm", root + "-" + argv[2] + ".ppm", str(pixels), str(rot)])
elif(argv[2] == "bump" or argv[2] == "blur" or argv[2] == "collect"):
subprocess.call([argv[1], argv[2], root + ".ppm", root + "-" + argv[2] + ".ppm", "1", str(pixels)])
elif(argv[2] == "obj"):
subprocess.call([argv[1], argv[2], root + "-bump.ppm", root + ".obj"])
elif(argv[2] == "jps"):
subprocess.call([argv[1], "tilt", "1", "4", str(psi), root + ".ppm", root + "-bump.ppm", root + "-L.ppm"])
subprocess.call([argv[1], "tilt", "-1", "4", str(psi), root + ".ppm", root + "-bump.ppm", root + "-R.ppm"])
subprocess.call(["montage", root + "-R.ppm", root + "-L.ppm", "-geometry", "100%x100%", root + "-stereo.jps"])
subprocess.call(["montage", root + "-L.ppm", root + "-R.ppm", "-geometry", "100%x100%", root + "-stereoR.jps"])
subprocess.call(["montage", root + "-stereo.jps", "-geometry", "100%x100%", root + "-stereo.png"])
subprocess.call(["montage", root + "-stereoR.jps", "-geometry", "100%x100%", root + "-stereoR.png"])
elif(argv[2] == "tilt"):
for s in range(0, pixels * 2):
subprocess.call([argv[1], argv[2], "1", "4", str((s - pixels) / float(pixels) * psi), root + ".ppm", root + "-bump.ppm", root + "-tilt-" + str(s) + ".ppm"])
subprocess.call(["cp", root + "-tilt-" + str(s) + ".ppm", root + "-tilt-" + str(pixels * 4 - s - 1) + ".ppm"])
subprocess.call(["ffmpeg", "-loop", "1", "-i", root + "-tilt-%d.ppm", "-framerate", "6", "-an", "-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2", "-vcodec", "libx264", "-pix_fmt", "yuv420p", "-t", "60", root + ".mp4"])
elif(argv[2] == "sbox"):
for s in range(0, pixels):
subprocess.call([argv[1], argv[2], str(int(s - (pixels + 1) / 2.)), str(pixels * 2), "0", root + ".ppm", root + "-bump.ppm", root + "-sbox-" + str(pixels - s) + ".ppm"])
elif(argv[2] == "sboxb2w"):
subprocess.call([argv[1], "b2w", root + "-sbox-1.ppm", root + "-sbox-bw-1.ppm", "1"])
for s in range(1, pixels):
subprocess.call([argv[1], "b2wd", root + "-sbox-" + str(s + 1) + ".ppm", root + "-sbox-bw-" + str(s + 1) + ".ppm", root + "-sbox-" + str(s) + ".ppm"])
elif(argv[2] == "prep"):
subprocess.call(["convert", line, "-resize", str(pixels) + "x>", "-resize", "x" + str(pixels) + ">", root + "-prep.png"])
elif(argv[2] == "prepsq"):
subprocess.call(["convert", line, "-resize", str(pixels) + "x" + str(pixels) + "!", root + "-prepsq.png"])
elif(argv[2] == "nurie"):
subprocess.call(["convert", root + ".ppm", "-modulate", "50", root + "-bump.ppm", "-compose", "softlight", "-composite", "-equalize", root + "-nurie.png"])
elif(argv[2] == "illust"):
subprocess.call([argv[1], "reshape", str(pixels), root + ".ppm", root + "-bump.ppm", root + "-illust.ppm", str(pow(float(pixels), - .5))])
elif(argv[2] == "gray"):
subprocess.call(["convert", line, "-colorspace", "Gray", "-separate", "-average", root + "-gray.png"])