Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crop_area_bytes_length calculation and add tests #15929

Merged
merged 1 commit into from Mar 17, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -746,7 +746,7 @@ fn crop_image(image_data: Vec<u8>,
// (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;
{}
]
],
"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",
{}
]
],
"2dcontext/2x4.png": [
[
{}
]
],
"2dcontext/4x2.png": [
[
{}
]
],
"2dcontext/best-practices/.gitkeep": [
[
{}
{}
]
],
"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": [
[
{}
"c67d3f646e86413722833d2308a9bfc793a916bf",
"support"
],
"2dcontext/2x4.png": [
"690bac789fecf2530b36dd889c68db3bd93ed9fd",
"support"
],
"2dcontext/4x2.png": [
"16f72935aaf97175593bcf27794506f0884f091b",
"support"
],
"2dcontext/best-practices/.gitkeep": [
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
"support"
"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"
Binary file not shown.
Binary file not shown.
@@ -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>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.