-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.js
42 lines (36 loc) · 1.25 KB
/
worker.js
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
onmessage = function(e) {
switch (e.data.msg) {
case 'setup':
self.canvas = e.data.canvas;
self.context = self.canvas.getContext('2d');
self.canvas.width = e.data.json.w;
self.canvas.height = e.data.json.h;
self.width = e.data.json.w;
self.height = e.data.json.h;
break;
case 'image':
self.bitmap = e.data.bitmap;
break;
case 'drawPreview':
self.canvas.width = self.width;
self.canvas.height = self.canvas.height;
self.context.drawImage(self.bitmap, e.data.x, e.data.y, self.width, self.height, 0, 0, self.canvas.width, self.canvas.height);
break;
case 'getBlob':
self.canvas.convertToBlob().then(function(blob) {
if (e.data.state) {
postMessage({ 'msg': 'blob', 'blob': blob, 'array': e.data.array, 'count': e.data.count, 'type': 'state' });
return
}
if (e.data.frame) {
postMessage({ 'msg': 'blob', 'blob': blob, 'array': e.data.array, 'count': e.data.count, 'type': 'frame' });
return
}
if (e.data.state_frame) {
postMessage({ 'msg': 'blob', 'blob': blob, 'array': e.data.array, 'count': e.data.count, 'type': 'state_frame', 'state_count': e.data.state_count });
return
}
postMessage({ 'msg': 'blob', 'blob': blob, 'array': e.data.array });
});
}
}