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

looks-same

Package Overview
Dependencies
Maintainers
4
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 3.0.0 to 3.1.0

AUTHORS

4

CHANGELOG.md
# Changelog
## 3.1.0 - 2016-11-11
* Add `ignoreAntialiasing` option to ignore diffs with anti-aliased pixels. Enabled by default.
## 3.0.0 - 2016-07-13

@@ -4,0 +8,0 @@

46

index.js

@@ -5,3 +5,4 @@ 'use strict';

png = require('./lib/png'),
IgnoreCaretComparator = require('./lib/ignore-caret-comparator');
IgnoreCaretComparator = require('./lib/ignore-caret-comparator'),
AntialiasingComparator = require('./lib/antialiasing-comparator');

@@ -48,3 +49,7 @@ var JND = 2.3; //Just noticable difference

color2 = png2.getPixel(x, y),
result = predicate(color1, color2, x, y);
result = predicate({
color1, color2,
x, y,
width, height
});

@@ -75,2 +80,6 @@ if (!result) {

var comparator = opts.strict? areColorsSame : makeCIEDE2000Comparator(opts.tolerance);
if (opts.ignoreAntialiasing) {
comparator = makeAntialiasingComparator(comparator, png1, png2);
}
if (opts.ignoreCaret) {

@@ -83,15 +92,20 @@ comparator = makeNoCaretColorComparator(comparator, opts.pixelRatio);

function makeAntialiasingComparator(comparator, png1, png2) {
const antialiasingComparator = new AntialiasingComparator(comparator, png1, png2);
return (data) => antialiasingComparator.compare(data);
}
function makeNoCaretColorComparator(comparator, pixelRatio) {
const caretComparator = new IgnoreCaretComparator(comparator, pixelRatio);
return (color1, color2, x, y) => caretComparator.compare(color1, color2, x, y);
return (data) => caretComparator.compare(data);
}
function makeCIEDE2000Comparator(tolerance) {
return function doColorsLookSame(c1, c2) {
if (areColorsSame(c1, c2)) {
return function doColorsLookSame(data) {
if (areColorsSame(data)) {
return true;
}
/*jshint camelcase:false*/
var lab1 = colorDiff.rgb_to_lab(c1),
lab2 = colorDiff.rgb_to_lab(c2);
var lab1 = colorDiff.rgb_to_lab(data.color1),
lab2 = colorDiff.rgb_to_lab(data.color2);

@@ -102,6 +116,8 @@ return colorDiff.diff(lab1, lab2) < tolerance;

function areColorsSame(c1, c2) {
return c1.R === c2.R &&
c1.G === c2.G &&
c1.B === c2.B;
function areColorsSame(data) {
const c1 = data.color1;
const c2 = data.color2;
return c1.R === c2.R
&& c1.G === c2.G
&& c1.B === c2.B;
}

@@ -117,2 +133,6 @@

if (opts.ignoreAntialiasing === undefined) {
opts.ignoreAntialiasing = true;
}
readPair(reference, image, function(error, result) {

@@ -145,3 +165,3 @@ if (error) {

if (!options.comparator(color1, color2)) {
if (!options.comparator({color1, color2})) {
result.setPixel(x, y, highlightColor);

@@ -221,3 +241,3 @@ } else {

var comparator = makeCIEDE2000Comparator(opts.tolerance);
return comparator(color1, color2);
return comparator({color1, color2});
};

@@ -36,12 +36,13 @@ 'use strict';

* Compare pixels for current active comparator state
* @param {Object} color1
* @param {Object} color2
* @param {Number} x coordinate
* @param {Number} y coordinate
* @param {Object} data
* @param {Object} data.color1
* @param {Object} data.color2
* @param {Number} data.x coordinate
* @param {Number} data.y coordinate
* @returns {boolean}
*/
compare(color1, color2, x, y) {
return this._baseComparator(color1, color2, x, y)
? this._state.validateOnEqual({x, y})
: this._state.validateOnDiff({x, y});
compare(data) {
return this._baseComparator(data)
? this._state.validateOnEqual({x: data.x, y: data.y})
: this._state.validateOnDiff({x: data.x, y: data.y});
}

@@ -48,0 +49,0 @@

{
"name": "looks-same",
"version": "3.0.0",
"version": "3.1.0",
"description": "Pure node.js library for comparing PNG-images, taking into account human color perception.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -57,3 +57,3 @@ # LooksSame

Some devices can have different proportion between physical and logical screen resolutions also
known as `pixel ratio`. Default value for this proportion is 1.
known as `pixel ratio`. Default value for this proportion is 1.
This param also affects the comparison result, so it can be set manually with `pixelRatio` option.

@@ -67,2 +67,10 @@

Some images has difference while comparing because of antialiasing. These diffs will be ignored by default. You can use `ignoreAntialiasing` option with `false` value to disable ignoring such diffs. In that way antialiased pixels will be marked as diffs. Read more about [anti-aliasing algorithm](http://www.eejournal.ktu.lt/index.php/elt/article/view/10058/5000).
```javascript
looksSame('image1.png', 'image2.png', {ignoreAntialiasing: true}, function(error, equal) {
...
});
```
## Building diff image

@@ -69,0 +77,0 @@

Sorry, the diff of this file is not supported yet

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