-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
125 lines (96 loc) · 4.1 KB
/
index.html
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
<!DOCTYPE html>
<html>
<body>
<h1>Insert the image converted for UTFT</h1>
<label for="imgCode">Image Code:</label>
<textarea type="text" id="imgCode" name="imgCode" cols="200" rows="20"></textarea><br><br>
<label for="colorCode">Color Code to minify:</label>
<input type="text" id="colorCode" name="colorCode"></input><br><br>
<button type="button" onclick="convOnly()">Convert only the color code!</button><br><br>
<button type="button" onclick="convAll()">Convert all data!</button><br><br>
<label for="imgComp">Image With Compression:</label>
<textarea type="text" id="imgComp" name="imgComp" cols="200" rows="20"></textarea><br><br>
<p>Insert the image code like this:<br>
0x0000,0x2839,0x0189,0xh123[...]</p>
<p id="imgDetails"></p>
</body>
</html>
<script>
function isWhatPercentOf(numA, numB) {
return (numA / numB) * 100;
}
function convOnly() {
var imageData = document.getElementById("imgCode").value;
var colorCode = document.getElementById("colorCode").value;
imageData = imageData.replace(/ /g, '');
imageData = imageData.split(",");
for (var i = imageData.length - 1; i >= 0; i--) {
if (imageData[i].includes('/')) {
imageData[i] = imageData[i].substr(imageData[i].length - 6);
}
}
imageData.pop();
var newImageData = "";
var Count = 0;
for (var i = 0; i < imageData.length - 1; i++) {
if (imageData[i].includes(colorCode) == false) {
newImageData += imageData[i] + ",";
} else {
try {
while (imageData[i + Count].includes(colorCode)) {
Count++;
}
}
catch (error) {
}
i += Count - 1;
newImageData += colorCode + "," + Count.toString() + ",";
Count = 0;
}
}
var dados = "const unsigned int image[] = {" + newImageData + "};";
document.getElementById("imgComp").value = dados;
newImageData = newImageData.split(',');
newImageData.pop();
document.getElementById("imgDetails").innerHTML = "Last image size: " + (imageData.length * 2) + " bytes - New image size: " +
(newImageData.length * 2) + " bytes, Reduzing the image in +-" + ((imageData.length * 2) - (newImageData.length * 2)) + " bytes or " +
(100 - isWhatPercentOf(newImageData.length, imageData.length)).toFixed(2) + "%";
newImageData = [];
imageData = [];
}
function convAll() {
var imageData = document.getElementById("imgCode").value;
imageData = imageData.replace(/ /g, '');
imageData = imageData.split(",");
for (var i = imageData.length - 1; i >= 0; i--) {
if (imageData[i].includes('/')) {
imageData[i] = imageData[i].substr(imageData[i].length - 6);
}
}
imageData.pop();
var newImageData = "";
var Count = 0;
for (var i = 0; i < imageData.length - 1; i++) {
var antes = imageData[i + Count];
try {
while (imageData[i + Count].includes(antes)) {
Count++;
}
}
catch (error) {
}
i += Count - 1;
newImageData += antes + "," + Count.toString() + ",";
Count = 0;
}
var dados = "const unsigned int image[] = {" + newImageData + "};";
document.getElementById("imgComp").value = dados;
newImageData = newImageData.split(',');
newImageData.pop();
document.getElementById("imgDetails").innerHTML = "Last image size: " + (imageData.length * 2) + " bytes - New image size: " +
(newImageData.length * 2) + " bytes, Reduzing the image in +-" + ((imageData.length * 2) - (newImageData.length * 2)) + " bytes or " +
(100 - isWhatPercentOf(newImageData.length, imageData.length)).toFixed(2) + "%";
newImageData = [];
imageData = [];
}
</script>