diff options
| author | jules <jules@okfoc.us> | 2014-07-30 09:34:57 -0400 |
|---|---|---|
| committer | jules <jules@okfoc.us> | 2014-07-30 09:34:57 -0400 |
| commit | b2375e11e2c9eee9d09bf30fd5ec8e900023c46f (patch) | |
| tree | 999a1d4b1a7df077ae7f1ba0e4e29033ed38114d /js | |
| parent | 28b6a443dd5760829fced2fae54ef8e02566ba7d (diff) | |
shader-cam
Diffstat (limited to 'js')
| -rw-r--r-- | js/camera.js | 61 | ||||
| -rw-r--r-- | js/image.js | 2 | ||||
| -rw-r--r-- | js/render.js | 8 |
3 files changed, 70 insertions, 1 deletions
diff --git a/js/camera.js b/js/camera.js new file mode 100644 index 0000000..3a0c8b4 --- /dev/null +++ b/js/camera.js @@ -0,0 +1,61 @@ +var camera = (function(){ + var loaded = false, video + + navigator.getMedia = ( navigator.getUserMedia || + navigator.webkitGetUserMedia || + navigator.mozGetUserMedia || + navigator.msGetUserMedia); + + if (! navigator.getMedia) { + $("#camera").hide() + return + } + + $("#camera").click(load) + function load(){ + if (! loaded) { + build() + } + else { + ready() + } + window.gif = window.img = null + } + + function ready(){ + cc.canvas.width = actual_w = w = min(video.videoWidth, 400) + cc.canvas.height = actual_h = h = video.videoHeight / (video.videoWidth/w) + video.setAttribute('width', video.videoWidth) + video.setAttribute('height', video.videoHeight) + window.gif = window.img = null + window.cam = video + } + + function build(){ + video = document.createElement("video") + navigator.getMedia({ + video: true, + audio: false + }, + function(stream) { + if (navigator.mozGetUserMedia) { + video.mozSrcObject = stream; + } else { + var vendorURL = window.URL || window.webkitURL; + video.src = vendorURL.createObjectURL(stream); + } + video.play(); + }, + function(err) { + console.log("An error occured! " + err); + } + ) + + video.addEventListener('canplay', function(ev){ + if (! loaded) { + loaded = true + ready() + } + }, false); + } +})() diff --git a/js/image.js b/js/image.js index 27b5c2c..d02673e 100644 --- a/js/image.js +++ b/js/image.js @@ -5,7 +5,7 @@ function loadImage(imageURL, callback) { var imageURL = proxify( imageURL ); window.imageURL = imageURL - window.gif = window.img = null + window.gif = window.img = window.cam = null if (! imageURL) { window.gif = null diff --git a/js/render.js b/js/render.js index e77711e..a589efc 100644 --- a/js/render.js +++ b/js/render.js @@ -74,6 +74,9 @@ function giveFrame(t){ if (window.img) { return img_frame } + else if (window.cam) { + return camera_frame() + } else { return empty_frame() } @@ -90,6 +93,11 @@ function feedback_frame(){ return { ctx: cc.context, cloneData: cc.getImageData(0,0,w,h) } } +function camera_frame(){ + var cx = cq(w, h).drawImage(cam, 0, 0, w, h) + return { ctx: cx.context, cloneData: cx.getImageData(0,0,w,h) } +} + function reset(){ start_t = old_t pause_t = 0 |
