forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iconsmooth.py
86 lines (73 loc) · 3.47 KB
/
iconsmooth.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
#!/usr/bin/env python3
# Copyright (c) 2021 Space Wizards Federation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import PIL
import PIL.Image
import sys
import iconsmooth_lib
if len(sys.argv) != 5:
print("iconsmooth.py in.png METRICS <" + iconsmooth_lib.all_conv + "> OUTPREFIX")
print("OUTPREFIX is something like, say, " + iconsmooth_lib.explain_prefix)
print(iconsmooth_lib.explain_mm)
raise Exception("see printed help")
# Input detail configuration
input_name = sys.argv[1]
metric_mode = sys.argv[2]
conversion_mode = sys.argv[3]
out_prefix = sys.argv[4]
# Metric configuration
tile_w, tile_h, subtile_w, subtile_h, remtile_w, remtile_h = iconsmooth_lib.parse_metric_mode(metric_mode)
# Output state configuration
out_states = iconsmooth_lib.conversion_modes[conversion_mode].states
# Source loading
src_img = PIL.Image.open(input_name)
input_row = src_img.size[0] // tile_w
tiles = []
# 48 is the amount of tiles that usually exist
for i in range(48):
tile = PIL.Image.new("RGBA", (tile_w, tile_h))
tx = i % input_row
ty = i // input_row
tile.paste(src_img, (tx * -tile_w, ty * -tile_h))
# now split that up
# note that THIS is where the weird ordering gets put into place
tile_a = PIL.Image.new("RGBA", (remtile_w, remtile_h))
tile_a.paste(tile, (-subtile_w, -subtile_h))
tile_b = PIL.Image.new("RGBA", (subtile_w, subtile_h))
tile_b.paste(tile, ( 0, 0))
tile_c = PIL.Image.new("RGBA", (remtile_w, subtile_h))
tile_c.paste(tile, (-subtile_w, 0))
tile_d = PIL.Image.new("RGBA", (subtile_w, remtile_h))
tile_d.paste(tile, ( 0, -subtile_h))
tiles.append([tile_a, tile_b, tile_c, tile_d])
state_size = (tile_w * 2, tile_h * 2)
for state in range(len(out_states)):
full = PIL.Image.new("RGBA", state_size)
full.paste(tiles[out_states[state][0]][0], (subtile_w, subtile_h))
full.paste(tiles[out_states[state][1]][1], (tile_w, 0))
full.paste(tiles[out_states[state][2]][2], (subtile_w, tile_h))
full.paste(tiles[out_states[state][3]][3], (tile_w, tile_h + subtile_h))
full.save(out_prefix + str(state) + ".png")
full_finale = PIL.Image.new("RGBA", (tile_w, tile_h))
full_finale.paste(tiles[out_states[0][0]][0], (subtile_w, subtile_h))
full_finale.paste(tiles[out_states[0][1]][1], (0, 0))
full_finale.paste(tiles[out_states[0][2]][2], (subtile_w, 0))
full_finale.paste(tiles[out_states[0][3]][3], (0, subtile_h))
full_finale.save(out_prefix + "full.png")