pixelmatch
Advanced tools
Comparing version 5.1.0 to 5.2.0
27
index.js
@@ -10,3 +10,4 @@ 'use strict'; | ||
aaColor: [255, 255, 0], // color of anti-aliased pixels in diff output | ||
diffColor: [255, 0, 0], // color of different pixels in diff output | ||
diffColor: [255, 0, 0], // color of different pixels in diff output | ||
diffColorAlt: null, // whether to detect dark on light differences between img1 and img2 and set an alternative color to differentiate between the two | ||
diffMask: false // draw the diff over a transparent background (a mask) | ||
@@ -46,6 +47,3 @@ }; | ||
const maxDelta = 35215 * options.threshold * options.threshold; | ||
let diff = 0; | ||
const [aaR, aaG, aaB] = options.aaColor; | ||
const [diffR, diffG, diffB] = options.diffColor; | ||
@@ -58,7 +56,7 @@ // compare each pixel of one image against the other one | ||
// squared YUV distance between colors at this pixel position | ||
// squared YUV distance between colors at this pixel position, negative if the img2 pixel is darker | ||
const delta = colorDelta(img1, img2, pos, pos); | ||
// the color difference is above the threshold | ||
if (delta > maxDelta) { | ||
if (Math.abs(delta) > maxDelta) { | ||
// check it's a real rendering difference or just anti-aliasing | ||
@@ -69,7 +67,9 @@ if (!options.includeAA && (antialiased(img1, x, y, width, height, img2) || | ||
// note that we do not include such pixels in a mask | ||
if (output && !options.diffMask) drawPixel(output, pos, aaR, aaG, aaB); | ||
if (output && !options.diffMask) drawPixel(output, pos, ...options.aaColor); | ||
} else { | ||
// found substantial difference not caused by anti-aliasing; draw it as red | ||
if (output) drawPixel(output, pos, diffR, diffG, diffB); | ||
// found substantial difference not caused by anti-aliasing; draw it as such | ||
if (output) { | ||
drawPixel(output, pos, ...(delta < 0 && options.diffColorAlt || options.diffColor)); | ||
} | ||
diff++; | ||
@@ -203,3 +203,5 @@ } | ||
const y = rgb2y(r1, g1, b1) - rgb2y(r2, g2, b2); | ||
const y1 = rgb2y(r1, g1, b1); | ||
const y2 = rgb2y(r2, g2, b2); | ||
const y = y1 - y2; | ||
@@ -211,3 +213,6 @@ if (yOnly) return y; // brightness difference only | ||
return 0.5053 * y * y + 0.299 * i * i + 0.1957 * q * q; | ||
const delta = 0.5053 * y * y + 0.299 * i * i + 0.1957 * q * q; | ||
// encode whether the pixel lightens or darkens in the sign | ||
return y1 > y2 ? -delta : delta; | ||
} | ||
@@ -214,0 +219,0 @@ |
{ | ||
"name": "pixelmatch", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "The smallest and fastest pixel-level image comparison library.", | ||
@@ -13,8 +13,8 @@ "main": "index.js", | ||
"dependencies": { | ||
"pngjs": "^3.4.0" | ||
"pngjs": "^4.0.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^6.4.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-mourner": "^3.0.0", | ||
"tape": "^4.11.0" | ||
"tape": "^4.13.2" | ||
}, | ||
@@ -21,0 +21,0 @@ "scripts": { |
@@ -52,2 +52,3 @@ # pixelmatch | ||
- `diffColor` — The color of differing pixels in the diff output in `[R, G, B]` format. `[255, 0, 0]` by default. | ||
- `diffColorAlt` — An alternative color to use for dark on light differences to differentiate between "added" and "removed" parts. If not provided, all differing pixels use the color specified by `diffColor`. `null` by default. | ||
- `diffMask` — Draw the diff over a transparent background (a mask), rather than over the original image. Will not draw anti-aliased pixels (if detected). | ||
@@ -107,5 +108,5 @@ | ||
```html | ||
<script src="https://bundle.run/pixelmatch@5.0.2"></script> | ||
<script src="https://bundle.run/pixelmatch"></script> | ||
``` | ||
## [Changelog](https://github.com/mapbox/pixelmatch/releases) |
Sorry, the diff of this file is not supported yet
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
16137
189
111
+ Addedpngjs@4.0.1(transitive)
- Removedpngjs@3.4.0(transitive)
Updatedpngjs@^4.0.1