looks-same
Advanced tools
Comparing version 2.2.0 to 2.2.1
# Changelog | ||
## 2.2.1 - 2015-09-11 | ||
* Use `lodepng` for png encoding/decoding (@LinusU). | ||
## 2.2.0 - 2015-09-11 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"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": { |
114
png.js
'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 |
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
3
95
17346
306
+ Addedlodepng@^0.2.0
+ Addedlodepng@0.2.3(transitive)
+ Addednan@2.22.0(transitive)
- Removedconcat-stream@^1.5.0
- Removedpngjs@^0.4.0
- Removedpngparse@^2.0.1
- Removedbuffer-from@1.1.2(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@1.0.0(transitive)
- Removedpngjs@0.4.0(transitive)
- Removedpngparse@2.0.1(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedutil-deprecate@1.0.2(transitive)