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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/frame/ImageBitmap.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-video-resize.html
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-video-resize.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-video-resize.html
new file mode 100644
index 0000000000000000000000000000000000000000..a64bedf898a512d82e417cf0d5cf5ada67660168
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-video-resize.html
@@ -0,0 +1,115 @@
+<!DOCTYPE HTML>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script>
+function checkNoCrop(imageBitmap)
+{
+ var canvas = document.createElement("canvas");
+ canvas.width = 50;
+ canvas.height = 50;
+ var ctx = canvas.getContext("2d");
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+ ctx.drawImage(imageBitmap, 0, 0);
+ var d = ctx.getImageData(0, 0, 1, 1).data;
+ assert_equals(d[3], 255, "This pixel should be opaque");
+ d = ctx.getImageData(29, 0, 1, 1).data;
+ assert_equals(d[3], 255, "This pixel should be opaque");
+ d = ctx.getImageData(0, 29, 1, 1).data;
+ assert_equals(d[3], 255, "This pixel should be opaque");
+ d = ctx.getImageData(29, 29, 1, 1).data;
+ assert_equals(d[3], 255, "This pixel should be opaque");
+ d = ctx.getImageData(41, 0, 1, 1).data;
+ assert_equals(d[3], 0, "This pixel should be transparent");
+ d = ctx.getImageData(0, 31, 1, 1).data;
+ assert_equals(d[3], 0, "This pixel should be transparent");
+ d = ctx.getImageData(41, 31, 1, 1).data;
+ assert_equals(d[3], 0, "This pixel should be transparent");
+}
+
+function checkCrop(imageBitmap)
+{
+ var canvas = document.createElement("canvas");
+ canvas.width = 50;
+ canvas.height = 50;
+ var ctx = canvas.getContext("2d");
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+ ctx.drawImage(imageBitmap, 0, 0);
+ var d = ctx.getImageData(0, 0, 1, 1).data;
+ assert_equals(d[3], 255, "This pixel should be opaque");
+ d = ctx.getImageData(39, 0, 1, 1).data;
+ assert_equals(d[3], 255, "This pixel should be opaque");
+ d = ctx.getImageData(0, 39, 1, 1).data;
+ assert_equals(d[3], 255, "This pixel should be opaque");
+ d = ctx.getImageData(39, 39, 1, 1).data;
+ assert_equals(d[3], 255, "This pixel should be opaque");
+ d = ctx.getImageData(41, 0, 1, 1).data;
+ assert_equals(d[3], 0, "This pixel should be transparent");
+ d = ctx.getImageData(0, 41, 1, 1).data;
+ assert_equals(d[3], 0, "This pixel should be transparent");
+ d = ctx.getImageData(41, 41, 1, 1).data;
+ assert_equals(d[3], 0, "This pixel should be transparent");
+}
+
+function compareBitmaps(bitmap1, bitmap2)
+{
+ var canvas1 = document.createElement("canvas");
+ var canvas2 = document.createElement("canvas");
+ canvas1.width = 50;
+ canvas1.height = 50;
+ canvas2.width = 50;
+ canvas2.height = 50;
+ var ctx1 = canvas1.getContext("2d");
+ var ctx2 = canvas2.getContext("2d");
+ ctx1.clearRect(0, 0, canvas1.width, canvas1.height);
+ ctx2.clearRect(0, 0, canvas2.width, canvas2.height);
+ ctx1.drawImage(bitmap1, 0, 0);
+ ctx2.drawImage(bitmap2, 0, 0);
+ var data1 = ctx1.getImageData(0, 0, 50, 50).data;
+ var data2 = ctx2.getImageData(0, 0, 50, 50).data;
+ var dataMatched = true;
+ for (var i = 0; i < data1.length; i++) {
+ if (data1[i] != data2[i]) {
+ dataMatched = false;
+ break;
+ }
+ }
+ assert_false(dataMatched);
+}
+
+function testImageBitmap(source)
+{
+ return Promise.all([
+ createImageBitmap(source, {resizeWidth: 40, resizeHeight: 30, resizeQuality: "high"}),
+ createImageBitmap(source, {resizeWidth: 40, resizeHeight: 30, resizeQuality: "medium"}),
+ createImageBitmap(source, {resizeWidth: 40, resizeHeight: 30, resizeQuality: "low"}),
+ createImageBitmap(source, {resizeWidth: 40, resizeHeight: 30, resizeQuality: "pixelated"}),
+ createImageBitmap(source, 50, 50, 100, 100, {resizeWidth: 40, resizeHeight: 40, resizeQuality: "high"}),
+ createImageBitmap(source, 50, 50, 100, 100, {resizeWidth: 40, resizeHeight: 40, resizeQuality: "medium"}),
+ createImageBitmap(source, 50, 50, 100, 100, {resizeWidth: 40, resizeHeight: 40, resizeQuality: "low"}),
+ createImageBitmap(source, 50, 50, 100, 100, {resizeWidth: 40, resizeHeight: 40, resizeQuality: "pixelated"}),
+ ]).then(([noCropHigh, noCropMedium, noCropLow, noCropPixelated, cropHigh, cropMedium, cropLow, cropPixelated]) => {
+ checkNoCrop(noCropHigh);
+ checkNoCrop(noCropMedium);
+ checkNoCrop(noCropLow);
+ checkNoCrop(noCropPixelated);
+ checkCrop(cropHigh);
+ checkCrop(cropMedium);
+ checkCrop(cropLow);
+ checkCrop(cropPixelated);
+ // Brute-force comparison among all bitmaps is too expensive
+ compareBitmaps(noCropHigh, noCropMedium);
+ compareBitmaps(noCropLow, noCropPixelated);
+ compareBitmaps(cropHigh, cropMedium);
+ compareBitmaps(cropLow, cropPixelated);
+ });
+}
+
+// HTMLVideoElement
+promise_test(function() {
+ var video = document.createElement("video");
+ video.oncanplaythrough = function() {
+ return testImageBitmap(video);
+ };
+ video.src = "../../compositing/resources/video.ogv";
+}, 'createImageBitmap from a HTMLVideoElement with resize option.');
+</script>
« 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