Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial code

  • Loading branch information...
commit 53ed98b37adfaaddf4fb145ad48521ab60aafad4 0 parents
Marcio Galli authored
6 build.sh
... ... @@ -0,0 +1,6 @@
  1 +#!/bin/sh
  2 +
  3 +# This compiles the binary for production. If you need to add debug level check mtasc options
  4 +
  5 +./swfmill simple library.xml ./swf/camcanvas.swf
  6 +./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 @@
  1 +This is CamCanvas API v 0.1
  2 +--
  3 +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.
  4 +
  5 +Marcio
11 library.xml
... ... @@ -0,0 +1,11 @@
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<movie width="320" height="240" framerate="24">
  3 + <background color="#ffffff" />
  4 + <DefineVideoStream objectID="1" frames="0" width="320" height="240" deblocking="0" smoothing="0" codec="0" />
  5 + <frame>
  6 + <library>
  7 + <clip id="ObjetVideo" objectID="1" />
  8 + </library>
  9 + </frame>
  10 +
  11 +</movie>
9 readme.txt
... ... @@ -0,0 +1,9 @@
  1 +Depends on:
  2 +
  3 +Mtasc - http://www.mtasc.org/#download
  4 +SwfMill - http://swfmill.org/
  5 +
  6 +Put mtasc and swfmill binary in this directory and use the build script.
  7 +You will also need ./lib/* from mtasc : ./lib/std and ./lib/std8
  8 +
  9 +
41 samples/camcanvas.as
... ... @@ -0,0 +1,41 @@
  1 +import flash.external.ExternalInterface;
  2 +import net.hiddenresource.util.debug.Debug;
  3 +import flash.display.BitmapData;
  4 +import flash.geom.Matrix;
  5 +
  6 +class camcanvas {
  7 +
  8 + static var app : camcanvas;
  9 +
  10 + public static function exportCapture(input:String):String {
  11 + snap();
  12 + return input;
  13 + }
  14 +
  15 + public static function main() {
  16 +
  17 + var cam = Camera.get();
  18 + cam.setMode(320,240, 24)
  19 + _root.attachMovie("ObjetVideo", "webcamVideo", 1);
  20 + _root.webcamVideo.attachVideo(cam);
  21 + _root.webcamVideo._x = 0;
  22 +
  23 + _root.refFunc = exportCapture;
  24 + ExternalInterface.addCallback("ccCapture", _root, _root.refFunc);
  25 +
  26 + }
  27 +
  28 + public static function snap() {
  29 +
  30 + var snapshot:flash.display.BitmapData = new flash.display.BitmapData(_root.webcamVideo._width,_root.webcamVideo.height,true);
  31 + snapshot.draw(_root.webcamVideo);
  32 + var string="";
  33 + for(var j=0;j<240;j++) {
  34 + var currLine = "";
  35 + for(var i=0;i<320;i++) {
  36 + currLine += snapshot.getPixel(i,j)+"-";
  37 + }
  38 + ExternalInterface.call("passLine", currLine)
  39 + }
  40 + }
  41 +}
155 samples/camcanvas.html
... ... @@ -0,0 +1,155 @@
  1 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2 +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  3 + <head>
  4 +<SCRIPT LANGUAGE="JavaScript">
  5 +
  6 +var canvas = null;
  7 +var ctx = null;
  8 +
  9 +function t1() {
  10 + replaceImageData();
  11 +}
  12 +
  13 +
  14 +var gCtx = null;
  15 +var gCanvas = null;
  16 + var gCanvas2 = null;
  17 + var gCtx = null;
  18 + var gCtx2 = null;
  19 + var gActive = false;
  20 + var gStartX = 0;
  21 + var gStartY = 0;
  22 + var gEndX = -1;
  23 + var gEndY = -1;
  24 +
  25 +
  26 +
  27 + function copyImageToCanvas(aImg)
  28 + {
  29 + gCanvas = document.getElementById("canvas");
  30 + var w = aImg.naturalWidth;
  31 + var h = aImg.naturalHeight;
  32 + gCanvas.style.width = w + "px";
  33 + gCanvas.style.height = h + "px";
  34 + gCanvas.width = w;
  35 + gCanvas.height = h;
  36 +
  37 + gCtx = gCanvas.getContext("2d");
  38 + gCtx.clearRect(0, 0, w, h);
  39 + gCtx.drawImage(aImg, 0, 0);
  40 +
  41 + var container = gCanvas.parentNode;
  42 + gCanvas2 = document.createElement('canvas');
  43 + gCanvas2.id = "imageTemp";
  44 + gCanvas2.width = w;
  45 + gCanvas2.height = h;
  46 + container.appendChild(gCanvas2);
  47 + gCtx2 = gCanvas2.getContext("2d");
  48 + }
  49 +
  50 +
  51 +function replaceImageData() {
  52 + var img = new Image();
  53 + img.src="canvas.png";
  54 + img.onload = function() { copyImageToCanvas(img); continueCanvas() }
  55 +}
  56 +
  57 +var imageData = null;
  58 +
  59 +function continueCanvas() {
  60 +
  61 + imageData = gCtx.getImageData( 0,0,320,240);
  62 +
  63 + for (var x = 0; x < imageData.width; x++)
  64 + for (var y = 0; y < imageData.height; y++)
  65 + {
  66 + var offset = (y * imageData.width + x) * 4;
  67 + var r = imageData.data[offset];
  68 + var g = imageData.data[offset + 1];
  69 + var b = imageData.data[offset + 2];
  70 + imageData.data[offset]=0;
  71 +
  72 + }
  73 + gCtx.putImageData(imageData, 0,0);
  74 +
  75 +}
  76 +
  77 + var ii=0;
  78 + var jj=0;
  79 + var c=0;
  80 +
  81 + function passLine(stringPixels) {
  82 + //a = (intVal >> 24) & 0xff;
  83 +
  84 + var coll = stringPixels.split("-");
  85 +
  86 + for(var i=0;i<320;i++) {
  87 +
  88 + var intVal = parseInt(coll[i]);
  89 +
  90 + r = (intVal >> 16) & 0xff;
  91 + g = (intVal >> 8) & 0xff;
  92 + b = (intVal ) & 0xff;
  93 + imageData.data[c+0]=r;
  94 + imageData.data[c+1]=g;
  95 + imageData.data[c+2]=b;
  96 + imageData.data[c+3]=128;
  97 + c+=4;
  98 + }
  99 +
  100 +
  101 + if(c>=320*240*4) {
  102 + c=0;
  103 + gCtx.putImageData(imageData, 0,0);
  104 + }
  105 + }
  106 +
  107 + function passImage(intVal) {
  108 + //a = (intVal >> 24) & 0xff;
  109 + r = (intVal >> 16) & 0xff;
  110 + g = (intVal >> 8) & 0xff;
  111 + b = (intVal ) & 0xff;
  112 + imageData.data[c+0]=r;
  113 + imageData.data[c+1]=g;
  114 + imageData.data[c+2]=b;
  115 + imageData.data[c+3]=128;
  116 + c+=4;
  117 + if(c>=320*240*4) {
  118 + gCtx.putImageData(imageData, 0,0);
  119 + }
  120 + }
  121 +
  122 + function fix() {
  123 + }
  124 +
  125 + function captureToCanvas() {
  126 + flash = document.getElementById("embedflash");
  127 + flash.ccCapture();
  128 + }
  129 +
  130 + </script>
  131 +
  132 +
  133 + <title>Camcanvas - Webcam to Canvas JavaScript API</title>
  134 + </head>
  135 +
  136 + <body onload="t1()">
  137 +
  138 +<input type="text" id="rr" value="" />
  139 +<button onclick="captureToCanvas()">Capture to Canvas</button>
  140 +
  141 + <div class="container">
  142 +
  143 + <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">
  144 + <param name="movie" value="camcanvas.swf" />
  145 + <param name="quality" value="high" />
  146 + <param name="allowScriptAccess" value="always" />
  147 + <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" />
  148 + </object>
  149 +
  150 + </div>
  151 +
  152 +
  153 + <canvas style="border:1px solid yellow" id="canvas" width="320" height="240"></canvas>
  154 + </body>
  155 +</html>
BIN  samples/camcanvas.swf
Binary file not shown
BIN  samples/canvas.png
38 src/camcanvas.as
... ... @@ -0,0 +1,38 @@
  1 +import flash.external.ExternalInterface;
  2 +import flash.display.BitmapData;
  3 +import flash.geom.Matrix;
  4 +
  5 +class camcanvas {
  6 +
  7 + public static function exportCapture(input:String):String {
  8 + snap();
  9 + return input;
  10 + }
  11 +
  12 + public static function main() {
  13 +
  14 + var cam = Camera.get();
  15 + cam.setMode(320,240, 24)
  16 + _root.attachMovie("ObjetVideo", "webcamVideo", 1);
  17 + _root.webcamVideo.attachVideo(cam);
  18 + _root.webcamVideo._x = 0;
  19 +
  20 + _root.refFunc = exportCapture;
  21 + ExternalInterface.addCallback("ccCapture", _root, _root.refFunc);
  22 +
  23 + }
  24 +
  25 + public static function snap() {
  26 +
  27 + var snapshot:flash.display.BitmapData = new flash.display.BitmapData(_root.webcamVideo._width,_root.webcamVideo.height,true);
  28 + snapshot.draw(_root.webcamVideo);
  29 + var string="";
  30 + for(var j=0;j<240;j++) {
  31 + var currLine = "";
  32 + for(var i=0;i<320;i++) {
  33 + currLine += snapshot.getPixel(i,j)+"-";
  34 + }
  35 + ExternalInterface.call("passLine", currLine)
  36 + }
  37 + }
  38 +}
BIN  swf/camcanvas.swf
Binary file not shown

0 comments on commit 53ed98b

Please sign in to comment.
Something went wrong with that request. Please try again.