improve yuv

This commit is contained in:
rustdesk 2022-01-28 04:30:38 +08:00
parent 6656a8cdbf
commit 604dcd6748
4 changed files with 14 additions and 18 deletions

View File

@ -239,7 +239,7 @@ export default class Connection {
draw(frame: any) { draw(frame: any) {
this._draw?.(frame); this._draw?.(frame);
// globals.I420ToABGR(frame); // globals.I420ToARGB(frame);
} }
close() { close() {

View File

@ -41,7 +41,7 @@ export function pushEvent(name, payload) {
} }
export function draw(frame) { export function draw(frame) {
currentFrame = I420ToABGR(frame); currentFrame = I420ToARGB(frame);
} }
export function setConn(conn) { export function setConn(conn) {
@ -282,7 +282,7 @@ window.init = async () => {
let yPtr, yPtrLen, uPtr, uPtrLen, vPtr, vPtrLen, outPtr, outPtrLen; let yPtr, yPtrLen, uPtr, uPtrLen, vPtr, vPtrLen, outPtr, outPtrLen;
// let testSpeed = [0, 0]; // let testSpeed = [0, 0];
export function I420ToABGR(yb) { export function I420ToARGB(yb) {
if (!wasmExports) return; if (!wasmExports) return;
// testSpeed[0] += 1; // testSpeed[0] += 1;
const tm0 = new Date().getTime(); const tm0 = new Date().getTime();
@ -318,8 +318,8 @@ export function I420ToABGR(yb) {
outPtr = malloc(n); outPtr = malloc(n);
} }
// const res = wasmExports.I420ToARGB(yPtr, yb.y.stride, uPtr, yb.u.stride, vPtr, yb.v.stride, outPtr, w * 4, w, h); // const res = wasmExports.I420ToARGB(yPtr, yb.y.stride, uPtr, yb.u.stride, vPtr, yb.v.stride, outPtr, w * 4, w, h);
// const res = wasmExports.AVX_YUV_to_RGB(outPtr, yPtr, uPtr, vPtr, w, h); const res = wasmExports.AVX_YUV_to_RGBA(outPtr, yPtr, uPtr, vPtr, w, h);
const res = wasmExports.yuv420_rgb24_std(w, h, yPtr, uPtr, vPtr, yb.y.stride, yb.v.stride, outPtr, w * 4, 0); // const res = wasmExports.yuv420_rgb24_std(w, h, yPtr, uPtr, vPtr, yb.y.stride, yb.v.stride, outPtr, w * 4, 0);
const out = HEAPU8.slice(outPtr, outPtr + n); const out = HEAPU8.slice(outPtr, outPtr + n);
/* /*
testSpeed[1] += new Date().getTime() - tm0; testSpeed[1] += new Date().getTime() - tm0;

View File

@ -24,7 +24,6 @@
#include <stdio.h> #include <stdio.h>
#define ZOF_TAB 65536 #define ZOF_TAB 65536
#define ZOF_RGB 3
static int T1[ZOF_TAB], T2[ZOF_TAB], T3[ZOF_TAB], T4[ZOF_TAB]; static int T1[ZOF_TAB], T2[ZOF_TAB], T3[ZOF_TAB], T4[ZOF_TAB];
static int initialized; static int initialized;
@ -46,19 +45,16 @@ static int foo;
static int frame; static int frame;
void void
AVX_YUV_to_RGB(unsigned char *dst, unsigned short *src, int width, int height) { AVX_YUV_to_RGBA(unsigned char *dst, unsigned char *y, unsigned char* u, unsigned char* v, int width, int height) {
int r, g, b; int r, g, b;
unsigned short *y, *u, *v, *uline, *vline; unsigned char *uline, *vline;
int w, h; int w, h;
if (initialized == 0) { if (initialized == 0) {
initialized = !0; initialized = !0;
build_tables(); build_tables();
} }
// Setup pointers to the Y, U, V planes int half_width = width / 2;
y = src;
u = src + (width * height);
v = u + (width * height) / 4; // Each chroma does 4 pixels in 4:2:0
// Loop the image, taking into account sub-sample for the chroma channels // Loop the image, taking into account sub-sample for the chroma channels
for (h = 0; h < height; h++) { for (h = 0; h < height; h++) {
uline = u; uline = u;
@ -67,18 +63,18 @@ AVX_YUV_to_RGB(unsigned char *dst, unsigned short *src, int width, int height) {
r = *y + T1[*vline]; r = *y + T1[*vline];
g = *y + T2[*vline] + T3[*uline]; g = *y + T2[*vline] + T3[*uline];
b = *y + T4[*uline]; b = *y + T4[*uline];
dst[0] = clamp(r); // 16-bit to 8-bit, chuck precision *dst++ = clamp(r); // 16-bit to 8-bit, chuck precision
dst[1] = clamp(g); *dst++ = clamp(g);
dst[2] = clamp(b); *dst++ = clamp(b);
dst += ZOF_RGB; *dst++ = 255;
if (w & 0x01) { if (w & 0x01) {
uline++; uline++;
vline++; vline++;
} }
} }
if (h & 0x01) { if (h & 0x01) {
u += width / 2; u += half_width;
v += width / 2; v += half_width;
} }
} }
} }

BIN
yuv.wasm

Binary file not shown.