-
Notifications
You must be signed in to change notification settings - Fork 3
/
colortest.html
94 lines (75 loc) · 3.72 KB
/
colortest.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
<script src="lib/jquery-1.11.1.min.js"></script>
<script>var Lighting = {}</script>
<script src="lut/intensityColorTable.js"></script>
<script>
// Generates an intensityColorTable from a palette (given by a set of color look-up tables -- index<->rgb)
// Also verifies it against a dumped intensityColorTable for errors
// TODO: Parse and load color.pal in TypeScript and generate this at load time instead of relying on LUTs
var color_rgb = null
var colorTable = null
var intensityColorTable = new Uint8Array(65536)
var mappedColor = new Array(256)
//mappedColor.fill(0)
for(var i = 0; i < 256; i++)
mappedColor[i] = 0
function Color2RGB(idx) {
var color = color_rgb[idx]
//return (color[0] << 16) | (color[1] << 8) | color[2]
// Normally this would be >> 1 (i.e., / 2), but our RGB values are already the palette color * 4, so (/ 8)
return (color[2] >> 3) | 32 * ((color[1] >> 3) | 32 * (color[0] >> 3))
}
function Index2Color(x) { return x }
function setIntensityTableColor(tableIdx) {
for(var tableIdx2 = 0; tableIdx2 < 128; tableIdx2++) {
var v5 = (Color2RGB(tableIdx) & 0x7C00) >> 10
var v6 = (Color2RGB(tableIdx) & 0x3E0) >> 5
var v7 = Color2RGB(tableIdx) & 0x1F
intensityColorTable[256 * tableIdx + tableIdx2] = Index2Color(colorTable[(((tableIdx2 << 9) * v7) >> 16) | ((tableIdx2 << 9) * v5 >> 16 << 10) | 32 * ((tableIdx2 << 9) * v6 >> 16)]);
intensityColorTable[256 * tableIdx + 128 + tableIdx2] = Index2Color(colorTable[((((tableIdx2 << 9) * (31 - v5) >> 16)
+ v5) << 10) | 32 * (((tableIdx2 << 9) * (31 - v6) >> 16) + v6) | ((((tableIdx2 << 9) * (31 - v7)) >> 16) + v7)]);
// intensityColorTable[256 * tableIdx + tableIdx2] = (colorTable[(((tableIdx2 << 9) * v7) >> 16) | (((tableIdx2 << 9) * v5) >> 16 << 10) | 32 * (((tableIdx2 << 9) * v6) >> 16)]);
// intensityColorTable[256 * tableIdx + 128 + tableIdx2] = (colorTable[(((((tableIdx2 << 9) * (31 - v5)) >> 16)
// + v5) << 10) | 32 * ((((tableIdx2 << 9) * (31 - v6)) >> 16) + v6) | ((((tableIdx2 << 9) * (31 - v7)) >> 16) + v7)]);
}
}
$.get("lut/color_rgb.json", function(_color_rgb) {
$.get("lut/colorTable.json", function(_colorTable) {
color_rgb = _color_rgb
colorTable = _colorTable
// set mapped colors
for(var i = 0; i < 256; i++) {
var r = color_rgb[i][0]
var g = color_rgb[i][1]
var b = color_rgb[i][2]
mappedColor[i] = (r > 0 || g > 0 || b > 0) // valid palette colors
/*if(mappedColor[i])
console.log("%d is mapped", i)*/
}
mappedColor[228] = 1 // HACK: 228 in color.pal is legitimately RGB (0, 0, 0) and we count it as unmapped, but it is
for(var tableIdx = 0; tableIdx < 256; tableIdx++) {
if(mappedColor[tableIdx])
setIntensityTableColor(tableIdx)
else {
// memset(intensityColorTable + 256*tableIdx, 0, 256)
/*var startIdx = 256 * tableIdx
intensityColorTable.fill(0, startIdx, startIdx + 256)*/
for(var i = 0; i < 256; i++)
intensityColorTable[256 * tableIdx + i] = 0
}
}
// var t = 1
// for(var i = 0; i < 256; i++) {
// console.log("intensityColorTable[256*%d + %d] = 0x%s", t, i, intensityColorTable[256*t + i].toString(16))
// }
// console.log("-----------------")
var numErrors = 0;
for(var i = 0; i < 65536; i++) {
if(intensityColorTable[i] !== Lighting.intensityColorTable[i]) {
console.log("%d (table %d) differs (%s, expected %s)", i, i / 256 | 0, intensityColorTable[i].toString(16), Lighting.intensityColorTable[i].toString(16))
numErrors++;
}
}
console.log("Done, " + numErrors + " errors");
}, "json")
}, "json")
</script>