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

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

Issue 2121043002: 16 bpp video stream capture, render and WebGL usage - Realsense R200 & SR300 support. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 2 months 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/renderer/media/video_capture_impl.cc ('k') | content/test/data/media/getusermedia.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)
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) { return runImage BitmapTest(imageBitmap, canvas, false); });
44 var p2 = createImageBitmap(video, {imageOrientation: "none", premultiplyAlpha: "premultiply"}).then(function(imageBitmap) { return runImageBitmapTest(imageBit map, canvas, false); });
45 var p3 = createImageBitmap(video, {imageOrientation: "none", premultiplyAlpha: "default"}).then(function(imageBitmap) { return runImageBitmapTest(imageBitmap, canvas, false); });
46 var p4 = createImageBitmap(video, {imageOrientation: "none", premultiplyAlpha: "none"}).then(function(imageBitmap) { return runImageBitmapTest(imageBitmap, ca nvas, false); });
47 var p5 = createImageBitmap(video, {imageOrientation: "flipY", premultiplyAlpha : "premultiply"}).then(function(imageBitmap) { return runImageBitmapTest(imageBi tmap, canvas, true); });
48 var p6 = createImageBitmap(video, {imageOrientation: "flipY", premultiplyAlpha : "default"}).then(function(imageBitmap) { return runImageBitmapTest(imageBitmap , canvas, true); });
49 var p7 = createImageBitmap(video, {imageOrientation: "flipY", premultiplyAlpha : "none"}).then(function(imageBitmap) { return runImageBitmapTest(imageBitmap, c anvas, true); });
50 return Promise.all([p1, p2, p3, p4, p5, p6, p7]).then(success(), reason => {
51 return error({name: reason});
52 });
53 }
54
55 function runImageBitmapTest(bitmap, canvas, flipped) {
56 var context = canvas.getContext('2d');
57 context.drawImage(bitmap,0,0);
58 var imageData = context.getImageData(0, 0, canvas.width, canvas.height);
59 // Fake capture device 96x96 depth image is gradient. See also
60 // Draw16BitGradient in fake_video_capture_device.cc.
61 var color_step = 255.0 / (canvas.width + canvas.height);
62 var rowsColumnsToCheck = [[1, 1],
63 [0, canvas.width - 1],
64 [canvas.height - 1, 0],
65 [canvas.height - 1, canvas.width - 1],
66 [canvas.height / 2, canvas.width / 3]];
67
68 // Same value is expected for all color components.
69 if (imageData.data[0] != imageData.data[1] || imageData.data[0] != imageData.d ata[2])
70 return Promise.reject("Values " + imageData.data[0] + ", " + imageData.data[ 1] + ", " + imageData.data[2] + " differ at top left");
71
72 // Calculate all reference points based on top left and compare with real valu es.
73 for (var j = 0; j < rowsColumnsToCheck.length; ++j) {
74 var row = rowsColumnsToCheck[j][0];
75 var column = rowsColumnsToCheck[j][1];
76 var i = (canvas.width * row + column) * 4;
77 if (imageData.data[i] != imageData.data[i + 1] || imageData.data[i] != image Data.data[i + 2])
78 return Promise.reject("Values " + imageData.data[i] + ", " + imageData.dat a[i + 1] + ", " + imageData.data[i + 2] + " differ at index " + i);
79 var calculated = (imageData.data[0] + color_step * ((flipped ? -row : row) + column)) % 255;
80 if (Math.abs(calculated - imageData.data[i]) > 2)
81 return Promise.reject("Reference value " + imageData.data[i] + " differs f rom calculated: " + calculated + " at index " + i + ". TopLeft value:" + imageDa ta.data[0]);
82 }
83 return true;
84 }
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl.cc ('k') | content/test/data/media/getusermedia.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698