pixelmatch
Advanced tools
Comparing version 1.0.0 to 1.1.0
32
index.js
@@ -7,3 +7,3 @@ 'use strict'; | ||
var maxDelta = 255 * 255 * 4 * (threshold === undefined ? 0.005 : threshold), | ||
var maxDelta = 255 * 255 * 3 * (threshold === undefined ? 0.005 : threshold), | ||
shift = antialiasing === undefined ? 1 : antialiasing, | ||
@@ -61,8 +61,21 @@ diff = 0; | ||
function colorDelta(img1, img2, pos1, pos2) { | ||
var r = img1[pos1 + 0] - img2[pos2 + 0], | ||
g = img1[pos1 + 1] - img2[pos2 + 1], | ||
b = img1[pos1 + 2] - img2[pos2 + 2], | ||
a = img1[pos1 + 3] - img2[pos2 + 3]; | ||
var a1 = img1[pos1 + 3] / 255, | ||
a2 = img2[pos2 + 3] / 255, | ||
return (r * r) + (g * g) + (b * b) + (a * a); | ||
r1 = img1[pos1 + 0] * a1, | ||
g1 = img1[pos1 + 1] * a1, | ||
b1 = img1[pos1 + 2] * a1, | ||
r2 = img2[pos2 + 0] * a2, | ||
g2 = img2[pos2 + 1] * a2, | ||
b2 = img2[pos2 + 2] * a2, | ||
y1 = 0.299 * r1 + 0.587 * g1 + 0.114 * b1, | ||
y2 = 0.299 * r2 + 0.587 * g2 + 0.114 * b2, | ||
yd = y1 - y2, | ||
ud = 0.492 * (b1 - y1) - 0.492 * (b1 - y2), | ||
vd = 0.877 * (r1 - y1) - 0.877 * (r2 - y2); | ||
return (yd * yd) + (ud * ud) + (vd * vd); | ||
} | ||
@@ -78,5 +91,6 @@ | ||
function grayPixel(img, pos) { | ||
return 0.30 * img[pos + 0] + | ||
0.59 * img[pos + 1] + | ||
0.11 * img[pos + 2]; | ||
var a = img[pos + 3] / 255; | ||
return (0.30 * img[pos + 0] + | ||
0.59 * img[pos + 1] + | ||
0.11 * img[pos + 2]) * a; | ||
} |
{ | ||
"name": "pixelmatch", | ||
"version": "1.0.0", | ||
"description": "A simpe, tiny and fast JavaScript image comparison tool and library.", | ||
"version": "1.1.0", | ||
"description": "The smallest and fastest pixel-level image comparison library.", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "bin": { |
@@ -10,10 +10,10 @@ ## pixelmatch | ||
Inspired by [Resemble.js](https://github.com/Huddle/Resemble.js) and | ||
[Blink-diff](https://github.com/yahoo/blink-diff) | ||
and borrows the algorithm from the latter. | ||
Unlike these libraries, pixelmatch is under 80 lines of code, | ||
has no dependencies, and works on raw image data arrays, | ||
so it's blazing fast and can be used in any environment (Node or browsers). | ||
[Blink-diff](https://github.com/yahoo/blink-diff), | ||
including features like anti-aliasing detection and perceptive color metrics. | ||
Unlike these libraries, pixelmatch is under **100 lines of code**, | ||
has **no dependencies**, and works on **raw arrays** of image data, | ||
so it's **blazing fast** and can be used in **any environment** (Node or browsers). | ||
```js | ||
var numMismatchedPixels = pixelmatch(img1.data, img2.data, diff.data, 800, 600); | ||
var numDiffPixels = pixelmatch(img1.data, img2.data, diff.data, 800, 600); | ||
``` | ||
@@ -25,9 +25,7 @@ | ||
- `img1` — image data of the first image (`Buffer` or `Uint8Array`) | ||
- `img2` — image data of the second image | ||
- `output` — image data to write the diff to | ||
- `width` — width of the images | ||
- `height` — height of the images | ||
- `threshold` — matching threshold, `0.005` by default, ranges from `0` to `1` | ||
- `antialiasing` — radius of antialiasing to ignore in pixels, `1` by default | ||
- `img1`, `img2` — Image data of the images to compare (`Buffer` or `Uint8Array`). | ||
- `output` — Image data to write the diff to. | ||
- `width`, `height` — Width and height of the images. Note that all three images need to have the same dimensions. | ||
- `threshold` — Matching threshold, ranges from `0` to `1`. Smaller values make the comparison more sensitive. `0.005` by default. | ||
- `antialiasing` — Radius of antialiasing to ignore in pixels. `1` by default. | ||
@@ -59,6 +57,9 @@ Compares two images, writes the output diff and returns the number of mismatched pixels. | ||
### Changelog | ||
### Example output | ||
#### 1.0.0 (Oct 14, 2015) | ||
| expected | actual | diff | | ||
| --- | --- | --- | | ||
| ![](https://mapbox.s3.amazonaws.com/mapbox-gl-native/tests/4307.1/text-halo-blur/default/expected.png) | ![](https://mapbox.s3.amazonaws.com/mapbox-gl-native/tests/4307.1/text-halo-blur/default/actual.png) | ![1diff](https://cloud.githubusercontent.com/assets/25395/10480779/d9ad1c66-7274-11e5-8b6c-9b4987316eaa.png) | | ||
| ![](https://pbs.twimg.com/media/CRYXm86VAAQxo-o.png) | ![](https://pbs.twimg.com/media/CRYXm9uUYAAIGAf.png) | ![](https://pbs.twimg.com/media/CRYXnAAUwAEsuzb.png) | | ||
- Initial release. | ||
### [Changelog](https://github.com/mapbox/pixelmatch/releases) |
@@ -9,3 +9,3 @@ 'use strict'; | ||
diffTest('1a', '1b', '1diff', 0.001, 1, 144); | ||
diffTest('1a', '1b', '1diff', 0.001, 1, 141); | ||
@@ -12,0 +12,0 @@ function diffTest(imgPath1, imgPath2, diffPath, threshold, antialiasing, expectedMismatch) { |
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
711279
95
63