Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Optimized for execution on iPhone Safari

Removed unnecessary switch option, optimized Math.floor with bitwise.
Math.ceil keept the same because faster than bitwise on iPhone Safari
  • Loading branch information...
commit a8a96e47bb25c6ad59f84a9144a38198ce974cfc 1 parent 5b2252c
@mimo84 mimo84 authored
Showing with 6 additions and 9 deletions.
  1. +6 −9 src/megapix-image.js
View
15 src/megapix-image.js
@@ -94,9 +94,9 @@
var sw = sx + d > iw ? iw - sx : d;
tmpCtx.clearRect(0, 0, d, d);
tmpCtx.drawImage(img, -sx, -sy);
- var dx = Math.floor(sx * width / iw);
+ var dx = (sx * width / iw) << 0;
var dw = Math.ceil(sw * width / iw);
- var dy = Math.floor(sy * height / ih / vertSquashRatio);
+ var dy = (sy * height / ih / vertSquashRatio) << 0;
var dh = Math.ceil(sh * height / ih / vertSquashRatio);
ctx.drawImage(tmpCanvas, 0, 0, sw, sh, dx, dy, dw, dh);
sx += d;
@@ -126,9 +126,6 @@
}
var ctx = canvas.getContext('2d');
switch (orientation) {
- case 1:
- // nothing
- break;
case 2:
// horizontal flip
ctx.translate(width, 0);
@@ -214,20 +211,20 @@
width = options.width, height = options.height,
maxWidth = options.maxWidth, maxHeight = options.maxHeight;
if (width && !height) {
- height = Math.floor(imgHeight * width / imgWidth);
+ height = (imgHeight * width / imgWidth) << 0;
} else if (height && !width) {
- width = Math.floor(imgWidth * height / imgHeight);
+ width = (imgWidth * height / imgHeight) << 0;
} else {
width = imgWidth;
height = imgHeight;
}
if (maxWidth && width > maxWidth) {
width = maxWidth;
- height = Math.floor(imgHeight * width / imgWidth);
+ height = (imgHeight * width / imgWidth) << 0;
}
if (maxHeight && height > maxHeight) {
height = maxHeight;
- width = Math.floor(imgWidth * height / imgHeight);
+ width = (imgWidth * height / imgHeight) << 0;
}
var opt = { width : width, height : height };
for (var k in options) opt[k] = options[k];
Please sign in to comment.
Something went wrong with that request. Please try again.