Repository navigation
feat: compare images with pixelmatch 8 #1289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| "@wdio/image-comparison-core": major | ||
| "@wdio/visual-service": major | ||
| --- | ||
|
|
||
| feat: compare images with pixelmatch 8 (OKLab/HyAB color distance) | ||
|
|
||
| The comparison engine is now pixelmatch 8. It measures color differences in the OKLab color space with the HyAB distance instead of YIQ, which is closer to how people see colors: fewer false positives and fewer missed changes. | ||
|
|
||
| The threshold scale did not change (`0` to `1`, where `1` is black vs white), so the `ignore*` presets keep their values. But **mismatch percentages can differ a little** from v10 for the same images. On real screenshots the number of different pixels changed by about −3 % to +3 % (for a 1-pixel shift of a full page with `ignoreAntialiasing`: 0.002 % → 0.003 %). If a check depends on an exact mismatch percentage or a tight tolerance, check it again after the upgrade. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/image-comparison-core/src/pixelmatch/compareImages.checkerboard.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { describe, it, expect } from 'vitest' | ||
| import compareImages from './compareImages.js' | ||
| import { DEFAULT_PIXELMATCH_OPTIONS } from '../helpers/constants.js' | ||
| import { createCanvas, encodeImage } from '../utils/imageUtils.js' | ||
|
|
||
| // Runs the real pixelmatch (no mock): `checkerboard` only changes how pixelmatch blends semi-transparent pixels | ||
| const SIZE = 16 | ||
| const transparent = encodeImage(createCanvas(SIZE, SIZE, 0, 0, 0, 0)) | ||
| const opaqueWhite = encodeImage(createCanvas(SIZE, SIZE, 255, 255, 255, 255)) | ||
|
|
||
| function compareWithCheckerboard(checkerboard: boolean) { | ||
| return compareImages(transparent, opaqueWhite, { | ||
| pixelmatch: { ...DEFAULT_PIXELMATCH_OPTIONS, threshold: 0.063, includeAA: true, checkerboard }, | ||
| }) | ||
| } | ||
|
|
||
| describe('compareImages checkerboard', () => { | ||
| it('blends transparent pixels with white when checkerboard is false, so they match white', async () => { | ||
| const result = await compareWithCheckerboard(false) | ||
|
|
||
| expect(result.rawMisMatchPercentage).toBe(0) | ||
| expect(result.diffPixels).toHaveLength(0) | ||
| }) | ||
|
|
||
| it('blends transparent pixels with a checker pattern when checkerboard is true, so they differ from white', async () => { | ||
| const result = await compareWithCheckerboard(true) | ||
|
|
||
| expect(result.rawMisMatchPercentage).toBeGreaterThan(0) | ||
| expect(result.diffPixels.length).toBeGreaterThan(0) | ||
| }) | ||
| }) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.