Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: content/test/data/media/depth_stream_test_utilities.js

Issue 2428263004: 16 bpp video stream capture, render and createImageBitmap(video) using (CPU) shared memory buffers (Closed)
Patch Set: Split webrtc_depth_capture_browsertest. Thanks phoglund@, Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/test/BUILD.gn ('k') | content/test/data/media/getusermedia-depth-capture.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 function getConstraintsForDevice(deviceLabel) {
6 return new Promise(function(resolve, reject) {
7 navigator.mediaDevices.enumerateDevices()
8 .then(function(devices) {
9 for (var i = 0; i < devices.length; ++i) {
10 if (deviceLabel == devices[i].label) {
11 return resolve({video:{deviceId: {exact: devices[i].deviceId},
12 width: {exact:96},
13 height: {exact:96}}
14 });
15 }
16 }
17 return reject("Expected to have a device with label:" + deviceLabel);
18 })
19 });
20 }
21
22 function getFake16bitStream() {
23 return new Promise(function(resolve, reject) {
24 getConstraintsForDevice("fake_device_1")
25 .then(function(constraints) {
26 if (!constraints)
27 return reject("No fake device found");
28 return navigator.mediaDevices.getUserMedia(constraints);
29 }).then(function(stream) {
30 return resolve(stream);
31 });
32 });
33 }
34
35 function testVideoToImageBitmap(videoElementName, success, error)
phoglund_chromium 2016/11/02 14:52:05 I'd move this function, and the next, to the .html
aleksandar.stojiljkovic 2016/11/02 15:10:41 Thanks. Yes, it is good to do but let's not do it
36 {
37 var bitmaps = {};
38 var video = $(videoElementName);
39 var canvas = document.createElement('canvas');
40 canvas.width = 96;
41 canvas.height = 96;
42 document.body.appendChild(canvas);
43 var p1 = createImageBitmap(video).then(function(imageBitmap) {
44 return runImageBitmapTest(imageBitmap, canvas, false); });
45 var p2 = createImageBitmap(video,
46 {imageOrientation: "none", premultiplyAlpha: "premultiply"}).then(
47 function(imageBitmap) {
48 return runImageBitmapTest(imageBitmap, canvas, false); });
49 var p3 = createImageBitmap(video,
50 {imageOrientation: "none", premultiplyAlpha: "default"}).then(
51 function(imageBitmap) {
52 return runImageBitmapTest(imageBitmap, canvas, false); });
53 var p4 = createImageBitmap(video,
54 {imageOrientation: "none", premultiplyAlpha: "none"}).then(
55 function(imageBitmap) {
56 return runImageBitmapTest(imageBitmap, canvas, false); });
57 var p5 = createImageBitmap(video,
58 {imageOrientation: "flipY", premultiplyAlpha: "premultiply"}).then(
59 function(imageBitmap) {
60 return runImageBitmapTest(imageBitmap, canvas, true); });
61 var p6 = createImageBitmap(video,
62 {imageOrientation: "flipY", premultiplyAlpha: "default"}).then(
63 function(imageBitmap) {
64 return runImageBitmapTest(imageBitmap, canvas, true); });
65 var p7 = createImageBitmap(video,
66 {imageOrientation: "flipY", premultiplyAlpha: "none"}).then(
67 function(imageBitmap) {
68 return runImageBitmapTest(imageBitmap, canvas, true); });
69 return Promise.all([p1, p2, p3, p4, p5, p6, p7]).then(success(), reason => {
70 return error({name: reason});
71 });
72 }
73
74 function runImageBitmapTest(bitmap, canvas, flipped) {
75 var context = canvas.getContext('2d');
76 context.drawImage(bitmap,0,0);
77 var imageData = context.getImageData(0, 0, canvas.width, canvas.height);
78 // Fake capture device 96x96 depth image is gradient. See also
79 // Draw16BitGradient in fake_video_capture_device.cc.
80 var color_step = 255.0 / (canvas.width + canvas.height);
81 var rowsColumnsToCheck = [[1, 1],
82 [0, canvas.width - 1],
83 [canvas.height - 1, 0],
84 [canvas.height - 1, canvas.width - 1],
85 [canvas.height - 3, canvas.width - 4]];
86
87 // Same value is expected for all color components.
88 if (imageData.data[0] != imageData.data[1] ||
89 imageData.data[0] != imageData.data[2])
90 return Promise.reject("Values " + imageData.data[0] + ", " +
91 imageData.data[1] + ", " + imageData.data[2] + " differ at top left");
92
93 // Calculate all reference points based on top left and compare.
94 for (var j = 0; j < rowsColumnsToCheck.length; ++j) {
95 var row = rowsColumnsToCheck[j][0];
96 var column = rowsColumnsToCheck[j][1];
97 var i = (canvas.width * row + column) * 4;
98 if (imageData.data[i] != imageData.data[i + 1] ||
99 imageData.data[i] != imageData.data[i + 2])
100 return Promise.reject("Values " + imageData.data[i] + ", " +
101 imageData.data[i + 1] + ", " + imageData.data[i + 2] +
102 " differ at index " + i);
103 var calculated = (imageData.data[0] +
104 color_step * ((flipped ? -row : row) + column)) % 255;
105 if (Math.abs(calculated - imageData.data[i]) > 2)
106 return Promise.reject("Reference value " + imageData.data[i] +
107 " differs from calculated: " + calculated + " at index " + i +
108 ". TopLeft value:" + imageData.data[0]);
109 }
110 return true;
111 }
OLDNEW
« no previous file with comments | « content/test/BUILD.gn ('k') | content/test/data/media/getusermedia-depth-capture.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698