mirror of
https://github.com/servo/servo.git
synced 2025-09-02 11:08:22 +01:00
Fix crop_area_byte_length calculation in crop_image and add tests
This commit is contained in:
parent
e34aac03ff
commit
6f470e497f
8 changed files with 185 additions and 1 deletions
BIN
tests/wpt/web-platform-tests/2dcontext/2x4.png
Normal file
BIN
tests/wpt/web-platform-tests/2dcontext/2x4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
tests/wpt/web-platform-tests/2dcontext/4x2.png
Normal file
BIN
tests/wpt/web-platform-tests/2dcontext/4x2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="reftest-wait">
|
||||
<meta charset="utf-8">
|
||||
<title>Canvas test: 2d.drawImage.crop.2x4</title>
|
||||
<link rel="match" href="drawimage_html_image_14_ref.html">
|
||||
<style>
|
||||
html, body {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
<canvas id="dest" height="100" width="100"></canvas>
|
||||
<script>
|
||||
|
||||
var sourceWidth = 256;
|
||||
var sourceHeight = 512;
|
||||
var smoothingEnabled = false;
|
||||
var destCanvas = document.getElementById('dest');
|
||||
var sourceImg = document.createElement('img');
|
||||
sourceImg.src = '../2x4.png'
|
||||
sourceImg.width = sourceWidth;
|
||||
sourceImg.height = sourceHeight;
|
||||
|
||||
sourceImg.onload = function() {
|
||||
var destCtx = destCanvas.getContext('2d');
|
||||
destCtx.fillStyle = "#FF0000";
|
||||
destCtx.fillRect(0, 0, destCanvas.width, destCanvas.height);
|
||||
destCtx.imageSmoothingEnabled = smoothingEnabled;
|
||||
|
||||
destCtx.drawImage(sourceImg, 64, 64, 192, 448, 0, 0, 30, 70);
|
||||
document.documentElement.classList.remove('reftest-wait');
|
||||
}
|
||||
|
||||
</script>
|
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<style>
|
||||
html, body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#destination {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
background-color: red;
|
||||
background-image: url("../2x4.png");
|
||||
background-position: -10px -10px;
|
||||
background-size: 40px 80px;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
</style>
|
||||
<body>
|
||||
<div id="destination"></div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="reftest-wait">
|
||||
<meta charset="utf-8">
|
||||
<title>Canvas test: 2d.drawImage.crop.4x2</title>
|
||||
<link rel="match" href="drawimage_html_image_15_ref.html">
|
||||
<style>
|
||||
html, body {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
<canvas id="dest" height="100" width="100"></canvas>
|
||||
<script>
|
||||
|
||||
var sourceWidth = 512;
|
||||
var sourceHeight = 256;
|
||||
var smoothingEnabled = false;
|
||||
var destCanvas = document.getElementById('dest');
|
||||
var sourceImg = document.createElement('img');
|
||||
sourceImg.src = '../4x2.png'
|
||||
sourceImg.width = sourceWidth;
|
||||
sourceImg.height = sourceHeight;
|
||||
|
||||
sourceImg.onload = function() {
|
||||
var destCtx = destCanvas.getContext('2d');
|
||||
destCtx.fillStyle = "#FF0000";
|
||||
destCtx.fillRect(0, 0, destCanvas.width, destCanvas.height);
|
||||
destCtx.imageSmoothingEnabled = smoothingEnabled;
|
||||
|
||||
destCtx.drawImage(sourceImg, 64, 64, 448, 192, 0, 0, 70, 30);
|
||||
document.documentElement.classList.remove('reftest-wait');
|
||||
}
|
||||
|
||||
</script>
|
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<style>
|
||||
html, body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#destination {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
background-color: red;
|
||||
background-image: url("../4x2.png");
|
||||
background-position: -10px -10px;
|
||||
background-size: 80px 40px;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
</style>
|
||||
<body>
|
||||
<div id="destination"></div>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue