Skip to content

fix(7-segment-clock): draw the digits, which had gone fully blank - #364

Merged
ChuckBuilds merged 1 commit into
mainfrom
fix/7-segment-clock-polarity
Sep 2, 2026
Merged

fix(7-segment-clock): draw the digits, which had gone fully blank#364
ChuckBuilds merged 1 commit into
mainfrom
fix/7-segment-clock-polarity

Conversation

@ChuckBuilds

Copy link
Copy Markdown
Owner

test_render_polarity.py has been failing on main, and it was right: the clock renders nothing at all on the panel.

The bug

Every digit and separator asset is a 1-bit bitmap carrying a tRNS chunk. Both loaders open them with .convert("RGBA"), which returns alpha 0 for the white (lit) pixels and alpha 255 for the black (unlit) ones — exactly inverted.

_colorize then asked for a > 0 and (r or g or b) — "visible and not black". That is false for every pixel in the file:

pixel alpha colour a > 0 r or g or b result
lit (white) 0 255,255,255 clear
unlit (black) 255 0,0,0 clear

Every tile came back fully transparent, so the panel stayed dark.

The fix

Lit-ness now comes from brightness, which the inverted alpha cannot reach.

The alpha check is removed, not relaxed, and the docstring says why: by the time _colorize runs, the alpha is already inverted, so "restoring" an alpha test blanks the display again. I hit that exact trap while writing this — an intermediate version kept a defensive alpha > 0 veto and reproduced the blank clock.

Verification

Against the goldens captured before the regression:

result
unfixed main all 8 renders drift — up to 7062px, max Δ=255 (black where the clock belongs)
fixed all 8 match byte-for-byte

So this restores exactly what the clock used to draw, rather than merely making it draw something.

test_render_polarity.py passes, and its three counts independently match an audit of the asset files: 8 lights 218 pixels, 1 lights 72, the separator 12 — the right ordering for correct polarity.

The panel showed nothing. Every asset is a 1-bit bitmap carrying a tRNS chunk,
and both loaders open them with .convert("RGBA") -- which returns alpha 0 for
the WHITE (lit) pixels and alpha 255 for the black ones, exactly inverted.

_colorize then asked for `a > 0 and (r or g or b)`: "visible and not black".
That is false for every pixel in the file. Lit pixels fail the first half, unlit
pixels fail the second. Each tile came back fully transparent, so the clock drew
nothing.

Lit-ness now comes from brightness, which the inverted alpha cannot reach. The
alpha check is not merely relaxed but removed, and the docstring says why: by
the time _colorize runs the alpha is already inverted, so "restoring" an alpha
test blanks the display again. That is the trap this fix exists to close.

Verified against the goldens captured before the regression: unfixed, all eight
harness renders drift (up to 7062px, max delta 255, i.e. black where the clock
should be); fixed, all eight match byte-for-byte. So this restores exactly what
the clock used to draw rather than just making it draw something.

test_render_polarity.py now passes, and its three counts match an independent
audit of the assets: '8' lights 218 pixels, '1' lights 72, the separator 12.
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 7a38b2a1-2de9-41bc-870a-38be1d0cf29e


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics -6 complexity

Metric Results
Complexity -6

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.

@ChuckBuilds
ChuckBuilds merged commit 6502ae9 into main Sep 2, 2026
4 checks passed
@ChuckBuilds
ChuckBuilds deleted the fix/7-segment-clock-polarity branch September 2, 2026 20:25
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.

2 participants