|
196 | 196 | for (i = 0; i < length; i += 4) {
|
197 | 197 | var pixelA = Array.prototype.slice.call(aData, i, i+3);
|
198 | 198 | var pixelB = Array.prototype.slice.call(bData, i, i+3);
|
199 |
| - var diffPixel = diffPixels(pixelA, pixelB, options); |
| 199 | + var pixelC = diffPixels(pixelA, pixelB, options); |
200 | 200 | for (var rgbIndex = 0; rgbIndex < 4; rgbIndex++) {
|
201 |
| - cData[i+rgbIndex] = diffPixel[rgbIndex]; |
| 201 | + cData[i+rgbIndex] = pixelC[rgbIndex]; |
202 | 202 | }
|
203 | 203 | }
|
204 | 204 |
|
|
244 | 244 | j = 4 * (row * b.width + column);
|
245 | 245 | var pixelA = Array.prototype.slice.call(cData, i, i+3);
|
246 | 246 | var pixelB = Array.prototype.slice.call(bData, j, j+3);
|
247 |
| - var diffPixel = diffPixels(pixelA, pixelB, options); |
| 247 | + var pixelC = diffPixels(pixelA, pixelB, options); |
248 | 248 | for (var rgbIndex = 0; rgbIndex < 4; rgbIndex++) {
|
249 |
| - cData[i+rgbIndex] = diffPixel[rgbIndex]; |
| 249 | + cData[i+rgbIndex] = pixelC[rgbIndex]; |
250 | 250 | }
|
251 | 251 | }
|
252 | 252 | }
|
|
267 | 267 |
|
268 | 268 | /**
|
269 | 269 | * Differentiates two rgb pixels by subtracting color values.
|
270 |
| - * The light value for each color marks the difference gap. |
| 270 | + * @see https://github.com/HumbleSoftware/js-imagediff/pull/52 |
271 | 271 | *
|
272 |
| - * @see https://github.com/HumbleSoftware/js-imagediff/issues/34 |
273 | 272 | * @param {Object} options
|
274 |
| - * options.lightness: light added to color value, increasing differences visibility |
275 |
| - * options.rgb : array used to specify rgb balance instead of lightness |
276 |
| - * options.stack: stack differences on top of the original image, preserving common pixels |
| 273 | + * options.lightboost: increases differences visibility with a light boost. |
| 274 | + * options.diffColor: a rgb array used to specify differences color instead of light gap. |
| 275 | + * options.stack: stacks differences on top of the original image, preserving common pixels. |
277 | 276 | *
|
278 | 277 | * @returns {Array} pixel rgba values between 0 and 255.
|
279 | 278 | */
|
280 | 279 | function diffPixels(pixelA, pixelB, options) {
|
281 |
| - var lightness = options && options.lightness || 25; |
282 |
| - if (options && options.lightness === 0) lightness = 0; |
283 |
| - var diffColor = options && options.rgb || [lightness,lightness,lightness]; |
284 |
| - var stack = options && options.stack; |
285 |
| - // diffPixel = [r,g,b,a] |
286 |
| - var diffPixel = [0,0,0,255]; |
| 280 | + var lightboost = options && options.lightboost || 0; |
| 281 | + var diffColor = options && options.diffColor || false; |
| 282 | + var stack = options && options.stack || false; |
| 283 | + // pixel = [r,g,b,a] |
| 284 | + var pixelC = [0,0,0,255]; |
287 | 285 | for (var rgbIndex = 0; rgbIndex < 3 ; rgbIndex++) {
|
288 |
| - diffPixel[rgbIndex] = Math.abs(pixelA[rgbIndex] - pixelB[rgbIndex]); |
289 |
| - if (diffPixel[rgbIndex] > 0) { |
290 |
| - // Optionally colors area of difference, adds visibility with lightness. |
291 |
| - diffPixel[rgbIndex] += diffColor[rgbIndex]; |
292 |
| - diffPixel[rgbIndex] = Math.min(diffPixel[rgbIndex], 255); |
| 286 | + pixelC[rgbIndex] = Math.abs(pixelA[rgbIndex] - pixelB[rgbIndex]); |
| 287 | + if (pixelC[rgbIndex] > 0) { |
| 288 | + if (diffColor) pixelC[rgbIndex] = diffColor[rgbIndex]; |
| 289 | + pixelC[rgbIndex] = Math.min(pixelC[rgbIndex] + lightboost, 255); |
293 | 290 | }
|
294 | 291 | else if (stack) {
|
295 |
| - // If options.stack and no pixel differences are found, |
296 |
| - // print original pixel instead of a black (0) pixel. |
297 |
| - diffPixel[rgbIndex] = pixelA[rgbIndex]; |
| 292 | + pixelC[rgbIndex] = pixelA[rgbIndex]; |
298 | 293 | }
|
299 | 294 | }
|
300 |
| - return diffPixel; |
| 295 | + return pixelC; |
301 | 296 | }
|
302 | 297 |
|
303 | 298 | // Validation
|
|
0 commit comments