Skip to content

Commit 28b1889

Browse files
Improve differentiation of semitransparent pixels
* add failing unit test when white is compared with transparent * fix failing unit test * fix failing unit test * increase sensitivity of transparent differenc detection by making pattern repeat with non-integer period. * remove repeated comparison * Add digits to color periods * fix unit test after changing coefficients ever so slightly --------- Co-authored-by: Volodymyr Agafonkin <[email protected]>
1 parent f735f88 commit 28b1889

File tree

5 files changed

+5
-4
lines changed

5 files changed

+5
-4
lines changed

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ function colorDelta(img1, img2, k, m, yOnly) {
188188
if (!da && !dr && !dg && !db) return 0;
189189

190190
if (a1 < 255 || a2 < 255) { // blend pixels with background
191-
const rb = 255;
192-
const gb = 255;
193-
const bb = 255;
191+
const rb = 48 + 159 * (k % 2);
192+
const gb = 48 + 159 * ((k / 1.618033988749895 | 0) % 2);
193+
const bb = 48 + 159 * ((k / 2.618033988749895 | 0) % 2);
194194
dr = (r1 * a1 - r2 * a2 - rb * da) / 255;
195195
dg = (g1 * a1 - g2 * a2 - gb * da) / 255;
196196
db = (b1 * a1 - b2 * a2 - bb * da) / 255;

test/fixtures/5diff.png

-1 Bytes
Loading

test/fixtures/8a.png

3.56 KB
Loading

test/fixtures/8diff.png

3.79 KB
Loading

test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ diffTest('2a', '2b', '2diff', {
2020
}, 12437);
2121
diffTest('3a', '3b', '3diff', options, 212);
2222
diffTest('4a', '4b', '4diff', options, 36049);
23-
diffTest('5a', '5b', '5diff', options, 0);
23+
diffTest('5a', '5b', '5diff', options, 6);
2424
diffTest('6a', '6b', '6diff', options, 51);
2525
diffTest('6a', '6a', '6empty', {threshold: 0}, 0);
2626
diffTest('7a', '7b', '7diff', {diffColorAlt: [0, 255, 0]}, 2448);
27+
diffTest('8a', '5b', '8diff', options, 32896);
2728

2829
test('throws error if image sizes do not match', () => {
2930
assert.throws(() => match(new Uint8Array(8), new Uint8Array(9), null, 2, 1), 'Image sizes do not match');

0 commit comments

Comments
 (0)