-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgetlas.js
More file actions
67 lines (62 loc) · 2.66 KB
/
Copy pathgetlas.js
File metadata and controls
67 lines (62 loc) · 2.66 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
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
postMessage("Initializing loader");
let start = Date.now();
(async()=>{
const atlases=await caches.open("atlases");
let json=await atlases.match(location.href+".json");
let rle=await atlases.match(location.href+".rle");
console.log("Checked cache",Date.now() - start);
if(json && rle){
importScripts("derle.js");
json=await json.json();
rle=new Uint8Array(await rle.arrayBuffer());
console.log("Got atlas from cache",Date.now() - start);
let message = "Decoding atlas<br>" + location.search.substring(1).replaceAll("_", " ") + "<br>";
const data = derle(rle, json.encoding, (x, y) => postMessage(message + (x / y * 100).toFixed(0) + "%"));
console.log(Date.now() - start, "Decoded:", data.length);
json.blob = data.buffer;
postMessage(json, [json.blob]);
}else{
importScripts("inflater.js", "derle.js");
let name = location.search.substring(1);
let message = "Loading atlas<br>" + name.replaceAll("_", " ") + "<br>";
postMessage(message + "0%");
let xhr = new XMLHttpRequest();
//xhr.open("GET", name + ".json", false);
xhr.open("GET", "https://data-proxy.ebrains.eu/api/v1/buckets/quint-atlas-binaries/LZ-flatpacks/" + name + ".json", false);
xhr.responseType = "json";
xhr.send();
let json = xhr.response;
for (let label of json.labels)
if (label.hasOwnProperty("rgb")) {
let rgb = parseInt(label.rgb, 16);
label.r = rgb >> 16;
label.g = (rgb >> 8) & 255;
label.b = rgb & 255;
}
await atlases.put(location.href+".json",new Response(JSON.stringify(json)));
console.log(Date.now() - start, "Got json");
xhr = new XMLHttpRequest();
//xhr.open("GET",name+".pack",false);
//xhr.open("GET", name + ".pack");
xhr.open("GET", "https://data-proxy.ebrains.eu/api/v1/buckets/quint-atlas-binaries/LZ-flatpacks/" + name + ".pack");
xhr.responseType = "arraybuffer";
//xhr.send();
xhr.onprogress = event => {
postMessage(message + (event.loaded / event.total * 10).toFixed(0) + "%");
};
xhr.onload = async() => {
let pack = xhr.response;
console.log(Date.now() - start, "Got pack");
let data = new Uint8Array(pack);
console.log(Date.now() - start, "Size:", data.length);
data = inflate(data, {progress: (x, y) => postMessage(message + (10 + x / y * 20).toFixed(0) + "%")});
console.log(Date.now() - start, "Inflated:", data.length);
await atlases.put(location.href+".rle",new Response(data));
data = derle(data, json.encoding, (x, y) => postMessage(message + (30 + x / y * 70).toFixed(0) + "%"));
console.log(Date.now() - start, "Decoded:", data.length);
json.blob = data.buffer;
postMessage(json, [json.blob]);
};
xhr.send();
}
})();