How to use makeI420_4x2 method in wpt

Best JavaScript code snippet using wpt

videoFrame-copyTo.any.js

Source:videoFrame-copyTo.any.js Github

copy

Full Screen

1// META: global=window,dedicatedworker2function makeI420_4x2() {3 const data = new Uint8Array([4 1, 2, 3, 4, // y5 5, 6, 7, 8,6 9, 10, // u7 11, 12, // v8 ]);9 const init = {10 format: 'I420',11 timestamp: 0,12 codedWidth: 4,13 codedHeight: 2,14 };15 return new VideoFrame(data, init);16}17function makeRGBA_2x2() {18 const data = new Uint8Array([19 1,2,3,4, 5,6,7,8,20 9,10,11,12, 13,14,15,16,21 ]);22 const init = {23 format: 'RGBA',24 timestamp: 0,25 codedWidth: 2,26 codedHeight: 2,27 };28 return new VideoFrame(data, init);29}30function assert_buffer_equals(actual, expected) {31 assert_true(actual instanceof Uint8Array, 'actual instanceof Uint8Array');32 assert_true(expected instanceof Uint8Array, 'buffer instanceof Uint8Array');33 assert_equals(actual.length, expected.length, 'buffer length');34 for (let i = 0; i < actual.length; i++) {35 if (actual[i] != expected[i]) {36 assert_equals(actual[i], expected[i], 'buffer contents at index ' + i);37 }38 }39}40function assert_layout_equals(actual, expected) {41 assert_equals(actual.length, expected.length, 'layout planes');42 for (let i = 0; i < actual.length; i++) {43 assert_object_equals(actual[i], expected[i], 'plane ' + i + ' layout');44 }45}46promise_test(async t => {47 const frame = makeI420_4x2();48 const expectedLayout = [49 {offset: 0, stride: 4},50 {offset: 8, stride: 2},51 {offset: 10, stride: 2},52 ];53 const expectedData = new Uint8Array([54 1, 2, 3, 4, // y55 5, 6, 7, 8,56 9, 10, // u57 11, 12 // v58 ]);59 assert_equals(frame.allocationSize(), expectedData.length, 'allocationSize()');60 const data = new Uint8Array(expectedData.length);61 const layout = await frame.copyTo(data);62 assert_layout_equals(layout, expectedLayout);63 assert_buffer_equals(data, expectedData);64}, 'Test I420 frame.');65promise_test(async t => {66 const frame = makeRGBA_2x2();67 const expectedLayout = [68 {offset: 0, stride: 8},69 ];70 const expectedData = new Uint8Array([71 1,2,3,4, 5,6,7,8,72 9,10,11,12, 13,14,15,16,73 ]);74 assert_equals(frame.allocationSize(), expectedData.length, 'allocationSize()');75 const data = new Uint8Array(expectedData.length);76 const layout = await frame.copyTo(data);77 assert_layout_equals(layout, expectedLayout);78 assert_buffer_equals(data, expectedData);79}, 'Test RGBA frame.');80promise_test(async t => {81 const frame = makeI420_4x2();82 const data = new Uint8Array(11);83 await promise_rejects_js(t, TypeError, frame.copyTo(data));84}, 'Test undersized buffer.');85promise_test(async t => {86 const frame = makeI420_4x2();87 const options = {88 layout: [{offset: 0, stride: 4}],89 };90 assert_throws_js(TypeError, () => frame.allocationSize(options));91 const data = new Uint8Array(12);92 await promise_rejects_js(t, TypeError, frame.copyTo(data, options));93}, 'Test incorrect plane count.');94promise_test(async t => {95 const frame = makeI420_4x2();96 const options = {97 layout: [98 {offset: 4, stride: 4},99 {offset: 0, stride: 2},100 {offset: 2, stride: 2},101 ],102 };103 const expectedData = new Uint8Array([104 9, 10, // u105 11, 12, // v106 1, 2, 3, 4, // y107 5, 6, 7, 8,108 ]);109 assert_equals(frame.allocationSize(options), expectedData.length, 'allocationSize()');110 const data = new Uint8Array(expectedData.length);111 const layout = await frame.copyTo(data, options);112 assert_layout_equals(layout, options.layout);113 assert_buffer_equals(data, expectedData);114}, 'Test stride and offset work.');115promise_test(async t => {116 const frame = makeI420_4x2();117 const options = {118 layout: [119 {offset: 9, stride: 5},120 {offset: 1, stride: 3},121 {offset: 5, stride: 3},122 ],123 };124 const expectedData = new Uint8Array([125 0,126 9, 10, 0, // u127 0,128 11, 12, 0, // v129 0,130 1, 2, 3, 4, 0, // y131 5, 6, 7, 8, 0,132 ]);133 assert_equals(frame.allocationSize(options), expectedData.length, 'allocationSize()');134 const data = new Uint8Array(expectedData.length);135 const layout = await frame.copyTo(data, options);136 assert_layout_equals(layout, options.layout);137 assert_buffer_equals(data, expectedData);138}, 'Test stride and offset with padding.');139promise_test(async t => {140 const frame = makeI420_4x2();141 const options = {142 layout: [143 {offset: 0, stride: 1},144 {offset: 8, stride: 2},145 {offset: 10, stride: 2},146 ],147 };148 assert_throws_js(TypeError, () => frame.allocationSize(options));149 const data = new Uint8Array(12);150 await promise_rejects_js(t, TypeError, frame.copyTo(data, options));151}, 'Test invalid stride.');152promise_test(async t => {153 const frame = makeI420_4x2();154 const options = {155 layout: [156 {offset: 0, stride: 4},157 {offset: 8, stride: 2},158 {offset: 2 ** 32 - 2, stride: 2},159 ],160 };161 assert_throws_js(TypeError, () => frame.allocationSize(options));162 const data = new Uint8Array(12);163 await promise_rejects_js(t, TypeError, frame.copyTo(data, options));164}, 'Test address overflow.');165promise_test(async t => {166 const frame = makeI420_4x2();167 const options = {168 rect: frame.codedRect,169 };170 const expectedLayout = [171 {offset: 0, stride: 4},172 {offset: 8, stride: 2},173 {offset: 10, stride: 2},174 ];175 const expectedData = new Uint8Array([176 1, 2, 3, 4, 5, 6, 7, 8, // y177 9, 10, // u178 11, 12 // v179 ]);180 assert_equals(frame.allocationSize(options), expectedData.length, 'allocationSize()');181 const data = new Uint8Array(expectedData.length);182 const layout = await frame.copyTo(data, options);183 assert_layout_equals(layout, expectedLayout);184 assert_buffer_equals(data, expectedData);185}, 'Test codedRect.');186promise_test(async t => {187 const frame = makeI420_4x2();188 const options = {189 rect: {x: 0, y: 0, width: 4, height: 0},190 };191 assert_throws_js(TypeError, () => frame.allocationSize(options));192 const data = new Uint8Array(12);193 await promise_rejects_js(t, TypeError, frame.copyTo(data, options));194}, 'Test empty rect.');195promise_test(async t => {196 const frame = makeI420_4x2();197 const options = {198 rect: {x: 0, y: 0, width: 4, height: 1},199 };200 assert_throws_js(TypeError, () => frame.allocationSize(options));201 const data = new Uint8Array(12);202 await promise_rejects_js(t, TypeError, frame.copyTo(data, options));203}, 'Test unaligned rect.');204promise_test(async t => {205 const frame = makeI420_4x2();206 const options = {207 rect: {x: 2, y: 0, width: 2, height: 2},208 };209 const expectedLayout = [210 {offset: 0, stride: 2},211 {offset: 4, stride: 1},212 {offset: 5, stride: 1},213 ];214 const expectedData = new Uint8Array([215 3, 4, // y216 7, 8,217 10, // u218 12 // v219 ]);220 assert_equals(frame.allocationSize(options), expectedData.length, 'allocationSize()');221 const data = new Uint8Array(expectedData.length);222 const layout = await frame.copyTo(data, options);223 assert_layout_equals(layout, expectedLayout);224 assert_buffer_equals(data, expectedData);225}, 'Test left crop.');226promise_test(async t => {227 const frame = makeI420_4x2();228 const options = {229 rect: {x: 0, y: 0, width: 4, height: 4},230 };231 assert_throws_js(TypeError, () => frame.allocationSize(options));232 const data = new Uint8Array(12);233 await promise_rejects_js(t, TypeError, frame.copyTo(data, options));...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('wpt');2wpt.makeI420_4x2(1, 2, 3, 4, 5, 6, 7, 8, (err, result) => {3 if (err) {4 console.log('error: ', err);5 } else {6 console.log('result: ', result);7 }8});9const wpt = require('wpt');10wpt.makeI420_4x2(1, 2, 3, 4, 5, 6, 7, 8, (err, result) => {11 if (err) {12 console.log('error: ', err);13 } else {14 console.log('result: ', result);15 }16});17const wpt = require('wpt');18wpt.makeI420_4x2(1, 2, 3, 4, 5, 6, 7, 8, (err, result) => {19 if (err) {20 console.log('error: ', err);21 } else {22 console.log('result: ', result);23 }24});25const wpt = require('wpt');26wpt.makeI420_4x2(1, 2, 3, 4, 5, 6, 7, 8, (err, result) => {27 if (err) {28 console.log('error: ', err);29 } else {30 console.log('result: ', result);31 }32});33const wpt = require('wpt');34wpt.makeI420_4x2(1, 2, 3, 4, 5, 6, 7, 8, (err, result) => {35 if (err) {36 console.log('error: ', err);37 } else {38 console.log('result: ', result);39 }40});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptc = require('./build/Release/wptc');2var frame = wptc.makeI420_4x2();3console.log(frame);4var wptc = require('./build/Release/wptc');5var frame = wptc.makeI420_4x2();6console.log(frame);7var wptc = require('./build/Release/wptc');8var frame = wptc.makeI420_4x2();9console.log(frame);10var wptc = require('./build/Release/wptc');11var frame = wptc.makeI420_4x2();12console.log(frame);13var wptc = require('./build/Release/wptc');14var frame = wptc.makeI420_4x2();15console.log(frame);16var wptc = require('./build/Release/wptc');17var frame = wptc.makeI420_4x2();18console.log(frame);19var wptc = require('./build/Release/wptc');20var frame = wptc.makeI420_4x2();21console.log(frame);22var wptc = require('./build/Release/wptc');23var frame = wptc.makeI420_4x2();24console.log(frame);25var wptc = require('./build/Release/wptc');26var frame = wptc.makeI420_4x2();27console.log(frame);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptc = require('wptc');2var frame = wptc.makeI420_4x2();3console.log(frame);4var wptc = require('wptc');5var frame = wptc.makeI420_4x2();6console.log(frame);7var wptc = require('wptc');8var frame = wptc.makeI420_4x2();9console.log(frame);10var wptc = require('wptc');11var frame = wptc.makeI420_4x2();12console.log(frame);13var wptc = require('wptc');14var frame = wptc.makeI420_4x2();15console.log(frame);16var wptc = require('wptc');17var frame = wptc.makeI420_4x2();18console.log(frame);19var wptc = require('wptc');20var frame = wptc.makeI420_4x2();21console.log(frame);22var wptc = require('wptc');23var frame = wptc.makeI420_4x2();24console.log(frame);25var wptc = require('wptc');26var frame = wptc.makeI420_4x2();27console.log(frame);28var wptc = require('wptc');29var frame = wptc.makeI420_4x2();30console.log(frame);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var fs = require('fs');3var i420_4x2 = wpt.makeI420_4x2();4fs.writeFileSync('i420_4x2.yuv', i420_4x2.y);5fs.writeFileSync('i420_4x2.u', i420_4x2.u);6fs.writeFileSync('i420_4x2.v', i420_4x2.v);7var addon = require('./build/Release/addon');8exports.makeI420_4x2 = function() {9 return addon.makeI420_4x2();10};11{12 {13 "<!(node -e \"require('nan')\")"14 "xcode_settings": {15 }16 }17}18using namespace v8;19NAN_METHOD(makeI420_4x2) {20 NanScope();21 char y[4 * 2];22 char u[2 * 1];23 char v[2 * 1];24 memset(y, 0x10, sizeof(y));25 memset(u, 0x80, sizeof(u));26 memset(v, 0x80, sizeof(v));27 Local<Object> obj = NanNew<Object>();28 obj->Set(NanNew("y"), NanNewBufferHandle(y, sizeof(y)));29 obj->Set(NanNew("u"), NanNewBufferHandle(u, sizeof(u)));30 obj->Set(NanNew("v"), NanNewBufferHandle(v, sizeof(v)));31 NanReturnValue(obj);32}33void Init(Handle<Object> exports) {34 exports->Set(NanNew("makeI420_4x2"), NanNew<FunctionTemplate>(makeI420_4x2)->GetFunction());

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var path = require('path');4var data = fs.readFileSync(path.join(__dirname, 'test.yuv'));5var width = 640;6var height = 480;7var ret = wptools.makeI420_4x2(data, width, height);8console.log(ret);

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2const fs = require('fs');3const input = fs.readFileSync('./test.png');4const output = wptools.makeI420_4x2(input);5fs.writeFileSync('./test.yuv', output);6import wptools7import sys8with open('./test.png', 'rb') as f:9 input = f.read()10output = wptools.makeI420_4x2(input)11with open('./test.yuv', 'wb') as f:12 f.write(output)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptc = require('wptc');2var image = wptc.makeI420_4x2(1, 2, 3, 4);3console.log(image);4var wptc = require('wptc');5var image = wptc.makeI420_4x2(1, 2, 3, 4);6console.log(image);7var wptc = require('wptc');8var image = wptc.makeI420_4x2(1, 2, 3, 4);9console.log(image);10var wptc = require('wptc');11var image = wptc.makeI420_4x2(1, 2, 3, 4);12console.log(image);13var wptc = require('wptc');14var image = wptc.makeI420_4x2(1, 2, 3, 4);15console.log(image);16var wptc = require('wptc');17var image = wptc.makeI420_4x2(1, 2, 3, 4);18console.log(image);19var wptc = require('wptc');20var image = wptc.makeI420_4x2(1, 2, 3, 4);21console.log(image);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptc = require('./wptc.js');2var test = new wptc();3var testBuffer = test.makeI420_4x2();4console.log(testBuffer);5function wptc() {6}7wptc.prototype.makeI420_4x2 = function() {8 var buffer = new Buffer(16);9 for (var i = 0; i < 16; i++) {10 buffer[i] = i;11 }12 return buffer;13};14module.exports = wptc;15var wptc = require('./wptc.js');16var test = new wptc();17var testBuffer = test.makeI420_4x2();18console.log(testBuffer);19var wptc = require('./wptc.js');20var test = new wptc.wptc();21var testBuffer = test.makeI420_4x2();22console.log(testBuffer);23var wptc = require('./wptc.js');24var test = new wptc.wptc();25var testBuffer = wptc.makeI420_4x2();26console.log(testBuffer);27var wptc = require('./wptc.js');28var test = new wptc.wptc();29var testBuffer = wptc.prototype.makeI420_4x2();30console.log(testBuffer);31var wptc = require('./wptc.js');32var test = new wptc.wptc();33var testBuffer = wptc.prototype.makeI420_4x2();34console.log(testBuffer);35var wptc = require('./wptc.js');36var test = new wptc.wptc();37var testBuffer = wptc.makeI420_4x2();38console.log(testBuffer);39var wptc = require('./wptc.js');40var test = new wptc.wptc();41var testBuffer = wptc.prototype.makeI420_4x2();42console.log(testBuffer);43var wptc = require('./wptc.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3var i420 = wpt.makeI420_4x2(2,2,2,2,2,2,2,2);4console.log(i420);5wpt = require('wpt');6var wpt = new WebPageTest('www.webpagetest.org');7var i420 = wpt.makeI420_4x2(2,2,2,2,2,2,2,2);8console.log(i420);9wpt = require('wpt');10var wpt = new WebPageTest('www.webpagetest.org');11var i420 = wpt.makeI420_4x2(2,2,2,2,2,2,2,2);12console.log(i420);13wpt = require('wpt');14var wpt = new WebPageTest('www.webpagetest.org');15var i420 = wpt.makeI420_4x2(2,2,2,2,2,2,2,2);16console.log(i420);17wpt = require('wpt');18var wpt = new WebPageTest('www.webpagetest.org');19var i420 = wpt.makeI420_4x2(2,2,2,2,2,2,2,2);20console.log(i420);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful