Skip to content

Commit 085205c

Browse files
committed
optimize diff drawing, close #105
1 parent ad43c33 commit 085205c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export default function pixelmatch(img1, img2, output, width, height, options) {
4040
// maximum acceptable square distance between two colors;
4141
// 35215 is the maximum possible value for the YIQ difference metric
4242
const maxDelta = 35215 * options.threshold * options.threshold;
43+
const [aaR, aaG, aaB] = options.aaColor;
44+
const [diffR, diffG, diffB] = options.diffColor;
45+
const [altR, altG, altB] = options.diffColorAlt || options.diffColor;
4346
let diff = 0;
4447

4548
// compare each pixel of one image against the other one
@@ -58,12 +61,16 @@ export default function pixelmatch(img1, img2, output, width, height, options) {
5861
antialiased(img2, x, y, width, height, img1))) {
5962
// one of the pixels is anti-aliasing; draw as yellow and do not count as difference
6063
// note that we do not include such pixels in a mask
61-
if (output && !options.diffMask) drawPixel(output, pos, ...options.aaColor);
64+
if (output && !options.diffMask) drawPixel(output, pos, aaR, aaG, aaB);
6265

6366
} else {
6467
// found substantial difference not caused by anti-aliasing; draw it as such
6568
if (output) {
66-
drawPixel(output, pos, ...(delta < 0 && options.diffColorAlt || options.diffColor));
69+
if (delta < 0) {
70+
drawPixel(output, pos, altR, altG, altB);
71+
} else {
72+
drawPixel(output, pos, diffR, diffG, diffB);
73+
}
6774
}
6875
diff++;
6976
}

0 commit comments

Comments
 (0)