Implementation:Microsoft Playwright ColorUtils
Appearance
Overview
ColorUtils provides color space conversion and perceptual color difference calculation functions used by Playwright's SSIM-based image comparison system.
Description
This module implements:
blendWithWhite-- blends a color channel value with white using alphargb2gray-- converts RGB to grayscale using the ITU-R BT.601 formulacolorDeltaE94-- calculates the CIE94 perceptual color difference between two RGB colors- Color space conversions -- sRGB to XYZ to CIELAB transformations needed for deltaE calculation
The CIE94 deltaE metric provides perceptually meaningful color differences:
- < 1.0: not perceptible by human eyes
- 1-2: perceptible through close observation
- 2-10: perceptible at a glance
Usage
Used by the SSIM image comparison algorithm to determine pixel-level color similarity.
Code Reference
Source Location
packages/playwright-core/src/server/utils/image_tools/colorUtils.ts (99 lines)
Function Signatures
export function blendWithWhite(c: number, a: number): number;
export function rgb2gray(r: number, g: number, b: number): number;
export function colorDeltaE94(rgb1: number[], rgb2: number[]): number;
Import
import { blendWithWhite, rgb2gray, colorDeltaE94 } from './server/utils/image_tools/colorUtils';
I/O Contract
blendWithWhite
- Input: color channel value (0-255), alpha (0-1)
- Output: blended color channel value
rgb2gray
- Input: r, g, b values (0-255)
- Output: grayscale value (0-255)
colorDeltaE94
- Input: two RGB arrays [r, g, b]
- Output: CIE94 deltaE value (0 = identical, ~1.0 = just noticeable difference)
Related Pages
- Microsoft_Playwright_ImageCompare -- SSIM comparison using color utilities
- Microsoft_Playwright_ImageChannel -- Image channel data structure
- Microsoft_Playwright_SsimStats -- SSIM statistical calculations
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment