Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Playwright ColorUtils

From Leeroopedia
Revision as of 11:36, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Microsoft_Playwright_ColorUtils.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:Implementation Page

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 alpha
  • rgb2gray -- converts RGB to grayscale using the ITU-R BT.601 formula
  • colorDeltaE94 -- 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

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment