Add contrast_map: grade on-screen text contrast by sampling its colours#444
Merged
Conversation
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.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 37 |
| Duplication | 0 |
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.
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Summary
Third feature of the ROUND-15 perception lane.
a11y_audit.contrast_ratiogrades a foreground/background pair you already know — but a button or label on screen is a patch of pixels, not two known colours.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 injectablesamplerand grade it). Grade + split are pure and reusea11y_audit.contrast_ratio, fully testable without a screen.__all__;AC_grade_contrast/AC_dominant_pair(pure) +AC_region_contrast(device) executor commands; matching read-onlyac_*MCP tools; Script Builder under Image.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+radonclean (extracted_partition_by_luminanceto keep CC < C); no float==; package stays Qt-free.