looks-same
Advanced tools
Comparing version 7.2.4 to 7.3.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [7.3.0](https://github.com/gemini-testing/looks-same/compare/v7.2.4...v7.3.0) (2021-02-03) | ||
### Features | ||
* add ability to compare screens by buffers ([#75](https://github.com/gemini-testing/looks-same/issues/75)) ([039ab0e](https://github.com/gemini-testing/looks-same/commit/039ab0e5ac2b591a46565677a562d3b6898ba4c5)) | ||
### [7.2.4](https://github.com/gemini-testing/looks-same/compare/v7.2.3...v7.2.4) (2020-11-13) | ||
@@ -7,0 +14,0 @@ |
60
index.js
@@ -6,8 +6,8 @@ 'use strict'; | ||
const colorDiff = require('color-diff'); | ||
const png = require('./lib/png'); | ||
const png = require('./lib/png-image'); | ||
const areColorsSame = require('./lib/same-colors'); | ||
const AntialiasingComparator = require('./lib/antialiasing-comparator'); | ||
const IgnoreCaretComparator = require('./lib/ignore-caret-comparator'); | ||
const DiffArea = require('./lib/diff-area'); | ||
const utils = require('./lib/utils'); | ||
const {getDiffPixelsCoords} = utils; | ||
const {JND} = require('./lib/constants'); | ||
@@ -141,3 +141,3 @@ | ||
module.exports = exports = function looksSame(image1, image2, opts, callback) { | ||
module.exports = exports = async function looksSame(image1, image2, opts, callback) { | ||
if (!callback) { | ||
@@ -151,25 +151,41 @@ callback = opts; | ||
utils | ||
.readPair(image1, image2) | ||
.then(({first, second}) => { | ||
const refImg = {size: {width: first.width, height: first.height}}; | ||
const metaInfo = {refImg}; | ||
try { | ||
const {first, second} = await utils.readPair(image1, image2, utils.readBufferCb); | ||
const areBuffersEqual = utils.areBuffersEqual(first, second); | ||
if (first.width !== second.width || first.height !== second.height) { | ||
const diffBounds = getMaxDiffBounds(first, second); | ||
return process.nextTick(() => callback(null, {equal: false, metaInfo, diffBounds, diffClusters: [diffBounds]})); | ||
} | ||
const refImg = {size: {width: first.width, height: first.height}}; | ||
const metaInfo = {refImg}; | ||
const comparator = createComparator(first, second, opts); | ||
const {stopOnFirstFail, shouldCluster, clustersSize} = opts; | ||
if (areBuffersEqual) { | ||
const diffBounds = (new DiffArea()).area; | ||
process.nextTick(() => callback(null, {equal: true, metaInfo, diffBounds, diffClusters: [diffBounds]})); | ||
getDiffPixelsCoords(first, second, comparator, {stopOnFirstFail, shouldCluster, clustersSize}, ({diffArea, diffClusters}) => { | ||
const diffBounds = diffArea.area; | ||
return; | ||
} | ||
callback(null, {equal: diffArea.isEmpty(), metaInfo, diffBounds, diffClusters}); | ||
}); | ||
}) | ||
.catch(error => { | ||
callback(error); | ||
if (first.width !== second.width || first.height !== second.height) { | ||
const diffBounds = getMaxDiffBounds(first, second); | ||
process.nextTick(() => callback(null, {equal: false, metaInfo, diffBounds, diffClusters: [diffBounds]})); | ||
return; | ||
} | ||
const {first: png1, second: png2} = await utils.readPair( | ||
{...image1, source: first.buffer}, | ||
{...image2, source: second.buffer}, | ||
utils.readPngCb | ||
); | ||
const comparator = createComparator(png1, png2, opts); | ||
const {stopOnFirstFail, shouldCluster, clustersSize} = opts; | ||
utils.getDiffPixelsCoords(png1, png2, comparator, {stopOnFirstFail, shouldCluster, clustersSize}, ({diffArea, diffClusters}) => { | ||
const diffBounds = diffArea.area; | ||
const equal = diffArea.isEmpty(); | ||
callback(null, {equal, metaInfo, diffBounds, diffClusters}); | ||
}); | ||
} catch (err) { | ||
return callback(err); | ||
} | ||
}; | ||
@@ -195,3 +211,3 @@ | ||
getDiffPixelsCoords(first, second, comparator, opts, ({diffArea}) => { | ||
utils.getDiffPixelsCoords(first, second, comparator, opts, ({diffArea}) => { | ||
if (diffArea.isEmpty()) { | ||
@@ -198,0 +214,0 @@ return callback(null, null); |
'use strict'; | ||
const _ = require('lodash'); | ||
const png = require('./png'); | ||
const png = require('./png-image'); | ||
const buffer = require('./png-buffer'); | ||
const DiffArea = require('./diff-area'); | ||
@@ -9,10 +10,15 @@ const DiffClusters = require('./diff-clusters'); | ||
function read({source, ...opts}) { | ||
exports.readPngCb = ({source, ...opts}) => { | ||
const readFunc = Buffer.isBuffer(source) ? png.fromBuffer : png.fromFile; | ||
return readFunc(source, opts); | ||
} | ||
}; | ||
exports.readPair = async (first, second) => { | ||
const [firstPng, secondPng] = await Promise.all([first, second].map(read)); | ||
exports.readBufferCb = ({source, ...opts}) => { | ||
const readFunc = Buffer.isBuffer(source) ? buffer.create : buffer.fromFile; | ||
return readFunc(source, opts); | ||
}; | ||
exports.readPair = async (first, second, readCb = exports.readPngCb) => { | ||
const [firstPng, secondPng] = await Promise.all([first, second].map(readCb)); | ||
return {first: firstPng, second: secondPng}; | ||
@@ -85,1 +91,9 @@ }; | ||
}; | ||
exports.areBuffersEqual = (img1, img2) => { | ||
if (img1.boundingBox || img2.boundingBox) { | ||
return false; | ||
} | ||
return img1.buffer.equals(img2.buffer); | ||
}; |
{ | ||
"name": "looks-same", | ||
"version": "7.2.4", | ||
"version": "7.3.0", | ||
"description": "Pure node.js library for comparing PNG-images, taking into account human color perception.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
48091
29
1086
0
3