Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

looks-same

Package Overview
Dependencies
Maintainers
7
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

looks-same - npm Package Compare versions

Comparing version 7.2.4 to 7.3.0

lib/png-base.js

7

CHANGELOG.md

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc