From 6f470e497f51cd37ad2da726464e855a9d1c8190 Mon Sep 17 00:00:00 2001 From: n0max Date: Mon, 13 Mar 2017 19:26:12 +0100 Subject: [PATCH] Fix crop_area_byte_length calculation in crop_image and add tests --- components/canvas/canvas_paint_thread.rs | 2 +- tests/wpt/metadata/MANIFEST.json | 68 ++++++++++++++++++ .../wpt/web-platform-tests/2dcontext/2x4.png | Bin 0 -> 1745 bytes .../wpt/web-platform-tests/2dcontext/4x2.png | Bin 0 -> 1258 bytes .../drawimage_html_image_14.html | 33 +++++++++ .../drawimage_html_image_14_ref.html | 25 +++++++ .../drawimage_html_image_15.html | 33 +++++++++ .../drawimage_html_image_15_ref.html | 25 +++++++ 8 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 tests/wpt/web-platform-tests/2dcontext/2x4.png create mode 100644 tests/wpt/web-platform-tests/2dcontext/4x2.png create mode 100644 tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_14.html create mode 100644 tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_14_ref.html create mode 100644 tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_15.html create mode 100644 tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_15_ref.html diff --git a/components/canvas/canvas_paint_thread.rs b/components/canvas/canvas_paint_thread.rs index 87ebcdf5cfc..8aca22bdbfb 100644 --- a/components/canvas/canvas_paint_thread.rs +++ b/components/canvas/canvas_paint_thread.rs @@ -746,7 +746,7 @@ fn crop_image(image_data: Vec, // (consecutive elements in a pixel row of the image are contiguous in memory) let stride = image_size.width * 4; let image_bytes_length = image_size.height * image_size.width * 4; - let crop_area_bytes_length = crop_rect.size.height * crop_rect.size.height * 4; + let crop_area_bytes_length = crop_rect.size.height * crop_rect.size.width * 4; // If the image size is less or equal than the crop area we do nothing if image_bytes_length <= crop_area_bytes_length { return image_data; diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index dddb770c796..760a3f00a0b 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -6033,6 +6033,30 @@ {} ] ], + "2dcontext/drawing-images-to-the-canvas/drawimage_html_image_14.html": [ + [ + "/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_14.html", + [ + [ + "/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_14_ref.html", + "==" + ] + ], + {} + ] + ], + "2dcontext/drawing-images-to-the-canvas/drawimage_html_image_15.html": [ + [ + "/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_15.html", + [ + [ + "/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_15_ref.html", + "==" + ] + ], + {} + ] + ], "2dcontext/drawing-images-to-the-canvas/drawimage_html_image_2.html": [ [ "/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_2.html", @@ -12845,6 +12869,16 @@ {} ] ], + "2dcontext/2x4.png": [ + [ + {} + ] + ], + "2dcontext/4x2.png": [ + [ + {} + ] + ], "2dcontext/best-practices/.gitkeep": [ [ {} @@ -13295,6 +13329,16 @@ {} ] ], + "2dcontext/drawing-images-to-the-canvas/drawimage_html_image_14_ref.html": [ + [ + {} + ] + ], + "2dcontext/drawing-images-to-the-canvas/drawimage_html_image_15_ref.html": [ + [ + {} + ] + ], "2dcontext/drawing-images-to-the-canvas/drawimage_html_image_1_ref.html": [ [ {} @@ -129763,6 +129807,14 @@ "c67d3f646e86413722833d2308a9bfc793a916bf", "support" ], + "2dcontext/2x4.png": [ + "690bac789fecf2530b36dd889c68db3bd93ed9fd", + "support" + ], + "2dcontext/4x2.png": [ + "16f72935aaf97175593bcf27794506f0884f091b", + "support" + ], "2dcontext/best-practices/.gitkeep": [ "da39a3ee5e6b4b0d3255bfef95601890afd80709", "support" @@ -130735,6 +130787,22 @@ "30150e3530438d42704fda8b3623286658f6c724", "support" ], + "2dcontext/drawing-images-to-the-canvas/drawimage_html_image_14.html": [ + "fa83293cfbdbb67a9d5d27a20ac19ff5d9c46d07", + "reftest" + ], + "2dcontext/drawing-images-to-the-canvas/drawimage_html_image_14_ref.html": [ + "0feedb34e5ade7a4e58cb4eb92e2b958a06929fe", + "support" + ], + "2dcontext/drawing-images-to-the-canvas/drawimage_html_image_15.html": [ + "b37463cc33b46e9aba5bbe73244fd422ef38406e", + "reftest" + ], + "2dcontext/drawing-images-to-the-canvas/drawimage_html_image_15_ref.html": [ + "d6817ddb2ac78b524f7cc80ebd4f348aded4d89f", + "support" + ], "2dcontext/drawing-images-to-the-canvas/drawimage_html_image_1_ref.html": [ "9a70c803aaf5bd8a843b18d6d16779575d4dc6f8", "support" diff --git a/tests/wpt/web-platform-tests/2dcontext/2x4.png b/tests/wpt/web-platform-tests/2dcontext/2x4.png new file mode 100644 index 0000000000000000000000000000000000000000..f5589a731840441ee6052912763f3ea0436a563f GIT binary patch literal 1745 zcmeAS@N?(olHy`uVBq!ia0y~yU<5Lm7&zE~RPL-zzkw7>v6E*A2N2Y7q;vrJoCO|{ z#S9EO-XP4l)OOlRprB-lYeY$Kep*R+Vo@qXd3m{BW?pu2a$-TMUVc&f>~}U&3=C|3 zo-U3d6?5KR+sJz;K!nB7!6WbJ)!OfmUadGh({n+O_!}Qq@wM-M+OE6byykD*Wnqag zv*Z}g2r_U8kD`GHf$I0)XWcun;Cz{%f5HTIhD4@OG(aJ6{(a%!W$p&)`>%gtVXI^i zP#Z-96awGwy*J(4=s5rFoOuTn_!$ndjG_Swfq$8wgs(c!xV;}({V;gC`njxgN@xNA D;(Zak literal 0 HcmV?d00001 diff --git a/tests/wpt/web-platform-tests/2dcontext/4x2.png b/tests/wpt/web-platform-tests/2dcontext/4x2.png new file mode 100644 index 0000000000000000000000000000000000000000..4a8d81e7c22f31106b942882767350cdd9397d5d GIT binary patch literal 1258 zcmeAS@N?(olHy`uVBq!ia0y~yU;;83893O0)X@p&(t#99v6E*A2N2Y7q;vrJoCO|{ z#S9EO-XP4l)OOlRprB-lYeY$Kep*R+Vo@qXd3m{BW?pu2a$-TMUVc&f>~}U&K!egf zT^vIy=DfXekhh6Jz}3-EZHrUs4eqOf?dCf&#NRzU8}dPa_MSII`|ai6{SV&%4ab(C}ZFfk8lpfkDB8fx%${14DxXBLjmY(8WzGK+`!H7&wGR6^w*% thyx~$d_>~7Q$L%3Gy#le1ZaU^pZJ&m^_H7?yMg5rgQu&X%Q~loCIDs)tGxgK literal 0 HcmV?d00001 diff --git a/tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_14.html b/tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_14.html new file mode 100644 index 00000000000..0a28aa46283 --- /dev/null +++ b/tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_14.html @@ -0,0 +1,33 @@ + + + +Canvas test: 2d.drawImage.crop.2x4 + + + + diff --git a/tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_14_ref.html b/tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_14_ref.html new file mode 100644 index 00000000000..f682f87cc6f --- /dev/null +++ b/tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_14_ref.html @@ -0,0 +1,25 @@ + + + + + + + +
+ + diff --git a/tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_15.html b/tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_15.html new file mode 100644 index 00000000000..507ff31eb9d --- /dev/null +++ b/tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_15.html @@ -0,0 +1,33 @@ + + + +Canvas test: 2d.drawImage.crop.4x2 + + + + diff --git a/tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_15_ref.html b/tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_15_ref.html new file mode 100644 index 00000000000..a7abc3cb28a --- /dev/null +++ b/tests/wpt/web-platform-tests/2dcontext/drawing-images-to-the-canvas/drawimage_html_image_15_ref.html @@ -0,0 +1,25 @@ + + + + + + + +
+ +