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

pam-diff

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pam-diff - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

82

index.js

@@ -14,5 +14,4 @@ 'use strict';

* @param [options.debug=false] {Boolean} - If true, debug info will be logged to console
* @param [options.sync=false] {Boolean} - If true, pixel change detection will block the event loop instead of using a worker
* @param [options.difference=5] {Number} - Pixel difference value 1 to 255
* @param [options.percent=5] {Number} - Percent of pixels or blobs that exceed difference value
* @param [options.percent=5] {Number} - Percent of pixels or blobs that exceed difference value, float 0.0 to 100.0
* @param [options.response=percent] {String} - Accepted values: percent or bounds or blobs

@@ -23,3 +22,3 @@ * @param [options.draw=false] {Boolean} - If true and response is 'bounds' or 'blobs', return a pixel buffer with drawn bounding box

* @param [options.regions[i].difference=options.difference] {Number} - Difference value for region
* @param [options.regions[i].percent=options.percent] {Number} - Percent value for region
* @param [options.regions[i].percent=options.percent] {Number} - Percent value for region, float 0.0 to 100.0
* @param options.regions[i].polygon {Array} - Array of x y coordinates [{x:0,y:0},{x:0,y:360},{x:160,y:360},{x:160,y:0}]

@@ -35,3 +34,2 @@ * @param [options.mask=false] {Boolean} - Indicate if regions should be used as masks of pixels to ignore

this.draw = PamDiff._parseOptions('draw', options); // return pixels with bounding box if response is bounds or blobs
this.sync = PamDiff._parseOptions('sync', options); // should be processed before regions
this.difference = PamDiff._parseOptions('difference', options); // global value, can be overridden per region

@@ -164,30 +162,2 @@ this.percent = PamDiff._parseOptions('percent', options); // global value, can be overridden per region

*/
set sync(bool) {
this._sync = PamDiff._validateBoolean(bool);
this._processRegions();
this._configurePixelDiffEngine();
}
/**
*
* @return {Boolean}
*/
get sync() {
return this._sync;
}
/**
*
* @param bool {Boolean}
* @return {PamDiff}
*/
setSync(bool) {
this.sync = bool;
return this;
}
/**
*
* @param bool {Boolean}
*/
set draw(bool) {

@@ -246,6 +216,6 @@ this._draw = PamDiff._validateBoolean(bool);

*
* @param number {Number}
* @param number {Number|String}
*/
set percent(number) {
this._percent = PamDiff._validateNumber(parseInt(number), 5, 1, 100);
this._percent = PamDiff._validateNumber(parseFloat(number), 5, 0, 100);
this._configurePixelDiffEngine();

@@ -282,3 +252,5 @@ }

} else if (!Array.isArray(array) || array.length < 1) {
throw new Error(`Regions must be an array of at least 1 region object { name: 'region1', difference: 10, percent: 10, polygon: [[0, 0], [0, 50], [50, 50], [50, 0]] }`);
throw new Error(
`Regions must be an array of at least 1 region object { name: 'region1', difference: 10, percent: 1, polygon: [{x: 0, y: 0}, {x: 0, y:50}, {x: 50, y:50}, {x: 50, y: 0}] }`
);
} else {

@@ -443,3 +415,3 @@ this._regions = array;

const difference = PamDiff._validateNumber(parseInt(region.difference), this._difference, 1, 255);
const percent = PamDiff._validateNumber(parseInt(region.percent), this._percent, 1, 100);
const percent = PamDiff._validateNumber(parseFloat(region.percent), this._percent, 0, 100);
regions.push({

@@ -471,3 +443,3 @@ name: region.name,

engine += `_${this._width}_x_${this._height}`;
const config = { width: this._width, height: this._height, depth: this._depth, response: this._response, sync: this._sync };
const config = { width: this._width, height: this._height, depth: this._depth, response: this._response, sync: false };
if (this._regionObj) {

@@ -491,5 +463,5 @@ engine += '_region';

}
engine += this._sync ? '_sync' : '_async';
engine += '_async';
const pixelChange = PC(config);
this._engine = this._sync ? pixelChange.compareSync.bind(pixelChange) : pixelChange.compare.bind(pixelChange);
this._engine = pixelChange.compare.bind(pixelChange);
if (this._debug) {

@@ -512,18 +484,14 @@ console.dir(this, { showHidden: false, depth: 0, colors: true });

this._newPix = chunk.pixels;
this._engine(this._oldPix, this._newPix, (err, results, pixels) => {
this._engine(this._oldPix, this._newPix, (err, data) => {
const { results } = data;
if (results.length) {
const data = { trigger: results, pam: chunk.pam, headers: chunk.headers };
if (pixels) {
data.pixels = pixels;
} else {
data.pixels = chunk.pixels;
}
const diff = { trigger: results, pam: chunk.pam, headers: chunk.headers, pixels: data.pixels || chunk.pixels };
if (this._callback) {
this._callback(data);
this._callback(diff);
}
if (this._readableState.pipesCount > 0) {
this.push(data);
this.push(diff);
}
if (this.listenerCount('diff') > 0) {
this.emit('diff', data);
this.emit('diff', diff);
}

@@ -544,19 +512,15 @@ }

this._newPix = chunk.pixels;
this._engine(this._oldPix, this._newPix, (err, results, pixels) => {
this._engine(this._oldPix, this._newPix, (err, data) => {
console.timeEnd(`${this._debugEngine}-${debugCount}`);
const { results } = data;
if (results.length) {
const data = { trigger: results, pam: chunk.pam, headers: chunk.headers };
if (pixels) {
data.pixels = pixels;
} else {
data.pixels = chunk.pixels;
}
const diff = { trigger: results, pam: chunk.pam, headers: chunk.headers, pixels: data.pixels || chunk.pixels };
if (this._callback) {
this._callback(data);
this._callback(diff);
}
if (this._readableState.pipesCount > 0) {
this.push(data);
this.push(diff);
}
if (this.listenerCount('diff') > 0) {
this.emit('diff', data);
this.emit('diff', diff);
}

@@ -563,0 +527,0 @@ }

{
"name": "pam-diff",
"version": "1.0.1",
"version": "1.1.0",
"description": "Measure differences between pixel arrays extracted from pam images",

@@ -15,106 +15,60 @@ "main": "index.js",

"gray": "npm run gray:all && npm run gray:mask && npm run gray:region && npm run gray:regions",
"gray:all": "npm run gray:all:1 && npm run gray:all:2 && npm run gray:all:3 && npm run gray:all:4 && npm run gray:all:5 && npm run gray:all:6",
"gray:all:1": "node tests/test_gray --sync false --response percent",
"gray:all:2": "node tests/test_gray --sync true --response percent",
"gray:all:3": "node tests/test_gray --sync false --response bounds",
"gray:all:4": "node tests/test_gray --sync true --response bounds",
"gray:all:5": "node tests/test_gray --sync false --response blobs",
"gray:all:6": "node tests/test_gray --sync true --response blobs",
"gray:mask": "npm run gray:mask:1 && npm run gray:mask:2 && npm run gray:mask:3 && npm run gray:mask:4 && npm run gray:mask:5 && npm run gray:mask:6",
"gray:mask:1": "node tests/test_gray2 --sync false --response percent",
"gray:mask:2": "node tests/test_gray2 --sync true --response percent",
"gray:mask:3": "node tests/test_gray2 --sync false --response bounds",
"gray:mask:4": "node tests/test_gray2 --sync true --response bounds",
"gray:mask:5": "node tests/test_gray2 --sync false --response blobs",
"gray:mask:6": "node tests/test_gray2 --sync true --response blobs",
"gray:region": "npm run gray:region:1 && npm run gray:region:2 && npm run gray:region:3 && npm run gray:region:4 && npm run gray:region:5 && npm run gray:region:6",
"gray:region:1": "node tests/test_gray3 --sync false --response percent",
"gray:region:2": "node tests/test_gray3 --sync true --response percent",
"gray:region:3": "node tests/test_gray3 --sync false --response bounds",
"gray:region:4": "node tests/test_gray3 --sync true --response bounds",
"gray:region:5": "node tests/test_gray3 --sync false --response blobs",
"gray:region:6": "node tests/test_gray3 --sync true --response blobs",
"gray:regions": "npm run gray:regions:1 && npm run gray:regions:2 && npm run gray:regions:3 && npm run gray:regions:4 && npm run gray:regions:5 && npm run gray:regions:6",
"gray:regions:1": "node tests/test_gray4 --sync false --response percent",
"gray:regions:2": "node tests/test_gray4 --sync true --response percent",
"gray:regions:3": "node tests/test_gray4 --sync false --response bounds",
"gray:regions:4": "node tests/test_gray4 --sync true --response bounds",
"gray:regions:5": "node tests/test_gray4 --sync false --response blobs",
"gray:regions:6": "node tests/test_gray4 --sync true --response blobs",
"gray:all": "npm run gray:all:percent && npm run gray:all:bounds && npm run gray:all:blobs",
"gray:all:percent": "node tests/test_gray --response percent",
"gray:all:bounds": "node tests/test_gray --response bounds",
"gray:all:blobs": "node tests/test_gray --response blobs",
"gray:mask": "npm run gray:mask:percent && npm run gray:mask:bounds && npm run gray:mask:blobs",
"gray:mask:percent": "node tests/test_gray2 --response percent",
"gray:mask:bounds": "node tests/test_gray2 --response bounds",
"gray:mask:blobs": "node tests/test_gray2 --response blobs",
"gray:region": "npm run gray:region:percent && npm run gray:region:bounds && npm run gray:region:blobs",
"gray:region:percent": "node tests/test_gray3 --response percent",
"gray:region:bounds": "node tests/test_gray3 --response bounds",
"gray:region:blobs": "node tests/test_gray3 --response blobs",
"gray:regions": "npm run gray:regions:percent && npm run gray:regions:bounds && npm run gray:regions:blobs",
"gray:regions:percent": "node tests/test_gray4 --response percent",
"gray:regions:bounds": "node tests/test_gray4 --response bounds",
"gray:regions:blobs": "node tests/test_gray4 --response blobs",
"rgb": "npm run rgb:all && npm run rgb:mask && npm run rgb:region && npm run rgb:regions",
"rgb:all": "npm run rgb:all:1 && npm run rgb:all:2 && npm run rgb:all:3 && npm run rgb:all:4 && npm run rgb:all:5 && npm run rgb:all:6",
"rgb:all:1": "node tests/test_rgb --sync false --response percent",
"rgb:all:2": "node tests/test_rgb --sync true --response percent",
"rgb:all:3": "node tests/test_rgb --sync false --response bounds",
"rgb:all:4": "node tests/test_rgb --sync true --response bounds",
"rgb:all:5": "node tests/test_rgb --sync false --response blobs",
"rgb:all:6": "node tests/test_rgb --sync true --response blobs",
"rgb:mask": "npm run rgb:mask:1 && npm run rgb:mask:2 && npm run rgb:mask:3 && npm run rgb:mask:4 && npm run rgb:mask:5 && npm run rgb:mask:6",
"rgb:mask:1": "node tests/test_rgb2 --sync false --response percent",
"rgb:mask:2": "node tests/test_rgb2 --sync true --response percent",
"rgb:mask:3": "node tests/test_rgb2 --sync false --response bounds",
"rgb:mask:4": "node tests/test_rgb2 --sync true --response bounds",
"rgb:mask:5": "node tests/test_rgb2 --sync false --response blobs",
"rgb:mask:6": "node tests/test_rgb2 --sync true --response blobs",
"rgb:region": "npm run rgb:region:1 && npm run rgb:region:2 && npm run rgb:region:3 && npm run rgb:region:4 && npm run rgb:region:5 && npm run rgb:region:6",
"rgb:region:1": "node tests/test_rgb3 --sync false --response percent",
"rgb:region:2": "node tests/test_rgb3 --sync true --response percent",
"rgb:region:3": "node tests/test_rgb3 --sync false --response bounds",
"rgb:region:4": "node tests/test_rgb3 --sync true --response bounds",
"rgb:region:5": "node tests/test_rgb3 --sync false --response blobs",
"rgb:region:6": "node tests/test_rgb3 --sync true --response blobs",
"rgb:regions": "npm run rgb:regions:1 && npm run rgb:regions:2 && npm run rgb:regions:3 && npm run rgb:regions:4 && npm run rgb:regions:5 && npm run rgb:regions:6",
"rgb:regions:1": "node tests/test_rgb4 --sync false --response percent",
"rgb:regions:2": "node tests/test_rgb4 --sync true --response percent",
"rgb:regions:3": "node tests/test_rgb4 --sync false --response bounds",
"rgb:regions:4": "node tests/test_rgb4 --sync true --response bounds",
"rgb:regions:5": "node tests/test_rgb4 --sync false --response blobs",
"rgb:regions:6": "node tests/test_rgb4 --sync true --response blobs",
"rgb:all": "npm run rgb:all:percent && npm run rgb:all:bounds && npm run rgb:all:blobs",
"rgb:all:percent": "node tests/test_rgb --response percent",
"rgb:all:bounds": "node tests/test_rgb --response bounds",
"rgb:all:blobs": "node tests/test_rgb --response blobs",
"rgb:mask": "npm run rgb:mask:percent && npm run rgb:mask:bounds && npm run rgb:mask:blobs",
"rgb:mask:percent": "node tests/test_rgb2 --response percent",
"rgb:mask:bounds": "node tests/test_rgb2 --response bounds",
"rgb:mask:blobs": "node tests/test_rgb2 --response blobs",
"rgb:region": "npm run rgb:region:percent && npm run rgb:region:bounds && npm run rgb:region:blobs",
"rgb:region:percent": "node tests/test_rgb3 --response percent",
"rgb:region:bounds": "node tests/test_rgb3 --response bounds",
"rgb:region:blobs": "node tests/test_rgb3 --response blobs",
"rgb:regions": "npm run rgb:regions:percent && npm run rgb:regions:bounds && npm run rgb:regions:blobs",
"rgb:regions:percent": "node tests/test_rgb4 --response percent",
"rgb:regions:bounds": "node tests/test_rgb4 --response bounds",
"rgb:regions:blobs": "node tests/test_rgb4 --response blobs",
"rgba": "npm run rgba:all && npm run rgba:mask && npm run rgba:region && npm run rgba:regions",
"rgba:all": "npm run rgba:all:1 && npm run rgba:all:2 && npm run rgba:all:3 && npm run rgba:all:4 && npm run rgba:all:5 && npm run rgba:all:6",
"rgba:all:1": "node tests/test_rgba --sync false --response percent",
"rgba:all:2": "node tests/test_rgba --sync true --response percent",
"rgba:all:3": "node tests/test_rgba --sync false --response bounds",
"rgba:all:4": "node tests/test_rgba --sync true --response bounds",
"rgba:all:5": "node tests/test_rgba --sync false --response blobs",
"rgba:all:6": "node tests/test_rgba --sync true --response blobs",
"rgba:mask": "npm run rgba:mask:1 && npm run rgba:mask:2 && npm run rgba:mask:3 && npm run rgba:mask:4 && npm run rgba:mask:5 && npm run rgba:mask:6",
"rgba:mask:1": "node tests/test_rgba2 --sync false --response percent",
"rgba:mask:2": "node tests/test_rgba2 --sync true --response percent",
"rgba:mask:3": "node tests/test_rgba2 --sync false --response bounds",
"rgba:mask:4": "node tests/test_rgba2 --sync true --response bounds",
"rgba:mask:5": "node tests/test_rgba2 --sync false --response blobs",
"rgba:mask:6": "node tests/test_rgba2 --sync true --response blobs",
"rgba:region": "npm run rgba:region:1 && npm run rgba:region:2 && npm run rgba:region:3 && npm run rgba:region:4 && npm run rgba:region:5 && npm run rgba:region:6",
"rgba:region:1": "node tests/test_rgba3 --sync false --response percent",
"rgba:region:2": "node tests/test_rgba3 --sync true --response percent",
"rgba:region:3": "node tests/test_rgba3 --sync false --response bounds",
"rgba:region:4": "node tests/test_rgba3 --sync true --response bounds",
"rgba:region:5": "node tests/test_rgba3 --sync false --response blobs",
"rgba:region:6": "node tests/test_rgba3 --sync true --response blobs",
"rgba:regions": "npm run rgba:regions:1 && npm run rgba:regions:2 && npm run rgba:regions:3 && npm run rgba:regions:4 && npm run rgba:regions:5 && npm run rgba:regions:6",
"rgba:regions:1": "node tests/test_rgba4 --sync false --response percent",
"rgba:regions:2": "node tests/test_rgba4 --sync true --response percent",
"rgba:regions:3": "node tests/test_rgba4 --sync false --response bounds",
"rgba:regions:4": "node tests/test_rgba4 --sync true --response bounds",
"rgba:regions:5": "node tests/test_rgba4 --sync false --response blobs",
"rgba:regions:6": "node tests/test_rgba4 --sync true --response blobs",
"pam": "npm run pam:async && npm run pam:sync",
"pam:async": "npm run pam:gray:async && npm run pam:rgb:async && npm run pam:rgba:async",
"pam:gray:async": "node --expose-gc examples/createPam --pixfmt gray --sync false --response bounds --draw false --target regions",
"pam:rgb:async": "node --expose-gc examples/createPam --pixfmt rgb24 --sync false --response bounds --draw false --target regions",
"pam:rgba:async": "node --expose-gc examples/createPam --pixfmt rgba --sync false --response bounds --draw false --target regions",
"pam:sync": "npm run pam:gray:sync && npm run pam:rgb:sync && npm run pam:rgba:sync",
"pam:gray:sync": "node --expose-gc examples/createJpegs --pixfmt gray --sync true --response bounds --draw false --target regions",
"pam:rgb:sync": "node --expose-gc examples/createJpegs --pixfmt rgb24 --sync true --response bounds --draw false --target regions",
"pam:rgba:sync": "node --expose-gc examples/createJpegs --pixfmt rgba --sync true --response bounds --draw false --target regions",
"draw": "npm run draw:async && npm run draw:sync",
"draw:async": "npm run draw:gray:async && npm run draw:rgb:async && npm run draw:rgba:async",
"draw:gray:async": "node --expose-gc examples/createPam --pixfmt gray --sync false --response blobs --draw true --target regions",
"draw:rgb:async": "node --expose-gc examples/createPam --pixfmt rgb24 --sync false --response blobs --draw true --target regions",
"draw:rgba:async": "node --expose-gc examples/createPam --pixfmt rgba --sync false --response blobs --draw true --target regions",
"draw:sync": "npm run draw:gray:sync && npm run draw:rgb:sync && npm run draw:rgba:sync",
"draw:gray:sync": "node --expose-gc examples/createPam --pixfmt gray --sync true --response blobs --draw true --target regions",
"draw:rgb:sync": "node --expose-gc examples/createPam --pixfmt rgb24 --sync true --response blobs --draw true --target regions",
"draw:rgba:sync": "node --expose-gc examples/createPam --pixfmt rgba --sync true --response blobs --draw true --target regions",
"rgba:all": "npm run rgba:all:percent && npm run rgba:all:bounds && npm run rgba:all:blobs",
"rgba:all:percent": "node tests/test_rgba --response percent",
"rgba:all:bounds": "node tests/test_rgba --response bounds",
"rgba:all:blobs": "node tests/test_rgba -response blobs",
"rgba:mask": "npm run rgba:mask:percent && npm run rgba:mask:bounds && npm run rgba:mask:blobs",
"rgba:mask:percent": "node tests/test_rgba2 --response percent",
"rgba:mask:bounds": "node tests/test_rgba2 --response bounds",
"rgba:mask:blobs": "node tests/test_rgba2 --response blobs",
"rgba:region": "npm run rgba:region:percent && npm run rgba:region:bounds && npm run rgba:region:blobs",
"rgba:region:percent": "node tests/test_rgba3 --response percent",
"rgba:region:bounds": "node tests/test_rgba3 --response bounds",
"rgba:region:blobs": "node tests/test_rgba3 --response blobs",
"rgba:regions": "npm run rgba:regions:percent && npm run rgba:regions:bounds && npm run rgba:regions:blobs",
"rgba:regions:percent": "node tests/test_rgba4 --response percent",
"rgba:regions:bounds": "node tests/test_rgba4 --response bounds",
"rgba:regions:blobs": "node tests/test_rgba4 --response blobs",
"pam": "npm run pam:gray && npm run pam:rgb && npm run pam:rgba",
"pam:gray": "node --expose-gc examples/createPam --pixfmt gray --response bounds --draw false --target regions",
"pam:rgb": "node --expose-gc examples/createPam --pixfmt rgb24 --response bounds --draw false --target regions",
"pam:rgba": "node --expose-gc examples/createPam --pixfmt rgba --response bounds --draw false --target regions",
"draw": "npm run draw:gray&& npm run draw:rgb && npm run draw:rgba",
"draw:gray": "node --expose-gc examples/createPam --pixfmt gray --response blobs --draw true --target regions",
"draw:rgb": "node --expose-gc examples/createPam --pixfmt rgb24 --response blobs --draw true --target regions",
"draw:rgba": "node --expose-gc examples/createPam --pixfmt rgba --response blobs --draw true --target regions",
"draw:big": "node examples/createPam2",

@@ -144,3 +98,3 @@ "draw:big:gc": "node --expose-gc examples/createPam2"

"dependencies": {
"pixel-change": "1.0.0",
"pixel-change": "1.1.0",
"polygon-points": "^0.6.0"

@@ -150,3 +104,3 @@ },

"@ffmpeg-installer/ffmpeg": "^1.1.0",
"dotenv": "^7.0.0",
"dotenv": "^10.0.0",
"eslint": "^7.32.0",

@@ -159,3 +113,3 @@ "eslint-config-prettier": "^7.1.0",

"pipe2pam": "^0.6.2",
"prettier": "^2.5.0"
"prettier": "^2.5.1"
},

@@ -168,3 +122,6 @@ "private": false,

"README.md"
]
],
"engines": {
"node": ">=10"
}
}

@@ -7,22 +7,12 @@ # pam-diff

### Installation:
## Installation:
```
npm install pam-diff@latest --save
npm install pam-diff --save
```
#### _Important Note:_ The js-only version will no longer receive any updates. All future work will be dedicated to the n-api version because it is much more efficient.
## Changelog:
#### _New Feature:_ Async made default in 0.13.6. ~~Starting with version 0.13.0, the option to use worker threads can be enabled by passing `{async: true}` to the pam-diff constructor.~~
###### _version 1.1.0:_ Percent is now a float to allow for more precise results. Sync option is removed.
#### _New Feature:_ Starting with version 0.13.2, the option to get x y bounding box coordinates can be set by passing `{response: "bounds"}` to the pam-diff constructor.
#### _New Feature:_ Starting with version 0.13.5, the option to get the pixel buffer containing the drawn x y bounding box can be set by passing `{draw: true}` to the pam-diff constructor.
#### _New Feature:_ Starting with version 0.13.6, the option to filter results by connected component labelling can be set by passing `{response: "blobs"}` to the pam-diff constructor.
#### _New Feature:_ Starting with version 0.13.6, async behavior will now be default. If you need the pixel difference measurements to block the event loop, use `{sync: true}`.
#### _New Feature:_ Starting with version 1.0.0, pre-built binaries will be used. If binaries are not available, installation will fall back to node-gyp.
## Usage Options:

@@ -32,3 +22,3 @@

### all (default)
- ### all (default)

@@ -38,7 +28,7 @@ - All pixels will be targeted when checking for differences.

```javascript
const pamDiff = new PamDiff({ difference: 5, percent: 5 });
```
```javascript
const pamDiff = new PamDiff({ difference: 5, percent: 5 });
```
### regions
- ### regions

@@ -48,30 +38,30 @@ - Specific regions of pixels will be targeted when checking for differences and the rest will be ignored.

```javascript
const region1 = {
name: 'region1',
difference: 12,
percent: 22,
polygon: [
{ x: 0, y: 0 },
{ x: 0, y: 225 },
{ x: 100, y: 225 },
{ x: 100, y: 0 },
],
};
const region2 = {
name: 'region2',
difference: 14,
percent: 10,
polygon: [
{ x: 100, y: 0 },
{ x: 100, y: 225 },
{ x: 200, y: 225 },
{ x: 200, y: 0 },
],
};
const regions = [region1, region2];
const pamDiff = new PamDiff({ regions: regions });
```
```javascript
const region1 = {
name: 'region1',
difference: 12,
percent: 22,
polygon: [
{ x: 0, y: 0 },
{ x: 0, y: 225 },
{ x: 100, y: 225 },
{ x: 100, y: 0 },
],
};
const region2 = {
name: 'region2',
difference: 14,
percent: 10,
polygon: [
{ x: 100, y: 0 },
{ x: 100, y: 225 },
{ x: 200, y: 225 },
{ x: 200, y: 0 },
],
};
const regions = [region1, region2];
const pamDiff = new PamDiff({ regions: regions });
```
### mask
- ### mask

@@ -82,58 +72,58 @@ - Specific regions of pixels will be ignored when checking for differences.

```javascript
const region1 = {
name: 'region1',
polygon: [
{ x: 0, y: 0 },
{ x: 0, y: 225 },
{ x: 100, y: 225 },
{ x: 100, y: 0 },
],
};
const region2 = {
name: 'region2',
polygon: [
{ x: 100, y: 0 },
{ x: 100, y: 225 },
{ x: 200, y: 225 },
{ x: 200, y: 0 },
],
};
const regions = [region1, region2];
const pamDiff = new PamDiff({ difference: 12, percent: 10, mask: true, regions: regions });
```
```javascript
const region1 = {
name: 'region1',
polygon: [
{ x: 0, y: 0 },
{ x: 0, y: 225 },
{ x: 100, y: 225 },
{ x: 100, y: 0 },
],
};
const region2 = {
name: 'region2',
polygon: [
{ x: 100, y: 0 },
{ x: 100, y: 225 },
{ x: 200, y: 225 },
{ x: 200, y: 0 },
],
};
const regions = [region1, region2];
const pamDiff = new PamDiff({ difference: 12, percent: 10, mask: true, regions: regions });
```
##### Getting results back from the pixel difference detection:
###### Getting results back from the pixel difference detection:
1. event
- A _diff_ event will be emitted with a data object passed as the only argument.
- A _diff_ event will be emitted with a data object passed as the only argument.
```javascript
pamDiff.on('diff', data => {
console.log(data);
});
```
```javascript
pamDiff.on('diff', data => {
console.log(data);
});
```
2. callback
- A _callback_ function will be called with a data object passed as the only argument.
- The callback can be passed as the 2nd argument to the constructor or it can be added later.
- The callback can be passed as the 2nd argument to the constructor, or it can be added later.
```javascript
/* callback function */
function myCallback(data) {
console.log(data);
}
```javascript
/* callback function */
function myCallback(data) {
console.log(data);
}
/* via the constructor */
const pamDiff = new pamDiff({ difference: 10, percent: 20 }, myCallback);
/* via the constructor */
const pamDiff = new pamDiff({ difference: 10, percent: 20 }, myCallback);
/* via the setter */
pamDiff.callback = myCallback;
/* via the setter */
pamDiff.callback = myCallback;
/* via the chain-able setter */
pamDiff.setCallback(myCallback).setDifference(10).setPercent(20);
/* via the chain-able setter */
pamDiff.setCallback(myCallback).setDifference(10).setPercent(20);
/* remove the callback */
pamDiff.callback = null;
```
/* remove the callback */
pamDiff.callback = null;
```

@@ -144,90 +134,90 @@ ##### Expected results:

```
{
trigger: [
{ name: 'all', percent: 13 }
],
pam: <Buffer>,
headers: <Buffer>,
pixels: <Buffer>
}
```
```
{
trigger: [
{ name: 'all', percent: 13 }
],
pam: <Buffer>,
headers: <Buffer>,
pixels: <Buffer>
}
```
2. When targeting regions of pixels:
```
{
trigger: [
{ name: 'region1', percent: 13 },
{ name: 'region2', percent: 22 }
],
pam: <Buffer>,
headers: <Buffer>,
pixels: <Buffer>
}
```
```
{
trigger: [
{ name: 'region1', percent: 13 },
{ name: 'region2', percent: 22 }
],
pam: <Buffer>,
headers: <Buffer>,
pixels: <Buffer>
}
```
3. When targeting all pixels ignored by mask:
```
{
trigger: [
{ name: 'mask', percent: 13 }
],
pam: <Buffer>,
headers: <Buffer>,
pixels: <Buffer>
}
```
```
{
trigger: [
{ name: 'mask', percent: 13 }
],
pam: <Buffer>,
headers: <Buffer>,
pixels: <Buffer>
}
```
4. When targeting all pixels and setting {response: "bounds"}:
```
{
trigger: [
{ name: 'all', percent: 13, minX: 42, maxX: 399, minY: 113, maxY: 198 }
],
pam: <Buffer>,
headers: <Buffer>,
pixels: <Buffer>
}
```
```
{
trigger: [
{ name: 'all', percent: 13, minX: 42, maxX: 399, minY: 113, maxY: 198 }
],
pam: <Buffer>,
headers: <Buffer>,
pixels: <Buffer>
}
```
5. When targeting all pixels and setting {response: "blobs"}:
```
{
trigger: [
{
name: "all",
percent: 9,
minX: 137,
maxX: 1782,
minY: 392,
maxY: 695,
blobs: [
{
label: 0,
percent: 3,
minX: 1192,
maxX: 1486,
minY: 392,
maxY: 695
},
{
label: 1,
percent: 3,
minX: 1488,
maxX: 1782,
minY: 392,
maxY: 695
}
]
}
],
pam: <Buffer>,
headers: <Buffer>,
pixels: <Buffer>
}
```
```
{
trigger: [
{
name: "all",
percent: 9,
minX: 137,
maxX: 1782,
minY: 392,
maxY: 695,
blobs: [
{
label: 0,
percent: 3,
minX: 1192,
maxX: 1486,
minY: 392,
maxY: 695
},
{
label: 1,
percent: 3,
minX: 1488,
maxX: 1782,
minY: 392,
maxY: 695
}
]
}
],
pam: <Buffer>,
headers: <Buffer>,
pixels: <Buffer>
}
```

@@ -237,10 +227,1 @@ ### Other Resources:

View the [docs](https://kevingodell.github.io/pam-diff/PamDiff.html), [tests](https://github.com/kevinGodell/pam-diff/tree/master/tests), or [examples](https://github.com/kevinGodell/pam-diff/tree/master/examples) for more implementations.
### Future Plans:
- [x] Make pre-built binaries available when using node-gyp is not an option.
- [x] Include option to return coordinates for bounding box of changed pixels.
- [x] Include option to return pixel buffer containing bounding boxes.
- [x] Introduce blob filtering to group changed pixels with their neighbors.
- [x] Include option to return pixel buffer containing bounding boxes around blobs.
- [x] Make async worker threads the default. Can be overridden with {sync: true}.

Sorry, the diff of this file is not supported yet

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