forked from conorbuck/canvas-video-effects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageSize.html
67 lines (59 loc) · 2.06 KB
/
ImageSize.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
<!DOCTYPE html>
<html>
<head>
<title>Image Size</title>
</head>
<body>
<video id="video-stream" style="display:none;" width=320 height=240></video>
<canvas id="canvas-video" width=320 height=240></canvas>
<canvas id="canvas-small" width=80 height=60></canvas>
<canvas id="canvas-effects" width=320 height=240></canvas>
<script type="text/javascript">
(function(){
var video = document.getElementById('video-stream'),
canvas = document.getElementById('canvas-video'),
canvasSmall = document.getElementById('canvas-small'),
canvasEffect = document.getElementById('canvas-effects'),
ctx = canvas.getContext('2d'),
ctxSmall = canvasSmall.getContext('2d');
ctxEffects = canvasEffect.getContext('2d'),
// processor = new Worker('image-worker.js');
w = video.width,
h = video.height;
var imgData = ctxEffects.getImageData(0,0,w,h);
/* Setup WebWorker messaging */
// processor.onmessage = function(event){
// // Now we're getting back an array buffer
// var buf8 = new Uint8ClampedArray(event.data);
// // Set that as the data for the ctxEffects context
// imgData.data.set(buf8);
// ctxEffects.putImageData(imgData, 0, 0);
// };
/* Setup video stream and canvas */
navigator.getUserMedia =
navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
navigator.getUserMedia({video:true}, function(stream){
video.src = URL.createObjectURL(stream);
video.play();
setInterval(render, 10);
}, function(error){
console.log('error', error);
});
var render = function(){
ctx.drawImage(video, 0, 0, w, h);
ctxSmall.drawImage(video, 0, 0, canvasSmall.width, canvasSmall.height);
var srcData = ctxSmall.getImageData(0,0,w,h);
ctxEffects.drawImage(canvasSmall, 0,0,w,h);
// Don't post the imageData
// Instead post the data directly
// It's an arrayBuffer, so it's a transferable object
var ab = srcData.data;
// processor.postMessage(ab.buffer, [ab.buffer]);
};
})();
</script>
</body>
</html>