testcafe-browser-tools
Advanced tools
Comparing version 1.4.1-git.201708230700 to 1.4.1-git.201708230930
'use strict'; | ||
var _Promise = require('babel-runtime/core-js/promise').default; | ||
var _regeneratorRuntime = require('babel-runtime/regenerator').default; | ||
@@ -13,11 +15,11 @@ | ||
var _utilsEnsureDirectory = require('../utils/ensure-directory'); | ||
var _gracefulFs = require('graceful-fs'); | ||
var _utilsEnsureDirectory2 = _interopRequireDefault(_utilsEnsureDirectory); | ||
var _gracefulFs2 = _interopRequireDefault(_gracefulFs); | ||
var _utilsExec = require('../utils/exec'); | ||
var _pngjs = require('pngjs'); | ||
var _binaries = require('../binaries'); | ||
var _utilsEnsureDirectory = require('../utils/ensure-directory'); | ||
var _binaries2 = _interopRequireDefault(_binaries); | ||
var _utilsEnsureDirectory2 = _interopRequireDefault(_utilsEnsureDirectory); | ||
@@ -27,2 +29,87 @@ var DEFAULT_THUMBNAIL_WIDTH = 240; | ||
function cubicInterpolation(t, t2, t3, f) { | ||
var C = [0 - 1 * t + 2 * t2 - 1 * t3, 2 + 0 * t - 5 * t2 + 3 * t3, 0 + 1 * t + 4 * t2 - 3 * t3, 0 + 0 * t - 1 * t2 + 1 * t3]; | ||
return 0.5 * (C[0] * f[0] + C[1] * f[1] + C[2] * f[2] + C[3] * f[3]); | ||
} | ||
function getSubpixel(img, y, x, channel) { | ||
if (y >= img.height || x >= img.width || y < 0 || x < 0) return 0; | ||
return img.data[y * img.width * 4 + x * 4 + channel]; | ||
} | ||
function setSubpixel(img, y, x, channel, color) { | ||
if (y >= img.height || x >= img.width || y < 0 || x < 0) return; | ||
if (color > 255) color = 255;else if (color < 0) color = 0; | ||
img.data[y * img.width * 4 + x * 4 + channel] = color; | ||
} | ||
function scale(src, width, height) { | ||
var dst = new _pngjs.PNG({ width: width, height: height }); | ||
var cx = src.width / width; | ||
var cy = src.height / height; | ||
var interpolated = [0, 0, 0, 0]; | ||
for (var i = 0; i < height; ++i) { | ||
var targetY = cy * i; | ||
var sourceY = Math.floor(targetY); | ||
var dy = targetY - sourceY; | ||
var dy2 = dy * dy; | ||
var dy3 = dy2 * dy; | ||
for (var j = 0; j < width; ++j) { | ||
var targetX = cx * j; | ||
var sourceX = Math.floor(targetX); | ||
var dx = targetX - sourceX; | ||
var dx2 = dx * dx; | ||
var dx3 = dx2 * dx; | ||
for (var k = 0; k < 3; ++k) { | ||
for (var ii = 0, interpolY = sourceY - 1; ii < 4; ++ii, ++interpolY) { | ||
var pixels = [getSubpixel(src, interpolY, sourceX - 1, k), getSubpixel(src, interpolY, sourceX, k), getSubpixel(src, interpolY, sourceX + 1, k), getSubpixel(src, interpolY, sourceX + 2, k)]; | ||
interpolated[ii] = cubicInterpolation(dx, dx2, dx3, pixels); | ||
} | ||
setSubpixel(dst, i, j, k, cubicInterpolation(dy, dy2, dy3, interpolated)); | ||
} | ||
setSubpixel(dst, i, j, 3, 255); | ||
} | ||
} | ||
return dst; | ||
} | ||
function generate(src, dst, width, height) { | ||
return new _Promise(function (resolve, reject) { | ||
var srcFileData = _gracefulFs2.default.readFileSync(src); | ||
var srcImage = new _pngjs.PNG(); | ||
srcImage.parse(srcFileData, function (e) { | ||
if (e) reject(e); | ||
try { | ||
var dstImage = scale(srcImage, width, height); | ||
var dstFileData = _pngjs.PNG.sync.write(dstImage); | ||
_gracefulFs2.default.writeFileSync(dst, dstFileData); | ||
resolve(); | ||
} catch (e3) { | ||
reject(e3); | ||
} | ||
}); | ||
}); | ||
} | ||
function getThumbnailPath(imagePath) { | ||
@@ -71,3 +158,3 @@ var imageName = _path2.default.basename(imagePath); | ||
context$2$0.next = 6; | ||
return _regeneratorRuntime.awrap(_utilsExec.execFile(_binaries2.default.generateThumbnail, [sourcePath, thumbnailPath, width, height])); | ||
return _regeneratorRuntime.awrap(generate(...[sourcePath, thumbnailPath, width, height])); | ||
@@ -74,0 +161,0 @@ case 6: |
{ | ||
"name": "testcafe-browser-tools", | ||
"version": "1.4.1-git.201708230700", | ||
"version": "1.4.1-git.201708230930", | ||
"description": "An utility library for performing platform-dependent actions on browsers.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/DevExpress/testcafe-browser-tools", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1600510
1699