tweaked new video-snap (still capture) feature

pull/89/head
jmoenig 2019-05-09 00:20:33 +02:00
rodzic 7647811884
commit d9f3c96f89
4 zmienionych plików z 27 dodań i 14 usunięć

Wyświetl plik

@ -13,6 +13,7 @@
* new blocks for setting and changing the stage's background color * new blocks for setting and changing the stage's background color
* new "microphone" reporter in Sensing for getting volume, note, pitch signals and frequencies * new "microphone" reporter in Sensing for getting volume, note, pitch signals and frequencies
* new experimental live audio-scripting support * new experimental live audio-scripting support
* new video capturing and video-motion detection support, thanks, Josep!
* new "object" reporter in the Sensing category for getting a sprite by its name * new "object" reporter in the Sensing category for getting a sprite by its name
* blocks for changing and querying the "flat line ends" setting * blocks for changing and querying the "flat line ends" setting
* selectors for changing and querying "draggable" and "rotation style" settings * selectors for changing and querying "draggable" and "rotation style" settings
@ -77,6 +78,9 @@
* German * German
* French * French
### 2019-05-09
* Blocks, Objects, Threads: tweaked new video-snap (still capture) feature
### 2019-05-08 ### 2019-05-08
* Blocks, Objects, Threads: integrated video capture control into global settings prims in Sensing * Blocks, Objects, Threads: integrated video capture control into global settings prims in Sensing
* Blocks, Threads: added a %self menu * Blocks, Threads: added a %self menu

Wyświetl plik

@ -7,8 +7,8 @@
<script type="text/javascript" src="src/morphic.js?version=2019-02-07"></script> <script type="text/javascript" src="src/morphic.js?version=2019-02-07"></script>
<script type="text/javascript" src="src/widgets.js?version=2019-04-05"></script> <script type="text/javascript" src="src/widgets.js?version=2019-04-05"></script>
<script type="text/javascript" src="src/blocks.js?version=2019-05-08"></script> <script type="text/javascript" src="src/blocks.js?version=2019-05-08"></script>
<script type="text/javascript" src="src/threads.js?version=2019-05-08"></script> <script type="text/javascript" src="src/threads.js?version=2019-05-09"></script>
<script type="text/javascript" src="src/objects.js?version=2019-05-08"></script> <script type="text/javascript" src="src/objects.js?version=2019-05-09"></script>
<script type="text/javascript" src="src/gui.js?version=2019-05-08"></script> <script type="text/javascript" src="src/gui.js?version=2019-05-08"></script>
<script type="text/javascript" src="src/paint.js?version=2019-02-22"></script> <script type="text/javascript" src="src/paint.js?version=2019-02-22"></script>
<script type="text/javascript" src="src/lists.js?version=2019-04-27"></script> <script type="text/javascript" src="src/lists.js?version=2019-04-27"></script>

Wyświetl plik

@ -84,7 +84,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph, TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph,
AlignmentMorph, Process, XML_Element, VectorPaintEditorMorph*/ AlignmentMorph, Process, XML_Element, VectorPaintEditorMorph*/
modules.objects = '2019-May-08'; modules.objects = '2019-May-09';
var SpriteMorph; var SpriteMorph;
var StageMorph; var StageMorph;
@ -1639,7 +1639,7 @@ SpriteMorph.prototype.init = function (globals) {
this.cachedPropagation = false; // not to be persisted this.cachedPropagation = false; // not to be persisted
this.inheritedAttributes = []; // 'x position', 'direction', 'size' etc... this.inheritedAttributes = []; // 'x position', 'direction', 'size' etc...
this.imageData = {}; // version: date, pixels: Uint32Array, canvas: Canvas this.imageData = {}; // version: date, pixels: Uint32Array
this.motionAmount = 0; this.motionAmount = 0;
this.motionDirection = 0; this.motionDirection = 0;
this.frameNumber = 0; this.frameNumber = 0;
@ -1929,7 +1929,7 @@ SpriteMorph.prototype.colorFiltered = function (aColor) {
return morph; return morph;
}; };
SpriteMorph.prototype.getImageData = function (asCanvas) { SpriteMorph.prototype.getImageData = function () {
// used for video motion detection. // used for video motion detection.
// Get sprite image data scaled to 1 an converted to ABGR array, // Get sprite image data scaled to 1 an converted to ABGR array,
// cache to reduce GC load // cache to reduce GC load
@ -1954,24 +1954,33 @@ SpriteMorph.prototype.getImageData = function (asCanvas) {
.getImageData(0, 0, newExtent.x, newExtent.y).data; .getImageData(0, 0, newExtent.x, newExtent.y).data;
this.imageData = { this.imageData = {
version : this.version, version : this.version,
pixels : new Uint32Array(imageData.buffer.slice(0)), pixels : new Uint32Array(imageData.buffer.slice(0))
canvas : canvas
}; };
} }
return asCanvas ? this.imageData.canvas : this.imageData.pixels; return this.imageData.pixels;
}; };
SpriteMorph.prototype.videoSnap = function() { SpriteMorph.prototype.videoSnap = function() {
var stage = this.parentThatIsA(StageMorph), var stage = this.parentThatIsA(StageMorph),
img = this.getImageData(true), center = this.center().subtract(stage.position())
offset = this.position().subtract(stage.position())
.divideBy(stage.scale), .divideBy(stage.scale),
snap = newCanvas(new Point(img.width, img.height), true), cst = this.costume || this.image,
ctx = snap.getContext('2d'); offset,
snap,
ctx;
if (cst instanceof Costume) {
cst = cst.contents;
}
offset = new Point(
Math.floor(center.x - (cst.width / 2)),
Math.floor(center.y - (cst.height / 2))
);
snap = newCanvas(new Point(cst.width, cst.height), true);
ctx = snap.getContext('2d');
ctx.drawImage(stage.videoLayer(), -offset.x, -offset.y); ctx.drawImage(stage.videoLayer(), -offset.x, -offset.y);
ctx.globalCompositeOperation = 'destination-atop'; ctx.globalCompositeOperation = 'destination-atop';
ctx.drawImage(img, 0, 0); ctx.drawImage(cst, 0, 0);
return new Costume(snap, this.newCostumeName(localize('snap'))); return new Costume(snap, this.newCostumeName(localize('snap')));
}; };

Wyświetl plik

@ -61,7 +61,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy,
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, Color, isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, Color,
TableFrameMorph, ColorSlotMorph, isSnapObject, Map, newCanvas, Symbol*/ TableFrameMorph, ColorSlotMorph, isSnapObject, Map, newCanvas, Symbol*/
modules.threads = '2019-May-08'; modules.threads = '2019-May-09';
var ThreadManager; var ThreadManager;
var Process; var Process;