Comparing version 0.8.4 to 0.8.5
99
index.js
@@ -87,2 +87,3 @@ // jshint esversion: 6, globalstrict: true, strict: true, bitwise: false | ||
this._regionsLength = this._regions.length; | ||
this._createPointsInPolygons(this._regions, this._width, this._height); | ||
}; | ||
@@ -109,2 +110,17 @@ | ||
PamDiff.prototype._createPointsInPolygons = function (regions, width, height) { | ||
if (regions && width && height) { | ||
this._pointsInPolygons = []; | ||
for (const region of regions) { | ||
const array = []; | ||
for (let y = 0, i = 0; y < height; y++) { | ||
for (let x = 0; x < width; x++, i++) { | ||
array.push(region.polygon.containsPoint(x, y)); | ||
} | ||
} | ||
this._pointsInPolygons.push(array); | ||
} | ||
} | ||
}; | ||
//convert rgb to gray | ||
@@ -147,4 +163,4 @@ PamDiff.prototype._averageToGray = function (r, g, b) { | ||
for (let j = 0; j < this._regionsLength; j++) { | ||
if (this._regions[j].polygon.containsPoint(x, y) === true) { | ||
this._regions[j].diffs++; | ||
if (this._pointsInPolygons[j][i] === true) { | ||
this._regions[j].diffs++; | ||
} | ||
@@ -169,3 +185,9 @@ } | ||
if (regionDiffArray.length > 0) { | ||
this.emit('diff', {trigger: regionDiffArray, pam: chunk.pam}); | ||
const data = {trigger: regionDiffArray, pam: chunk.pam}; | ||
if (this._readableState.pipesCount > 0) { | ||
this.push(data); | ||
} | ||
if (this.listenerCount('diff') > 0) { | ||
this.emit('diff', data); | ||
} | ||
} | ||
@@ -175,3 +197,9 @@ } else { | ||
if (percent >= this._percent) { | ||
this.emit('diff', {trigger: [{name: 'percent', percent: percent}], pam: chunk.pam}); | ||
const data = {trigger: [{name: 'percent', percent: percent}], pam: chunk.pam}; | ||
if (this._readableState.pipesCount > 0) { | ||
this.push(data); | ||
} | ||
if (this.listenerCount('diff') > 0) { | ||
this.emit('diff', data); | ||
} | ||
} | ||
@@ -191,3 +219,3 @@ this._diffs = 0; | ||
for (let j = 0; j < this._regionsLength; j++) { | ||
if (diff >= this._regions[j].difference && this._regions[j].polygon.containsPoint(x, y) === true) { | ||
if (this._pointsInPolygons[j][i] === true && diff >= this._regions[j].difference) { | ||
this._regions[j].diffs++; | ||
@@ -214,3 +242,9 @@ } | ||
if (regionDiffArray.length > 0) { | ||
this.emit('diff', {trigger: regionDiffArray, pam: chunk.pam}); | ||
const data = {trigger: regionDiffArray, pam: chunk.pam}; | ||
if (this._readableState.pipesCount > 0) { | ||
this.push(data); | ||
} | ||
if (this.listenerCount('diff') > 0) { | ||
this.emit('diff', data); | ||
} | ||
} | ||
@@ -220,3 +254,9 @@ } else { | ||
if (percent >= this._percent) { | ||
this.emit('diff', {trigger: [{name: 'percent', percent: percent}], pam: chunk.pam}); | ||
const data = {trigger: [{name: 'percent', percent: percent}], pam: chunk.pam}; | ||
if (this._readableState.pipesCount > 0) { | ||
this.push(data); | ||
} | ||
if (this.listenerCount('diff') > 0) { | ||
this.emit('diff', data); | ||
} | ||
} | ||
@@ -230,4 +270,4 @@ this._diffs = 0; | ||
this._newPix = chunk.pixels; | ||
for (let y = 0, i = 0; y < this._height; y++) { | ||
for (let x = 0; x < this._width; x++, i += 3) { | ||
for (let y = 0, i = 0, p = 0; y < this._height; y++) { | ||
for (let x = 0; x < this._width; x++, i += 3, p++) { | ||
if (this._oldPix[i] !== this._newPix[i] || this._oldPix[i + 1] !== this._newPix[i + 1] || this._oldPix[i + 2] !== this._newPix[i + 2]) { | ||
@@ -237,3 +277,3 @@ const diff = Math.abs(this._grayscale(this._oldPix[i], this._oldPix[i + 1], this._oldPix[i + 2]) - this._grayscale(this._newPix[i], this._newPix[i + 1], this._newPix[i + 2])); | ||
for (let j = 0; j < this._regionsLength; j++) { | ||
if (diff >= this._regions[j].difference && this._regions[j].polygon.containsPoint(x, y) === true) { | ||
if (this._pointsInPolygons[j][p] === true && diff >= this._regions[j].difference) { | ||
this._regions[j].diffs++; | ||
@@ -260,3 +300,9 @@ } | ||
if (regionDiffArray.length > 0) { | ||
this.emit('diff', {trigger: regionDiffArray, pam: chunk.pam}); | ||
const data = {trigger: regionDiffArray, pam: chunk.pam}; | ||
if (this._readableState.pipesCount > 0) { | ||
this.push(data); | ||
} | ||
if (this.listenerCount('diff') > 0) { | ||
this.emit('diff', data); | ||
} | ||
} | ||
@@ -266,3 +312,9 @@ } else { | ||
if (percent >= this._percent) { | ||
this.emit('diff', {trigger: [{name: 'percent', percent: percent}], pam: chunk.pam}); | ||
const data = {trigger: [{name: 'percent', percent: percent}], pam: chunk.pam}; | ||
if (this._readableState.pipesCount > 0) { | ||
this.push(data); | ||
} | ||
if (this.listenerCount('diff') > 0) { | ||
this.emit('diff', data); | ||
} | ||
} | ||
@@ -276,4 +328,4 @@ this._diffs = 0; | ||
this._newPix = chunk.pixels; | ||
for (let y = 0, i = 0; y < this._height; y++) { | ||
for (let x = 0; x < this._width; x++, i += 4) { | ||
for (let y = 0, i = 0, p = 0; y < this._height; y++) { | ||
for (let x = 0; x < this._width; x++, i += 4, p++) { | ||
if (this._oldPix[i] !== this._newPix[i] || this._oldPix[i + 1] !== this._newPix[i + 1] || this._oldPix[i + 2] !== this._newPix[i + 2]) { | ||
@@ -283,3 +335,3 @@ const diff = Math.abs(this._grayscale(this._oldPix[i], this._oldPix[i + 1], this._oldPix[i + 2]) - this._grayscale(this._newPix[i], this._newPix[i + 1], this._newPix[i + 2])); | ||
for (let j = 0; j < this._regionsLength; j++) { | ||
if (diff >= this._regions[j].difference && this._regions[j].polygon.containsPoint(x, y) === true) { | ||
if (this._pointsInPolygons[j][p] === true && diff >= this._regions[j].difference) { | ||
this._regions[j].diffs++; | ||
@@ -306,3 +358,9 @@ } | ||
if (regionDiffArray.length > 0) { | ||
this.emit('diff', {trigger: regionDiffArray, pam: chunk.pam}); | ||
const data = {trigger: regionDiffArray, pam: chunk.pam}; | ||
if (this._readableState.pipesCount > 0) { | ||
this.push(data); | ||
} | ||
if (this.listenerCount('diff') > 0) { | ||
this.emit('diff', data); | ||
} | ||
} | ||
@@ -312,3 +370,9 @@ } else { | ||
if (percent >= this._percent) { | ||
this.emit('diff', {trigger: [{name: 'percent', percent: percent}], pam: chunk.pam}); | ||
const data = {trigger: [{name: 'percent', percent: percent}], pam: chunk.pam}; | ||
if (this._readableState.pipesCount > 0) { | ||
this.push(data); | ||
} | ||
if (this.listenerCount('diff') > 0) { | ||
this.emit('diff', data); | ||
} | ||
} | ||
@@ -325,2 +389,3 @@ this._diffs = 0; | ||
this._length = this._oldPix.length; | ||
this._createPointsInPolygons(this._regions, this._width, this._height); | ||
switch (chunk.tupltype) { | ||
@@ -327,0 +392,0 @@ case 'blackandwhite' : |
{ | ||
"name": "pam-diff", | ||
"version": "0.8.4", | ||
"version": "0.8.5", | ||
"description": "Measure differences between pixel arrays extracted from pam images", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
21359
384