looks-same
Advanced tools
Comparing version 2.2.1 to 2.2.2
# Changelog | ||
## 2.2.2 - 2015-12-19 | ||
* Use `pngjs2` instead of `lodepng` (@SevInf). | ||
## 2.2.1 - 2015-09-11 | ||
@@ -4,0 +8,0 @@ |
'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": { |
131
png.js
'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 | ||
})); | ||
}; |
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
17685
315
4
+ Addedconcat-stream@^1.5.0
+ Addedpngjs@^2.2.0
+ Addedbuffer-from@1.1.2(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedpngjs@2.3.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedlodepng@^0.2.0
- Removedlodepng@0.2.3(transitive)
- Removednan@2.22.0(transitive)