Skip to content

Commit

Permalink
Merge pull request #6 from mapbox/no-diff-image
Browse files Browse the repository at this point in the history
Avoid need for diff image writing
  • Loading branch information
mourner committed Oct 23, 2015
2 parents 3d24e31 + ba8441d commit eed59ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ function pixelmatch(img1, img2, output, width, height, options) {
if (!options.includeAA && (antialiased(img1, x, y, width, height, img2) ||
antialiased(img2, x, y, width, height, img1))) {
// one of the pixels is anti-aliasing; draw as yellow and do not count as difference
drawPixel(output, pos, 255, 255, 0);
if (output) drawPixel(output, pos, 255, 255, 0);

} else {
// found substantial difference not caused by anti-aliasing; draw it as red
drawPixel(output, pos, 255, 0, 0);
if (output) drawPixel(output, pos, 255, 0, 0);
diff++;
}

} else {
// pixels are similar; draw background as grayscale image blended with white
var val = 255 - 0.1 * (255 - grayPixel(img1, pos)) * img1[pos + 3] / 255;
drawPixel(output, pos, val, val, val);
if (output) drawPixel(output, pos, val, val, val);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ function diffTest(imgPath1, imgPath2, diffPath, threshold, includeAA, expectedMi
includeAA: includeAA
});

var mismatch2 = match(img1.data, img2.data, null, diff.width, diff.height, {
threshold: threshold,
includeAA: includeAA
});

t.same(diff.data, expectedDiff.data, 'diff image');
t.same(mismatch, expectedMismatch, 'number of mismatched pixels');
t.same(mismatch, mismatch2, 'number of mismatched pixels');

t.end();
});
Expand Down

0 comments on commit eed59ff

Please sign in to comment.