Skip to content

Commit

Permalink
Merge pull request #311 from happo/lcs-image-diff
Browse files Browse the repository at this point in the history
Update lcs-image-diff from v2 to v3
  • Loading branch information
lencioni authored Feb 13, 2025
2 parents f4bade3 + 62e31e2 commit 9edc992
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"https-proxy-agent": "^5.0.0",
"jose": "^5.4.1",
"jsdom": "^16.4.0",
"lcs-image-diff": "^2.0.0",
"lcs-image-diff": "^3.0.0",
"node-fetch": "^2.6.6",
"parse-srcset": "^1.0.2",
"pngjs": "^3.4.0",
Expand Down
12 changes: 6 additions & 6 deletions src/compareSnapshots.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncRetry from 'async-retry';
import colorDelta from 'lcs-image-diff/src/colorDelta';
import { colorDeltaChannels } from 'lcs-image-diff/src/colorDelta';

import fetchPng from './fetchPng';

Expand All @@ -12,21 +12,21 @@ function makeAbsolute(url, endpoint) {

function imageDiff({ bitmap1, bitmap2, compareThreshold }) {
const len = bitmap1.width * bitmap1.height * 4;

for (let i = 0; i < len; i += 4) {
const distance = colorDelta(
[
const distance = Math.abs(
colorDeltaChannels(
bitmap1.data[i],
bitmap1.data[i + 1],
bitmap1.data[i + 2],
bitmap1.data[i + 3],
],
[
bitmap2.data[i],
bitmap2.data[i + 1],
bitmap2.data[i + 2],
bitmap2.data[i + 3],
],
),
);

if (distance > compareThreshold) {
return distance;
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5295,10 +5295,10 @@ lazystream@^1.0.0:
dependencies:
readable-stream "^2.0.5"

lcs-image-diff@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/lcs-image-diff/-/lcs-image-diff-2.1.1.tgz#eaa88f344853500f0acbb3e1430f1339ee047ef0"
integrity sha512-pMsEXSN3GibFRxP5oH3b+3sJ6DA926XCeFLmkdxbp9QucwiAQ2nmMOaQECTP+NZ8+zo1ZIbs+Qqfa6Jm9Qtb0Q==
lcs-image-diff@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lcs-image-diff/-/lcs-image-diff-3.0.0.tgz#9f924f534d68b3d923a02215e6a61afc75c26ee7"
integrity sha512-ZzaqR8dVbA5ISLpKBnn3gV1M8TELWg81cFuQsTutf5IRCt93vV5yRuK2ZrIgOucOQhYeB6ml6o9+pefs1QD6mw==
dependencies:
imagetracerjs "^1.2.5"

Expand Down

0 comments on commit 9edc992

Please sign in to comment.