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

pixel-change

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pixel-change - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

78

lib/pixel-change.js

@@ -13,3 +13,3 @@ 'use strict';

* @requires events.EventEmitter
* @version v0.0.5
* @version v0.0.8
*/

@@ -23,3 +23,3 @@ class PixelChange extends EventEmitter {

* @param {Number} options.depth - 1 for gray, 3 for rgb, or 4 for rgba.
* @param {Number} options.difference - Difference level threshold ranging from 1 to 255. Lower number is more sensitive.
* @param {Number} options.diff - Difference between 2 pixels ranging from 1 to 255. Lower number is more sensitive to change.
* @param {Number} options.percent - Percent of pixels that meet or exceed difference threshold.

@@ -34,3 +34,3 @@ * @param {Function} [callback] - Function to be called when pixel change is detected.

}
if (options && options.width && options.height && options.depth && options.difference && options.percent) {
if (options && options.width && options.height && options.depth && options.diff && options.percent) {

@@ -40,3 +40,3 @@ this._width = parseInt(options.width);

this._depth = parseInt(options.depth);
this._difference = parseInt(options.difference);
this._diff = parseInt(options.diff);
this._percent = parseInt(options.percent);

@@ -52,3 +52,3 @@

if (this._difference < 1 || this._difference > 255) {
if (this._diff < 1 || this._diff > 255) {
throw new Error('Difference value must be between 1 and 255');

@@ -64,9 +64,9 @@ }

case 1 :
this._pixelChangeEngine = bindings.compareGrayPixels.bind(this, this._width, this._height, this._difference);
this._pixelChangeEngine = bindings.compareGrayPixels.bind(this, this._width, this._height, this._diff);
break;
case 3 :
this._pixelChangeEngine = bindings.compareRgbPixels.bind(this, this._width, this._height, this._difference);
this._pixelChangeEngine = bindings.compareRgbPixels.bind(this, this._width, this._height, this._diff);
break;
case 4 :
this._pixelChangeEngine = bindings.compareRgbaPixels.bind(this, this._width, this._height, this._difference);
this._pixelChangeEngine = bindings.compareRgbaPixels.bind(this, this._width, this._height, this._diff);
break;

@@ -77,4 +77,2 @@ default :

//byte size of image will be width * height * depth

@@ -176,2 +174,62 @@ this._size = this._width * this._height * this._depth;

/**
* Get the region specific percentage of different pixels between 2 gray pixel buffers.
*
* @param {Number} width - Width of image.
* @param {Number} height - Height of image.
* @param {Array} regions - Array of regions. [{name: "reg1", diff: 5, count: 76800, bitset: Buffer}]
* @param {string} regions[i].name - Name of region.
* @param {Number} regions[i].diff - Difference between 2 pixels, 1 to 255.
* @param {Number} regions[i].count - Total number of pixels in region. (Number of 1's in bitset)
* @param {Buffer} regions[i].bitset - Buffer of 1's and 0's to use as bitset for each pixel of image. 0 means that the index of the pixel is not in the region, while 1 indicates that it is. The pixel array is indexed from top left to bottom right. An image that is 640x480 will have 307200 pixels. The bitset for an image of that size is 307200, with 1's for each pixel that is in the targeted region, and 0 for the rest.
* @param {Buffer} buf0 - Buffer array of pixels.
* @param {Buffer} buf1 - Buffer array of pixels.
* @returns {Number} - Returns the percentage of pixels that are different.
* @static
* @public
*/
static compareGrayRegions(width, height, regions, buf0, buf1) {
return bindings.compareGrayRegions(width, height, regions, buf0, buf1);
}
/**
* Get the region specific percentage of different pixels between 2 rgb pixel buffers.
*
* @param {Number} width - Width of image.
* @param {Number} height - Height of image.
* @param {Array} regions - Array of regions. [{name: "reg1", diff: 5, count: 76800, bitset: Buffer}]
* @param {string} regions[i].name - Name of region.
* @param {Number} regions[i].diff - Difference between 2 pixels, 1 to 255.
* @param {Number} regions[i].count - Total number of pixels in region. (Number of 1's in bitset)
* @param {Buffer} regions[i].bitset - Buffer of 1's and 0's to use as bitset for each pixel of image. 0 means that the index of the pixel is not in the region, while 1 indicates that it is. The pixel array is indexed from top left to bottom right. An image that is 640x480 will have 307200 pixels. The bitset for an image of that size is 307200, with 1's for each pixel that is in the targeted region, and 0 for the rest.
* @param {Buffer} buf0 - Buffer array of pixels.
* @param {Buffer} buf1 - Buffer array of pixels.
* @returns {Number} - Returns the percentage of pixels that are different.
* @static
* @public
*/
static compareRgbRegions(width, height, regions, buf0, buf1) {
return bindings.compareRgbRegions(width, height, regions, buf0, buf1);
}
/**
* Get the region specific percentage of different pixels between 2 rgba pixel buffers.
*
* @param {Number} width - Width of image.
* @param {Number} height - Height of image.
* @param {Array} regions - Array of regions. [{name: "reg1", diff: 5, count: 76800, bitset: Buffer}]
* @param {string} regions[i].name - Name of region.
* @param {Number} regions[i].diff - Difference between 2 pixels, 1 to 255.
* @param {Number} regions[i].count - Total number of pixels in region. (Number of 1's in bitset)
* @param {Buffer} regions[i].bitset - Buffer of 1's and 0's to use as bitset for each pixel of image. 0 means that the index of the pixel is not in the region, while 1 indicates that it is. The pixel array is indexed from top left to bottom right. An image that is 640x480 will have 307200 pixels. The bitset for an image of that size is 307200, with 1's for each pixel that is in the targeted region, and 0 for the rest.
* @param {Buffer} buf0 - Buffer array of pixels.
* @param {Buffer} buf1 - Buffer array of pixels.
* @returns {Number} - Returns the percentage of pixels that are different.
* @static
* @public
*/
static compareRgbaRegions(width, height, regions, buf0, buf1) {
return bindings.compareRgbaRegions(width, height, regions, buf0, buf1);
}
static jsCompareGrayPixels(width, height, diff, buf0, buf1) {

@@ -178,0 +236,0 @@ if (!width || !height || !diff || !buf0 || !buf1) {

13

package.json
{
"name": "pixel-change",
"version": "0.0.7",
"version": "0.0.8",
"description": "Measure differences between 2 identically sized buffer arrays of gray, rgb, or rgba pixels.",

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

"preversion": "npm test",
"postversion": "npm run jsdoc",
"jsdoc": "jsdoc lib/pixel-change.js -d docs && git commit -m 'update docs' -- docs",
"local": "npm install && node test/local && node test/local2 && node test/local3"
"postversion": "npm run doc",
"doc": "jsdoc lib/pixel-change.js -d docs && git commit -m 'update docs' -- docs",
"local": "npm install && node test/local && node test/local2 && node test/local3",
"compare": "npm install && node test/js_vs_cpp && node test/js_vs_cpp2 && node test/js_vs_cpp3",
"regions": "npm install && node test/gray_regions && node test/rgb_regions && node test/rgba_regions"
},

@@ -54,3 +56,4 @@ "repository": {

"dependencies": {
"node-addon-api": "^1.2.0"
"node-addon-api": "^1.2.0",
"polygon-points": "^0.5.1"
},

@@ -57,0 +60,0 @@ "devDependencies": {

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