1+ //Imports bltings (https://github.com/irtsa-dev/builtin-greyscript)
2+ import_code("/bin/bltings")
3+
4+
5+
6+
7+
8+ //Necessary separation of the lfill function from String class. (custom)
9+ __lfill = function(string)
10+ return ("0" * [0, 3 - string.len]).max + string
11+ end function
12+
13+
14+
15+
16+
17+ //Public Functions
18+ monoSprite = function(filepath, zeroIsInvisible = true)
19+ file = get_shell.host_computer.File(filepath)
20+ if not file then exit("<color=red>Error: File does not exist.")
21+
22+ imageData = file.get_content.split("\n")
23+ imageSize = imageData[-1].to_int
24+ imageData.pop
25+
26+ for i in range(imageData.len - 1)
27+ imageData[i] = imageData[i].group(3)
28+ if imageData[i][-1].len < 3 then exit("<color=red>Error: Could not correctly parse image data in file.")
29+ end for
30+
31+ picture = ""
32+ for a in range(0, imageData.len - 1)
33+ for b in range(0, imageData[a].len - 1)
34+ color = hex(imageData[a][b])
35+ if color == "0" and zeroIsInvisible then color = "0b0b0c" else color = color + color * (6 / color.len)
36+ picture = picture + "<pos=" + floor(b * (imageSize * 0.6)) + "px><size=" + imageSize + "><sprite=0 color=#" + color + ">"
37+ end for
38+ picture = picture + "<voffset=-" + floor((a + 1) * imageSize * 1.2) + "px>"
39+ end for
40+
41+ return picture
42+ end function
43+
44+
45+
46+ rgbSprite = function(filepath, zeroIsInvisible = true)
47+ file = get_shell.host_computer.File(filepath)
48+ if not file then exit("<color=red>Error: File does not exist.")
49+
50+ imageData = file.get_content.split("\n")
51+ imageSize = imageData[-1].to_int
52+ imageData.pop
53+
54+ for i in range(imageData.len - 1)
55+ imageData[i] = imageData[i].group(9)
56+ if imageData[i][-1].len < 9 then exit("<color=red>Error: Could not correctly parse image data in file.")
57+ end for
58+
59+ picture = ""
60+ for a in range(0, imageData.len - 1)
61+ for b in range(0, imageData[a].len - 1)
62+ color = imageData[a][b].group(3)
63+ if color[-1].len < 3 then exit("<color=red>Error: Could not correctly parse image data in file.")
64+ color.applyFunction(@hex)
65+ color.applyFunction(@__lfill)
66+ color = color.join("")
67+ if color == "000000" and zeroIsInvisible then color = "0b0b0c"
68+ picture = picture + "<pos=" + floor(b * imageSize * 0.6) + "px><size=" + imageSize + "><sprite=0 color=#" + color + ">"
69+ end for
70+ picture = picture + "<voffset=-" + floor((a + 1) * imageSize * 1.2) + "px>"
71+ end for
72+
73+ return picture
74+ end function
0 commit comments