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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-video-resize.html

Issue 2192103002: Implement resize option for createImageBitmap(HTMLVideoElement) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make ratio local var Created 4 years, 4 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 | « no previous file | third_party/WebKit/Source/core/frame/ImageBitmap.cpp » ('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 <!DOCTYPE HTML>
2 <script src="../../resources/testharness.js"></script>
3 <script src="../../resources/testharnessreport.js"></script>
4 <script>
5 function checkNoCrop(imageBitmap)
6 {
7 var canvas = document.createElement("canvas");
8 canvas.width = 50;
9 canvas.height = 50;
10 var ctx = canvas.getContext("2d");
11 ctx.clearRect(0, 0, canvas.width, canvas.height);
12 ctx.drawImage(imageBitmap, 0, 0);
13 var d = ctx.getImageData(0, 0, 1, 1).data;
14 assert_equals(d[3], 255, "This pixel should be opaque");
15 d = ctx.getImageData(29, 0, 1, 1).data;
16 assert_equals(d[3], 255, "This pixel should be opaque");
17 d = ctx.getImageData(0, 29, 1, 1).data;
18 assert_equals(d[3], 255, "This pixel should be opaque");
19 d = ctx.getImageData(29, 29, 1, 1).data;
20 assert_equals(d[3], 255, "This pixel should be opaque");
21 d = ctx.getImageData(41, 0, 1, 1).data;
22 assert_equals(d[3], 0, "This pixel should be transparent");
23 d = ctx.getImageData(0, 31, 1, 1).data;
24 assert_equals(d[3], 0, "This pixel should be transparent");
25 d = ctx.getImageData(41, 31, 1, 1).data;
26 assert_equals(d[3], 0, "This pixel should be transparent");
27 }
28
29 function checkCrop(imageBitmap)
30 {
31 var canvas = document.createElement("canvas");
32 canvas.width = 50;
33 canvas.height = 50;
34 var ctx = canvas.getContext("2d");
35 ctx.clearRect(0, 0, canvas.width, canvas.height);
36 ctx.drawImage(imageBitmap, 0, 0);
37 var d = ctx.getImageData(0, 0, 1, 1).data;
38 assert_equals(d[3], 255, "This pixel should be opaque");
39 d = ctx.getImageData(39, 0, 1, 1).data;
40 assert_equals(d[3], 255, "This pixel should be opaque");
41 d = ctx.getImageData(0, 39, 1, 1).data;
42 assert_equals(d[3], 255, "This pixel should be opaque");
43 d = ctx.getImageData(39, 39, 1, 1).data;
44 assert_equals(d[3], 255, "This pixel should be opaque");
45 d = ctx.getImageData(41, 0, 1, 1).data;
46 assert_equals(d[3], 0, "This pixel should be transparent");
47 d = ctx.getImageData(0, 41, 1, 1).data;
48 assert_equals(d[3], 0, "This pixel should be transparent");
49 d = ctx.getImageData(41, 41, 1, 1).data;
50 assert_equals(d[3], 0, "This pixel should be transparent");
51 }
52
53 function compareBitmaps(bitmap1, bitmap2)
54 {
55 var canvas1 = document.createElement("canvas");
56 var canvas2 = document.createElement("canvas");
57 canvas1.width = 50;
58 canvas1.height = 50;
59 canvas2.width = 50;
60 canvas2.height = 50;
61 var ctx1 = canvas1.getContext("2d");
62 var ctx2 = canvas2.getContext("2d");
63 ctx1.clearRect(0, 0, canvas1.width, canvas1.height);
64 ctx2.clearRect(0, 0, canvas2.width, canvas2.height);
65 ctx1.drawImage(bitmap1, 0, 0);
66 ctx2.drawImage(bitmap2, 0, 0);
67 var data1 = ctx1.getImageData(0, 0, 50, 50).data;
68 var data2 = ctx2.getImageData(0, 0, 50, 50).data;
69 var dataMatched = true;
70 for (var i = 0; i < data1.length; i++) {
71 if (data1[i] != data2[i]) {
72 dataMatched = false;
73 break;
74 }
75 }
76 assert_false(dataMatched);
77 }
78
79 function testImageBitmap(source)
80 {
81 return Promise.all([
82 createImageBitmap(source, {resizeWidth: 40, resizeHeight: 30, resizeQual ity: "high"}),
83 createImageBitmap(source, {resizeWidth: 40, resizeHeight: 30, resizeQual ity: "medium"}),
84 createImageBitmap(source, {resizeWidth: 40, resizeHeight: 30, resizeQual ity: "low"}),
85 createImageBitmap(source, {resizeWidth: 40, resizeHeight: 30, resizeQual ity: "pixelated"}),
86 createImageBitmap(source, 50, 50, 100, 100, {resizeWidth: 40, resizeHeig ht: 40, resizeQuality: "high"}),
87 createImageBitmap(source, 50, 50, 100, 100, {resizeWidth: 40, resizeHeig ht: 40, resizeQuality: "medium"}),
88 createImageBitmap(source, 50, 50, 100, 100, {resizeWidth: 40, resizeHeig ht: 40, resizeQuality: "low"}),
89 createImageBitmap(source, 50, 50, 100, 100, {resizeWidth: 40, resizeHeig ht: 40, resizeQuality: "pixelated"}),
90 ]).then(([noCropHigh, noCropMedium, noCropLow, noCropPixelated, cropHigh, cr opMedium, cropLow, cropPixelated]) => {
91 checkNoCrop(noCropHigh);
92 checkNoCrop(noCropMedium);
93 checkNoCrop(noCropLow);
94 checkNoCrop(noCropPixelated);
95 checkCrop(cropHigh);
96 checkCrop(cropMedium);
97 checkCrop(cropLow);
98 checkCrop(cropPixelated);
99 // Brute-force comparison among all bitmaps is too expensive
100 compareBitmaps(noCropHigh, noCropMedium);
101 compareBitmaps(noCropLow, noCropPixelated);
102 compareBitmaps(cropHigh, cropMedium);
103 compareBitmaps(cropLow, cropPixelated);
104 });
105 }
106
107 // HTMLVideoElement
108 promise_test(function() {
109 var video = document.createElement("video");
110 video.oncanplaythrough = function() {
111 return testImageBitmap(video);
112 };
113 video.src = "../../compositing/resources/video.ogv";
114 }, 'createImageBitmap from a HTMLVideoElement with resize option.');
115 </script>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/frame/ImageBitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698