Clock photo renders as a black screen: jpegDataURL re-encode path ships a solid-black JPEG for every bundled photo > 350 KB #3
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Clock photo renders as a solid black screen (re-encode path produces a black JPEG)
Summary
A photo-backed clock shows a black screen instead of the photo whenever the shuffle
lands on a bundled photo larger than 350 KB. The photo is not missing — the app ships a
solid-black JPEG as the photo's data URL, which WebKit then paints full-bleed. The next
photo (≤ 350 KB, shipped verbatim) renders fine, so the symptom looks intermittent.
io.rishav.tvdbuilt frommain@880d318. Config under test: one clock cell,photoSet: "new-york",shuffleSeconds: 300.Repro
photoSet: "new-york").bundled file is > 350,000 bytes — 158 of the 518
new-yorkphotos qualify.Deterministic check (no kiosk needed): resolve one such photo through the real code path,
e.g.
ClockPhotoLibrary.image(setID: "new-york", index: 229)(
new-york/dl-047dbb39d4dd401e.jpg, 506,502 bytes). The returnedsrcdecodes to asolid-black 1280×960 JPEG:
Photos ≤ 350 KB are base64'd verbatim (
dataURL(for:)fast path) and render correctly —which is why the next image after a black one looks fine.
Root cause
ClockPhotoLibrary.jpegDataURL(_:maxSide:)(
Sources/TVDashboard/Clock/ClockPhotoLibrary.swift:222-240) re-encodes oversized photosinto an
NSBitmapImageRepconfigured as 3 samples, no alpha (24-bit packed RGB):On macOS 27,
NSGraphicsContext(bitmapImageRep:)for that pixel format fails to createa CG context:
Verified in the running app: for a 3-sample/no-alpha rep,
NSGraphicsContext(bitmapImageRep:)?.cgContext == nil, soimage.draw(in:)silentlypaints nothing; the zeroed rep is then JPEG-encoded and shipped as the photo.
No error is logged —
dataURL(for:)returns a non-nil (black) data URL, soClockPhotoLibrary.imagesucceeds and the failure is invisible Swift-side.The sibling draw paths already use the working configuration —
ScriptingMusicSource.pngDataURL(ScriptingMusicSource.swift:329-333) andAlbumArtPalette.downsampledRGBA(AlbumArtPalette.swift:47-51) both usesamplesPerPixel: 4, hasAlpha: true.Verified fix direction
Same draw, rep changed to
samplesPerPixel: 4, hasAlpha: true(RGBA; JPEG encoding dropsalpha):
Note:
samplesPerPixel: 4, hasAlpha: false(RGBX) is rejected by theNSBitmapImageRepinitializer ("Inconsistent set of values to create NSBitmapImageRep"),so the fix is
hasAlpha: true(or an explicitbitsPerPixel: 32).Secondary issues found while debugging (same function)
jpegDataURLcomputes the downscale target fromNSImage.size(points, DPI-scaled), not pixel dimensions. A 1280 px-wide photo with300 DPI metadata gets a ~307 px target — squashed to ~24% resolution. 79 of the 158
affected
new-yorkphotos carry non-72 DPI density. (pngDataURLhas the samepoint-size logic.) Fix: size from
representations.first?.pixelsWide/pixelsHigh(or
cgImage.width/height).new-york/dl-12597627ac0c4d63.jpg("Radio City Music Hall",index 86) is a 4-component CMYK JPEG.
scripts/fetch-clock-photos.shre-encodesdownloads with
sips -Z 1280 -s format jpeg, which preserves CMYK (verified), soit stays CMYK in the pool and the shared download cache. It is > 350 KB so it takes the
re-encode path today; a ≤ 350 KB CMYK file would be shipped verbatim to WebKit.
Consider normalizing to RGB (or rejecting non-RGB) at fetch/build time.
JPEG ships with no log line. A
cgContext == nilcheck (log + return nil) would turnthis into a visible, diagnosable failure.
Why the tests didn't catch it
SelfTestonly asserts that an on-demand photo resolves to a data URL with a caption(
SelfTest.swift:261-263) — it never decodes or inspects pixels. The selftest's ownbitmap-rep usage (
SelfTest.swift:336) uses the working 4-sample config and assertsnothing about pixel content.
Suggested fix
ClockPhotoLibrary.jpegDataURL, create the rep withsamplesPerPixel: 4, hasAlpha: true(the config the music paths already use), and bail out with a log lineif
NSGraphicsContext(bitmapImageRep:)?.cgContext == nilinstead of shipping a blackJPEG.
image.sizepoints.non-uniform image (mean/stddev within sane bounds of the source file).
scripts/fetch-clock-photos.sh.Fix implemented and pushed in PR #4 (branch
implement_tea_issues_three).aacddb2switches clock-photo JPEG rendering to a four-sample RGBA bitmap, uses true pixel dimensions for photo/artwork scaling, guards graphics-context creation, normalizes downloaded/CMYK cached photos to sRGB, and adds pixel-content and dimension regression checks.e4b81a5makes both CMYK conversion paths publish shared-cache updates via a temporary file and rename, preventing concurrent worktree builds from reading partially written JPEGs. The cache-write rule is documented in the agent wiki.Validation:
make testpassed (Swift selftests, Reminders selftests, and JS runtime checks). Targeted script checks passed for both the existing-local-photo and shared-cache-hit conversion paths. AirPlay rendering was not manually verified.The fix is on PR #4; it has not been merged into
mainyet.