jpeg_camera 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0744de71724242b1e51b85a02350184aba99817d
4
- data.tar.gz: 22fea3b498ed0de84ecbbc713b8c1829d9e844e8
3
+ metadata.gz: dfa56163cd863c48fd89a61645370bf358ba929c
4
+ data.tar.gz: 56f8ed8419349b847244fe72f37356756f8b6ecd
5
5
  SHA512:
6
- metadata.gz: 18865fe71b18a1b2c5b70ba2a82a1b04f0fdcb096a47dc0dc1d1b860e5c5aa8cb1232f7343b1f5353cc182efe093477db324d0f23883544a948f236d09dc1bc3
7
- data.tar.gz: a584863d07b75f83ede1d901bb49bd193ed3afbb93b8a9be1ac5d3fdececab354e36c7ce79ea7e6c04f29622a280e2a3fd771480e63735d50141707b3dab990f
6
+ metadata.gz: b35cb767d37def1dd25e03767c4e0e06003430d9f27453d942cd25ae212021df94837e997db414bd526b1052eb85d07e0daec1508dcb0b847b50af820fbd02f5
7
+ data.tar.gz: 07fc68d18ae20247e83f01c5560f6893e9627651449ecacbab21f8e87672bec7ecf8bdda785ddf81459aeb7e03cbcc39b38d8a552fb504f09e2ed7a1e733f621
data/README.md CHANGED
@@ -74,7 +74,7 @@ to also load Canvas-to-Blob. You don't need SWFObject for HTML5.
74
74
 
75
75
  Require the gem in your Gemfile.
76
76
 
77
- gem "jpeg_camera", "~> 1.1.3"
77
+ gem "jpeg_camera", "~> 1.2.0"
78
78
 
79
79
  Add appropriate requires to your application.js. SWFObject and Canvas-to-Blob
80
80
  are stored in separate files so that you don't have to load them again if you
@@ -1,8 +1,8 @@
1
- /*! JpegCamera 1.1.3 | 2013-08-09
1
+ /*! JpegCamera 1.2.0 | 2013-11-07
2
2
  (c) 2013 Adam Wrobel
3
3
  http://amw.github.io/jpeg_camera */
4
4
  (function() {
5
- var JpegCamera, JpegCameraFlash, JpegCameraHtml5, Snapshot, check_canvas_to_blob, supported_flash_version, _ref, _ref1,
5
+ var JpegCamera, JpegCameraFlash, JpegCameraHtml5, Snapshot, Stats, check_canvas_to_blob, supported_flash_version, _ref, _ref1,
6
6
  __hasProp = {}.hasOwnProperty,
7
7
  __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
8
8
 
@@ -19,7 +19,8 @@
19
19
  shutter: true,
20
20
  mirror: false,
21
21
  timeout: 0,
22
- retry_success: false
22
+ retry_success: false,
23
+ scale: 1.0
23
24
  };
24
25
 
25
26
  JpegCamera._canvas_supported = !!document.createElement('canvas').getContext;
@@ -50,7 +51,10 @@
50
51
  JpegCamera.prototype.ready = function(callback) {
51
52
  this.options.on_ready = callback;
52
53
  if (this.options.on_ready && this._is_ready) {
53
- this.options.on_ready.call(this);
54
+ this.options.on_ready.call(this, {
55
+ video_width: this.video_width,
56
+ video_height: this.video_height
57
+ });
54
58
  }
55
59
  return this;
56
60
  };
@@ -80,7 +84,7 @@
80
84
  };
81
85
 
82
86
  JpegCamera.prototype.capture = function(options) {
83
- var snapshot, _options;
87
+ var scale, snapshot, _options;
84
88
  if (options == null) {
85
89
  options = {};
86
90
  }
@@ -90,7 +94,9 @@
90
94
  if (_options.shutter) {
91
95
  this._engine_play_shutter_sound();
92
96
  }
93
- this._engine_capture(snapshot, _options.mirror, _options.quality, 1.0);
97
+ scale = Math.min(1.0, _options.scale);
98
+ scale = Math.max(0.01, scale);
99
+ this._engine_capture(snapshot, _options.mirror, _options.quality, scale);
94
100
  return snapshot;
95
101
  };
96
102
 
@@ -154,8 +160,11 @@
154
160
  return delete this._snapshots[snapshot.id];
155
161
  };
156
162
 
157
- JpegCamera.prototype._prepared = function() {
163
+ JpegCamera.prototype._prepared = function(video_width, video_height) {
158
164
  var that;
165
+ this.video_width = video_width;
166
+ this.video_height = video_height;
167
+ this._debug("Camera resolution " + this.video_width + "x" + this.video_height + "px");
159
168
  that = this;
160
169
  return setTimeout((function() {
161
170
  return that._wait_until_stream_looks_ok(true);
@@ -170,7 +179,10 @@
170
179
  this._debug("Camera is ready");
171
180
  this._is_ready = true;
172
181
  if (this.options.on_ready) {
173
- return this.options.on_ready.call(this);
182
+ return this.options.on_ready.call(this, {
183
+ video_width: this.video_width,
184
+ video_height: this.video_height
185
+ });
174
186
  }
175
187
  } else {
176
188
  if (show_debug) {
@@ -381,13 +393,31 @@
381
393
  return context.getImageData(0, 0, canvas.width, canvas.height);
382
394
  };
383
395
 
396
+ JpegCameraHtml5.prototype._engine_get_blob = function(snapshot, mime, mirror, quality, callback) {
397
+ var canvas, context;
398
+ if (mirror) {
399
+ canvas = document.createElement("canvas");
400
+ canvas.width = snapshot._canvas.width;
401
+ canvas.height = snapshot._canvas.height;
402
+ context = canvas.getContext("2d");
403
+ context.setTransform(1, 0, 0, 1, 0, 0);
404
+ context.translate(canvas.width, 0);
405
+ context.scale(-1, 1);
406
+ context.drawImage(snapshot._canvas, 0, 0);
407
+ } else {
408
+ canvas = snapshot._canvas;
409
+ }
410
+ return canvas.toBlob((function(blob) {
411
+ return callback(blob);
412
+ }), mime, quality);
413
+ };
414
+
384
415
  JpegCameraHtml5.prototype._engine_discard = function(snapshot) {
385
416
  if (snapshot._xhr) {
386
417
  snapshot._xhr.abort();
387
418
  }
388
419
  delete snapshot._xhr;
389
- delete snapshot._canvas;
390
- return delete snapshot._jpeg_blob;
420
+ return delete snapshot._canvas;
391
421
  };
392
422
 
393
423
  JpegCameraHtml5.prototype._engine_show_stream = function() {
@@ -399,10 +429,9 @@
399
429
  };
400
430
 
401
431
  JpegCameraHtml5.prototype._engine_upload = function(snapshot, api_url, csrf_token, timeout) {
402
- var canvas, context, handler, that, xhr;
403
- that = this;
404
- if (snapshot._jpeg_blob) {
405
- this._debug("Uploading the file");
432
+ this._debug("Uploading the file");
433
+ return snapshot.get_blob(function(blob) {
434
+ var handler, xhr;
406
435
  handler = function(event) {
407
436
  delete snapshot._xhr;
408
437
  snapshot._status = event.target.status;
@@ -423,27 +452,9 @@
423
452
  xhr.onload = handler;
424
453
  xhr.onerror = handler;
425
454
  xhr.onabort = handler;
426
- xhr.send(snapshot._jpeg_blob);
455
+ xhr.send(blob);
427
456
  return snapshot._xhr = xhr;
428
- } else {
429
- this._debug("Generating JPEG file");
430
- if (snapshot._mirror) {
431
- canvas = document.createElement("canvas");
432
- canvas.width = snapshot._canvas.width;
433
- canvas.height = snapshot._canvas.height;
434
- context = canvas.getContext("2d");
435
- context.setTransform(1, 0, 0, 1, 0, 0);
436
- context.translate(canvas.width, 0);
437
- context.scale(-1, 1);
438
- context.drawImage(snapshot._canvas, 0, 0);
439
- } else {
440
- canvas = snapshot._canvas;
441
- }
442
- return canvas.toBlob(function(blob) {
443
- snapshot._jpeg_blob = blob;
444
- return that._engine_upload(snapshot, api_url, csrf_token, timeout);
445
- }, "image/jpeg", this.quality);
446
- }
457
+ }, "image/jpeg");
447
458
  };
448
459
 
449
460
  JpegCameraHtml5.prototype._remove_message = function() {
@@ -476,14 +487,13 @@
476
487
  this.video_container.appendChild(this.video);
477
488
  this.video_width = video_width;
478
489
  this.video_height = video_height;
479
- this._debug("Camera resolution " + this.video_width + "x" + this.video_height + "px");
480
490
  crop = this._get_video_crop();
481
491
  this.video.style.position = "relative";
482
492
  this.video.style.width = "" + crop.width + "px";
483
493
  this.video.style.height = "" + crop.height + "px";
484
494
  this.video.style.left = "" + crop.x_offset + "px";
485
495
  this.video.style.top = "" + crop.y_offset + "px";
486
- return this._prepared();
496
+ return this._prepared(this.video_width, this.video_height);
487
497
  } else if (this._status_checks_count > 100) {
488
498
  return this._got_error("Camera failed to initialize in 10 seconds");
489
499
  } else {
@@ -685,6 +695,26 @@
685
695
  return result;
686
696
  };
687
697
 
698
+ JpegCameraFlash.prototype._engine_get_blob = function(snapshot, mime, mirror, quality, callback) {
699
+ var canvas, context;
700
+ snapshot._extra_canvas || (snapshot._extra_canvas = this._engine_get_canvas(snapshot));
701
+ if (mirror) {
702
+ canvas = document.createElement("canvas");
703
+ canvas.width = snapshot._canvas.width;
704
+ canvas.height = snapshot._canvas.height;
705
+ context = canvas.getContext("2d");
706
+ context.setTransform(1, 0, 0, 1, 0, 0);
707
+ context.translate(canvas.width, 0);
708
+ context.scale(-1, 1);
709
+ context.drawImage(snapshot._extra_canvas, 0, 0);
710
+ } else {
711
+ canvas = snapshot._extra_canvas;
712
+ }
713
+ return canvas.toBlob((function(blob) {
714
+ return callback(blob);
715
+ }), mime, quality);
716
+ };
717
+
688
718
  JpegCameraFlash.prototype._engine_discard = function(snapshot) {
689
719
  return this._flash._discard(snapshot.id);
690
720
  };
@@ -697,11 +727,11 @@
697
727
  return this._flash._upload(snapshot.id, api_url, csrf_token, timeout);
698
728
  };
699
729
 
700
- JpegCameraFlash.prototype._flash_prepared = function() {
730
+ JpegCameraFlash.prototype._flash_prepared = function(width, height) {
701
731
  this._block_element_access();
702
732
  document.body.tabIndex = 0;
703
733
  document.body.focus();
704
- return this._prepared();
734
+ return this._prepared(width, height);
705
735
  };
706
736
 
707
737
  JpegCameraFlash.prototype._flash_upload_complete = function(snapshot_id, status_code, error, response) {
@@ -772,22 +802,59 @@
772
802
  that._extra_canvas || (that._extra_canvas = that.camera._engine_get_canvas(that));
773
803
  JpegCamera._add_prefixed_style(that._extra_canvas, "transform", "scalex(-1.0)");
774
804
  return callback.call(that, that._extra_canvas);
775
- }, 10);
805
+ }, 1);
776
806
  return true;
777
807
  };
778
808
 
779
809
  Snapshot.prototype._extra_canvas = null;
780
810
 
811
+ Snapshot.prototype.get_blob = function(callback, mime_type) {
812
+ var that;
813
+ if (mime_type == null) {
814
+ mime_type = "image/jpeg";
815
+ }
816
+ if (this._discarded) {
817
+ raise("discarded snapshot cannot be used");
818
+ }
819
+ if (!JpegCamera._canvas_supported) {
820
+ false;
821
+ }
822
+ that = this;
823
+ setTimeout(function() {
824
+ var mirror, quality;
825
+ if (that._blob_mime !== mime_type) {
826
+ that._blob = null;
827
+ }
828
+ that._blob_mime = mime_type;
829
+ if (that._blob) {
830
+ return callback.call(that, that._blob);
831
+ } else {
832
+ mirror = that.options.mirror;
833
+ quality = that.options.quality;
834
+ return that.camera._engine_get_blob(that, mime_type, mirror, quality, function(b) {
835
+ that._blob = b;
836
+ return callback.call(that, that._blob);
837
+ });
838
+ }
839
+ }, 1);
840
+ return true;
841
+ };
842
+
843
+ Snapshot.prototype._blob = null;
844
+
845
+ Snapshot.prototype._blob_mime = null;
846
+
781
847
  Snapshot.prototype.get_image_data = function(callback) {
782
848
  var that;
783
849
  if (this._discarded) {
784
850
  raise("discarded snapshot cannot be used");
785
851
  }
786
852
  that = this;
787
- return setTimeout(function() {
853
+ setTimeout(function() {
788
854
  that._image_data || (that._image_data = that.camera._engine_get_image_data(that));
789
855
  return callback.call(that, that._image_data);
790
- }, 5);
856
+ }, 1);
857
+ return null;
791
858
  };
792
859
 
793
860
  Snapshot.prototype._image_data = null;
@@ -860,6 +927,9 @@
860
927
 
861
928
  Snapshot.prototype.discard = function() {
862
929
  this.camera._discard(this);
930
+ delete this._extra_canvas;
931
+ delete this._image_data;
932
+ delete this._blob;
863
933
  return void 0;
864
934
  };
865
935
 
@@ -901,10 +971,9 @@
901
971
  gray = gray_values[_j];
902
972
  sum_of_square_distances += Math.pow(gray - mean, 2);
903
973
  }
904
- this._stats = {
905
- mean: mean,
906
- std: Math.round(Math.sqrt(sum_of_square_distances / n))
907
- };
974
+ this._stats = new Stats();
975
+ this._stats.mean = mean;
976
+ this._stats.std = Math.round(Math.sqrt(sum_of_square_distances / n));
908
977
  }
909
978
  return callback.call(this, this._stats);
910
979
  };
@@ -975,4 +1044,15 @@
975
1044
 
976
1045
  })();
977
1046
 
1047
+ Stats = (function() {
1048
+ function Stats() {}
1049
+
1050
+ Stats.prototype.mean = null;
1051
+
1052
+ Stats.prototype.std = null;
1053
+
1054
+ return Stats;
1055
+
1056
+ })();
1057
+
978
1058
  }).call(this);
@@ -1,4 +1,4 @@
1
- /*! JpegCamera 1.1.3 | 2013-08-09
1
+ /*! JpegCamera 1.2.0 | 2013-11-07
2
2
  (c) 2013 Adam Wrobel
3
3
  http://amw.github.io/jpeg_camera */
4
- !function(){var a,b,c,d,e,f,g,h,i={}.hasOwnProperty,j=function(a,b){function c(){this.constructor=a}for(var d in b)i.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};if(a=function(){function a(a,b){if("string"==typeof a&&(a=document.getElementById(a.replace("#",""))),!a||!a.offsetWidth)throw"JpegCamera: invalid container";a.innerHTML="",this.view_width=parseInt(a.offsetWidth,10),this.view_height=parseInt(a.offsetHeight,10),this.container=document.createElement("div"),this.container.style.width="100%",this.container.style.height="100%",this.container.style.position="relative",a.appendChild(this.container),this.options=this._extend({},this.constructor.DefaultOptions,b),this._engine_init()}return a.DefaultOptions={shutter_url:"/jpeg_camera/shutter.mp3",swf_url:"/jpeg_camera/jpeg_camera.swf",on_debug:function(a){return console&&console.log?console.log("JpegCamera: "+a):void 0},quality:.9,shutter:!0,mirror:!1,timeout:0,retry_success:!1},a._canvas_supported=!!document.createElement("canvas").getContext,a.canvas_supported=function(){return this._canvas_supported},a.prototype.ready=function(a){return this.options.on_ready=a,this.options.on_ready&&this._is_ready&&this.options.on_ready.call(this),this},a.prototype._is_ready=!1,a.prototype.error=function(a){return this.options.on_error=a,this.options.on_error&&this._error_occured&&this.options.on_error.call(this,this._error_occured),this},a.prototype._error_occured=!1,a.StatsCaptureScale=.2,a.prototype.get_stats=function(b){var c,e;return c=new d(this,{}),this._engine_capture(c,!1,.1,a.StatsCaptureScale),e=this,c.get_stats(function(a){return b.call(e,a)})},a.prototype.capture=function(a){var b,c;return null==a&&(a={}),b=new d(this,a),this._snapshots[b.id]=b,c=b._options(),c.shutter&&this._engine_play_shutter_sound(),this._engine_capture(b,c.mirror,c.quality,1),b},a.prototype._snapshots={},a.prototype.show_stream=function(){return this._engine_show_stream(),this._displayed_snapshot=null,this},a.prototype.discard_all=function(){var a,b,c;this._displayed_snapshot&&this.show_stream(),c=this._snapshots;for(a in c)b=c[a],this._engine_discard(b),b._discarded=!0;return this._snapshots={},this},a.prototype._extend=function(a){var b,c,d,e,f,g;for(d=Array.prototype.slice.call(arguments,1),f=0,g=d.length;g>f;f++)if(c=d[f])for(b in c)e=c[b],a[b]=e;return a},a.prototype._debug=function(a){return this.options.on_debug?this.options.on_debug.call(this,a):void 0},a.prototype._display=function(a){return this._engine_display(a),this._displayed_snapshot=a},a.prototype._displayed_snapshot=null,a.prototype._discard=function(a){return this._displayed_snapshot===a&&this.show_stream(),this._engine_discard(a),a._discarded=!0,delete this._snapshots[a.id]},a.prototype._prepared=function(){var a;return a=this,setTimeout(function(){return a._wait_until_stream_looks_ok(!0)},1)},a.prototype._wait_until_stream_looks_ok=function(a){return this.get_stats(function(b){var c;return b.std>2?(this._debug("Stream mean gray value = "+b.mean+" standard deviation = "+b.std),this._debug("Camera is ready"),this._is_ready=!0,this.options.on_ready?this.options.on_ready.call(this):void 0):(a&&this._debug("Stream mean gray value = "+b.mean+" standard deviation = "+b.std),c=this,setTimeout(function(){return c._wait_until_stream_looks_ok(!1)},100))})},a.prototype._got_error=function(a){return this._debug("Error - "+a),this._error_occured=a,this.options.on_error?this.options.on_error.call(this,this._error_occured):void 0},a.prototype._block_element_access=function(){return this._overlay=document.createElement("div"),this._overlay.style.width="100%",this._overlay.style.height="100%",this._overlay.style.position="absolute",this._overlay.style.top=0,this._overlay.style.left=0,this._overlay.style.zIndex=2,this.container.appendChild(this._overlay)},a.prototype._overlay=null,a.prototype.view_width=null,a.prototype.view_height=null,a._add_prefixed_style=function(a,b,c){var d;return d=b.charAt(0).toUpperCase()+b.slice(1),a.style[b]=c,a.style["Webkit"+d]=c,a.style["Moz"+d]=c,a.style["ms"+d]=c,a.style["O"+d]=c},a}(),navigator.getUserMedia||(navigator.getUserMedia=navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia),e=function(){var a;if(a=document.createElement("canvas"),a.getContext&&!a.toBlob)throw"JpegCamera: Canvas-to-Blob is not loaded"},navigator.getUserMedia&&(e(),c=function(b){function c(){return g=c.__super__.constructor.apply(this,arguments)}return j(c,b),c.prototype._engine_init=function(){var b,c,d,e,f,g,h;this._debug("Using HTML5 engine"),h=Math.floor(.2*this.view_height),e=Math.floor(.2*this.view_width),this.message=document.createElement("div"),this.message["class"]="message",this.message.style.width="100%",this.message.style.height="100%",a._add_prefixed_style(this.message,"boxSizing","border-box"),this.message.style.overflow="hidden",this.message.style.textAlign="center",this.message.style.paddingTop=""+h+"px",this.message.style.paddingBottom=""+h+"px",this.message.style.paddingLeft=""+e+"px",this.message.style.paddingRight=""+e+"px",this.message.style.position="absolute",this.message.style.zIndex=3,this.message.innerHTML="Please allow camera access when prompted by the browser.<br><br>Look for camera icon around your address bar.",this.container.appendChild(this.message),this.video_container=document.createElement("div"),this.video_container.style.width=""+this.view_width+"px",this.video_container.style.height=""+this.view_height+"px",this.video_container.style.overflow="hidden",this.video_container.style.position="absolute",this.video_container.style.zIndex=1,this.container.appendChild(this.video_container),this.video=document.createElement("video"),this.video.autoplay=!0,a._add_prefixed_style(this.video,"transform","scalex(-1.0)"),window.AudioContext||(window.AudioContext=window.webkitAudioContext),window.AudioContext&&this._load_shutter_sound(),d={video:{optional:[{minWidth:1280},{minWidth:640},{minWidth:480},{minWidth:360}]}},g=this,f=function(a){return g._remove_message(),g.video.src=window.URL?URL.createObjectURL(a):a,g._block_element_access(),g._wait_for_video_ready()},c=function(a){var b,c,d;g.message.innerHTML='<span style="color: red;">You have denied camera access.</span><br><br>Look for camera icon around your address bar to change your decision.',b=a.code;for(c in a)if(d=a[c],"code"!==c)return g._got_error(c),void 0;return g._got_error("UNKNOWN ERROR")};try{return navigator.getUserMedia(d,f,c)}catch(i){return b=i,navigator.getUserMedia("video",f,c)}},c.prototype._engine_play_shutter_sound=function(){var a;if(this.shutter_buffer)return a=this.audio_context.createBufferSource(),a.buffer=this.shutter_buffer,a.connect(this.audio_context.destination),a.start(0)},c.prototype._engine_capture=function(a,b,c,d){var e,f,g;return g=this._get_capture_crop(),e=document.createElement("canvas"),e.width=Math.round(g.width*d),e.height=Math.round(g.height*d),f=e.getContext("2d"),f.drawImage(this.video,g.x_offset,g.y_offset,g.width,g.height,0,0,Math.round(g.width*d),Math.round(g.height*d)),a._canvas=e,a._mirror=b,a._quality=c},c.prototype._engine_display=function(b){return this.displayed_canvas&&this.container.removeChild(this.displayed_canvas),this.displayed_canvas=b._canvas,this.displayed_canvas.style.width=""+this.view_width+"px",this.displayed_canvas.style.height=""+this.view_height+"px",this.displayed_canvas.style.top=0,this.displayed_canvas.style.left=0,this.displayed_canvas.style.position="absolute",this.displayed_canvas.style.zIndex=2,a._add_prefixed_style(this.displayed_canvas,"transform","scalex(-1.0)"),this.container.appendChild(this.displayed_canvas)},c.prototype._engine_get_canvas=function(a){var b,c;return b=document.createElement("canvas"),b.width=a._canvas.width,b.height=a._canvas.height,c=b.getContext("2d"),c.drawImage(a._canvas,0,0),b},c.prototype._engine_get_image_data=function(a){var b,c;return b=a._canvas,c=b.getContext("2d"),c.getImageData(0,0,b.width,b.height)},c.prototype._engine_discard=function(a){return a._xhr&&a._xhr.abort(),delete a._xhr,delete a._canvas,delete a._jpeg_blob},c.prototype._engine_show_stream=function(){return this.displayed_canvas&&(this.container.removeChild(this.displayed_canvas),this.displayed_canvas=null),this.video_container.style.display="block"},c.prototype._engine_upload=function(a,b,c,d){var e,f,g,h,i;return h=this,a._jpeg_blob?(this._debug("Uploading the file"),g=function(b){return delete a._xhr,a._status=b.target.status,a._response=b.target.responseText,a._status>=200&&a._status<300?a._upload_done():(a._error_message=b.target.statusText||"Unknown error",a._upload_fail())},i=new XMLHttpRequest,i.open("POST",b),i.timeout=d,c&&i.setRequestHeader("X-CSRF-Token",c),i.onload=g,i.onerror=g,i.onabort=g,i.send(a._jpeg_blob),a._xhr=i):(this._debug("Generating JPEG file"),a._mirror?(e=document.createElement("canvas"),e.width=a._canvas.width,e.height=a._canvas.height,f=e.getContext("2d"),f.setTransform(1,0,0,1,0,0),f.translate(e.width,0),f.scale(-1,1),f.drawImage(a._canvas,0,0)):e=a._canvas,e.toBlob(function(e){return a._jpeg_blob=e,h._engine_upload(a,b,c,d)},"image/jpeg",this.quality))},c.prototype._remove_message=function(){return this.message.style.display="none"},c.prototype._load_shutter_sound=function(){var a,b;if(!this.audio_context)return this.audio_context=new AudioContext,a=new XMLHttpRequest,a.open("GET",this.options.shutter_url,!0),a.responseType="arraybuffer",b=this,a.onload=function(){return b.audio_context.decodeAudioData(a.response,function(a){return b.shutter_buffer=a})},a.send()},c.prototype._wait_for_video_ready=function(){var a,b,c,d;return d=parseInt(this.video.videoWidth),c=parseInt(this.video.videoHeight),d>0&&c>0?(this.video_container.appendChild(this.video),this.video_width=d,this.video_height=c,this._debug("Camera resolution "+this.video_width+"x"+this.video_height+"px"),a=this._get_video_crop(),this.video.style.position="relative",this.video.style.width=""+a.width+"px",this.video.style.height=""+a.height+"px",this.video.style.left=""+a.x_offset+"px",this.video.style.top=""+a.y_offset+"px",this._prepared()):this._status_checks_count>100?this._got_error("Camera failed to initialize in 10 seconds"):(this._status_checks_count++,b=this,setTimeout(function(){return b._wait_for_video_ready()},100))},c.prototype._status_checks_count=0,c.prototype._get_video_crop=function(){var a,b,c,d,e;return c=this.video_width/this.video_height,e=this.view_width/this.view_height,c>=e?(this._debug("Filling height"),d=this.view_height/this.video_height,b=Math.round(this.video_width*d),{width:b,height:this.view_height,x_offset:-Math.floor((b-this.view_width)/2),y_offset:0}):(this._debug("Filling width"),d=this.view_width/this.video_width,a=Math.round(this.video_height*d),{width:this.view_width,height:a,x_offset:0,y_offset:-Math.floor((a-this.view_height)/2)})},c.prototype._get_capture_crop=function(){var a,b,c,d;return c=this.video_width/this.video_height,d=this.view_width/this.view_height,c>=d?(b=Math.round(this.video_height*d),{width:b,height:this.video_height,x_offset:Math.floor((this.video_width-b)/2),y_offset:0}):(a=Math.round(this.video_width/d),{width:this.video_width,height:a,x_offset:0,y_offset:Math.floor((this.video_height-a)/2)})},c}(a),window.JpegCamera=c),f="9",!window.swfobject)throw"JpegCamera: SWFObject is not loaded";!window.JpegCamera&&window.swfobject&&swfobject.hasFlashPlayerVersion(f)&&(b=function(b){function c(){return h=c.__super__.constructor.apply(this,arguments)}return j(c,b),c._send_message=function(a,b){var c,d;return(d=this._instances[parseInt(a)])?(c=Array.prototype.slice.call(arguments,2),this.prototype[b].apply(d,c)):void 0},c._instances={},c._next_id=1,c.prototype._engine_init=function(){var a,b,c,d,e,f,g;return this._debug("Using Flash engine"),this._id=this.constructor._next_id++,this.constructor._instances[this._id]=this,this.view_width<215||this.view_height<138?(this._got_error("camera is too small to display privacy dialog"),void 0):(d="flash_object_"+this._id,f={loop:"false",allowScriptAccess:"always",allowFullScreen:"false",quality:"best",wmode:"opaque",menu:"false"},a={id:d,align:"middle"},e={id:this._id,width:this.view_width,height:this.view_height,shutter_url:this.options.shutter_url},g=this,b=function(a){return a.success?(g._debug("Flash loaded"),g._flash=document.getElementById(d)):g._got_error("Flash loading failed.")},c=document.createElement("div"),c.id="jpeg_camera_flash_"+this._id,c.style.width="100%",c.style.height="100%",this.container.appendChild(c),swfobject.embedSWF(this.options.swf_url,c.id,this.view_width,this.view_height,"9",null,e,f,a,b))},c.prototype._engine_play_shutter_sound=function(){return this._flash._play_shutter()},c.prototype._engine_capture=function(a,b,c,d){return this._flash._capture(a.id,b,c,d)},c.prototype._engine_display=function(a){return this._flash._display(a.id)},c.prototype._engine_get_canvas=function(a){var b,c;return a._image_data||(a._image_data=this._engine_get_image_data(a)),b=document.createElement("canvas"),b.width=a._image_data.width,b.height=a._image_data.height,c=b.getContext("2d"),c.putImageData(a._image_data,0,0),b},c.prototype._engine_get_image_data=function(b){var c,d,e,f,g,h,i,j,k,l,m,n,o;for(f=this._flash._get_image_data(b.id),a.canvas_supported()?(d=document.createElement("canvas"),d.width=f.width,d.height=f.height,e=d.getContext("2d"),l=e.createImageData(f.width,f.height)):l={data:[],width:f.width,height:f.height},o=f.data,h=m=0,n=o.length;n>m;h=++m)j=o[h],i=4*h,k=255&j>>16,g=255&j>>8,c=255&j,l.data[i+0]=k,l.data[i+1]=g,l.data[i+2]=c,l.data[i+3]=255;return l},c.prototype._engine_discard=function(a){return this._flash._discard(a.id)},c.prototype._engine_show_stream=function(){return this._flash._show_stream()},c.prototype._engine_upload=function(a,b,c,d){return this._flash._upload(a.id,b,c,d)},c.prototype._flash_prepared=function(){return this._block_element_access(),document.body.tabIndex=0,document.body.focus(),this._prepared()},c.prototype._flash_upload_complete=function(a,b,c,d){var e;return a=parseInt(a),e=this._snapshots[a],e._status=parseInt(b),e._response=d,e._status>=200&&e._status<300?e._upload_done():(e._error_message=c,e._upload_fail())},c}(a),window.JpegCamera=b),d=function(){function b(a,b){this.camera=a,this.options=b,this.id=this.constructor._next_snapshot_id++}return b._next_snapshot_id=1,b.prototype._discarded=!1,b.prototype.show=function(){return this._discarded&&raise("discarded snapshot cannot be used"),this.camera._display(this),this},b.prototype.hide=function(){return this.camera.displayed_snapshot()===this&&this.camera.show_stream(),this},b.prototype.get_stats=function(a){return this._discarded&&raise("discarded snapshot cannot be used"),this.get_image_data(function(b){return this._get_stats(b,a)})},b.prototype.get_canvas=function(b){var c;return this._discarded&&raise("discarded snapshot cannot be used"),!a._canvas_supported,c=this,setTimeout(function(){return c._extra_canvas||(c._extra_canvas=c.camera._engine_get_canvas(c)),a._add_prefixed_style(c._extra_canvas,"transform","scalex(-1.0)"),b.call(c,c._extra_canvas)},10),!0},b.prototype._extra_canvas=null,b.prototype.get_image_data=function(a){var b;return this._discarded&&raise("discarded snapshot cannot be used"),b=this,setTimeout(function(){return b._image_data||(b._image_data=b.camera._engine_get_image_data(b)),a.call(b,b._image_data)},5)},b.prototype._image_data=null,b.prototype.upload=function(a){var b;if(null==a&&(a={}),this._discarded&&raise("discarded snapshot cannot be used"),this._uploading)return this.camera._debug("Upload already in progress"),void 0;if(this._uploading=!0,this._retry=1,this._upload_options=a,b=this._options(),!b.api_url)throw this.camera._debug("Snapshot#upload called without valid api_url"),"Snapshot#upload called without valid api_url";return this._start_upload(b),this},b.prototype._upload_options={},b.prototype._uploading=!1,b.prototype._retry=1,b.prototype.done=function(a){var b;return this._discarded&&raise("discarded snapshot cannot be used"),this._upload_options.on_upload_done=a,b=this._options(),b.on_upload_done&&this._done&&b.on_upload_done.call(this,this._response),this},b.prototype._done=!1,b.prototype._response=null,b.prototype.fail=function(a){var b;return this._discarded&&raise("discarded snapshot cannot be used"),this._upload_options.on_upload_fail=a,b=this._options(),b.on_upload_fail&&this._fail&&b.on_upload_fail.call(this,this._status,this._error_message,this._response),this},b.prototype._fail=!1,b.prototype._status=null,b.prototype._error_message=null,b.prototype.discard=function(){return this.camera._discard(this),void 0},b.prototype._options=function(){return this.camera._extend({},this.camera.options,this.options,this._upload_options)},b.prototype._start_upload=function(a){var b;return b="string"==typeof a.csrf_token&&a.csrf_token.length>0?a.csrf_token:null,this._done=!1,this._response=null,this._fail=!1,this._status=null,this._error_message=null,this.camera._engine_upload(this,a.api_url,b,a.timeout)},b.prototype._get_stats=function(a,b){var c,d,e,f,g,h,i,j,k,l,m;if(!this._stats){for(h=a.width*a.height,i=0,d=new Array(h),e=k=0;h>k;e=k+=1)f=4*e,c=.2126*a.data[f+0]+.7152*a.data[f+1]+.0722*a.data[f+2],c=Math.round(c),i+=c,d[e]=c;for(g=Math.round(i/h),j=0,l=0,m=d.length;m>l;l++)c=d[l],j+=Math.pow(c-g,2);this._stats={mean:g,std:Math.round(Math.sqrt(j/h))}}return b.call(this,this._stats)},b.prototype._stats=null,b.prototype._upload_done=function(){var a,b,c,d;return this.camera._debug("Upload completed with status "+this._status),this._done=!0,a=this._options(),c=a.retry_success&&a.retry_if&&a.retry_if.call(this,this._status,this._error_message,this._response,this._retry),!0===c&&(c=0),"number"==typeof c?(this._retry++,c>0?(b=parseInt(c),this.camera._debug("Will retry the upload in "+b+"ms (attempt #"+this._retry+")"),d=this,setTimeout(function(){return d._start_upload(a)},b)):(this.camera._debug("Will retry the upload immediately (attempt #"+this._retry+")"),this._start_upload(a))):(this._uploading=!1,a.on_upload_done?a.on_upload_done.call(this,this._response):void 0)},b.prototype._upload_fail=function(){var a,b,c,d;return this.camera._debug("Upload failed with status "+this._status),this._fail=!0,a=this._options(),c=a.retry_if&&a.retry_if.call(this,this._status,this._error_message,this._response,this._retry),!0===c&&(c=0),"number"==typeof c?(this._retry++,c>0?(b=parseInt(c),this.camera._debug("Will retry the upload in "+b+"ms (attempt #"+this._retry+")"),d=this,setTimeout(function(){return d._start_upload(a)},b)):(this.camera._debug("Will retry the upload immediately (attempt #"+this._retry+")"),this._start_upload(a))):(this._uploading=!1,a.on_upload_fail?a.on_upload_fail.call(this,this._status,this._error_message,this._response):void 0)},b}()}.call(this);
4
+ (function(){var a,b,c,d,e,f,g,h,i,j={}.hasOwnProperty,k=function(a,b){function c(){this.constructor=a}for(var d in b)j.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};if(a=function(){function a(a,b){if("string"==typeof a&&(a=document.getElementById(a.replace("#",""))),!a||!a.offsetWidth)throw"JpegCamera: invalid container";a.innerHTML="",this.view_width=parseInt(a.offsetWidth,10),this.view_height=parseInt(a.offsetHeight,10),this.container=document.createElement("div"),this.container.style.width="100%",this.container.style.height="100%",this.container.style.position="relative",a.appendChild(this.container),this.options=this._extend({},this.constructor.DefaultOptions,b),this._engine_init()}return a.DefaultOptions={shutter_url:"/jpeg_camera/shutter.mp3",swf_url:"/jpeg_camera/jpeg_camera.swf",on_debug:function(a){return console&&console.log?console.log("JpegCamera: "+a):void 0},quality:.9,shutter:!0,mirror:!1,timeout:0,retry_success:!1,scale:1},a._canvas_supported=!!document.createElement("canvas").getContext,a.canvas_supported=function(){return this._canvas_supported},a.prototype.ready=function(a){return this.options.on_ready=a,this.options.on_ready&&this._is_ready&&this.options.on_ready.call(this,{video_width:this.video_width,video_height:this.video_height}),this},a.prototype._is_ready=!1,a.prototype.error=function(a){return this.options.on_error=a,this.options.on_error&&this._error_occured&&this.options.on_error.call(this,this._error_occured),this},a.prototype._error_occured=!1,a.StatsCaptureScale=.2,a.prototype.get_stats=function(b){var c,e;return c=new d(this,{}),this._engine_capture(c,!1,.1,a.StatsCaptureScale),e=this,c.get_stats(function(a){return b.call(e,a)})},a.prototype.capture=function(a){var b,c,e;return null==a&&(a={}),c=new d(this,a),this._snapshots[c.id]=c,e=c._options(),e.shutter&&this._engine_play_shutter_sound(),b=Math.min(1,e.scale),b=Math.max(.01,b),this._engine_capture(c,e.mirror,e.quality,b),c},a.prototype._snapshots={},a.prototype.show_stream=function(){return this._engine_show_stream(),this._displayed_snapshot=null,this},a.prototype.discard_all=function(){var a,b,c;this._displayed_snapshot&&this.show_stream(),c=this._snapshots;for(a in c)b=c[a],this._engine_discard(b),b._discarded=!0;return this._snapshots={},this},a.prototype._extend=function(a){var b,c,d,e,f,g;for(d=Array.prototype.slice.call(arguments,1),f=0,g=d.length;g>f;f++)if(c=d[f])for(b in c)e=c[b],a[b]=e;return a},a.prototype._debug=function(a){return this.options.on_debug?this.options.on_debug.call(this,a):void 0},a.prototype._display=function(a){return this._engine_display(a),this._displayed_snapshot=a},a.prototype._displayed_snapshot=null,a.prototype._discard=function(a){return this._displayed_snapshot===a&&this.show_stream(),this._engine_discard(a),a._discarded=!0,delete this._snapshots[a.id]},a.prototype._prepared=function(a,b){var c;return this.video_width=a,this.video_height=b,this._debug("Camera resolution "+this.video_width+"x"+this.video_height+"px"),c=this,setTimeout(function(){return c._wait_until_stream_looks_ok(!0)},1)},a.prototype._wait_until_stream_looks_ok=function(a){return this.get_stats(function(b){var c;return b.std>2?(this._debug("Stream mean gray value = "+b.mean+" standard deviation = "+b.std),this._debug("Camera is ready"),this._is_ready=!0,this.options.on_ready?this.options.on_ready.call(this,{video_width:this.video_width,video_height:this.video_height}):void 0):(a&&this._debug("Stream mean gray value = "+b.mean+" standard deviation = "+b.std),c=this,setTimeout(function(){return c._wait_until_stream_looks_ok(!1)},100))})},a.prototype._got_error=function(a){return this._debug("Error - "+a),this._error_occured=a,this.options.on_error?this.options.on_error.call(this,this._error_occured):void 0},a.prototype._block_element_access=function(){return this._overlay=document.createElement("div"),this._overlay.style.width="100%",this._overlay.style.height="100%",this._overlay.style.position="absolute",this._overlay.style.top=0,this._overlay.style.left=0,this._overlay.style.zIndex=2,this.container.appendChild(this._overlay)},a.prototype._overlay=null,a.prototype.view_width=null,a.prototype.view_height=null,a._add_prefixed_style=function(a,b,c){var d;return d=b.charAt(0).toUpperCase()+b.slice(1),a.style[b]=c,a.style["Webkit"+d]=c,a.style["Moz"+d]=c,a.style["ms"+d]=c,a.style["O"+d]=c},a}(),navigator.getUserMedia||(navigator.getUserMedia=navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia),f=function(){var a;if(a=document.createElement("canvas"),a.getContext&&!a.toBlob)throw"JpegCamera: Canvas-to-Blob is not loaded"},navigator.getUserMedia&&(f(),c=function(b){function c(){return h=c.__super__.constructor.apply(this,arguments)}return k(c,b),c.prototype._engine_init=function(){var b,c,d,e,f,g,h;this._debug("Using HTML5 engine"),h=Math.floor(.2*this.view_height),e=Math.floor(.2*this.view_width),this.message=document.createElement("div"),this.message["class"]="message",this.message.style.width="100%",this.message.style.height="100%",a._add_prefixed_style(this.message,"boxSizing","border-box"),this.message.style.overflow="hidden",this.message.style.textAlign="center",this.message.style.paddingTop=""+h+"px",this.message.style.paddingBottom=""+h+"px",this.message.style.paddingLeft=""+e+"px",this.message.style.paddingRight=""+e+"px",this.message.style.position="absolute",this.message.style.zIndex=3,this.message.innerHTML="Please allow camera access when prompted by the browser.<br><br>Look for camera icon around your address bar.",this.container.appendChild(this.message),this.video_container=document.createElement("div"),this.video_container.style.width=""+this.view_width+"px",this.video_container.style.height=""+this.view_height+"px",this.video_container.style.overflow="hidden",this.video_container.style.position="absolute",this.video_container.style.zIndex=1,this.container.appendChild(this.video_container),this.video=document.createElement("video"),this.video.autoplay=!0,a._add_prefixed_style(this.video,"transform","scalex(-1.0)"),window.AudioContext||(window.AudioContext=window.webkitAudioContext),window.AudioContext&&this._load_shutter_sound(),d={video:{optional:[{minWidth:1280},{minWidth:640},{minWidth:480},{minWidth:360}]}},g=this,f=function(a){return g._remove_message(),g.video.src=window.URL?URL.createObjectURL(a):a,g._block_element_access(),g._wait_for_video_ready()},c=function(a){var b,c,d;g.message.innerHTML='<span style="color: red;">You have denied camera access.</span><br><br>Look for camera icon around your address bar to change your decision.',b=a.code;for(c in a)if(d=a[c],"code"!==c)return g._got_error(c),void 0;return g._got_error("UNKNOWN ERROR")};try{return navigator.getUserMedia(d,f,c)}catch(i){return b=i,navigator.getUserMedia("video",f,c)}},c.prototype._engine_play_shutter_sound=function(){var a;if(this.shutter_buffer)return a=this.audio_context.createBufferSource(),a.buffer=this.shutter_buffer,a.connect(this.audio_context.destination),a.start(0)},c.prototype._engine_capture=function(a,b,c,d){var e,f,g;return g=this._get_capture_crop(),e=document.createElement("canvas"),e.width=Math.round(g.width*d),e.height=Math.round(g.height*d),f=e.getContext("2d"),f.drawImage(this.video,g.x_offset,g.y_offset,g.width,g.height,0,0,Math.round(g.width*d),Math.round(g.height*d)),a._canvas=e,a._mirror=b,a._quality=c},c.prototype._engine_display=function(b){return this.displayed_canvas&&this.container.removeChild(this.displayed_canvas),this.displayed_canvas=b._canvas,this.displayed_canvas.style.width=""+this.view_width+"px",this.displayed_canvas.style.height=""+this.view_height+"px",this.displayed_canvas.style.top=0,this.displayed_canvas.style.left=0,this.displayed_canvas.style.position="absolute",this.displayed_canvas.style.zIndex=2,a._add_prefixed_style(this.displayed_canvas,"transform","scalex(-1.0)"),this.container.appendChild(this.displayed_canvas)},c.prototype._engine_get_canvas=function(a){var b,c;return b=document.createElement("canvas"),b.width=a._canvas.width,b.height=a._canvas.height,c=b.getContext("2d"),c.drawImage(a._canvas,0,0),b},c.prototype._engine_get_image_data=function(a){var b,c;return b=a._canvas,c=b.getContext("2d"),c.getImageData(0,0,b.width,b.height)},c.prototype._engine_get_blob=function(a,b,c,d,e){var f,g;return c?(f=document.createElement("canvas"),f.width=a._canvas.width,f.height=a._canvas.height,g=f.getContext("2d"),g.setTransform(1,0,0,1,0,0),g.translate(f.width,0),g.scale(-1,1),g.drawImage(a._canvas,0,0)):f=a._canvas,f.toBlob(function(a){return e(a)},b,d)},c.prototype._engine_discard=function(a){return a._xhr&&a._xhr.abort(),delete a._xhr,delete a._canvas},c.prototype._engine_show_stream=function(){return this.displayed_canvas&&(this.container.removeChild(this.displayed_canvas),this.displayed_canvas=null),this.video_container.style.display="block"},c.prototype._engine_upload=function(a,b,c,d){return this._debug("Uploading the file"),a.get_blob(function(e){var f,g;return f=function(b){return delete a._xhr,a._status=b.target.status,a._response=b.target.responseText,a._status>=200&&a._status<300?a._upload_done():(a._error_message=b.target.statusText||"Unknown error",a._upload_fail())},g=new XMLHttpRequest,g.open("POST",b),g.timeout=d,c&&g.setRequestHeader("X-CSRF-Token",c),g.onload=f,g.onerror=f,g.onabort=f,g.send(e),a._xhr=g},"image/jpeg")},c.prototype._remove_message=function(){return this.message.style.display="none"},c.prototype._load_shutter_sound=function(){var a,b;if(!this.audio_context)return this.audio_context=new AudioContext,a=new XMLHttpRequest,a.open("GET",this.options.shutter_url,!0),a.responseType="arraybuffer",b=this,a.onload=function(){return b.audio_context.decodeAudioData(a.response,function(a){return b.shutter_buffer=a})},a.send()},c.prototype._wait_for_video_ready=function(){var a,b,c,d;return d=parseInt(this.video.videoWidth),c=parseInt(this.video.videoHeight),d>0&&c>0?(this.video_container.appendChild(this.video),this.video_width=d,this.video_height=c,a=this._get_video_crop(),this.video.style.position="relative",this.video.style.width=""+a.width+"px",this.video.style.height=""+a.height+"px",this.video.style.left=""+a.x_offset+"px",this.video.style.top=""+a.y_offset+"px",this._prepared(this.video_width,this.video_height)):this._status_checks_count>100?this._got_error("Camera failed to initialize in 10 seconds"):(this._status_checks_count++,b=this,setTimeout(function(){return b._wait_for_video_ready()},100))},c.prototype._status_checks_count=0,c.prototype._get_video_crop=function(){var a,b,c,d,e;return c=this.video_width/this.video_height,e=this.view_width/this.view_height,c>=e?(this._debug("Filling height"),d=this.view_height/this.video_height,b=Math.round(this.video_width*d),{width:b,height:this.view_height,x_offset:-Math.floor((b-this.view_width)/2),y_offset:0}):(this._debug("Filling width"),d=this.view_width/this.video_width,a=Math.round(this.video_height*d),{width:this.view_width,height:a,x_offset:0,y_offset:-Math.floor((a-this.view_height)/2)})},c.prototype._get_capture_crop=function(){var a,b,c,d;return c=this.video_width/this.video_height,d=this.view_width/this.view_height,c>=d?(b=Math.round(this.video_height*d),{width:b,height:this.video_height,x_offset:Math.floor((this.video_width-b)/2),y_offset:0}):(a=Math.round(this.video_width/d),{width:this.video_width,height:a,x_offset:0,y_offset:Math.floor((this.video_height-a)/2)})},c}(a),window.JpegCamera=c),g="9",!window.swfobject)throw"JpegCamera: SWFObject is not loaded";!window.JpegCamera&&window.swfobject&&swfobject.hasFlashPlayerVersion(g)&&(b=function(b){function c(){return i=c.__super__.constructor.apply(this,arguments)}return k(c,b),c._send_message=function(a,b){var c,d;return(d=this._instances[parseInt(a)])?(c=Array.prototype.slice.call(arguments,2),this.prototype[b].apply(d,c)):void 0},c._instances={},c._next_id=1,c.prototype._engine_init=function(){var a,b,c,d,e,f,g;return this._debug("Using Flash engine"),this._id=this.constructor._next_id++,this.constructor._instances[this._id]=this,this.view_width<215||this.view_height<138?(this._got_error("camera is too small to display privacy dialog"),void 0):(d="flash_object_"+this._id,f={loop:"false",allowScriptAccess:"always",allowFullScreen:"false",quality:"best",wmode:"opaque",menu:"false"},a={id:d,align:"middle"},e={id:this._id,width:this.view_width,height:this.view_height,shutter_url:this.options.shutter_url},g=this,b=function(a){return a.success?(g._debug("Flash loaded"),g._flash=document.getElementById(d)):g._got_error("Flash loading failed.")},c=document.createElement("div"),c.id="jpeg_camera_flash_"+this._id,c.style.width="100%",c.style.height="100%",this.container.appendChild(c),swfobject.embedSWF(this.options.swf_url,c.id,this.view_width,this.view_height,"9",null,e,f,a,b))},c.prototype._engine_play_shutter_sound=function(){return this._flash._play_shutter()},c.prototype._engine_capture=function(a,b,c,d){return this._flash._capture(a.id,b,c,d)},c.prototype._engine_display=function(a){return this._flash._display(a.id)},c.prototype._engine_get_canvas=function(a){var b,c;return a._image_data||(a._image_data=this._engine_get_image_data(a)),b=document.createElement("canvas"),b.width=a._image_data.width,b.height=a._image_data.height,c=b.getContext("2d"),c.putImageData(a._image_data,0,0),b},c.prototype._engine_get_image_data=function(b){var c,d,e,f,g,h,i,j,k,l,m,n,o;for(f=this._flash._get_image_data(b.id),a.canvas_supported()?(d=document.createElement("canvas"),d.width=f.width,d.height=f.height,e=d.getContext("2d"),l=e.createImageData(f.width,f.height)):l={data:[],width:f.width,height:f.height},o=f.data,h=m=0,n=o.length;n>m;h=++m)j=o[h],i=4*h,k=255&j>>16,g=255&j>>8,c=255&j,l.data[i+0]=k,l.data[i+1]=g,l.data[i+2]=c,l.data[i+3]=255;return l},c.prototype._engine_get_blob=function(a,b,c,d,e){var f,g;return a._extra_canvas||(a._extra_canvas=this._engine_get_canvas(a)),c?(f=document.createElement("canvas"),f.width=a._canvas.width,f.height=a._canvas.height,g=f.getContext("2d"),g.setTransform(1,0,0,1,0,0),g.translate(f.width,0),g.scale(-1,1),g.drawImage(a._extra_canvas,0,0)):f=a._extra_canvas,f.toBlob(function(a){return e(a)},b,d)},c.prototype._engine_discard=function(a){return this._flash._discard(a.id)},c.prototype._engine_show_stream=function(){return this._flash._show_stream()},c.prototype._engine_upload=function(a,b,c,d){return this._flash._upload(a.id,b,c,d)},c.prototype._flash_prepared=function(a,b){return this._block_element_access(),document.body.tabIndex=0,document.body.focus(),this._prepared(a,b)},c.prototype._flash_upload_complete=function(a,b,c,d){var e;return a=parseInt(a),e=this._snapshots[a],e._status=parseInt(b),e._response=d,e._status>=200&&e._status<300?e._upload_done():(e._error_message=c,e._upload_fail())},c}(a),window.JpegCamera=b),d=function(){function b(a,b){this.camera=a,this.options=b,this.id=this.constructor._next_snapshot_id++}return b._next_snapshot_id=1,b.prototype._discarded=!1,b.prototype.show=function(){return this._discarded&&raise("discarded snapshot cannot be used"),this.camera._display(this),this},b.prototype.hide=function(){return this.camera.displayed_snapshot()===this&&this.camera.show_stream(),this},b.prototype.get_stats=function(a){return this._discarded&&raise("discarded snapshot cannot be used"),this.get_image_data(function(b){return this._get_stats(b,a)})},b.prototype.get_canvas=function(b){var c;return this._discarded&&raise("discarded snapshot cannot be used"),!a._canvas_supported,c=this,setTimeout(function(){return c._extra_canvas||(c._extra_canvas=c.camera._engine_get_canvas(c)),a._add_prefixed_style(c._extra_canvas,"transform","scalex(-1.0)"),b.call(c,c._extra_canvas)},1),!0},b.prototype._extra_canvas=null,b.prototype.get_blob=function(b,c){var d;return null==c&&(c="image/jpeg"),this._discarded&&raise("discarded snapshot cannot be used"),!a._canvas_supported,d=this,setTimeout(function(){var a,e;return d._blob_mime!==c&&(d._blob=null),d._blob_mime=c,d._blob?b.call(d,d._blob):(a=d.options.mirror,e=d.options.quality,d.camera._engine_get_blob(d,c,a,e,function(a){return d._blob=a,b.call(d,d._blob)}))},1),!0},b.prototype._blob=null,b.prototype._blob_mime=null,b.prototype.get_image_data=function(a){var b;return this._discarded&&raise("discarded snapshot cannot be used"),b=this,setTimeout(function(){return b._image_data||(b._image_data=b.camera._engine_get_image_data(b)),a.call(b,b._image_data)},1),null},b.prototype._image_data=null,b.prototype.upload=function(a){var b;if(null==a&&(a={}),this._discarded&&raise("discarded snapshot cannot be used"),this._uploading)return this.camera._debug("Upload already in progress"),void 0;if(this._uploading=!0,this._retry=1,this._upload_options=a,b=this._options(),!b.api_url)throw this.camera._debug("Snapshot#upload called without valid api_url"),"Snapshot#upload called without valid api_url";return this._start_upload(b),this},b.prototype._upload_options={},b.prototype._uploading=!1,b.prototype._retry=1,b.prototype.done=function(a){var b;return this._discarded&&raise("discarded snapshot cannot be used"),this._upload_options.on_upload_done=a,b=this._options(),b.on_upload_done&&this._done&&b.on_upload_done.call(this,this._response),this},b.prototype._done=!1,b.prototype._response=null,b.prototype.fail=function(a){var b;return this._discarded&&raise("discarded snapshot cannot be used"),this._upload_options.on_upload_fail=a,b=this._options(),b.on_upload_fail&&this._fail&&b.on_upload_fail.call(this,this._status,this._error_message,this._response),this},b.prototype._fail=!1,b.prototype._status=null,b.prototype._error_message=null,b.prototype.discard=function(){return this.camera._discard(this),delete this._extra_canvas,delete this._image_data,delete this._blob,void 0},b.prototype._options=function(){return this.camera._extend({},this.camera.options,this.options,this._upload_options)},b.prototype._start_upload=function(a){var b;return b="string"==typeof a.csrf_token&&a.csrf_token.length>0?a.csrf_token:null,this._done=!1,this._response=null,this._fail=!1,this._status=null,this._error_message=null,this.camera._engine_upload(this,a.api_url,b,a.timeout)},b.prototype._get_stats=function(a,b){var c,d,f,g,h,i,j,k,l,m,n;if(!this._stats){for(i=a.width*a.height,j=0,d=new Array(i),f=l=0;i>l;f=l+=1)g=4*f,c=.2126*a.data[g+0]+.7152*a.data[g+1]+.0722*a.data[g+2],c=Math.round(c),j+=c,d[f]=c;for(h=Math.round(j/i),k=0,m=0,n=d.length;n>m;m++)c=d[m],k+=Math.pow(c-h,2);this._stats=new e,this._stats.mean=h,this._stats.std=Math.round(Math.sqrt(k/i))}return b.call(this,this._stats)},b.prototype._stats=null,b.prototype._upload_done=function(){var a,b,c,d;return this.camera._debug("Upload completed with status "+this._status),this._done=!0,a=this._options(),c=a.retry_success&&a.retry_if&&a.retry_if.call(this,this._status,this._error_message,this._response,this._retry),!0===c&&(c=0),"number"==typeof c?(this._retry++,c>0?(b=parseInt(c),this.camera._debug("Will retry the upload in "+b+"ms (attempt #"+this._retry+")"),d=this,setTimeout(function(){return d._start_upload(a)},b)):(this.camera._debug("Will retry the upload immediately (attempt #"+this._retry+")"),this._start_upload(a))):(this._uploading=!1,a.on_upload_done?a.on_upload_done.call(this,this._response):void 0)},b.prototype._upload_fail=function(){var a,b,c,d;return this.camera._debug("Upload failed with status "+this._status),this._fail=!0,a=this._options(),c=a.retry_if&&a.retry_if.call(this,this._status,this._error_message,this._response,this._retry),!0===c&&(c=0),"number"==typeof c?(this._retry++,c>0?(b=parseInt(c),this.camera._debug("Will retry the upload in "+b+"ms (attempt #"+this._retry+")"),d=this,setTimeout(function(){return d._start_upload(a)},b)):(this.camera._debug("Will retry the upload immediately (attempt #"+this._retry+")"),this._start_upload(a))):(this._uploading=!1,a.on_upload_fail?a.on_upload_fail.call(this,this._status,this._error_message,this._response):void 0)},b}(),e=function(){function a(){}return a.prototype.mean=null,a.prototype.std=null,a}()}).call(this);
@@ -1,8 +1,8 @@
1
- /*! JpegCamera 1.1.3 | 2013-08-09
1
+ /*! JpegCamera 1.2.0 | 2013-11-07
2
2
  (c) 2013 Adam Wrobel
3
3
  http://amw.github.io/jpeg_camera */
4
4
  (function() {
5
- var JpegCamera, JpegCameraHtml5, Snapshot, check_canvas_to_blob, _ref,
5
+ var JpegCamera, JpegCameraHtml5, Snapshot, Stats, check_canvas_to_blob, _ref,
6
6
  __hasProp = {}.hasOwnProperty,
7
7
  __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
8
8
 
@@ -19,7 +19,8 @@
19
19
  shutter: true,
20
20
  mirror: false,
21
21
  timeout: 0,
22
- retry_success: false
22
+ retry_success: false,
23
+ scale: 1.0
23
24
  };
24
25
 
25
26
  JpegCamera._canvas_supported = !!document.createElement('canvas').getContext;
@@ -50,7 +51,10 @@
50
51
  JpegCamera.prototype.ready = function(callback) {
51
52
  this.options.on_ready = callback;
52
53
  if (this.options.on_ready && this._is_ready) {
53
- this.options.on_ready.call(this);
54
+ this.options.on_ready.call(this, {
55
+ video_width: this.video_width,
56
+ video_height: this.video_height
57
+ });
54
58
  }
55
59
  return this;
56
60
  };
@@ -80,7 +84,7 @@
80
84
  };
81
85
 
82
86
  JpegCamera.prototype.capture = function(options) {
83
- var snapshot, _options;
87
+ var scale, snapshot, _options;
84
88
  if (options == null) {
85
89
  options = {};
86
90
  }
@@ -90,7 +94,9 @@
90
94
  if (_options.shutter) {
91
95
  this._engine_play_shutter_sound();
92
96
  }
93
- this._engine_capture(snapshot, _options.mirror, _options.quality, 1.0);
97
+ scale = Math.min(1.0, _options.scale);
98
+ scale = Math.max(0.01, scale);
99
+ this._engine_capture(snapshot, _options.mirror, _options.quality, scale);
94
100
  return snapshot;
95
101
  };
96
102
 
@@ -154,8 +160,11 @@
154
160
  return delete this._snapshots[snapshot.id];
155
161
  };
156
162
 
157
- JpegCamera.prototype._prepared = function() {
163
+ JpegCamera.prototype._prepared = function(video_width, video_height) {
158
164
  var that;
165
+ this.video_width = video_width;
166
+ this.video_height = video_height;
167
+ this._debug("Camera resolution " + this.video_width + "x" + this.video_height + "px");
159
168
  that = this;
160
169
  return setTimeout((function() {
161
170
  return that._wait_until_stream_looks_ok(true);
@@ -170,7 +179,10 @@
170
179
  this._debug("Camera is ready");
171
180
  this._is_ready = true;
172
181
  if (this.options.on_ready) {
173
- return this.options.on_ready.call(this);
182
+ return this.options.on_ready.call(this, {
183
+ video_width: this.video_width,
184
+ video_height: this.video_height
185
+ });
174
186
  }
175
187
  } else {
176
188
  if (show_debug) {
@@ -381,13 +393,31 @@
381
393
  return context.getImageData(0, 0, canvas.width, canvas.height);
382
394
  };
383
395
 
396
+ JpegCameraHtml5.prototype._engine_get_blob = function(snapshot, mime, mirror, quality, callback) {
397
+ var canvas, context;
398
+ if (mirror) {
399
+ canvas = document.createElement("canvas");
400
+ canvas.width = snapshot._canvas.width;
401
+ canvas.height = snapshot._canvas.height;
402
+ context = canvas.getContext("2d");
403
+ context.setTransform(1, 0, 0, 1, 0, 0);
404
+ context.translate(canvas.width, 0);
405
+ context.scale(-1, 1);
406
+ context.drawImage(snapshot._canvas, 0, 0);
407
+ } else {
408
+ canvas = snapshot._canvas;
409
+ }
410
+ return canvas.toBlob((function(blob) {
411
+ return callback(blob);
412
+ }), mime, quality);
413
+ };
414
+
384
415
  JpegCameraHtml5.prototype._engine_discard = function(snapshot) {
385
416
  if (snapshot._xhr) {
386
417
  snapshot._xhr.abort();
387
418
  }
388
419
  delete snapshot._xhr;
389
- delete snapshot._canvas;
390
- return delete snapshot._jpeg_blob;
420
+ return delete snapshot._canvas;
391
421
  };
392
422
 
393
423
  JpegCameraHtml5.prototype._engine_show_stream = function() {
@@ -399,10 +429,9 @@
399
429
  };
400
430
 
401
431
  JpegCameraHtml5.prototype._engine_upload = function(snapshot, api_url, csrf_token, timeout) {
402
- var canvas, context, handler, that, xhr;
403
- that = this;
404
- if (snapshot._jpeg_blob) {
405
- this._debug("Uploading the file");
432
+ this._debug("Uploading the file");
433
+ return snapshot.get_blob(function(blob) {
434
+ var handler, xhr;
406
435
  handler = function(event) {
407
436
  delete snapshot._xhr;
408
437
  snapshot._status = event.target.status;
@@ -423,27 +452,9 @@
423
452
  xhr.onload = handler;
424
453
  xhr.onerror = handler;
425
454
  xhr.onabort = handler;
426
- xhr.send(snapshot._jpeg_blob);
455
+ xhr.send(blob);
427
456
  return snapshot._xhr = xhr;
428
- } else {
429
- this._debug("Generating JPEG file");
430
- if (snapshot._mirror) {
431
- canvas = document.createElement("canvas");
432
- canvas.width = snapshot._canvas.width;
433
- canvas.height = snapshot._canvas.height;
434
- context = canvas.getContext("2d");
435
- context.setTransform(1, 0, 0, 1, 0, 0);
436
- context.translate(canvas.width, 0);
437
- context.scale(-1, 1);
438
- context.drawImage(snapshot._canvas, 0, 0);
439
- } else {
440
- canvas = snapshot._canvas;
441
- }
442
- return canvas.toBlob(function(blob) {
443
- snapshot._jpeg_blob = blob;
444
- return that._engine_upload(snapshot, api_url, csrf_token, timeout);
445
- }, "image/jpeg", this.quality);
446
- }
457
+ }, "image/jpeg");
447
458
  };
448
459
 
449
460
  JpegCameraHtml5.prototype._remove_message = function() {
@@ -476,14 +487,13 @@
476
487
  this.video_container.appendChild(this.video);
477
488
  this.video_width = video_width;
478
489
  this.video_height = video_height;
479
- this._debug("Camera resolution " + this.video_width + "x" + this.video_height + "px");
480
490
  crop = this._get_video_crop();
481
491
  this.video.style.position = "relative";
482
492
  this.video.style.width = "" + crop.width + "px";
483
493
  this.video.style.height = "" + crop.height + "px";
484
494
  this.video.style.left = "" + crop.x_offset + "px";
485
495
  this.video.style.top = "" + crop.y_offset + "px";
486
- return this._prepared();
496
+ return this._prepared(this.video_width, this.video_height);
487
497
  } else if (this._status_checks_count > 100) {
488
498
  return this._got_error("Camera failed to initialize in 10 seconds");
489
499
  } else {
@@ -605,22 +615,59 @@
605
615
  that._extra_canvas || (that._extra_canvas = that.camera._engine_get_canvas(that));
606
616
  JpegCamera._add_prefixed_style(that._extra_canvas, "transform", "scalex(-1.0)");
607
617
  return callback.call(that, that._extra_canvas);
608
- }, 10);
618
+ }, 1);
609
619
  return true;
610
620
  };
611
621
 
612
622
  Snapshot.prototype._extra_canvas = null;
613
623
 
624
+ Snapshot.prototype.get_blob = function(callback, mime_type) {
625
+ var that;
626
+ if (mime_type == null) {
627
+ mime_type = "image/jpeg";
628
+ }
629
+ if (this._discarded) {
630
+ raise("discarded snapshot cannot be used");
631
+ }
632
+ if (!JpegCamera._canvas_supported) {
633
+ false;
634
+ }
635
+ that = this;
636
+ setTimeout(function() {
637
+ var mirror, quality;
638
+ if (that._blob_mime !== mime_type) {
639
+ that._blob = null;
640
+ }
641
+ that._blob_mime = mime_type;
642
+ if (that._blob) {
643
+ return callback.call(that, that._blob);
644
+ } else {
645
+ mirror = that.options.mirror;
646
+ quality = that.options.quality;
647
+ return that.camera._engine_get_blob(that, mime_type, mirror, quality, function(b) {
648
+ that._blob = b;
649
+ return callback.call(that, that._blob);
650
+ });
651
+ }
652
+ }, 1);
653
+ return true;
654
+ };
655
+
656
+ Snapshot.prototype._blob = null;
657
+
658
+ Snapshot.prototype._blob_mime = null;
659
+
614
660
  Snapshot.prototype.get_image_data = function(callback) {
615
661
  var that;
616
662
  if (this._discarded) {
617
663
  raise("discarded snapshot cannot be used");
618
664
  }
619
665
  that = this;
620
- return setTimeout(function() {
666
+ setTimeout(function() {
621
667
  that._image_data || (that._image_data = that.camera._engine_get_image_data(that));
622
668
  return callback.call(that, that._image_data);
623
- }, 5);
669
+ }, 1);
670
+ return null;
624
671
  };
625
672
 
626
673
  Snapshot.prototype._image_data = null;
@@ -693,6 +740,9 @@
693
740
 
694
741
  Snapshot.prototype.discard = function() {
695
742
  this.camera._discard(this);
743
+ delete this._extra_canvas;
744
+ delete this._image_data;
745
+ delete this._blob;
696
746
  return void 0;
697
747
  };
698
748
 
@@ -734,10 +784,9 @@
734
784
  gray = gray_values[_j];
735
785
  sum_of_square_distances += Math.pow(gray - mean, 2);
736
786
  }
737
- this._stats = {
738
- mean: mean,
739
- std: Math.round(Math.sqrt(sum_of_square_distances / n))
740
- };
787
+ this._stats = new Stats();
788
+ this._stats.mean = mean;
789
+ this._stats.std = Math.round(Math.sqrt(sum_of_square_distances / n));
741
790
  }
742
791
  return callback.call(this, this._stats);
743
792
  };
@@ -808,4 +857,15 @@
808
857
 
809
858
  })();
810
859
 
860
+ Stats = (function() {
861
+ function Stats() {}
862
+
863
+ Stats.prototype.mean = null;
864
+
865
+ Stats.prototype.std = null;
866
+
867
+ return Stats;
868
+
869
+ })();
870
+
811
871
  }).call(this);
@@ -1,4 +1,4 @@
1
- /*! JpegCamera 1.1.3 | 2013-08-09
1
+ /*! JpegCamera 1.2.0 | 2013-11-07
2
2
  (c) 2013 Adam Wrobel
3
3
  http://amw.github.io/jpeg_camera */
4
- !function(){var a,b,c,d,e,f={}.hasOwnProperty,g=function(a,b){function c(){this.constructor=a}for(var d in b)f.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};a=function(){function a(a,b){if("string"==typeof a&&(a=document.getElementById(a.replace("#",""))),!a||!a.offsetWidth)throw"JpegCamera: invalid container";a.innerHTML="",this.view_width=parseInt(a.offsetWidth,10),this.view_height=parseInt(a.offsetHeight,10),this.container=document.createElement("div"),this.container.style.width="100%",this.container.style.height="100%",this.container.style.position="relative",a.appendChild(this.container),this.options=this._extend({},this.constructor.DefaultOptions,b),this._engine_init()}return a.DefaultOptions={shutter_url:"/jpeg_camera/shutter.mp3",swf_url:"/jpeg_camera/jpeg_camera.swf",on_debug:function(a){return console&&console.log?console.log("JpegCamera: "+a):void 0},quality:.9,shutter:!0,mirror:!1,timeout:0,retry_success:!1},a._canvas_supported=!!document.createElement("canvas").getContext,a.canvas_supported=function(){return this._canvas_supported},a.prototype.ready=function(a){return this.options.on_ready=a,this.options.on_ready&&this._is_ready&&this.options.on_ready.call(this),this},a.prototype._is_ready=!1,a.prototype.error=function(a){return this.options.on_error=a,this.options.on_error&&this._error_occured&&this.options.on_error.call(this,this._error_occured),this},a.prototype._error_occured=!1,a.StatsCaptureScale=.2,a.prototype.get_stats=function(b){var d,e;return d=new c(this,{}),this._engine_capture(d,!1,.1,a.StatsCaptureScale),e=this,d.get_stats(function(a){return b.call(e,a)})},a.prototype.capture=function(a){var b,d;return null==a&&(a={}),b=new c(this,a),this._snapshots[b.id]=b,d=b._options(),d.shutter&&this._engine_play_shutter_sound(),this._engine_capture(b,d.mirror,d.quality,1),b},a.prototype._snapshots={},a.prototype.show_stream=function(){return this._engine_show_stream(),this._displayed_snapshot=null,this},a.prototype.discard_all=function(){var a,b,c;this._displayed_snapshot&&this.show_stream(),c=this._snapshots;for(a in c)b=c[a],this._engine_discard(b),b._discarded=!0;return this._snapshots={},this},a.prototype._extend=function(a){var b,c,d,e,f,g;for(d=Array.prototype.slice.call(arguments,1),f=0,g=d.length;g>f;f++)if(c=d[f])for(b in c)e=c[b],a[b]=e;return a},a.prototype._debug=function(a){return this.options.on_debug?this.options.on_debug.call(this,a):void 0},a.prototype._display=function(a){return this._engine_display(a),this._displayed_snapshot=a},a.prototype._displayed_snapshot=null,a.prototype._discard=function(a){return this._displayed_snapshot===a&&this.show_stream(),this._engine_discard(a),a._discarded=!0,delete this._snapshots[a.id]},a.prototype._prepared=function(){var a;return a=this,setTimeout(function(){return a._wait_until_stream_looks_ok(!0)},1)},a.prototype._wait_until_stream_looks_ok=function(a){return this.get_stats(function(b){var c;return b.std>2?(this._debug("Stream mean gray value = "+b.mean+" standard deviation = "+b.std),this._debug("Camera is ready"),this._is_ready=!0,this.options.on_ready?this.options.on_ready.call(this):void 0):(a&&this._debug("Stream mean gray value = "+b.mean+" standard deviation = "+b.std),c=this,setTimeout(function(){return c._wait_until_stream_looks_ok(!1)},100))})},a.prototype._got_error=function(a){return this._debug("Error - "+a),this._error_occured=a,this.options.on_error?this.options.on_error.call(this,this._error_occured):void 0},a.prototype._block_element_access=function(){return this._overlay=document.createElement("div"),this._overlay.style.width="100%",this._overlay.style.height="100%",this._overlay.style.position="absolute",this._overlay.style.top=0,this._overlay.style.left=0,this._overlay.style.zIndex=2,this.container.appendChild(this._overlay)},a.prototype._overlay=null,a.prototype.view_width=null,a.prototype.view_height=null,a._add_prefixed_style=function(a,b,c){var d;return d=b.charAt(0).toUpperCase()+b.slice(1),a.style[b]=c,a.style["Webkit"+d]=c,a.style["Moz"+d]=c,a.style["ms"+d]=c,a.style["O"+d]=c},a}(),navigator.getUserMedia||(navigator.getUserMedia=navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia),d=function(){var a;if(a=document.createElement("canvas"),a.getContext&&!a.toBlob)throw"JpegCamera: Canvas-to-Blob is not loaded"},navigator.getUserMedia&&(d(),b=function(b){function c(){return e=c.__super__.constructor.apply(this,arguments)}return g(c,b),c.prototype._engine_init=function(){var b,c,d,e,f,g,h;this._debug("Using HTML5 engine"),h=Math.floor(.2*this.view_height),e=Math.floor(.2*this.view_width),this.message=document.createElement("div"),this.message["class"]="message",this.message.style.width="100%",this.message.style.height="100%",a._add_prefixed_style(this.message,"boxSizing","border-box"),this.message.style.overflow="hidden",this.message.style.textAlign="center",this.message.style.paddingTop=""+h+"px",this.message.style.paddingBottom=""+h+"px",this.message.style.paddingLeft=""+e+"px",this.message.style.paddingRight=""+e+"px",this.message.style.position="absolute",this.message.style.zIndex=3,this.message.innerHTML="Please allow camera access when prompted by the browser.<br><br>Look for camera icon around your address bar.",this.container.appendChild(this.message),this.video_container=document.createElement("div"),this.video_container.style.width=""+this.view_width+"px",this.video_container.style.height=""+this.view_height+"px",this.video_container.style.overflow="hidden",this.video_container.style.position="absolute",this.video_container.style.zIndex=1,this.container.appendChild(this.video_container),this.video=document.createElement("video"),this.video.autoplay=!0,a._add_prefixed_style(this.video,"transform","scalex(-1.0)"),window.AudioContext||(window.AudioContext=window.webkitAudioContext),window.AudioContext&&this._load_shutter_sound(),d={video:{optional:[{minWidth:1280},{minWidth:640},{minWidth:480},{minWidth:360}]}},g=this,f=function(a){return g._remove_message(),g.video.src=window.URL?URL.createObjectURL(a):a,g._block_element_access(),g._wait_for_video_ready()},c=function(a){var b,c,d;g.message.innerHTML='<span style="color: red;">You have denied camera access.</span><br><br>Look for camera icon around your address bar to change your decision.',b=a.code;for(c in a)if(d=a[c],"code"!==c)return g._got_error(c),void 0;return g._got_error("UNKNOWN ERROR")};try{return navigator.getUserMedia(d,f,c)}catch(i){return b=i,navigator.getUserMedia("video",f,c)}},c.prototype._engine_play_shutter_sound=function(){var a;if(this.shutter_buffer)return a=this.audio_context.createBufferSource(),a.buffer=this.shutter_buffer,a.connect(this.audio_context.destination),a.start(0)},c.prototype._engine_capture=function(a,b,c,d){var e,f,g;return g=this._get_capture_crop(),e=document.createElement("canvas"),e.width=Math.round(g.width*d),e.height=Math.round(g.height*d),f=e.getContext("2d"),f.drawImage(this.video,g.x_offset,g.y_offset,g.width,g.height,0,0,Math.round(g.width*d),Math.round(g.height*d)),a._canvas=e,a._mirror=b,a._quality=c},c.prototype._engine_display=function(b){return this.displayed_canvas&&this.container.removeChild(this.displayed_canvas),this.displayed_canvas=b._canvas,this.displayed_canvas.style.width=""+this.view_width+"px",this.displayed_canvas.style.height=""+this.view_height+"px",this.displayed_canvas.style.top=0,this.displayed_canvas.style.left=0,this.displayed_canvas.style.position="absolute",this.displayed_canvas.style.zIndex=2,a._add_prefixed_style(this.displayed_canvas,"transform","scalex(-1.0)"),this.container.appendChild(this.displayed_canvas)},c.prototype._engine_get_canvas=function(a){var b,c;return b=document.createElement("canvas"),b.width=a._canvas.width,b.height=a._canvas.height,c=b.getContext("2d"),c.drawImage(a._canvas,0,0),b},c.prototype._engine_get_image_data=function(a){var b,c;return b=a._canvas,c=b.getContext("2d"),c.getImageData(0,0,b.width,b.height)},c.prototype._engine_discard=function(a){return a._xhr&&a._xhr.abort(),delete a._xhr,delete a._canvas,delete a._jpeg_blob},c.prototype._engine_show_stream=function(){return this.displayed_canvas&&(this.container.removeChild(this.displayed_canvas),this.displayed_canvas=null),this.video_container.style.display="block"},c.prototype._engine_upload=function(a,b,c,d){var e,f,g,h,i;return h=this,a._jpeg_blob?(this._debug("Uploading the file"),g=function(b){return delete a._xhr,a._status=b.target.status,a._response=b.target.responseText,a._status>=200&&a._status<300?a._upload_done():(a._error_message=b.target.statusText||"Unknown error",a._upload_fail())},i=new XMLHttpRequest,i.open("POST",b),i.timeout=d,c&&i.setRequestHeader("X-CSRF-Token",c),i.onload=g,i.onerror=g,i.onabort=g,i.send(a._jpeg_blob),a._xhr=i):(this._debug("Generating JPEG file"),a._mirror?(e=document.createElement("canvas"),e.width=a._canvas.width,e.height=a._canvas.height,f=e.getContext("2d"),f.setTransform(1,0,0,1,0,0),f.translate(e.width,0),f.scale(-1,1),f.drawImage(a._canvas,0,0)):e=a._canvas,e.toBlob(function(e){return a._jpeg_blob=e,h._engine_upload(a,b,c,d)},"image/jpeg",this.quality))},c.prototype._remove_message=function(){return this.message.style.display="none"},c.prototype._load_shutter_sound=function(){var a,b;if(!this.audio_context)return this.audio_context=new AudioContext,a=new XMLHttpRequest,a.open("GET",this.options.shutter_url,!0),a.responseType="arraybuffer",b=this,a.onload=function(){return b.audio_context.decodeAudioData(a.response,function(a){return b.shutter_buffer=a})},a.send()},c.prototype._wait_for_video_ready=function(){var a,b,c,d;return d=parseInt(this.video.videoWidth),c=parseInt(this.video.videoHeight),d>0&&c>0?(this.video_container.appendChild(this.video),this.video_width=d,this.video_height=c,this._debug("Camera resolution "+this.video_width+"x"+this.video_height+"px"),a=this._get_video_crop(),this.video.style.position="relative",this.video.style.width=""+a.width+"px",this.video.style.height=""+a.height+"px",this.video.style.left=""+a.x_offset+"px",this.video.style.top=""+a.y_offset+"px",this._prepared()):this._status_checks_count>100?this._got_error("Camera failed to initialize in 10 seconds"):(this._status_checks_count++,b=this,setTimeout(function(){return b._wait_for_video_ready()},100))},c.prototype._status_checks_count=0,c.prototype._get_video_crop=function(){var a,b,c,d,e;return c=this.video_width/this.video_height,e=this.view_width/this.view_height,c>=e?(this._debug("Filling height"),d=this.view_height/this.video_height,b=Math.round(this.video_width*d),{width:b,height:this.view_height,x_offset:-Math.floor((b-this.view_width)/2),y_offset:0}):(this._debug("Filling width"),d=this.view_width/this.video_width,a=Math.round(this.video_height*d),{width:this.view_width,height:a,x_offset:0,y_offset:-Math.floor((a-this.view_height)/2)})},c.prototype._get_capture_crop=function(){var a,b,c,d;return c=this.video_width/this.video_height,d=this.view_width/this.view_height,c>=d?(b=Math.round(this.video_height*d),{width:b,height:this.video_height,x_offset:Math.floor((this.video_width-b)/2),y_offset:0}):(a=Math.round(this.video_width/d),{width:this.video_width,height:a,x_offset:0,y_offset:Math.floor((this.video_height-a)/2)})},c}(a),window.JpegCamera=b),c=function(){function b(a,b){this.camera=a,this.options=b,this.id=this.constructor._next_snapshot_id++}return b._next_snapshot_id=1,b.prototype._discarded=!1,b.prototype.show=function(){return this._discarded&&raise("discarded snapshot cannot be used"),this.camera._display(this),this},b.prototype.hide=function(){return this.camera.displayed_snapshot()===this&&this.camera.show_stream(),this},b.prototype.get_stats=function(a){return this._discarded&&raise("discarded snapshot cannot be used"),this.get_image_data(function(b){return this._get_stats(b,a)})},b.prototype.get_canvas=function(b){var c;return this._discarded&&raise("discarded snapshot cannot be used"),!a._canvas_supported,c=this,setTimeout(function(){return c._extra_canvas||(c._extra_canvas=c.camera._engine_get_canvas(c)),a._add_prefixed_style(c._extra_canvas,"transform","scalex(-1.0)"),b.call(c,c._extra_canvas)},10),!0},b.prototype._extra_canvas=null,b.prototype.get_image_data=function(a){var b;return this._discarded&&raise("discarded snapshot cannot be used"),b=this,setTimeout(function(){return b._image_data||(b._image_data=b.camera._engine_get_image_data(b)),a.call(b,b._image_data)},5)},b.prototype._image_data=null,b.prototype.upload=function(a){var b;if(null==a&&(a={}),this._discarded&&raise("discarded snapshot cannot be used"),this._uploading)return this.camera._debug("Upload already in progress"),void 0;if(this._uploading=!0,this._retry=1,this._upload_options=a,b=this._options(),!b.api_url)throw this.camera._debug("Snapshot#upload called without valid api_url"),"Snapshot#upload called without valid api_url";return this._start_upload(b),this},b.prototype._upload_options={},b.prototype._uploading=!1,b.prototype._retry=1,b.prototype.done=function(a){var b;return this._discarded&&raise("discarded snapshot cannot be used"),this._upload_options.on_upload_done=a,b=this._options(),b.on_upload_done&&this._done&&b.on_upload_done.call(this,this._response),this},b.prototype._done=!1,b.prototype._response=null,b.prototype.fail=function(a){var b;return this._discarded&&raise("discarded snapshot cannot be used"),this._upload_options.on_upload_fail=a,b=this._options(),b.on_upload_fail&&this._fail&&b.on_upload_fail.call(this,this._status,this._error_message,this._response),this},b.prototype._fail=!1,b.prototype._status=null,b.prototype._error_message=null,b.prototype.discard=function(){return this.camera._discard(this),void 0},b.prototype._options=function(){return this.camera._extend({},this.camera.options,this.options,this._upload_options)},b.prototype._start_upload=function(a){var b;return b="string"==typeof a.csrf_token&&a.csrf_token.length>0?a.csrf_token:null,this._done=!1,this._response=null,this._fail=!1,this._status=null,this._error_message=null,this.camera._engine_upload(this,a.api_url,b,a.timeout)},b.prototype._get_stats=function(a,b){var c,d,e,f,g,h,i,j,k,l,m;if(!this._stats){for(h=a.width*a.height,i=0,d=new Array(h),e=k=0;h>k;e=k+=1)f=4*e,c=.2126*a.data[f+0]+.7152*a.data[f+1]+.0722*a.data[f+2],c=Math.round(c),i+=c,d[e]=c;for(g=Math.round(i/h),j=0,l=0,m=d.length;m>l;l++)c=d[l],j+=Math.pow(c-g,2);this._stats={mean:g,std:Math.round(Math.sqrt(j/h))}}return b.call(this,this._stats)},b.prototype._stats=null,b.prototype._upload_done=function(){var a,b,c,d;return this.camera._debug("Upload completed with status "+this._status),this._done=!0,a=this._options(),c=a.retry_success&&a.retry_if&&a.retry_if.call(this,this._status,this._error_message,this._response,this._retry),!0===c&&(c=0),"number"==typeof c?(this._retry++,c>0?(b=parseInt(c),this.camera._debug("Will retry the upload in "+b+"ms (attempt #"+this._retry+")"),d=this,setTimeout(function(){return d._start_upload(a)},b)):(this.camera._debug("Will retry the upload immediately (attempt #"+this._retry+")"),this._start_upload(a))):(this._uploading=!1,a.on_upload_done?a.on_upload_done.call(this,this._response):void 0)},b.prototype._upload_fail=function(){var a,b,c,d;return this.camera._debug("Upload failed with status "+this._status),this._fail=!0,a=this._options(),c=a.retry_if&&a.retry_if.call(this,this._status,this._error_message,this._response,this._retry),!0===c&&(c=0),"number"==typeof c?(this._retry++,c>0?(b=parseInt(c),this.camera._debug("Will retry the upload in "+b+"ms (attempt #"+this._retry+")"),d=this,setTimeout(function(){return d._start_upload(a)},b)):(this.camera._debug("Will retry the upload immediately (attempt #"+this._retry+")"),this._start_upload(a))):(this._uploading=!1,a.on_upload_fail?a.on_upload_fail.call(this,this._status,this._error_message,this._response):void 0)},b}()}.call(this);
4
+ (function(){var a,b,c,d,e,f,g={}.hasOwnProperty,h=function(a,b){function c(){this.constructor=a}for(var d in b)g.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};a=function(){function a(a,b){if("string"==typeof a&&(a=document.getElementById(a.replace("#",""))),!a||!a.offsetWidth)throw"JpegCamera: invalid container";a.innerHTML="",this.view_width=parseInt(a.offsetWidth,10),this.view_height=parseInt(a.offsetHeight,10),this.container=document.createElement("div"),this.container.style.width="100%",this.container.style.height="100%",this.container.style.position="relative",a.appendChild(this.container),this.options=this._extend({},this.constructor.DefaultOptions,b),this._engine_init()}return a.DefaultOptions={shutter_url:"/jpeg_camera/shutter.mp3",swf_url:"/jpeg_camera/jpeg_camera.swf",on_debug:function(a){return console&&console.log?console.log("JpegCamera: "+a):void 0},quality:.9,shutter:!0,mirror:!1,timeout:0,retry_success:!1,scale:1},a._canvas_supported=!!document.createElement("canvas").getContext,a.canvas_supported=function(){return this._canvas_supported},a.prototype.ready=function(a){return this.options.on_ready=a,this.options.on_ready&&this._is_ready&&this.options.on_ready.call(this,{video_width:this.video_width,video_height:this.video_height}),this},a.prototype._is_ready=!1,a.prototype.error=function(a){return this.options.on_error=a,this.options.on_error&&this._error_occured&&this.options.on_error.call(this,this._error_occured),this},a.prototype._error_occured=!1,a.StatsCaptureScale=.2,a.prototype.get_stats=function(b){var d,e;return d=new c(this,{}),this._engine_capture(d,!1,.1,a.StatsCaptureScale),e=this,d.get_stats(function(a){return b.call(e,a)})},a.prototype.capture=function(a){var b,d,e;return null==a&&(a={}),d=new c(this,a),this._snapshots[d.id]=d,e=d._options(),e.shutter&&this._engine_play_shutter_sound(),b=Math.min(1,e.scale),b=Math.max(.01,b),this._engine_capture(d,e.mirror,e.quality,b),d},a.prototype._snapshots={},a.prototype.show_stream=function(){return this._engine_show_stream(),this._displayed_snapshot=null,this},a.prototype.discard_all=function(){var a,b,c;this._displayed_snapshot&&this.show_stream(),c=this._snapshots;for(a in c)b=c[a],this._engine_discard(b),b._discarded=!0;return this._snapshots={},this},a.prototype._extend=function(a){var b,c,d,e,f,g;for(d=Array.prototype.slice.call(arguments,1),f=0,g=d.length;g>f;f++)if(c=d[f])for(b in c)e=c[b],a[b]=e;return a},a.prototype._debug=function(a){return this.options.on_debug?this.options.on_debug.call(this,a):void 0},a.prototype._display=function(a){return this._engine_display(a),this._displayed_snapshot=a},a.prototype._displayed_snapshot=null,a.prototype._discard=function(a){return this._displayed_snapshot===a&&this.show_stream(),this._engine_discard(a),a._discarded=!0,delete this._snapshots[a.id]},a.prototype._prepared=function(a,b){var c;return this.video_width=a,this.video_height=b,this._debug("Camera resolution "+this.video_width+"x"+this.video_height+"px"),c=this,setTimeout(function(){return c._wait_until_stream_looks_ok(!0)},1)},a.prototype._wait_until_stream_looks_ok=function(a){return this.get_stats(function(b){var c;return b.std>2?(this._debug("Stream mean gray value = "+b.mean+" standard deviation = "+b.std),this._debug("Camera is ready"),this._is_ready=!0,this.options.on_ready?this.options.on_ready.call(this,{video_width:this.video_width,video_height:this.video_height}):void 0):(a&&this._debug("Stream mean gray value = "+b.mean+" standard deviation = "+b.std),c=this,setTimeout(function(){return c._wait_until_stream_looks_ok(!1)},100))})},a.prototype._got_error=function(a){return this._debug("Error - "+a),this._error_occured=a,this.options.on_error?this.options.on_error.call(this,this._error_occured):void 0},a.prototype._block_element_access=function(){return this._overlay=document.createElement("div"),this._overlay.style.width="100%",this._overlay.style.height="100%",this._overlay.style.position="absolute",this._overlay.style.top=0,this._overlay.style.left=0,this._overlay.style.zIndex=2,this.container.appendChild(this._overlay)},a.prototype._overlay=null,a.prototype.view_width=null,a.prototype.view_height=null,a._add_prefixed_style=function(a,b,c){var d;return d=b.charAt(0).toUpperCase()+b.slice(1),a.style[b]=c,a.style["Webkit"+d]=c,a.style["Moz"+d]=c,a.style["ms"+d]=c,a.style["O"+d]=c},a}(),navigator.getUserMedia||(navigator.getUserMedia=navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia),e=function(){var a;if(a=document.createElement("canvas"),a.getContext&&!a.toBlob)throw"JpegCamera: Canvas-to-Blob is not loaded"},navigator.getUserMedia&&(e(),b=function(b){function c(){return f=c.__super__.constructor.apply(this,arguments)}return h(c,b),c.prototype._engine_init=function(){var b,c,d,e,f,g,h;this._debug("Using HTML5 engine"),h=Math.floor(.2*this.view_height),e=Math.floor(.2*this.view_width),this.message=document.createElement("div"),this.message["class"]="message",this.message.style.width="100%",this.message.style.height="100%",a._add_prefixed_style(this.message,"boxSizing","border-box"),this.message.style.overflow="hidden",this.message.style.textAlign="center",this.message.style.paddingTop=""+h+"px",this.message.style.paddingBottom=""+h+"px",this.message.style.paddingLeft=""+e+"px",this.message.style.paddingRight=""+e+"px",this.message.style.position="absolute",this.message.style.zIndex=3,this.message.innerHTML="Please allow camera access when prompted by the browser.<br><br>Look for camera icon around your address bar.",this.container.appendChild(this.message),this.video_container=document.createElement("div"),this.video_container.style.width=""+this.view_width+"px",this.video_container.style.height=""+this.view_height+"px",this.video_container.style.overflow="hidden",this.video_container.style.position="absolute",this.video_container.style.zIndex=1,this.container.appendChild(this.video_container),this.video=document.createElement("video"),this.video.autoplay=!0,a._add_prefixed_style(this.video,"transform","scalex(-1.0)"),window.AudioContext||(window.AudioContext=window.webkitAudioContext),window.AudioContext&&this._load_shutter_sound(),d={video:{optional:[{minWidth:1280},{minWidth:640},{minWidth:480},{minWidth:360}]}},g=this,f=function(a){return g._remove_message(),g.video.src=window.URL?URL.createObjectURL(a):a,g._block_element_access(),g._wait_for_video_ready()},c=function(a){var b,c,d;g.message.innerHTML='<span style="color: red;">You have denied camera access.</span><br><br>Look for camera icon around your address bar to change your decision.',b=a.code;for(c in a)if(d=a[c],"code"!==c)return g._got_error(c),void 0;return g._got_error("UNKNOWN ERROR")};try{return navigator.getUserMedia(d,f,c)}catch(i){return b=i,navigator.getUserMedia("video",f,c)}},c.prototype._engine_play_shutter_sound=function(){var a;if(this.shutter_buffer)return a=this.audio_context.createBufferSource(),a.buffer=this.shutter_buffer,a.connect(this.audio_context.destination),a.start(0)},c.prototype._engine_capture=function(a,b,c,d){var e,f,g;return g=this._get_capture_crop(),e=document.createElement("canvas"),e.width=Math.round(g.width*d),e.height=Math.round(g.height*d),f=e.getContext("2d"),f.drawImage(this.video,g.x_offset,g.y_offset,g.width,g.height,0,0,Math.round(g.width*d),Math.round(g.height*d)),a._canvas=e,a._mirror=b,a._quality=c},c.prototype._engine_display=function(b){return this.displayed_canvas&&this.container.removeChild(this.displayed_canvas),this.displayed_canvas=b._canvas,this.displayed_canvas.style.width=""+this.view_width+"px",this.displayed_canvas.style.height=""+this.view_height+"px",this.displayed_canvas.style.top=0,this.displayed_canvas.style.left=0,this.displayed_canvas.style.position="absolute",this.displayed_canvas.style.zIndex=2,a._add_prefixed_style(this.displayed_canvas,"transform","scalex(-1.0)"),this.container.appendChild(this.displayed_canvas)},c.prototype._engine_get_canvas=function(a){var b,c;return b=document.createElement("canvas"),b.width=a._canvas.width,b.height=a._canvas.height,c=b.getContext("2d"),c.drawImage(a._canvas,0,0),b},c.prototype._engine_get_image_data=function(a){var b,c;return b=a._canvas,c=b.getContext("2d"),c.getImageData(0,0,b.width,b.height)},c.prototype._engine_get_blob=function(a,b,c,d,e){var f,g;return c?(f=document.createElement("canvas"),f.width=a._canvas.width,f.height=a._canvas.height,g=f.getContext("2d"),g.setTransform(1,0,0,1,0,0),g.translate(f.width,0),g.scale(-1,1),g.drawImage(a._canvas,0,0)):f=a._canvas,f.toBlob(function(a){return e(a)},b,d)},c.prototype._engine_discard=function(a){return a._xhr&&a._xhr.abort(),delete a._xhr,delete a._canvas},c.prototype._engine_show_stream=function(){return this.displayed_canvas&&(this.container.removeChild(this.displayed_canvas),this.displayed_canvas=null),this.video_container.style.display="block"},c.prototype._engine_upload=function(a,b,c,d){return this._debug("Uploading the file"),a.get_blob(function(e){var f,g;return f=function(b){return delete a._xhr,a._status=b.target.status,a._response=b.target.responseText,a._status>=200&&a._status<300?a._upload_done():(a._error_message=b.target.statusText||"Unknown error",a._upload_fail())},g=new XMLHttpRequest,g.open("POST",b),g.timeout=d,c&&g.setRequestHeader("X-CSRF-Token",c),g.onload=f,g.onerror=f,g.onabort=f,g.send(e),a._xhr=g},"image/jpeg")},c.prototype._remove_message=function(){return this.message.style.display="none"},c.prototype._load_shutter_sound=function(){var a,b;if(!this.audio_context)return this.audio_context=new AudioContext,a=new XMLHttpRequest,a.open("GET",this.options.shutter_url,!0),a.responseType="arraybuffer",b=this,a.onload=function(){return b.audio_context.decodeAudioData(a.response,function(a){return b.shutter_buffer=a})},a.send()},c.prototype._wait_for_video_ready=function(){var a,b,c,d;return d=parseInt(this.video.videoWidth),c=parseInt(this.video.videoHeight),d>0&&c>0?(this.video_container.appendChild(this.video),this.video_width=d,this.video_height=c,a=this._get_video_crop(),this.video.style.position="relative",this.video.style.width=""+a.width+"px",this.video.style.height=""+a.height+"px",this.video.style.left=""+a.x_offset+"px",this.video.style.top=""+a.y_offset+"px",this._prepared(this.video_width,this.video_height)):this._status_checks_count>100?this._got_error("Camera failed to initialize in 10 seconds"):(this._status_checks_count++,b=this,setTimeout(function(){return b._wait_for_video_ready()},100))},c.prototype._status_checks_count=0,c.prototype._get_video_crop=function(){var a,b,c,d,e;return c=this.video_width/this.video_height,e=this.view_width/this.view_height,c>=e?(this._debug("Filling height"),d=this.view_height/this.video_height,b=Math.round(this.video_width*d),{width:b,height:this.view_height,x_offset:-Math.floor((b-this.view_width)/2),y_offset:0}):(this._debug("Filling width"),d=this.view_width/this.video_width,a=Math.round(this.video_height*d),{width:this.view_width,height:a,x_offset:0,y_offset:-Math.floor((a-this.view_height)/2)})},c.prototype._get_capture_crop=function(){var a,b,c,d;return c=this.video_width/this.video_height,d=this.view_width/this.view_height,c>=d?(b=Math.round(this.video_height*d),{width:b,height:this.video_height,x_offset:Math.floor((this.video_width-b)/2),y_offset:0}):(a=Math.round(this.video_width/d),{width:this.video_width,height:a,x_offset:0,y_offset:Math.floor((this.video_height-a)/2)})},c}(a),window.JpegCamera=b),c=function(){function b(a,b){this.camera=a,this.options=b,this.id=this.constructor._next_snapshot_id++}return b._next_snapshot_id=1,b.prototype._discarded=!1,b.prototype.show=function(){return this._discarded&&raise("discarded snapshot cannot be used"),this.camera._display(this),this},b.prototype.hide=function(){return this.camera.displayed_snapshot()===this&&this.camera.show_stream(),this},b.prototype.get_stats=function(a){return this._discarded&&raise("discarded snapshot cannot be used"),this.get_image_data(function(b){return this._get_stats(b,a)})},b.prototype.get_canvas=function(b){var c;return this._discarded&&raise("discarded snapshot cannot be used"),!a._canvas_supported,c=this,setTimeout(function(){return c._extra_canvas||(c._extra_canvas=c.camera._engine_get_canvas(c)),a._add_prefixed_style(c._extra_canvas,"transform","scalex(-1.0)"),b.call(c,c._extra_canvas)},1),!0},b.prototype._extra_canvas=null,b.prototype.get_blob=function(b,c){var d;return null==c&&(c="image/jpeg"),this._discarded&&raise("discarded snapshot cannot be used"),!a._canvas_supported,d=this,setTimeout(function(){var a,e;return d._blob_mime!==c&&(d._blob=null),d._blob_mime=c,d._blob?b.call(d,d._blob):(a=d.options.mirror,e=d.options.quality,d.camera._engine_get_blob(d,c,a,e,function(a){return d._blob=a,b.call(d,d._blob)}))},1),!0},b.prototype._blob=null,b.prototype._blob_mime=null,b.prototype.get_image_data=function(a){var b;return this._discarded&&raise("discarded snapshot cannot be used"),b=this,setTimeout(function(){return b._image_data||(b._image_data=b.camera._engine_get_image_data(b)),a.call(b,b._image_data)},1),null},b.prototype._image_data=null,b.prototype.upload=function(a){var b;if(null==a&&(a={}),this._discarded&&raise("discarded snapshot cannot be used"),this._uploading)return this.camera._debug("Upload already in progress"),void 0;if(this._uploading=!0,this._retry=1,this._upload_options=a,b=this._options(),!b.api_url)throw this.camera._debug("Snapshot#upload called without valid api_url"),"Snapshot#upload called without valid api_url";return this._start_upload(b),this},b.prototype._upload_options={},b.prototype._uploading=!1,b.prototype._retry=1,b.prototype.done=function(a){var b;return this._discarded&&raise("discarded snapshot cannot be used"),this._upload_options.on_upload_done=a,b=this._options(),b.on_upload_done&&this._done&&b.on_upload_done.call(this,this._response),this},b.prototype._done=!1,b.prototype._response=null,b.prototype.fail=function(a){var b;return this._discarded&&raise("discarded snapshot cannot be used"),this._upload_options.on_upload_fail=a,b=this._options(),b.on_upload_fail&&this._fail&&b.on_upload_fail.call(this,this._status,this._error_message,this._response),this},b.prototype._fail=!1,b.prototype._status=null,b.prototype._error_message=null,b.prototype.discard=function(){return this.camera._discard(this),delete this._extra_canvas,delete this._image_data,delete this._blob,void 0},b.prototype._options=function(){return this.camera._extend({},this.camera.options,this.options,this._upload_options)},b.prototype._start_upload=function(a){var b;return b="string"==typeof a.csrf_token&&a.csrf_token.length>0?a.csrf_token:null,this._done=!1,this._response=null,this._fail=!1,this._status=null,this._error_message=null,this.camera._engine_upload(this,a.api_url,b,a.timeout)},b.prototype._get_stats=function(a,b){var c,e,f,g,h,i,j,k,l,m,n;if(!this._stats){for(i=a.width*a.height,j=0,e=new Array(i),f=l=0;i>l;f=l+=1)g=4*f,c=.2126*a.data[g+0]+.7152*a.data[g+1]+.0722*a.data[g+2],c=Math.round(c),j+=c,e[f]=c;for(h=Math.round(j/i),k=0,m=0,n=e.length;n>m;m++)c=e[m],k+=Math.pow(c-h,2);this._stats=new d,this._stats.mean=h,this._stats.std=Math.round(Math.sqrt(k/i))}return b.call(this,this._stats)},b.prototype._stats=null,b.prototype._upload_done=function(){var a,b,c,d;return this.camera._debug("Upload completed with status "+this._status),this._done=!0,a=this._options(),c=a.retry_success&&a.retry_if&&a.retry_if.call(this,this._status,this._error_message,this._response,this._retry),!0===c&&(c=0),"number"==typeof c?(this._retry++,c>0?(b=parseInt(c),this.camera._debug("Will retry the upload in "+b+"ms (attempt #"+this._retry+")"),d=this,setTimeout(function(){return d._start_upload(a)},b)):(this.camera._debug("Will retry the upload immediately (attempt #"+this._retry+")"),this._start_upload(a))):(this._uploading=!1,a.on_upload_done?a.on_upload_done.call(this,this._response):void 0)},b.prototype._upload_fail=function(){var a,b,c,d;return this.camera._debug("Upload failed with status "+this._status),this._fail=!0,a=this._options(),c=a.retry_if&&a.retry_if.call(this,this._status,this._error_message,this._response,this._retry),!0===c&&(c=0),"number"==typeof c?(this._retry++,c>0?(b=parseInt(c),this.camera._debug("Will retry the upload in "+b+"ms (attempt #"+this._retry+")"),d=this,setTimeout(function(){return d._start_upload(a)},b)):(this.camera._debug("Will retry the upload immediately (attempt #"+this._retry+")"),this._start_upload(a))):(this._uploading=!1,a.on_upload_fail?a.on_upload_fail.call(this,this._status,this._error_message,this._response):void 0)},b}(),d=function(){function a(){}return a.prototype.mean=null,a.prototype.std=null,a}()}).call(this);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpeg_camera
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Wróbel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-09 00:00:00.000000000 Z
11
+ date: 2013-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  requirements: []
72
72
  rubyforge_project:
73
- rubygems_version: 2.0.5
73
+ rubygems_version: 2.1.9
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: Use JpegCamera in Rails 3 app