playwright/packages/playwright-core/src/utils
Andrey Lushnikov 6d82460a02
feat: implement a new image comparison function (#19166)
This patch implements a new image comparison function, codenamed
"ssim-cie94". The goal of the new comparison function is to cancel out
browser non-determenistic rendering.

To use the new comparison function:

```ts
await expect(page).toHaveScreenshot({
  comparator: 'ssim-cie94',
});
```

As of Nov 30, 2022, we identified the following sources of
non-determenistic rendering for Chromium:
- Anti-aliasing for certain shapes might be different due to the
  way skia rasterizes certain shapes.
- Color blending might be different on `x86` and `aarch64`
architectures.

The new function employs a few heuristics to fight these
differences.

Consider two non-equal image pixels `(r1, g1, b1)` and `(r2, g2, b2)`:
1. If the [CIE94] metric is less then 1.0, then we consider these pixels
   **EQUAL**. (The value `1.0` is the [just-noticeable difference] for
   [CIE94].). Otherwise, proceed to next step.
1. If all the 8 neighbors of the first pixel match its color, or
   if the 8 neighbors of the second pixel match its color, then these
   pixels are **DIFFERENT**. (In case of anti-aliasing, some of the
   direct neighbors have to be blended up or down.) Otherwise, proceed
   to next step.
1. If SSIM in some locality around the different pixels is more than
   0.99, then consider this pixels to be **EQUAL**. Otherwise, mark them
   as **DIFFERENT**. (Local SSIM for anti-aliased pixels turns out to be
   very close to 1.0).

[CIE94]: https://en.wikipedia.org/wiki/Color_difference#CIE94
[just-noticeable difference]:
https://en.wikipedia.org/wiki/Just-noticeable_difference
2022-12-02 15:22:05 -08:00
..
isomorphic fix(getByRole): name and exact (#18719) 2022-11-11 15:58:36 -08:00
comparators.ts feat: implement a new image comparison function (#19166) 2022-12-02 15:22:05 -08:00
DEPS.list feat: implement a new image comparison function (#19166) 2022-12-02 15:22:05 -08:00
eventsHelper.ts chore: always import type (#13365) 2022-04-06 14:57:14 -07:00
fileUtils.ts chore: make generated report writable (#18750) 2022-11-13 12:46:35 -08:00
hostPlatform.ts chore: drop Ubuntu 18.04 support (#18924) 2022-11-21 11:23:45 -10:00
httpServer.ts feat: allow opening multiple html reporters and trace viewers (#17636) 2022-09-27 12:45:42 -07:00
index.ts Revert "chore: support narrow terminal windows for messages (#18714)" 2022-11-14 08:47:17 -08:00
linuxUtils.ts chore: add support for debian 11 downloads (#15596) 2022-07-13 04:09:24 -07:00
manualPromise.ts feat(server): queue run-server clients (#16234) 2022-08-03 19:37:06 -07:00
mimeType.ts feat: print response text when toBeOK fails (#16040) 2022-07-29 11:46:48 -07:00
multimap.ts fix: make viewer reference all trace urls (#16561) 2022-08-15 20:54:57 -07:00
processLauncher.ts Revert "feat: send SIGTERM to webserver before SIGKILL'ing it. (#18220)" (#18661) 2022-11-09 09:18:33 -08:00
processLauncherCleanupEntrypoint.ts fix(process launcher): use spawnSync to cleanup synchronously (#13769) 2022-04-27 15:01:30 +01:00
spawnAsync.ts chore: use utils via index export (5) (#13413) 2022-04-07 20:18:22 -07:00
stackTrace.ts chore: sunset Node.js 12 (#16512) 2022-08-15 18:10:04 +02:00
timeoutRunner.ts chore: use utils via index export (3) (#13403) 2022-04-07 13:55:44 -07:00
zipFile.ts chore(har): allow replaying from zip har (#14962) 2022-06-17 16:11:22 -07:00
zones.ts chore(zones): prepare to remove wrapApiCall, introduce zones (#10427) 2021-11-18 22:30:09 -08:00