use webgl for yuv transform, wasm one not work well for image from mac,
no idea why
This commit is contained in:
parent
620fe81017
commit
6aad58bfe5
@ -48,11 +48,12 @@ export function pushEvent(name, payload) {
|
|||||||
events.push(payload);
|
events.push(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
let yuvWorker = new Worker("./yuv.js");
|
let yuvWorker;
|
||||||
/*
|
|
||||||
let yuvCanvas;
|
let yuvCanvas;
|
||||||
let gl;
|
let gl;
|
||||||
let pixels;
|
let pixels;
|
||||||
|
let flipPixels;
|
||||||
|
let oldSize;
|
||||||
if (YUVCanvas.WebGLFrameSink.isAvailable()) {
|
if (YUVCanvas.WebGLFrameSink.isAvailable()) {
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
yuvCanvas = YUVCanvas.attach(canvas, { webGL: true });
|
yuvCanvas = YUVCanvas.attach(canvas, { webGL: true });
|
||||||
@ -60,21 +61,38 @@ if (YUVCanvas.WebGLFrameSink.isAvailable()) {
|
|||||||
} else {
|
} else {
|
||||||
yuvWorker = new Worker("./yuv.js");
|
yuvWorker = new Worker("./yuv.js");
|
||||||
}
|
}
|
||||||
*/
|
let testSpeed = [0, 0];
|
||||||
|
|
||||||
export function draw(frame) {
|
export function draw(frame) {
|
||||||
if (yuvWorker) {
|
if (yuvWorker) {
|
||||||
// frame's (y/u/v).bytes already detached, can not transferrable any more.
|
// frame's (y/u/v).bytes already detached, can not transferrable any more.
|
||||||
yuvWorker.postMessage(frame);
|
yuvWorker.postMessage(frame);
|
||||||
} else {
|
} else {
|
||||||
var now = new Date().getTime();
|
var tm0 = new Date().getTime();
|
||||||
yuvCanvas.drawFrame(frame);
|
yuvCanvas.drawFrame(frame);
|
||||||
console.log(new Date().getTime() - now);
|
var width = canvas.width;
|
||||||
now = new Date().getTime();
|
var height = canvas.height;
|
||||||
if (!pixels) pixels = new Uint8Array(canvas.width * canvas.height * 4);
|
var size = width * height * 4;
|
||||||
gl.readPixels(0, 0, canvas.width, canvas.height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
if (size != oldSize) {
|
||||||
console.log(new Date().getTime() - now);
|
pixels = new Uint8Array(size);
|
||||||
|
flipPixels = new Uint8Array(size);
|
||||||
|
oldSize = size;
|
||||||
|
}
|
||||||
|
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
||||||
|
const row = width * 4;
|
||||||
|
const end = (height - 1) * row;
|
||||||
|
for (let i = 0; i < size; i += row) {
|
||||||
|
flipPixels.set(pixels.subarray(i, i + row), end - i);
|
||||||
|
}
|
||||||
|
currentFrame = flipPixels;
|
||||||
|
testSpeed[1] += new Date().getTime() - tm0;
|
||||||
|
testSpeed[0] += 1;
|
||||||
|
if (testSpeed[0] > 30) {
|
||||||
|
console.log('gl: ' + parseInt('' + testSpeed[1] / testSpeed[0]));
|
||||||
|
testSpeed = [0, 0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
var testCanvas = document.getElementById("test-yuv-decoder-canvas");
|
var testCanvas = document.getElementById("test-yuv-decoder-canvas");
|
||||||
if (testCanvas && currentFrame) {
|
if (testCanvas && currentFrame) {
|
||||||
var ctx = testCanvas.getContext("2d");
|
var ctx = testCanvas.getContext("2d");
|
||||||
@ -84,6 +102,7 @@ export function draw(frame) {
|
|||||||
img.data.set(currentFrame);
|
img.data.set(currentFrame);
|
||||||
ctx.putImageData(img, 0, 0);
|
ctx.putImageData(img, 0, 0);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendOffCanvas(c) {
|
export function sendOffCanvas(c) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user