From 7db037ab7a09383ffbb18241d1189d4ba78ba304 Mon Sep 17 00:00:00 2001
From: Michael Shapiro
Date: Fri, 8 Jun 2012 20:44:53 -0400
Subject: [PATCH 1/2] formatting
---
jquery.webcam.js | 171 +++++++++++----------
src/jscam.as | 376 +++++++++++++++++++++++------------------------
2 files changed, 273 insertions(+), 274 deletions(-)
diff --git a/jquery.webcam.js b/jquery.webcam.js
index ed0c205..00c205c 100644
--- a/jquery.webcam.js
+++ b/jquery.webcam.js
@@ -1,93 +1,92 @@
/**
-* jQuery webcam
-* Copyright (c) 2010, Robert Eisele (robert@xarg.org)
-* Dual licensed under the MIT or GPL Version 2 licenses.
-* Date: 09/12/2010
-*
-* @author Robert Eisele
-* @version 1.0
-*
-* @see http://www.xarg.org/project/jquery-webcam-plugin/
-**/
+ * jQuery webcam
+ * Copyright (c) 2010, Robert Eisele (robert@xarg.org)
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * Date: 09/12/2010
+ *
+ * @author Robert Eisele
+ * @version 1.0
+ *
+ * @see http://www.xarg.org/project/jquery-webcam-plugin/
+ **/
(function ($) {
- var webcam = {
-
- extern: null, // external select token to support jQuery dialogs
- append: true, // append object instead of overwriting
-
- width: 320,
- height: 240,
-
- mode: "callback", // callback | save | stream
-
- swffile: "jscam.swf",
- quality: 85,
-
- debug: function () {},
- onCapture: function () {},
- onTick: function () {},
- onSave: function () {},
- onLoad: function () {}
- };
-
- window.webcam = webcam;
-
- $.fn.webcam = function(options) {
-
- if (typeof options === "object") {
- for (var ndx in webcam) {
- if (options[ndx] !== undefined) {
- webcam[ndx] = options[ndx];
- }
- }
- }
-
- var source = '';
-
- if (null !== webcam.extern) {
- $(webcam.extern)[webcam.append ? "append" : "html"](source);
- } else {
- this[webcam.append ? "append" : "html"](source);
- }
-
- (_register = function(run) {
-
- var cam = document.getElementById('XwebcamXobjectX');
-
- if (cam.capture !== undefined) {
-
- /* Simple callback methods are not allowed :-/ */
- webcam.capture = function(x) {
- try {
- return cam.capture(x);
- } catch(e) {}
- }
- webcam.save = function(x) {
- try {
- return cam.save(x);
- } catch(e) {}
- }
- webcam.setCamera = function(x) {
- try {
- return cam.setCamera(x);
- } catch(e) {}
- }
- webcam.getCameraList = function() {
- try {
- return cam.getCameraList();
- } catch(e) {}
- }
-
- webcam.onLoad();
- } else if (0 == run) {
- webcam.debug("error", "Flash movie not yet registered!");
- } else {
- /* Flash interface not ready yet */
- window.setTimeout(_register, 1000 * (4 - run), run - 1);
- }
- })(3);
+ var webcam = {
+ extern: null, // external select token to support jQuery dialogs
+ append: true, // append object instead of overwriting
+
+ width: 320,
+ height: 240,
+
+ mode: "callback", // callback | save | stream
+
+ swffile: "jscam.swf",
+ quality: 85,
+
+ debug: function () {},
+ onCapture: function () {},
+ onTick: function () {},
+ onSave: function () {},
+ onLoad: function () {}
+ };
+
+ window.webcam = webcam;
+
+ $.fn.webcam = function(options) {
+
+ if (typeof options === "object") {
+ for (var ndx in webcam) {
+ if (options[ndx] !== undefined) {
+ webcam[ndx] = options[ndx];
+ }
+ }
}
+ var source = '';
+
+ if (null !== webcam.extern) {
+ $(webcam.extern)[webcam.append ? "append" : "html"](source);
+ } else {
+ this[webcam.append ? "append" : "html"](source);
+ }
+
+ (_register = function(run) {
+
+ var cam = document.getElementById('XwebcamXobjectX');
+
+ if (cam.capture !== undefined) {
+
+ /* Simple callback methods are not allowed :-/ */
+ webcam.capture = function(x) {
+ try {
+ return cam.capture(x);
+ } catch(e) {}
+ }
+ webcam.save = function(x) {
+ try {
+ return cam.save(x);
+ } catch(e) {}
+ }
+ webcam.setCamera = function(x) {
+ try {
+ return cam.setCamera(x);
+ } catch(e) {}
+ }
+ webcam.getCameraList = function() {
+ try {
+ return cam.getCameraList();
+ } catch(e) {}
+ }
+
+ webcam.onLoad();
+ } else if (0 == run) {
+ webcam.debug("error", "Flash movie not yet registered!");
+ } else {
+ /* Flash interface not ready yet */
+ window.setTimeout(_register, 1000 * (4 - run), run - 1);
+ }
+ })(3);
+ }
+
})(jQuery);
diff --git a/src/jscam.as b/src/jscam.as
index aa70172..fe92cc3 100644
--- a/src/jscam.as
+++ b/src/jscam.as
@@ -1,14 +1,14 @@
/**
-* jQuery webcam
-* Copyright (c) 2010, Robert Eisele (robert@xarg.org)
-* Dual licensed under the MIT or GPL Version 2 licenses.
-* Date: 09/12/2010
-*
-* @author Robert Eisele
-* @version 1.0
-*
-* @see http://www.xarg.org/project/jquery-webcam-plugin/
-**/
+ * jQuery webcam
+ * Copyright (c) 2010, Robert Eisele (robert@xarg.org)
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * Date: 09/12/2010
+ *
+ * @author Robert Eisele
+ * @version 1.0
+ *
+ * @see http://www.xarg.org/project/jquery-webcam-plugin/
+ **/
import flash.system.Security;
import flash.external.ExternalInterface;
@@ -17,227 +17,227 @@ import JPGEncoder;
class JSCam {
- private static var camera:Camera = null;
- private static var buffer:BitmapData = null;
- private static var quality:Number = 85;
- private static var interval = null;
- private static var stream = null;
- private static var mode = "callback";
-
- public static function main():Void {
-
- System.security.allowDomain("*");
-
- if (_root.mode) {
- mode = _root.mode;
- } else {
- ExternalInterface.call('webcam.debug', "error", "No camera mode present, falling back...");
- }
-
- if (_root.quality) {
- quality = _root.quality;
- }
-
- // From: http://www.squidder.com/2009/03/09/trick-auto-select-mac-isight-in-flash/
- var id:Number = -1;
- for (var i = 0, l = Camera.names.length; i < l; i++) {
- if (Camera.names[i] == "USB Video Class Video") {
- id = i;
- break;
- }
- }
- if (id > -1) {
- camera = Camera.get(id);
- } else {
- camera = Camera.get();
- }
-
- if (null != camera) {
-
- // http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary133.html
- camera.onStatus = function(info:Object) {
-
- switch (info.code) {
- case 'Camera.Muted':
- ExternalInterface.call('webcam.debug', "notify", "Camera stopped");
- break;
- case 'Camera.Unmuted' :
- ExternalInterface.call('webcam.debug', "notify", "Camera started");
- break;
- }
- }
+ private static var camera:Camera = null;
+ private static var buffer:BitmapData = null;
+ private static var quality:Number = 85;
+ private static var interval = null;
+ private static var stream = null;
+ private static var mode = "callback";
+
+ public static function main():Void {
+
+ System.security.allowDomain("*");
+
+ if (_root.mode) {
+ mode = _root.mode;
+ } else {
+ ExternalInterface.call('webcam.debug', "error", "No camera mode present, falling back...");
+ }
+
+ if (_root.quality) {
+ quality = _root.quality;
+ }
+
+ // From: http://www.squidder.com/2009/03/09/trick-auto-select-mac-isight-in-flash/
+ var id:Number = -1;
+ for (var i = 0, l = Camera.names.length; i < l; i++) {
+ if (Camera.names[i] == "USB Video Class Video") {
+ id = i;
+ break;
+ }
+ }
+ if (id > -1) {
+ camera = Camera.get(id);
+ } else {
+ camera = Camera.get();
+ }
+
+ if (null != camera) {
+
+ // http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary133.html
+ camera.onStatus = function(info:Object) {
+
+ switch (info.code) {
+ case 'Camera.Muted':
+ ExternalInterface.call('webcam.debug', "notify", "Camera stopped");
+ break;
+ case 'Camera.Unmuted' :
+ ExternalInterface.call('webcam.debug', "notify", "Camera started");
+ break;
+ }
+ }
- camera.setQuality(0, 100);
- camera.setMode(Stage.width, Stage.height, 24, false);
+ camera.setQuality(0, 100);
+ camera.setMode(Stage.width, Stage.height, 24, false);
- ExternalInterface.addCallback("capture", null, capture);
+ ExternalInterface.addCallback("capture", null, capture);
- ExternalInterface.addCallback("save", null, save);
+ ExternalInterface.addCallback("save", null, save);
- ExternalInterface.addCallback("setCamera", null, setCamera);
- ExternalInterface.addCallback("getCameraList", null, getCameraList);
+ ExternalInterface.addCallback("setCamera", null, setCamera);
+ ExternalInterface.addCallback("getCameraList", null, getCameraList);
- _root.attachMovie("clip", "video", 1);
- _root.video.attachVideo(camera);
- _root.video._x = 0;
- _root.video._y = 0;
+ _root.attachMovie("clip", "video", 1);
+ _root.video.attachVideo(camera);
+ _root.video._x = 0;
+ _root.video._y = 0;
- } else {
- ExternalInterface.call('webcam.debug', "error", "No camera was detected.");
- }
- }
+ } else {
+ ExternalInterface.call('webcam.debug', "error", "No camera was detected.");
+ }
+ }
- public static function capture(time:Number):Boolean {
+ public static function capture(time:Number):Boolean {
- if (null != camera) {
+ if (null != camera) {
- if (null != buffer) {
- return false;
- }
+ if (null != buffer) {
+ return false;
+ }
- buffer = new BitmapData(Stage.width, Stage.height);
- ExternalInterface.call('webcam.debug', "notify", "Capturing started.");
+ buffer = new BitmapData(Stage.width, Stage.height);
+ ExternalInterface.call('webcam.debug', "notify", "Capturing started.");
- if ("stream" == mode) {
- _stream();
- return true;
- }
+ if ("stream" == mode) {
+ _stream();
+ return true;
+ }
- if (!time) {
- time = -1;
- } else if (time > 10) {
- time = 10;
- }
+ if (!time) {
+ time = -1;
+ } else if (time > 10) {
+ time = 10;
+ }
- _capture(time + 1);
+ _capture(time + 1);
- return true;
- }
- return false;
- }
-
- private static function _capture(time:Number):Void {
-
- if (null != interval) {
- clearInterval(interval);
- }
+ return true;
+ }
+ return false;
+ }
+
+ private static function _capture(time:Number):Void {
+
+ if (null != interval) {
+ clearInterval(interval);
+ }
- if (0 == time) {
- buffer.draw(_root.video);
- ExternalInterface.call('webcam.onCapture');
- ExternalInterface.call('webcam.debug', "notify", "Capturing finished.");
- } else {
- ExternalInterface.call('webcam.onTick', time - 1);
- interval = setInterval(_capture, 1000, time - 1);
- }
- }
+ if (0 == time) {
+ buffer.draw(_root.video);
+ ExternalInterface.call('webcam.onCapture');
+ ExternalInterface.call('webcam.debug', "notify", "Capturing finished.");
+ } else {
+ ExternalInterface.call('webcam.onTick', time - 1);
+ interval = setInterval(_capture, 1000, time - 1);
+ }
+ }
- public static function getCameraList():Array {
+ public static function getCameraList():Array {
- var list = new Array();
+ var list = new Array();
- for (var i = 0, l = Camera.names.length; i < l; i++) {
- list[i] = Camera.names[i];
- }
- return list;
- }
+ for (var i = 0, l = Camera.names.length; i < l; i++) {
+ list[i] = Camera.names[i];
+ }
+ return list;
+ }
- public static function setCamera(id:Number):Boolean {
+ public static function setCamera(id:Number):Boolean {
- if (0 <= id && id < Camera.names.length) {
- camera = Camera.get(id);
- camera.setQuality(0, 100);
- camera.setMode(Stage.width, Stage.height, 24, false);
+ if (0 <= id && id < Camera.names.length) {
+ camera = Camera.get(id);
+ camera.setQuality(0, 100);
+ camera.setMode(Stage.width, Stage.height, 24, false);
- _root.removeMovieClip();
- _root.attachMovie("clip", "video", 1);
- _root.video.attachVideo(camera);
- _root.video._x = 0;
- _root.video._y = 0;
+ _root.removeMovieClip();
+ _root.attachMovie("clip", "video", 1);
+ _root.video.attachVideo(camera);
+ _root.video._x = 0;
+ _root.video._y = 0;
- return true;
+ return true;
- }
- return false;
- }
+ }
+ return false;
+ }
- public static function save(file:String):Boolean {
+ public static function save(file:String):Boolean {
- if ("stream" == mode) {
+ if ("stream" == mode) {
- return true;
+ return true;
- } else if (null != buffer) {
+ } else if (null != buffer) {
- if ("callback" == mode) {
+ if ("callback" == mode) {
- for (var i = 0; i < 240; ++i) {
+ for (var i = 0; i < 240; ++i) {
- var row = "";
- for (var j=0; j < 320; ++j) {
- row+= buffer.getPixel(j, i);
- row+= ";";
- }
- ExternalInterface.call("webcam.onSave", row);
- }
+ var row = "";
+ for (var j=0; j < 320; ++j) {
+ row+= buffer.getPixel(j, i);
+ row+= ";";
+ }
+ ExternalInterface.call("webcam.onSave", row);
+ }
- } else if ("save" == mode) {
+ } else if ("save" == mode) {
- if (file) {
+ if (file) {
- var e = new JPGEncoder(quality);
+ var e = new JPGEncoder(quality);
- var sal = {};
- sal.sendAndLoad = XML.prototype.sendAndLoad;
- sal.contentType = "image/jpeg";
- sal.toString = function() {
- return e.encode(JSCam.buffer);
- }
+ var sal = {};
+ sal.sendAndLoad = XML.prototype.sendAndLoad;
+ sal.contentType = "image/jpeg";
+ sal.toString = function() {
+ return e.encode(JSCam.buffer);
+ }
- var doc = new XML();
- doc.onLoad = function(success) {
- ExternalInterface.call("webcam.onSave", "done", this.toString());
- }
+ var doc = new XML();
+ doc.onLoad = function(success) {
+ ExternalInterface.call("webcam.onSave", "done", this.toString());
+ }
- sal.sendAndLoad(file, doc);
-/*
- ExternalInterface.call('webcam.debug', "error", "No save mode compiled in.");
- return false;
-*/
- } else {
- ExternalInterface.call('webcam.debug', "error", "No file name specified.");
- return false;
- }
+ sal.sendAndLoad(file, doc);
+ /*
+ ExternalInterface.call('webcam.debug', "error", "No save mode compiled in.");
+ return false;
+ */
+ } else {
+ ExternalInterface.call('webcam.debug', "error", "No file name specified.");
+ return false;
+ }
- } else {
- ExternalInterface.call('webcam.debug', "error", "Unsupported storage mode.");
- }
+ } else {
+ ExternalInterface.call('webcam.debug', "error", "Unsupported storage mode.");
+ }
- buffer = null;
- return true;
- }
- return false;
- }
+ buffer = null;
+ return true;
+ }
+ return false;
+ }
- private static function _stream():Void {
+ private static function _stream():Void {
- buffer.draw(_root.video);
+ buffer.draw(_root.video);
- if (null != stream) {
- clearInterval(stream);
- }
+ if (null != stream) {
+ clearInterval(stream);
+ }
- for (var i = 0; i < 240; ++i) {
+ for (var i = 0; i < 240; ++i) {
- var row = "";
- for (var j=0; j < 320; ++j) {
- row+= buffer.getPixel(j, i);
- row+= ";";
- }
- ExternalInterface.call("webcam.onSave", row);
- }
+ var row = "";
+ for (var j=0; j < 320; ++j) {
+ row+= buffer.getPixel(j, i);
+ row+= ";";
+ }
+ ExternalInterface.call("webcam.onSave", row);
+ }
- stream = setInterval(_stream, 10);
- }
+ stream = setInterval(_stream, 10);
+ }
}
From 4e9a374dcdafb3d09aaf4657ec2308025796d6f1 Mon Sep 17 00:00:00 2001
From: Michael Shapiro
Date: Sun, 10 Jun 2012 13:54:15 -0400
Subject: [PATCH 2/2] Fixes, speedups (canvas only)
---
jquery.webcam.js | 14 +---
jscam.swf | Bin 5230 -> 1096 bytes
src/jscam.as | 193 ++++++++---------------------------------------
src/jscam.xml | 13 ++--
4 files changed, 43 insertions(+), 177 deletions(-)
diff --git a/jquery.webcam.js b/jquery.webcam.js
index 00c205c..535a501 100644
--- a/jquery.webcam.js
+++ b/jquery.webcam.js
@@ -19,22 +19,17 @@
width: 320,
height: 240,
- mode: "callback", // callback | save | stream
-
swffile: "jscam.swf",
quality: 85,
debug: function () {},
onCapture: function () {},
- onTick: function () {},
- onSave: function () {},
onLoad: function () {}
};
window.webcam = webcam;
$.fn.webcam = function(options) {
-
if (typeof options === "object") {
for (var ndx in webcam) {
if (options[ndx] !== undefined) {
@@ -63,16 +58,13 @@
return cam.capture(x);
} catch(e) {}
}
- webcam.save = function(x) {
- try {
- return cam.save(x);
- } catch(e) {}
- }
+
webcam.setCamera = function(x) {
try {
return cam.setCamera(x);
} catch(e) {}
}
+
webcam.getCameraList = function() {
try {
return cam.getCameraList();
@@ -80,7 +72,7 @@
}
webcam.onLoad();
- } else if (0 == run) {
+ } else if (run == 0) {
webcam.debug("error", "Flash movie not yet registered!");
} else {
/* Flash interface not ready yet */
diff --git a/jscam.swf b/jscam.swf
index 7cbd2ef081b95e35ab9799f63e5aad5fdaae5058..ef144ad6261816c2ea0a4280ebbda0973d498547 100644
GIT binary patch
literal 1096
zcmV-O1h@M`S5pYO2><|i+PqdvciTi1zIr&4lg4Qcsne2zLlPhb+)@fVnxvvYIQ0XY
zaM=0C)>zg-mW(uxU1h0rSnxC8C$Qm9@DsXbBkrA%9mj=)1+egF?(3WHK1S9M
zu6+-X0Bk5=scD+-uPp<$$~H}vLV1n3_c57-iPDX<6mSMAQhKEpLuSd!`O2$0kl?$S=S!&QN+M@91B4@SWvQAvrOdf
zsTXrNkx5cRY|ia&zZ#x+EZfTpv`?Wufm&FWr6`Z>xa=^_y2z*kEQ-Pi4x`APK*R>&
z2@?nwAzFfn7r4^|D$p7AdMpAbvd6@v;hi#nT9`1fGUn%jJumR$K1Ck3TIe5z!%uwM
zjUiFNgw0~{Cl!8QB0<>{sxy(ZuL9N_YEni!y~f`Us49IQj>^l
z%{oTho;qOW1;O^*oLO)!h@77*^BP*OpB3n$YI~r1K`(^wfcUHC4N6WR7ke031X=2r
zNT?9eCM2t1zHF|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PxX8=AS?!)X9`w6m2^}_(~
z6ApB@GU#V2C|)r?LCHs_Xt0t3THAX97n+IOzd6RRBLNK?1*u0R?Fq8
z$YonaW$nxX$@{&cpFyw6A+O4~yOQ6$m-x;5cD#8nId9(E7um}V4No
zz2agtTz-d3@Qw@87s-bInYS|hmQVBKN^z=)9V(?rOa`;Owv}=in;e{oPmc|bCW(1D
oSK|M0kN-fA!@^imE{63&OhSp|@hAZ;{SN>D0RR630I;1k>o-UUQ2+n{
diff --git a/src/jscam.as b/src/jscam.as
index fe92cc3..ab03f37 100644
--- a/src/jscam.as
+++ b/src/jscam.as
@@ -13,50 +13,38 @@
import flash.system.Security;
import flash.external.ExternalInterface;
import flash.display.BitmapData;
-import JPGEncoder;
class JSCam {
private static var camera:Camera = null;
+ private static var display:MovieClip = null;
private static var buffer:BitmapData = null;
private static var quality:Number = 85;
- private static var interval = null;
- private static var stream = null;
- private static var mode = "callback";
public static function main():Void {
System.security.allowDomain("*");
- if (_root.mode) {
- mode = _root.mode;
- } else {
- ExternalInterface.call('webcam.debug', "error", "No camera mode present, falling back...");
- }
-
- if (_root.quality) {
+ if (_root.quality)
quality = _root.quality;
- }
+
// From: http://www.squidder.com/2009/03/09/trick-auto-select-mac-isight-in-flash/
- var id:Number = -1;
- for (var i = 0, l = Camera.names.length; i < l; i++) {
+ var cameraId:Number = -1;
+ for (var i = 0, l = Camera.names.length; i < l; i++)
if (Camera.names[i] == "USB Video Class Video") {
- id = i;
+ cameraId = i;
break;
}
- }
- if (id > -1) {
- camera = Camera.get(id);
- } else {
- camera = Camera.get();
- }
- if (null != camera) {
+ if (cameraId > -1)
+ camera = Camera.get(cameraId);
+ else
+ camera = Camera.get();
+ if (camera) {
// http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary133.html
camera.onStatus = function(info:Object) {
-
switch (info.code) {
case 'Camera.Muted':
ExternalInterface.call('webcam.debug', "notify", "Camera stopped");
@@ -71,173 +59,58 @@ class JSCam {
camera.setMode(Stage.width, Stage.height, 24, false);
ExternalInterface.addCallback("capture", null, capture);
-
- ExternalInterface.addCallback("save", null, save);
-
ExternalInterface.addCallback("setCamera", null, setCamera);
ExternalInterface.addCallback("getCameraList", null, getCameraList);
- _root.attachMovie("clip", "video", 1);
- _root.video.attachVideo(camera);
- _root.video._x = 0;
- _root.video._y = 0;
+ display = _root.attachMovie("clip", "video", 1);
+ display.video.attachVideo(camera);
+ display.video._x = 0;
+ display.video._y = 0;
} else {
ExternalInterface.call('webcam.debug', "error", "No camera was detected.");
}
}
- public static function capture(time:Number):Boolean {
-
- if (null != camera) {
-
- if (null != buffer) {
- return false;
- }
-
- buffer = new BitmapData(Stage.width, Stage.height);
- ExternalInterface.call('webcam.debug', "notify", "Capturing started.");
-
- if ("stream" == mode) {
- _stream();
- return true;
- }
-
- if (!time) {
- time = -1;
- } else if (time > 10) {
- time = 10;
- }
-
- _capture(time + 1);
-
- return true;
- }
- return false;
- }
-
- private static function _capture(time:Number):Void {
-
- if (null != interval) {
- clearInterval(interval);
- }
-
- if (0 == time) {
- buffer.draw(_root.video);
- ExternalInterface.call('webcam.onCapture');
- ExternalInterface.call('webcam.debug', "notify", "Capturing finished.");
- } else {
- ExternalInterface.call('webcam.onTick', time - 1);
- interval = setInterval(_capture, 1000, time - 1);
- }
- }
public static function getCameraList():Array {
-
var list = new Array();
- for (var i = 0, l = Camera.names.length; i < l; i++) {
+ for (var i=0, l = Camera.names.length; i < l; i++)
list[i] = Camera.names[i];
- }
+
return list;
}
- public static function setCamera(id:Number):Boolean {
- if (0 <= id && id < Camera.names.length) {
- camera = Camera.get(id);
+ public static function setCamera(cameraId:Number):Boolean {
+ if (0 <= cameraId && cameraId < Camera.names.length) {
+ camera = Camera.get(cameraId);
camera.setQuality(0, 100);
camera.setMode(Stage.width, Stage.height, 24, false);
-
- _root.removeMovieClip();
- _root.attachMovie("clip", "video", 1);
- _root.video.attachVideo(camera);
- _root.video._x = 0;
- _root.video._y = 0;
-
return true;
-
}
return false;
}
- public static function save(file:String):Boolean {
- if ("stream" == mode) {
-
- return true;
+ public static function capture():Boolean {
+ if (!camera)
+ return false;
- } else if (null != buffer) {
+ ExternalInterface.call('webcam.debug', "notify", "Capturing started.");
- if ("callback" == mode) {
+ buffer = new BitmapData(Stage.width, Stage.height);
+ buffer.draw(display.video);
- for (var i = 0; i < 240; ++i) {
+ var pixels = [];
+ for (var i=0; i < 240; ++i)
+ for (var j=0; j < 320; ++j)
+ pixels.push(buffer.getPixel(j, i).valueOf())
- var row = "";
- for (var j=0; j < 320; ++j) {
- row+= buffer.getPixel(j, i);
- row+= ";";
- }
- ExternalInterface.call("webcam.onSave", row);
- }
-
- } else if ("save" == mode) {
-
- if (file) {
-
- var e = new JPGEncoder(quality);
-
- var sal = {};
- sal.sendAndLoad = XML.prototype.sendAndLoad;
- sal.contentType = "image/jpeg";
- sal.toString = function() {
- return e.encode(JSCam.buffer);
- }
-
- var doc = new XML();
- doc.onLoad = function(success) {
- ExternalInterface.call("webcam.onSave", "done", this.toString());
- }
-
- sal.sendAndLoad(file, doc);
- /*
- ExternalInterface.call('webcam.debug', "error", "No save mode compiled in.");
- return false;
- */
- } else {
- ExternalInterface.call('webcam.debug', "error", "No file name specified.");
- return false;
- }
-
- } else {
- ExternalInterface.call('webcam.debug', "error", "Unsupported storage mode.");
- }
-
- buffer = null;
- return true;
- }
- return false;
- }
-
- private static function _stream():Void {
-
- buffer.draw(_root.video);
-
- if (null != stream) {
- clearInterval(stream);
- }
-
-
- for (var i = 0; i < 240; ++i) {
-
- var row = "";
- for (var j=0; j < 320; ++j) {
- row+= buffer.getPixel(j, i);
- row+= ";";
- }
- ExternalInterface.call("webcam.onSave", row);
- }
+ ExternalInterface.call("webcam.onCapture", pixels);
+ ExternalInterface.call('webcam.debug', "notify", "Capturing finished.");
- stream = setInterval(_stream, 10);
+ return true;
}
}
diff --git a/src/jscam.xml b/src/jscam.xml
index a0734a0..b76dc45 100644
--- a/src/jscam.xml
+++ b/src/jscam.xml
@@ -1,11 +1,12 @@
-
-
-
-
+