Mozilla Home
Privacy
Cookies
Legal
Bugzilla
Browse
Advanced Search
New Bug
Reports
Documentation
Log In
Log In with GitHub
or
Remember me
Browse
Advanced Search
New Bug
Reports
Documentation
Attachment 523801 Details for
Bug 630040
[patch]
Patch for checkin.
630040-cID-ID-Yury-C-N (text/plain), 13.46 KB, created by
:Ms2ger (he/him; ⌚ UTC+1/+2)
(
hide
)
Description:
Patch for checkin.
Filename:
MIME Type:
Creator:
:Ms2ger (he/him; ⌚ UTC+1/+2)
Size:
13.46 KB
patch
obsolete
># HG changeset patch ># User Yury <async.processingjs@yahoo.com> ># Date 1301769926 -7200 ># Node ID 8d1074794d6c18b32d46cd6e4f61f1c0fc85b45f ># Parent b25eda4835bc587af8032f9edefe802f02cfe6f8 >Bug 630040 - Implement createImageData(ImageData); r=bz > >diff --git a/content/canvas/src/CustomQS_Canvas2D.h b/content/canvas/src/CustomQS_Canvas2D.h >--- a/content/canvas/src/CustomQS_Canvas2D.h >+++ b/content/canvas/src/CustomQS_Canvas2D.h >@@ -18,16 +18,17 @@ > * The Initial Developer of the Original Code is > * the Mozilla Foundation. > * Portions created by the Initial Developer are Copyright (C) 2010 > * the Initial Developer. All Rights Reserved. > * > * Contributor(s): > * Vladimir Vukicevic <vladimir@pobox.com> (original author) > * Ms2ger <ms2ger@gmail.com> >+ * Yury <async.processingjs@yahoo.com> > * > * Alternatively, the contents of this file may be used under the terms of > * either of the GNU General Public License Version 2 or later (the "GPL"), > * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), > * in which case the provisions of the GPL or the LGPL are applicable instead > * of those above. If you wish to allow use of your version of this file only > * under the terms of either the GPL or the LGPL, and not to allow others to > * use your version of this file under the terms of the MPL, indicate your >@@ -214,28 +215,69 @@ CreateImageData(JSContext* cx, > JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) { > return false; > } > > *vp = OBJECT_TO_JSVAL(result); > return true; > } > >+static bool >+GetImageDataDimensions(JSContext *cx, JSObject *dataObject, uint32 *width, uint32 *height) >+{ >+ jsval temp; >+ int32 wi, hi; >+ >+ // Need to check that dataObject is ImageData object. That's hard for the moment >+ // because they're just vanilla objects in our implementation. >+ // Let's guess, if the object has valid width and height then it's suitable >+ // for this operation. >+ if (!JS_GetProperty(cx, dataObject, "width", &temp) || >+ !JS_ValueToECMAInt32(cx, temp, &wi)) >+ return false; >+ >+ if (!JS_GetProperty(cx, dataObject, "height", &temp) || >+ !JS_ValueToECMAInt32(cx, temp, &hi)) >+ return false; >+ >+ if (wi <= 0 || hi <= 0) >+ return xpc_qsThrow(cx, NS_ERROR_DOM_INDEX_SIZE_ERR); >+ >+ *width = (uint32)wi; >+ *height = (uint32)hi; >+ return true; >+} >+ > static JSBool > nsIDOMCanvasRenderingContext2D_CreateImageData(JSContext *cx, uintN argc, jsval *vp) > { > XPC_QS_ASSERT_CONTEXT_OK(cx); > > /* Note: this doesn't need JS_THIS_OBJECT */ > >- if (argc < 2) >+ if (argc < 1) > return xpc_qsThrow(cx, NS_ERROR_XPC_NOT_ENOUGH_ARGS); > > jsval *argv = JS_ARGV(cx, vp); > >+ if (argc == 1) { >+ // The specification asks to throw NOT_SUPPORTED if first argument is NULL, >+ // An object is expected, so throw an exception for all primitives. >+ if (JSVAL_IS_PRIMITIVE(argv[0])) >+ return xpc_qsThrow(cx, NS_ERROR_DOM_NOT_SUPPORTED_ERR); >+ >+ JSObject *dataObject = JSVAL_TO_OBJECT(argv[0]); >+ >+ uint32 data_width, data_height; >+ if (!GetImageDataDimensions(cx, dataObject, &data_width, &data_height)) >+ return false; >+ >+ return CreateImageData(cx, data_width, data_height, NULL, 0, 0, vp); >+ } >+ > jsdouble width, height; > if (!JS_ValueToNumber(cx, argv[0], &width) || > !JS_ValueToNumber(cx, argv[1], &height)) > return false; > > if (!NS_finite(width) || !NS_finite(height)) > return xpc_qsThrow(cx, NS_ERROR_DOM_NOT_SUPPORTED_ERR); > >@@ -333,36 +375,25 @@ nsIDOMCanvasRenderingContext2D_PutImageD > return xpc_qsThrow(cx, NS_ERROR_DOM_TYPE_MISMATCH_ERR); > > JSObject *dataObject = JSVAL_TO_OBJECT(argv[0]); > int32 x, y; > if (!JS_ValueToECMAInt32(cx, argv[1], &x) || > !JS_ValueToECMAInt32(cx, argv[2], &y)) > return JS_FALSE; > >- int32 wi, hi; >+ uint32 w, h; > JSObject *darray; > > // grab width, height, and the dense array from the dataObject > js::AutoValueRooter tv(cx); > >- if (!JS_GetProperty(cx, dataObject, "width", tv.jsval_addr()) || >- !JS_ValueToECMAInt32(cx, tv.jsval_value(), &wi)) >+ if (!GetImageDataDimensions(cx, dataObject, &w, &h)) > return JS_FALSE; > >- if (!JS_GetProperty(cx, dataObject, "height", tv.jsval_addr()) || >- !JS_ValueToECMAInt32(cx, tv.jsval_value(), &hi)) >- return JS_FALSE; >- >- if (wi <= 0 || hi <= 0) >- return xpc_qsThrow(cx, NS_ERROR_DOM_INDEX_SIZE_ERR); >- >- uint32 w = (uint32) wi; >- uint32 h = (uint32) hi; >- > // the optional dirty rect > PRBool hasDirtyRect = PR_FALSE; > int32 dirtyX = 0, > dirtyY = 0, > dirtyWidth = w, > dirtyHeight = h; > > if (argc >= 7) { >diff --git a/content/canvas/test/test_canvas.html b/content/canvas/test/test_canvas.html >--- a/content/canvas/test/test_canvas.html >+++ b/content/canvas/test/test_canvas.html >@@ -7225,16 +7225,34 @@ var canvas = document.getElementById('c2 > var ctx = canvas.getContext('2d'); > > ok(ctx.createImageData(1, 1) !== null, "ctx.createImageData(1, 1) !== null"); > > > } > </script> > >+<!-- [[[ test_2d.imageData.create1.basic.html ]]] --> >+ >+<p>Canvas test: 2d.imageData.create1.basic - bug 630040</p> >+<!-- Testing: createImageData(imgdata) exists and returns something --> >+<canvas id="c254a" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> >+<script> >+ >+function test_2d_imageData_create1_basic() { >+ >+var canvas = document.getElementById('c254a'); >+var ctx = canvas.getContext('2d'); >+ >+ok(ctx.createImageData(ctx.createImageData(1, 1)) != null, "ctx.createImageData(ctx.createImageData(1, 1)) != null"); >+ >+ >+} >+</script> >+ > <!-- [[[ test_2d.imageData.create.initial.html ]]] --> > > <p>Canvas test: 2d.imageData.create.initial - bug 433004</p> > <!-- Testing: createImageData() returns transparent black data of the right size --> > <canvas id="c255" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> > <script> > > function test_2d_imageData_create_initial() { >@@ -7251,16 +7269,45 @@ for (var i = 0; i < imgdata.data.length; > if (imgdata.data[i] !== 0) > isTransparentBlack = false; > ok(isTransparentBlack, "isTransparentBlack"); > > > } > </script> > >+<!-- [[[ test_2d.imageData.create1.initial.html ]]] --> >+ >+<p>Canvas test: 2d.imageData.create1.initial - bug 630040</p> >+<!-- Testing: createImageData(imgdata) returns transparent black data of the right size --> >+<canvas id="c255a" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> >+<script> >+ >+function test_2d_imageData_create1_initial() { >+ >+var canvas = document.getElementById('c255a'); >+var ctx = canvas.getContext('2d'); >+ >+ctx.fillStyle = '#0f0'; >+ctx.fillRect(0, 0, 100, 50); >+var imgdata1 = ctx.getImageData(0, 0, 10, 20); >+var imgdata2 = ctx.createImageData(imgdata1); >+ok(imgdata2.data.length == imgdata1.data.length, "imgdata2.data.length == imgdata1.data.length"); >+ok(imgdata2.width == imgdata1.width, "imgdata2.width == imgdata1.width"); >+ok(imgdata2.height == imgdata1.height, "imgdata2.height == imgdata1.height"); >+var isTransparentBlack = true; >+for (var i = 0; i < imgdata2.data.length; ++i) >+ if (imgdata2.data[i] !== 0) >+ isTransparentBlack = false; >+ok(isTransparentBlack, "isTransparentBlack"); >+ >+ >+} >+</script> >+ > <!-- [[[ test_2d.imageData.create.large.html ]]] --> > > <p>Canvas test: 2d.imageData.create.large - bug 433004</p> > <!-- Testing: createImageData() works for sizes much larger than the canvas --> > <canvas id="c256" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> > <script> > > function test_2d_imageData_create_large() { >@@ -7459,16 +7506,48 @@ ok(imgdata.data.thisImplementsCanvasPixe > _thrown_outer = true; > } > todo(!_thrown_outer, 'should not throw exception'); > > > } > </script> > >+<!-- [[[ test_2d.imageData.create1.type.html ]]] --> >+ >+<p>Canvas test: 2d.imageData.create1.type - bug 630040</p> >+<!-- Testing: createImageData(imgdata) returns an ImageData object containing a CanvasPixelArray object --> >+<canvas id="c261a" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> >+<script> >+ >+function test_2d_imageData_create1_type() { >+ >+var canvas = document.getElementById('c261a'); >+var ctx = canvas.getContext('2d'); >+ >+var _thrown_outer = false; >+try { >+ >+todo(window.ImageData !== undefined, "window.ImageData !== undefined"); >+todo(window.CanvasPixelArray !== undefined, "window.CanvasPixelArray !== undefined"); >+window.ImageData.prototype.thisImplementsImageData = true; >+window.CanvasPixelArray.prototype.thisImplementsCanvasPixelArray = true; >+var imgdata = ctx.createImageData(ctx.createImageData(1, 1)); >+todo(imgdata.thisImplementsImageData, "imgdata.thisImplementsImageData"); >+todo(imgdata.data.thisImplementsCanvasPixelArray, "imgdata.data.thisImplementsCanvasPixelArray"); >+ >+} catch (e) { >+ _thrown_outer = true; >+} >+todo(!_thrown_outer, 'should not throw exception'); >+ >+ >+} >+</script> >+ > <!-- [[[ test_2d.imageData.create.zero.html ]]] --> > > <p>Canvas test: 2d.imageData.create.zero - bug 433004</p> > <!-- Testing: createImageData() throws INDEX_SIZE_ERR if size is zero --> > <canvas id="c262" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> > <script> > > function test_2d_imageData_create_zero() { >@@ -7485,16 +7564,36 @@ var _thrown = undefined; try { > var _thrown = undefined; try { > ctx.createImageData(0, 0); > } catch (e) { _thrown = e }; ok(_thrown && _thrown.code == DOMException.INDEX_SIZE_ERR, "should throw INDEX_SIZE_ERR"); > > > } > </script> > >+<!-- [[[ test_2d.imageData.create1.zero.html ]]] --> >+ >+<p>Canvas test: 2d.imageData.create1.zero - bug 630040</p> >+<!-- Testing: createImageData(null) throws NOT_SUPPORTED_ERR --> >+<canvas id="c262a" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> >+<script> >+ >+function test_2d_imageData_create1_zero() { >+ >+var canvas = document.getElementById('c262a'); >+var ctx = canvas.getContext('2d'); >+ >+var _thrown = undefined; try { >+ ctx.createImageData(null); >+} catch (e) { _thrown = e }; ok(_thrown && _thrown.code == DOMException.NOT_SUPPORTED_ERR, "should throw NOT_SUPPORTED_ERR"); >+ >+ >+} >+</script> >+ > <!-- [[[ test_2d.imageData.get.basic.html ]]] --> > > <p>Canvas test: 2d.imageData.get.basic</p> > <!-- Testing: getImageData() exists and returns something --> > <canvas id="c263" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> > <script> > > function test_2d_imageData_get_basic() { >@@ -10547,17 +10646,17 @@ var _thrown = undefined; try { > // or too few for another overload, or too many for another > // overload - what should happen? > if (ctx.createImageData) { > var _thrown = undefined; try { > ctx.createImageData(); > } catch (e) { _thrown = e }; todo(_thrown && _thrown.code == DOMException.NOT_SUPPORTED_ERR, "should throw NOT_SUPPORTED_ERR"); > var _thrown = undefined; try { > ctx.createImageData(1); >-} catch (e) { _thrown = e }; todo(_thrown && _thrown.code == DOMException.NOT_SUPPORTED_ERR, "should throw NOT_SUPPORTED_ERR"); >+} catch (e) { _thrown = e }; ok(_thrown && _thrown.code == DOMException.NOT_SUPPORTED_ERR, "should throw NOT_SUPPORTED_ERR"); > } > if (ctx.getImageData) { > var _thrown = undefined; try { > ctx.getImageData(); > } catch (e) { _thrown = e }; todo(_thrown && _thrown.code == DOMException.NOT_SUPPORTED_ERR, "should throw NOT_SUPPORTED_ERR"); > var _thrown = undefined; try { > ctx.getImageData(0); > } catch (e) { _thrown = e }; todo(_thrown && _thrown.code == DOMException.NOT_SUPPORTED_ERR, "should throw NOT_SUPPORTED_ERR"); >@@ -22232,21 +22331,31 @@ function runTests() { > ok(false, "unexpected exception thrown in: test_2d_gradient_radial_transform_3"); > } > try { > test_2d_imageData_create_basic(); > } catch (e) { > ok(false, "unexpected exception thrown in: test_2d_imageData_create_basic"); > } > try { >+ test_2d_imageData_create1_basic(); >+ } catch (e) { >+ ok(false, "unexpected exception thrown in: test_2d_imageData_create1_basic"); >+ } >+ try { > test_2d_imageData_create_initial(); > } catch (e) { > ok(false, "unexpected exception thrown in: test_2d_imageData_create_initial"); > } > try { >+ test_2d_imageData_create1_initial(); >+ } catch (e) { >+ ok(false, "unexpected exception thrown in: test_2d_imageData_create1_initial"); >+ } >+ try { > test_2d_imageData_create_large(); > } catch (e) { > ok(false, "unexpected exception thrown in: test_2d_imageData_create_large"); > } > try { > test_2d_imageData_create_negative(); > } catch (e) { > ok(false, "unexpected exception thrown in: test_2d_imageData_create_negative"); >@@ -22267,21 +22376,31 @@ function runTests() { > ok(false, "unexpected exception thrown in: test_2d_imageData_create_tiny"); > } > try { > test_2d_imageData_create_type(); > } catch (e) { > ok(false, "unexpected exception thrown in: test_2d_imageData_create_type"); > } > try { >+ test_2d_imageData_create1_type(); >+ } catch (e) { >+ ok(false, "unexpected exception thrown in: test_2d_imageData_create1_type"); >+ } >+ try { > test_2d_imageData_create_zero(); > } catch (e) { > ok(false, "unexpected exception thrown in: test_2d_imageData_create_zero"); > } > try { >+ test_2d_imageData_create1_zero(); >+ } catch (e) { >+ ok(false, "unexpected exception thrown in: test_2d_imageData_create1_zero"); >+ } >+ try { > test_2d_imageData_get_basic(); > } catch (e) { > ok(false, "unexpected exception thrown in: test_2d_imageData_get_basic"); > } > try { > test_2d_imageData_get_clamp(); > } catch (e) { > ok(false, "unexpected exception thrown in: test_2d_imageData_get_clamp");
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Actions:
View
|
Diff
|
Review
Attachments on
bug 630040
:
516499
|
516730
|
517063
|
520161
| 523801