Bug 629894 - createImageData and getImageData should work for sizes smaller than one pixel; r=bz
authorMs2ger <ms2ger@gmail.com>
Sat, 02 Apr 2011 20:42:07 +0200
changeset 64667 c47b3a690698354fd558e5c3a75dd4e2df1fc1bf
parent 64666 7c9c29d52829b088aecc405125fc0de7cff18c83
child 64668 b6af6b28b7294e1be7855f004b62467857662209
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs629894
milestone2.2a1pre
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 629894 - createImageData and getImageData should work for sizes smaller than one pixel; r=bz
content/canvas/src/CustomQS_Canvas2D.h
content/canvas/test/test_canvas.html
--- a/content/canvas/src/CustomQS_Canvas2D.h
+++ b/content/canvas/src/CustomQS_Canvas2D.h
@@ -162,16 +162,22 @@ CreateImageData(JSContext* cx,
                 uint32 w,
                 uint32 h,
                 nsIDOMCanvasRenderingContext2D* self,
                 int32 x,
                 int32 y,
                 jsval* vp)
 {
     using mozilla::CheckedInt;
+
+    if (w == 0)
+        w = 1;
+    if (h == 0)
+        h = 1;
+
     CheckedInt<uint32> len = CheckedInt<uint32>(w) * h * 4;
     if (!len.valid()) {
         return xpc_qsThrow(cx, NS_ERROR_DOM_INDEX_SIZE_ERR);
     }
 
     // Create the fast typed array; it's initialized to 0 by default.
     JSObject* darray =
       js_CreateTypedArray(cx, js::TypedArray::TYPE_UINT8_CLAMPED, len.value());
--- a/content/canvas/test/test_canvas.html
+++ b/content/canvas/test/test_canvas.html
@@ -7457,18 +7457,18 @@ function test_2d_imageData_create_tiny()
 var canvas = document.getElementById('c260');
 var ctx = canvas.getContext('2d');
 
 var _thrown_outer = false;
 try {
 
 var imgdata = ctx.createImageData(0.0001, 0.0001);
 ok(imgdata.data.length == imgdata.width*imgdata.height*4, "imgdata.data.length == imgdata.width*imgdata.height*4");
-todo(imgdata.width == 1, "imgdata.width == 1");
-todo(imgdata.height == 1, "imgdata.height == 1");
+ok(imgdata.width == 1, "imgdata.width == 1");
+ok(imgdata.height == 1, "imgdata.height == 1");
 var isTransparentBlack = true;
 for (var i = 0; i < imgdata.data.length; ++i)
     if (imgdata.data[i] !== 0)
         isTransparentBlack = false;
 ok(isTransparentBlack, "isTransparentBlack");
 
 } catch (e) {
     _thrown_outer = true;
@@ -8076,17 +8076,17 @@ try {
 var imgdata = ctx.getImageData(0, 0, 0.0001, 0.0001);
 ok(imgdata.data.length == imgdata.width*imgdata.height*4, "imgdata.data.length == imgdata.width*imgdata.height*4");
 ok(imgdata.width == 1, "imgdata.width == 1");
 ok(imgdata.height == 1, "imgdata.height == 1");
 
 } catch (e) {
     _thrown_outer = true;
 }
-todo(!_thrown_outer, 'should not throw exception');
+ok(!_thrown_outer, 'should not throw exception');
 
 
 }
 </script>
 
 <!-- [[[ test_2d.imageData.get.type.html ]]] -->
 
 <p>Canvas test: 2d.imageData.get.type</p>