Package Exports
- pixel-change
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pixel-change) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
pixel-change
EXPERIMENTAL. FIRST ATTEMPT AT USING N-API WHICH IS ONLY SUPPORTED ON NODE 8.5 AND UP
Measure differences between 2 identically sized buffer arrays of gray, rgb, or rgba pixels. Backed by c++ libraries iterating pixel buffers, converting to grayscale, measuring differences, and reporting back the percent of pixels that have changed.
installation
npm install pixel-changeusage
const PixelChange = require('pixel-change');
/* -- access static methods -- */
//will return a percent of how many gray pixels are changed between the 2 buffer pixel arrays
const percent = PixelChange.compareGrayPixels(width, height, diff, buffer1, buffer2);
//will return a percent of how many rgb pixels are changed between the 2 buffer pixel arrays
const percent = PixelChange.compareRgbPixels(width, height, diff, buffer1, buffer2);
//will return a percent of how many rgba pixels are changed between the 2 buffer pixel arrays
const percent = PixelChange.compareRgbaPixels(width, height, diff, buffer1, buffer2);
/* -- access instance methods -- */
//create a new instance to access convenience methods
const pc = new PixelChange({width: 1920, height: 1080, depth: 3, diff: 25, percent: 12});
//listen to change event when percent of different pixels is detected
pc.on('change', (percent)=>{
//do something when change event is dispatched because of percent
});
//compare 2 buffers, will dispatch event if change is detected
pc.compare(buffer1, buffer2);
//alternate convenience method, keep feeding pixel buffer via push
//instance will cache previous buffer to compare with next one pushed
pc.push(buffer);
/* -- alternative to listening to "change" event
//pass callback to new instance
const pc = new PixelChange({width: 1920, height: 1080, depth: 3, diff: 25, percent: 12}, (err, percent)=>{
if (err) {
throw err;
}
//do something when callback is called with percent
});