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

looks-same

Package Overview
Dependencies
Maintainers
2
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 2.2.0 to 2.2.1

4

CHANGELOG.md
# Changelog
## 2.2.1 - 2015-09-11
* Use `lodepng` for png encoding/decoding (@LinusU).
## 2.2.0 - 2015-09-11

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

8

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

@@ -11,6 +11,4 @@ "main": "index.js",

"color-diff": "^0.1.5",
"concat-stream": "^1.5.0",
"parse-color": "^1.0.0",
"pngjs": "^0.4.0",
"pngparse": "^2.0.1"
"lodepng": "^0.2.0",
"parse-color": "^1.0.0"
},

@@ -17,0 +15,0 @@ "devDependencies": {

'use strict';
var fs = require('fs'),
pngparse = require('pngparse'),
PNG = require('pngjs').PNG,
concat = require('concat-stream');
lodepng = require('lodepng');
function PNGIn(data) {
this._data = data;
function getIdx(imageData, x, y) {
return (imageData.width * y + x) * 4;
}
function getPixel(imageData, x, y) {
var idx = getIdx(imageData, x, y);
return {
R: imageData.data[idx],
G: imageData.data[idx + 1],
B: imageData.data[idx + 2]
};
}
function PNGIn(imageData) {
this.width = imageData.width;
this.height = imageData.height;
this.data = imageData.data;
}
PNGIn.prototype = {

@@ -15,26 +28,11 @@ constructor: PNGIn,

getPixel: function(x, y) {
var pixel = this._data.getPixel(x, y);
return {
R: (pixel & 0xFF000000) >>> 24,
G: (pixel & 0x00FF0000) >>> 16,
B: (pixel & 0x0000FF00) >>> 8
};
},
get width() {
return this._data.width;
},
get height() {
return this._data.height;
return getPixel(this, x, y);
}
};
PNGIn.fromFile = function fromFile(filePath, callback) {
pngparse.parseFile(filePath, function(error, data) {
if (error) {
return callback(error, null);
}
callback(null, new PNGIn(data));
fs.readFile(filePath, function (err, raw) {
if (err) return callback(err);
PNGIn.fromBuffer(raw, callback);
});

@@ -44,7 +42,6 @@ };

PNGIn.fromBuffer = function fromBuffer(buffer, callback) {
pngparse.parse(buffer, function(error, data) {
if (error) {
return callback(error, null);
}
callback(null, new PNGIn(data));
lodepng.decode(buffer, function (err, imageData) {
if (err) return callback(err);
callback(null, new PNGIn(imageData));
});

@@ -56,6 +53,5 @@ };

function PNGOut(width, height) {
this._png = new PNG({
width: width,
height: height
});
this.width = width;
this.height = height;
this.data = new Uint8ClampedArray(width * height * 4);
}

@@ -67,51 +63,23 @@

getPixel: function(x, y) {
var idx = this._getIdx(x, y);
return {
R: this._png.data[idx],
G: this._png.data[idx + 1],
B: this._png.data[idx + 2]
};
return getPixel(this, x, y);
},
get width() {
return this._png.width;
},
get height() {
return this._png.height;
},
setPixel: function(x, y, color) {
var idx = this._getIdx(x, y);
this._png.data[idx] = color.R;
this._png.data[idx + 1] = color.G;
this._png.data[idx + 2] = color.B;
this._png.data[idx + 3] = 255;
var idx = getIdx(this, x, y);
this.data[idx] = color.R;
this.data[idx + 1] = color.G;
this.data[idx + 2] = color.B;
this.data[idx + 3] = 255;
},
_getIdx: function(x, y) {
return (this._png.width * y + x) * 4;
},
save: function(path, callback) {
lodepng.encode(this, function (err, raw) {
if (err) return callback(err);
save: function(path, callback) {
var writeStream = fs.createWriteStream(path);
this._png.pack().pipe(writeStream);
writeStream.on('error', function(error) {
callback(error);
fs.writeFile(path, raw, callback);
});
writeStream.on('finish', function() {
callback(null);
});
},
createBuffer: function(callback) {
this._png.pack().pipe(concat(gotDiff));
this._png.on('error', function(error) {
callback(error, null);
});
function gotDiff(data) {
callback(null, data);
}
lodepng.encode(this, callback);
}

@@ -118,0 +86,0 @@ };

@@ -5,5 +5,6 @@ # LooksSame

Pure node.js library for comparing PNG-images, taking into account human color perception.
It is created specially for the needs of visual regression testing for [`gemini`](http://github.com/gemini-testing/gemini)
utility, but can be used for other purposes.
Node.js library for comparing PNG-images, taking into account human color
perception. It is created specially for the needs of visual regression testing
for [`gemini`](http://github.com/gemini-testing/gemini) utility, but can be used
for other purposes.

@@ -10,0 +11,0 @@ ## Comparing images

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