-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflagconvert.py
136 lines (106 loc) · 4.92 KB
/
flagconvert.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
#!/usr/bin/python
import os
import sys
import math
import numpy
import PythonMagick
MaxRGB = 256
def ColourToRGBArray(colour):
return [int(colour.redQuantum() / MaxRGB),
int(colour.greenQuantum() / MaxRGB),
int(colour.blueQuantum() / MaxRGB)]
def ColourSet(image):
colourset = {}
for x in range(image.size().width()):
for y in range(image.size().height()):
colour = str(ColourToRGBArray(image.pixelColor(x, y)))
if colour not in colourset:
colourset[colour] = 1
else:
colourset[colour] += 1
return colourset
def CompileFlag(sourcepath, destFolder):
if not destFolder:
destFolder = "output/"
filename = os.path.splitext(os.path.basename(sourcepath))[0]
if not os.path.exists(sourcepath):
print("WARNING: Could not find \"" + sourcepath + "\".")
return
image = PythonMagick.Image(sourcepath)
imagetype = image.type
nonecolor = PythonMagick.Color(1 * MaxRGB, 0, 0, 255 * MaxRGB)
canvas = PythonMagick.Image(PythonMagick.Geometry(128, 128), nonecolor)
canvas.type = imagetype
dropshadow = PythonMagick.Image(PythonMagick.Geometry(128, 128), nonecolor)
dropshadow.type = imagetype
image = PythonMagick.Image(sourcepath)
image2 = PythonMagick.Image(sourcepath)
image.transform("115x73")
image.enhance()
dropshadow.fillColor(PythonMagick.Color(0, 0, 0, 25 * MaxRGB))
dropshadow.draw(PythonMagick.DrawableRectangle((128 / 2) - (115 / 2) - 1, (128 / 2) - (73 / 2) - 1,
(128 / 2) + (115 / 2) + 1, (128 / 2) + (73 / 2) + 1))
dropshadow.blur(5, 5)
x = int(128 / 2)
y = int(128 / 2)
geom = PythonMagick.Geometry(0, 0, int(128 / 2) - int(115 / 2), int(128 / 2) - int(73 / 2))
op = PythonMagick.CompositeOperator.OverCompositeOp
dropshadow.composite(image, geom, op)
dropshadow.type = imagetype
dropshadow.write(destFolder + filename + ".dds")
tiny = PythonMagick.Image(dropshadow)
tiny.type = imagetype
tiny.transform("24x24")
tiny.write(destFolder + "small/" + filename + ".dds")
mapflag = PythonMagick.Image(PythonMagick.Geometry(256, 256), nonecolor)
colourFrequencies = ColourSet(image2)
sortedColours = [(k, colourFrequencies[k]) for k in sorted(colourFrequencies, key=colourFrequencies.get, reverse=True)]
maxIntensity = 0
minIntensity = 255
for i in range(10):
if i >= len(sortedColours):
break
sortedColour = sortedColours[i][0][1:-1].split(',')
intensity = int(sortedColour[0]) + int(1.2 * float(sortedColour[1])) + \
int(0.5 * float(sortedColour[2]))
if intensity > maxIntensity:
maxIntensity = intensity
if intensity < minIntensity:
minIntensity = intensity
for x in range(image2.size().width()):
for y in range(image2.size().height()):
c = ColourToRGBArray(image2.pixelColor(x, y))
intensity = c[0] + (1.2 * float(c[1])) + (0.5 * float(c[2]))
actualIntensity = (intensity - minIntensity) / (maxIntensity - minIntensity)
if (actualIntensity < 0.0):
actualIntensity = 0
elif (actualIntensity > 1.0):
actualIntensity = 255 * MaxRGB
else:
actualIntensity = int(actualIntensity * 255 * MaxRGB)
newColour = PythonMagick.Color(min(actualIntensity + MaxRGB, 255 * MaxRGB),
actualIntensity, actualIntensity, 1 * MaxRGB)
image2.pixelColor(x, y, newColour)
image2.transform("186x118")
dropshadow2 = PythonMagick.Image(PythonMagick.Geometry(256, 256), nonecolor)
dropshadow2.type = imagetype
dropshadow2.fillColor(PythonMagick.Color(0, 0, 0, 25 * MaxRGB))
dropshadow2.draw(PythonMagick.DrawableRectangle((256 / 2) - (186 / 2) - 1, (256 / 2) - (118 / 2) - 1,
(256 / 2) + (186 / 2) + 1, (256 / 2) + (118 / 2) + 1))
dropshadow2.blur(10, 10)
x = int(256 / 2)
y = int(256 / 2)
geom = PythonMagick.Geometry(0, 0, int(256 / 2) - int(186 / 2), int(256 / 2) - int(118 / 2))
op = PythonMagick.CompositeOperator.OverCompositeOp
dropshadow2.composite(image2, geom, op)
dropshadow2.type = imagetype
dropshadow2.fillColor(PythonMagick.Color(0, 0, 0, 255 * MaxRGB))
dropshadow2.strokeColor(PythonMagick.Color(255 * MaxRGB, 255 * MaxRGB, 255 * MaxRGB, 1 * MaxRGB))
dropshadow2.strokeWidth(2)
dropshadow2.draw(PythonMagick.DrawableRectangle((256 / 2) - (186 / 2) - 1, (256 / 2) - (118 / 2) - 1,
(256 / 2) + (186 / 2) + 1, (256 / 2) + (118 / 2) + 1))
dropshadow2.write(destFolder + "map/" + filename + ".dds")
if __name__ == "__main__":
SetUpFolders()
for filename in os.listdir("hoi4samples"):
CompileFlag("hoi4samples/" + filename)