-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConvert icon to 8bit color.ijm
More file actions
39 lines (29 loc) · 1.06 KB
/
Copy pathConvert icon to 8bit color.ijm
File metadata and controls
39 lines (29 loc) · 1.06 KB
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
macro "Convert Icon to Image..." {
requires("1.35r");
code = getString("Input the code for the icon: ", "");
// Parsing code
newCode = replace(code, "C", "xC");
eachColor = split(newCode, "x");
newImage("Icon", "RGB white", 16, 16, 1);
for (c=0; c<eachColor.length; c++) {
// Get color as hexadecimal string
rColor = substring(eachColor[c], 1, 2);
gColor = substring(eachColor[c], 2, 3);
bColor = substring(eachColor[c], 3, 4);
rgbHexColor = Color.toString(convertHexToNumber(rColor), convertHexToNumber(gColor), convertHexToNumber(bColor));
// Set drawing color
Color.set(rgbHexColor);
// Collect pixel positions
positionCode = split(eachColor[c], "D");
// Color pixels
for (p=1; p<positionCode.length; p++) {
xPos = parseInt(substring(positionCode[p], 0, 1), 16);
yPos = parseInt(substring(positionCode[p], 1, 2), 16);
fillRect(xPos, yPos, 1, 1);
}
}
function convertHexToNumber(hexText) {
nb16 = parseInt(hexText, 16);
nb256 = (nb16 + 1) * 16 - 1;
return nb256;
}