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.1 to 2.2.2

4

CHANGELOG.md
# Changelog
## 2.2.2 - 2015-12-19
* Use `pngjs2` instead of `lodepng` (@SevInf).
## 2.2.1 - 2015-09-11

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

8

index.js
'use strict';
var parseColor = require('parse-color'),
colorDiff = require('color-diff'),
png = require('./png'),
PNGIn = png.PNGIn,
PNGOut = png.PNGOut;
png = require('./png');

@@ -20,3 +18,3 @@ var JND = 2.3; //Just noticable difference

var source = src[key],
readFunc = Buffer.isBuffer(source)? PNGIn.fromBuffer : PNGIn.fromFile;
readFunc = Buffer.isBuffer(source)? png.fromBuffer : png.fromFile;

@@ -143,3 +141,3 @@ readFunc(source, function(error, png) {

highlightColor = options.highlightColor,
result = new PNGOut(width, height);
result = png.empty(width, height);

@@ -146,0 +144,0 @@ iterateRect(width, height, function(x, y) {

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

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

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

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

'use strict';
var fs = require('fs'),
lodepng = require('lodepng');
PNG = require('pngjs').PNG,
concat = require('concat-stream');
function getIdx(imageData, x, y) {
return (imageData.width * y + x) * 4;
function PNGImage(png) {
this._png = png;
}
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]
};
}
PNGImage.prototype = {
constructor: PNGImage,
function PNGIn(imageData) {
this.width = imageData.width;
this.height = imageData.height;
this.data = imageData.data;
}
PNGIn.prototype = {
constructor: PNGIn,
getPixel: function(x, y) {
return getPixel(this, 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]
};
},
PNGIn.fromFile = function fromFile(filePath, callback) {
fs.readFile(filePath, function (err, raw) {
if (err) return callback(err);
get width() {
return this._png.width;
},
PNGIn.fromBuffer(raw, callback);
});
};
PNGIn.fromBuffer = function fromBuffer(buffer, callback) {
lodepng.decode(buffer, function (err, imageData) {
if (err) return callback(err);
callback(null, new PNGIn(imageData));
});
};
exports.PNGIn = PNGIn;
function PNGOut(width, height) {
this.width = width;
this.height = height;
this.data = new Uint8ClampedArray(width * height * 4);
}
PNGOut.prototype = {
constructor: PNGOut,
getPixel: function(x, y) {
return getPixel(this, x, y);
get height() {
return this._png.height;
},
setPixel: function(x, y, color) {
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;
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;
},
_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);
fs.writeFile(path, raw, callback);
var writeStream = fs.createWriteStream(path);
this._png.pack().pipe(writeStream);
writeStream.on('error', function(error) {
callback(error);
});
writeStream.on('finish', function() {
callback(null);
});
},
createBuffer: function(callback) {
lodepng.encode(this, callback);
this._png.pack().pipe(concat(gotDiff));
this._png.on('error', function(error) {
callback(error, null);
});
function gotDiff(data) {
callback(null, data);
}
}
};
exports.PNGOut = PNGOut;
exports.fromFile = function fromFile(filePath, callback) {
var png = new PNG();
fs.createReadStream(filePath)
.pipe(png)
.on('parsed', function() {
callback(null, new PNGImage(png));
})
.on('error', callback);
};
exports.fromBuffer = function fromBuffer(buffer, callback) {
var png = new PNG();
png.parse(buffer, function(error, data) {
if (error) {
return callback(error, null);
}
callback(null, new PNGImage(png));
});
};
exports.empty = function empty(width, height) {
return new PNGImage(new PNG({
width: width,
height: height
}));
};
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