Bug 1141979 - part17 - mochitest - draw special color formats onto canvas; r=jrmuizel
authorKaku Kuo <tkuo@mozilla.com>
Mon, 25 Apr 2016 22:30:11 +0800
changeset 339155 2e661c7c4e071752c56dc6b6f410a4b3ae347e15
parent 339154 e4a8bb1e52cda4b038d55c5871cde7639fdb53db
child 339156 df4c70f4b9f6a5403afc565f65262ac20e2d7086
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1141979
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1141979 - part17 - mochitest - draw special color formats onto canvas; r=jrmuizel MozReview-Commit-ID: 8BYDS2tqlDc
dom/canvas/test/imagebitmap_extensions.html
dom/canvas/test/imagebitmap_extensions.js
--- a/dom/canvas/test/imagebitmap_extensions.html
+++ b/dom/canvas/test/imagebitmap_extensions.html
@@ -15,18 +15,16 @@ runTests();
 
 function ok(expect, msg) {
   window.parent.postMessage({"type": "status", status: !!expect, msg: msg}, "*");
 }
 
 function runTests() {
 
   prepareSources().
-    then(testExceptions).
-    then(testColorConversions()).
     then( function() { return Promise.all([testAccessing_randomTest("Video", gVideo, 20), // video might use slightly different frames
                                            testAccessing_randomTest("Image", gImage, 0),
                                            testAccessing_randomTest("Canvas", gCanvas, 0),
                                            testAccessing_randomTest("Ctx", gCtx, 0),
                                            testAccessing_randomTest("ImageData", gImageData, 0),
                                            testAccessing_randomTest("ImageBitmap", gImageBitmap, 0),
                                            testAccessing_randomTest("PNG", gPNGBlob, 0),
                                            testAccessing_randomTest("JPEG", gJPEGBlob, 10) // JPEG loses information
@@ -35,13 +33,16 @@ function runTests() {
                                            testCreateFromArrayBffer_randomTest("Image", gImage, 0),
                                            testCreateFromArrayBffer_randomTest("Canvas", gCanvas, 0),
                                            testCreateFromArrayBffer_randomTest("Ctx", gCtx, 0),
                                            testCreateFromArrayBffer_randomTest("ImageData", gImageData, 0),
                                            testCreateFromArrayBffer_randomTest("ImageBitmap", gImageBitmap, 0),
                                            testCreateFromArrayBffer_randomTest("PNG", gPNGBlob, 0),
                                            testCreateFromArrayBffer_randomTest("JPEG", gJPEGBlob, 10) // JPEG loses information
                                           ]); }).
+    then(testDraw()).
+    then(testExceptions).
+    then(testColorConversions()).
     then(function() {window.parent.postMessage({"type": "finish"}, "*");}, function(ev) { failed(ev); window.parent.postMessage({"type": "finish"}, "*"); });
 }
 
 </script>
 </body>
--- a/dom/canvas/test/imagebitmap_extensions.js
+++ b/dom/canvas/test/imagebitmap_extensions.js
@@ -246,16 +246,28 @@ function testColorConversions() {
                       // From GRAY8
                       testColorConversion("GRAY8", "GRAY8"),
 
                       // From DEPTH
                       testColorConversion("DEPTH", "DEPTH", 0, Uint16Array),
                      ]);
 }
 
+function testDraw() {
+  return Promise.all([doOneDrawTest("RGB24"),
+                      doOneDrawTest("BGR24"),
+                      doOneDrawTest("YUV444P", 5),
+                      doOneDrawTest("YUV422P", 2),
+                      doOneDrawTest("YUV420P", 2),
+                      doOneDrawTest("YUV420SP_NV12", 2),
+                      doOneDrawTest("YUV420SP_NV21", 2),
+                      doOneDrawTest("HSV", 2),
+                      doOneDrawTest("Lab", 2)]);
+}
+
 // Create an ImageBitmap, _bitmap_, from the _source_.
 // Read the underlying data of _bitmap_ into _bitmapBuffer_.
 // Compare the _bitmapBuffer_ with gGroundTruthImageData.
 function testAccessing_randomTest(sourceType, source, duration) {
   return new Promise(function(resolve, reject) {
     var p  = createImageBitmap(source);
     p.then(
       function(bitmap) {
@@ -414,8 +426,75 @@ function testColorConversion(sourceFroma
         );
       },
       function(ev) {
         reject(ev);
       }
     );
   });
 }
+
+function doOneDrawTest(sourceFromat, tolerance) {
+  tolerance = tolerance || 0;
+  var destinationFormat = "RGBA32";
+
+  return new Promise(function(resolve, reject) {
+
+    var [srcData, dstData] = getTestData(sourceFromat, destinationFormat);
+    ok(!!srcData, "Get valid srcData of type:" + sourceFromat);
+    ok(!!dstData, "Get valid dstData of type:" + destinationFormat);
+
+    var p = createImageBitmap(srcData.buffer,
+                              0,
+                              srcData.bufferLength,
+                              srcData.format,
+                              srcData.pixelLayout);
+
+    p.then(
+      function(srcBitmap) {
+        ok(!!srcBitmap, "Should get a valid srcBitmap.");
+        ok(srcBitmap.findOptimalFormat() == sourceFromat, "srcBitmap.findOptimalFormat():" + srcBitmap.findOptimalFormat() +
+                                                          " should equal to sourceFromat:" + sourceFromat);
+
+        var canvas = document.createElement("canvas");
+        canvas.width = srcBitmap.width;
+        canvas.height = srcBitmap.height;
+        var ctx = canvas.getContext("2d");
+
+        ctx.drawImage(srcBitmap, 0, 0, srcBitmap.width, srcBitmap.height);
+
+        // Get an ImageData from the canvas.
+        var imageData = ctx.getImageData(0, 0, srcBitmap.width, srcBitmap.height);
+
+        for (var i = 0; i < srcBitmap.height; ++i) {
+          for (var j = 0; j < srcBitmap.width; ++j) {
+            var pixelOffset = i * srcBitmap.width * dstData.channelCount + j * dstData.channelCount;
+            var dstImageDataValue_R = imageData.data[pixelOffset + 0];
+            var dstImageDataValue_G = imageData.data[pixelOffset + 1];
+            var dstImageDataValue_B = imageData.data[pixelOffset + 2];
+            var dstImageDataValue_A = imageData.data[pixelOffset + 3];
+
+            var logPrefix = "[" + sourceFromat + " -> " + destinationFormat + "] pixel(" + i + "," + j + ")";
+
+            var dstDataValue_R = dstData.getPixelValue(i, j, 0);
+            var dstDataValue_G = dstData.getPixelValue(i, j, 1);
+            var dstDataValue_B = dstData.getPixelValue(i, j, 2);
+            var dstDataValue_A = dstData.getPixelValue(i, j, 3);
+            ok(Math.abs(dstImageDataValue_R - dstDataValue_R) <= tolerance,
+               logPrefix + "channnel(R): dstImageDataValue:" + dstImageDataValue_R + " should equal to dstDataValue_R: " + dstDataValue_R);
+            ok(Math.abs(dstImageDataValue_G - dstDataValue_G) <= tolerance,
+               logPrefix + "channnel(G): dstImageDataValue:" + dstImageDataValue_G + " should equal to dstDataValue_G: " + dstDataValue_G);
+            ok(Math.abs(dstImageDataValue_B - dstDataValue_B) <= tolerance,
+               logPrefix + "channnel(B): dstImageDataValue:" + dstImageDataValue_B + " should equal to dstDataValue_B: " + dstDataValue_B);
+            ok(Math.abs(dstImageDataValue_A - dstDataValue_A) <= tolerance,
+               logPrefix + "channnel(A): dstImageDataValue:" + dstImageDataValue_A + " should equal to dstDataValue_A: " + dstDataValue_A);
+          }
+        }
+
+        resolve();
+      },
+      function(ev) {
+        failed(ev);
+        reject(ev);
+      }
+    );
+  });
+}
\ No newline at end of file