-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ability to compare images by regions
- Loading branch information
Showing
18 changed files
with
519 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
JND: 2.3, // Just noticeable difference if ciede2000 >= JND then colors difference is noticeable by human eye | ||
REQUIRED_IMAGE_FIELDS: ['source', 'boundingBox'], | ||
REQUIRED_BOUNDING_BOX_FIELDS: ['left', 'top', 'right', 'bottom'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
const PNGImage = require('./png'); | ||
|
||
module.exports = class BoundedPNGImage extends PNGImage { | ||
constructor(png, boundingBox) { | ||
super(png); | ||
|
||
this._boundingBox = boundingBox; | ||
} | ||
|
||
getPixel(x, y) { | ||
const {x: actX, y: actY} = this.getActualCoord(x, y); | ||
|
||
return super.getPixel(actX, actY); | ||
} | ||
|
||
setPixel(x, y, color) { | ||
const {x: actX, y: actY} = this.getActualCoord(x, y); | ||
|
||
super.setPixel(actX, actY, color); | ||
} | ||
|
||
getActualCoord(x, y) { | ||
return {x: x + this._boundingBox.left, y: y + this._boundingBox.top}; | ||
} | ||
|
||
get width() { | ||
return this._boundingBox.right - this._boundingBox.left + 1; | ||
} | ||
|
||
get height() { | ||
return this._boundingBox.bottom - this._boundingBox.top + 1; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const {PNG} = require('pngjs'); | ||
const OriginalPNG = require('./original-png'); | ||
const BoundedPNG = require('./bounded-png'); | ||
|
||
exports.create = (png, {boundingBox} = {}) => { | ||
return boundingBox | ||
? BoundedPNG.create(png, boundingBox) | ||
: OriginalPNG.create(png); | ||
}; | ||
|
||
exports.fromFile = (filePath, opts = {}, callback) => { | ||
fs.readFile(filePath, (error, data) => { | ||
error | ||
? callback(error, null) | ||
: exports.fromBuffer(data, opts, callback); | ||
}); | ||
}; | ||
|
||
exports.fromBuffer = (buffer, opts = {}, callback) => { | ||
const png = new PNG(); | ||
png.parse(buffer, (error) => { | ||
error | ||
? callback(error, null) | ||
: callback(null, exports.create(png, opts)); | ||
}); | ||
}; | ||
|
||
exports.empty = (width, height) => exports.create(new PNG({width, height})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
const PNGImage = require('./png'); | ||
|
||
module.exports = class OriginalPNGImage extends PNGImage { | ||
getActualCoord(x, y) { | ||
return {x, y}; | ||
} | ||
|
||
get width() { | ||
return this._png.width; | ||
} | ||
|
||
get height() { | ||
return this._png.height; | ||
} | ||
}; |
Oops, something went wrong.