Skip to content

Add contrast_map: grade on-screen text contrast by sampling its colours#444

Merged
JE-Chen merged 1 commit into
devfrom
feat/contrast-map-batch
Jun 26, 2026
Merged

Add contrast_map: grade on-screen text contrast by sampling its colours#444
JE-Chen merged 1 commit into
devfrom
feat/contrast-map-batch

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Jun 26, 2026

Copy link
Copy Markdown
Member

Summary

Third feature of the ROUND-15 perception lane. a11y_audit.contrast_ratio grades a foreground/background pair you already know — but a button or label on screen is a patch of pixels, not two known colours.

  • Headless core utils/contrast_map/: dominant_pair (split sampled pixels at the mean luminance into the dominant foreground = minority/text and background = majority; uniform patch → same colour, no contrast), grade_contrast (grade a pair against WCAG 2.x AA/AAA for normal + large text → {ratio, aa, aaa, aa_large, aaa_large}), region_contrast (sample a screen region through an injectable sampler and grade it). Grade + split are pure and reuse a11y_audit.contrast_ratio, fully testable without a screen.
  • 5 layers wired: facade __all__; AC_grade_contrast / AC_dominant_pair (pure) + AC_region_contrast (device) executor commands; matching read-only ac_* MCP tools; Script Builder under Image.
  • Docs: EN + Zh v216_features_doc.rst + WHATS_NEW.md.

Test

test/unit_test/headless/test_contrast_map_batch.py — grade black/white passes all, low-contrast fails AAA, symmetry; dominant_pair text-on-bg / uniform / empty; region_contrast with injected sampler + region passthrough; plus JSON executor coercion and facade + executor/MCP/builder wiring. All 11 green; ruff + bandit + radon clean (extracted _partition_by_luminance to keep CC < C); no float ==; package stays Qt-free.

a11y_audit.contrast_ratio grades a known foreground/background pair, but
a button or label on screen is a patch of pixels, not two known colours.
dominant_pair splits sampled pixels at the mean luminance into the
dominant text (minority) and background (majority); grade_contrast grades
a pair against WCAG AA/AAA; region_contrast samples a region (injectable
sampler) and grades it. Grade + split are pure, reuse contrast_ratio.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 37 complexity · 0 duplication

Metric Results
Complexity 37
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@JE-Chen JE-Chen merged commit 91cb1b3 into dev Jun 26, 2026
16 checks passed
@JE-Chen JE-Chen deleted the feat/contrast-map-batch branch June 26, 2026 01:13
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant