Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial code

  • Loading branch information...
commit 53ed98b37adfaaddf4fb145ad48521ab60aafad4 0 parents
Marcio Galli authored
6 build.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# This compiles the binary for production. If you need to add debug level check mtasc options
+
+./swfmill simple library.xml ./swf/camcanvas.swf
+./mtasc -version 8 -swf ./swf/camcanvas.swf -main ./src/camcanvas.as -cp lib/std -cp lib/std8
5 doc/info.txt
@@ -0,0 +1,5 @@
+This is CamCanvas API v 0.1
+--
+We need your help. Please help with a bit of your brain or a bit of your money. Visit the labs.taboca.com/p/camcanvas for additional information. This API offers webcam image access via JavaScript and canvas tag. This version comes with a swf binary ( Flash ) compiled using Mtasc - this is flash 8 compatible. The flash code renders the live webcam image and does the initial capture. Settings, snapshot control, and the resulting image can be accessed from JavaScript.
+
+Marcio
11 library.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<movie width="320" height="240" framerate="24">
+ <background color="#ffffff" />
+ <DefineVideoStream objectID="1" frames="0" width="320" height="240" deblocking="0" smoothing="0" codec="0" />
+ <frame>
+ <library>
+ <clip id="ObjetVideo" objectID="1" />
+ </library>
+ </frame>
+
+</movie>
9 readme.txt
@@ -0,0 +1,9 @@
+Depends on:
+
+Mtasc - http://www.mtasc.org/#download
+SwfMill - http://swfmill.org/
+
+Put mtasc and swfmill binary in this directory and use the build script.
+You will also need ./lib/* from mtasc : ./lib/std and ./lib/std8
+
+
41 samples/camcanvas.as
@@ -0,0 +1,41 @@
+import flash.external.ExternalInterface;
+import net.hiddenresource.util.debug.Debug;
+import flash.display.BitmapData;
+import flash.geom.Matrix;
+
+class camcanvas {
+
+ static var app : camcanvas;
+
+ public static function exportCapture(input:String):String {
+ snap();
+ return input;
+ }
+
+ public static function main() {
+
+ var cam = Camera.get();
+ cam.setMode(320,240, 24)
+ _root.attachMovie("ObjetVideo", "webcamVideo", 1);
+ _root.webcamVideo.attachVideo(cam);
+ _root.webcamVideo._x = 0;
+
+ _root.refFunc = exportCapture;
+ ExternalInterface.addCallback("ccCapture", _root, _root.refFunc);
+
+ }
+
+ public static function snap() {
+
+ var snapshot:flash.display.BitmapData = new flash.display.BitmapData(_root.webcamVideo._width,_root.webcamVideo.height,true);
+ snapshot.draw(_root.webcamVideo);
+ var string="";
+ for(var j=0;j<240;j++) {
+ var currLine = "";
+ for(var i=0;i<320;i++) {
+ currLine += snapshot.getPixel(i,j)+"-";
+ }
+ ExternalInterface.call("passLine", currLine)
+ }
+ }
+}
155 samples/camcanvas.html
@@ -0,0 +1,155 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+<SCRIPT LANGUAGE="JavaScript">
+
+var canvas = null;
+var ctx = null;
+
+function t1() {
+ replaceImageData();
+}
+
+
+var gCtx = null;
+var gCanvas = null;
+ var gCanvas2 = null;
+ var gCtx = null;
+ var gCtx2 = null;
+ var gActive = false;
+ var gStartX = 0;
+ var gStartY = 0;
+ var gEndX = -1;
+ var gEndY = -1;
+
+
+
+ function copyImageToCanvas(aImg)
+ {
+ gCanvas = document.getElementById("canvas");
+ var w = aImg.naturalWidth;
+ var h = aImg.naturalHeight;
+ gCanvas.style.width = w + "px";
+ gCanvas.style.height = h + "px";
+ gCanvas.width = w;
+ gCanvas.height = h;
+
+ gCtx = gCanvas.getContext("2d");
+ gCtx.clearRect(0, 0, w, h);
+ gCtx.drawImage(aImg, 0, 0);
+
+ var container = gCanvas.parentNode;
+ gCanvas2 = document.createElement('canvas');
+ gCanvas2.id = "imageTemp";
+ gCanvas2.width = w;
+ gCanvas2.height = h;
+ container.appendChild(gCanvas2);
+ gCtx2 = gCanvas2.getContext("2d");
+ }
+
+
+function replaceImageData() {
+ var img = new Image();
+ img.src="canvas.png";
+ img.onload = function() { copyImageToCanvas(img); continueCanvas() }
+}
+
+var imageData = null;
+
+function continueCanvas() {
+
+ imageData = gCtx.getImageData( 0,0,320,240);
+
+ for (var x = 0; x < imageData.width; x++)
+ for (var y = 0; y < imageData.height; y++)
+ {
+ var offset = (y * imageData.width + x) * 4;
+ var r = imageData.data[offset];
+ var g = imageData.data[offset + 1];
+ var b = imageData.data[offset + 2];
+ imageData.data[offset]=0;
+
+ }
+ gCtx.putImageData(imageData, 0,0);
+
+}
+
+ var ii=0;
+ var jj=0;
+ var c=0;
+
+ function passLine(stringPixels) {
+ //a = (intVal >> 24) & 0xff;
+
+ var coll = stringPixels.split("-");
+
+ for(var i=0;i<320;i++) {
+
+ var intVal = parseInt(coll[i]);
+
+ r = (intVal >> 16) & 0xff;
+ g = (intVal >> 8) & 0xff;
+ b = (intVal ) & 0xff;
+ imageData.data[c+0]=r;
+ imageData.data[c+1]=g;
+ imageData.data[c+2]=b;
+ imageData.data[c+3]=128;
+ c+=4;
+ }
+
+
+ if(c>=320*240*4) {
+ c=0;
+ gCtx.putImageData(imageData, 0,0);
+ }
+ }
+
+ function passImage(intVal) {
+ //a = (intVal >> 24) & 0xff;
+ r = (intVal >> 16) & 0xff;
+ g = (intVal >> 8) & 0xff;
+ b = (intVal ) & 0xff;
+ imageData.data[c+0]=r;
+ imageData.data[c+1]=g;
+ imageData.data[c+2]=b;
+ imageData.data[c+3]=128;
+ c+=4;
+ if(c>=320*240*4) {
+ gCtx.putImageData(imageData, 0,0);
+ }
+ }
+
+ function fix() {
+ }
+
+ function captureToCanvas() {
+ flash = document.getElementById("embedflash");
+ flash.ccCapture();
+ }
+
+ </script>
+
+
+ <title>Camcanvas - Webcam to Canvas JavaScript API</title>
+ </head>
+
+ <body onload="t1()">
+
+<input type="text" id="rr" value="" />
+<button onclick="captureToCanvas()">Capture to Canvas</button>
+
+ <div class="container">
+
+ <object id="iembedflash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="640" height="240">
+ <param name="movie" value="camcanvas.swf" />
+ <param name="quality" value="high" />
+ <param name="allowScriptAccess" value="always" />
+ <embed allowScriptAccess="always" id="embedflash" src="camcanvas.swf" quality="high" width="640" height="240" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" mayscript="true" />
+ </object>
+
+ </div>
+
+
+ <canvas style="border:1px solid yellow" id="canvas" width="320" height="240"></canvas>
+ </body>
+</html>
BIN  samples/camcanvas.swf
Binary file not shown
BIN  samples/canvas.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 src/camcanvas.as
@@ -0,0 +1,38 @@
+import flash.external.ExternalInterface;
+import flash.display.BitmapData;
+import flash.geom.Matrix;
+
+class camcanvas {
+
+ public static function exportCapture(input:String):String {
+ snap();
+ return input;
+ }
+
+ public static function main() {
+
+ var cam = Camera.get();
+ cam.setMode(320,240, 24)
+ _root.attachMovie("ObjetVideo", "webcamVideo", 1);
+ _root.webcamVideo.attachVideo(cam);
+ _root.webcamVideo._x = 0;
+
+ _root.refFunc = exportCapture;
+ ExternalInterface.addCallback("ccCapture", _root, _root.refFunc);
+
+ }
+
+ public static function snap() {
+
+ var snapshot:flash.display.BitmapData = new flash.display.BitmapData(_root.webcamVideo._width,_root.webcamVideo.height,true);
+ snapshot.draw(_root.webcamVideo);
+ var string="";
+ for(var j=0;j<240;j++) {
+ var currLine = "";
+ for(var i=0;i<320;i++) {
+ currLine += snapshot.getPixel(i,j)+"-";
+ }
+ ExternalInterface.call("passLine", currLine)
+ }
+ }
+}
BIN  swf/camcanvas.swf
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.