js-glyph-coverage-gamma-correct-compositor
Done. The verified solution is at ~/glyph/SOLUTION.md (self-contained; its embedded code was extracted to a clean directory and re-run successfully).
Root cause: Two distinct bugs.
c is a linear-light area fraction, but sRGB bytes are a non-linear encoding. Blending encoded values (src_srgb*c + dst_srgb*(1-c)) is not source-over. It is near-correct at c≈0/c≈1 (thin stems/full coverage) and explodes mid-tone: white-on-black at c=0.5 gives 128 instead of 188 (60 levels). Measured max across the sweep: 74/255. Double-encoding (encode then alpha-composite again) reaches 105/255. Premultiplication must be srgbToLinear(src) * c, not src_srgb * c.SAGITTA_TOL=1e-3). Horizontal edges return early; prefix sum resets per row.out_linear = src_linear*c + dst_linear*(1-c), then linearToSrgb once, then round. Correct premultiplied variant included.| Check | Result |
|---|---|
| Scanline coverage vs exact Sutherland–Hodgman/shoelace clipping | 2.7e-14 |
| sRGB round-trip | 1.1e-16 |
| Coverage sweep: correct / naive / double / premul | 0 / 74 / 105 / 0 per 255 |
| 64-glyph conformance vs independent reference (coverage + compositor) | ≤ 1/255 (naive 74/255) |
| Horizontal-on-centre / in-pixel extremum / coincident endpoints | exact / 2.65e-4 / 9.46e-4 |
Because the embedded markdown code was re-extracted and run standalone, the document is directly usable.
# Evidence - Problem class: js-glyph-coverage-gamma-correct-compositor - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-09-18T10:08:04.588Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Implement an analytic glyph rasterizer: given a quadratic-Bezier outline and a horizontal scanline, compute exact signed area coverage per pixel (true antialiasing, no supersampling), then composite the glyph color onto an arbitrary sRGB background so the result matches a reference renderer within +/-1/255 over a 64-glyph conformance set. The trap is that coverage is a linear-light fraction: blending coverage directly against sRGB-encoded values (or alpha-compositing the already-encoded result twice) passes thin stems but fails at mid-tone coverage, and premultiplication must be handled in linear light before re-encoding. Also handle the degenerate cases a naive scanline integrator drops: horizontal edges exactly on a pixel center, three-point extrema inside one pixel, and closed contours with coincident endpoints.", "environment": "node20", "language": "js", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "js-glyph-coverage-gamma-correct-compositor", "provider": "openrouter", "solved_at": "2026-09-18T10:08:04.588Z", "version": "20"}Done. The verified solution is at ~/glyph/SOLUTION.md (self-contained; its embedded code was extracted to a clean directory and re-run successfully).
Root cause: Two distinct bugs.
c is a linear-light area fraction, but sRGB bytes are a non-linear encoding. Blending encoded values (src_srgb*c + dst_srgb*(1-c)) is not source-over. It is near-correct at c≈0/c≈1 (thin stems/full coverage) and explodes mid-tone: white-on-black at c=0.5 gives 128 instead of 188 (60 levels). Measured max across the sweep: 74/255. Double-encoding (encode then alpha-composite again) reaches 105/255. Premultiplication must be srgbToLinear(src) * c, not src_srgb * c.SAGITTA_TOL=1e-3). Horizontal edges return early; prefix sum resets per row.out_linear = src_linear*c + dst_linear*(1-c), then linearToSrgb once, then round. Correct premultiplied variant included.| Check | Result |
|---|---|
| Scanline coverage vs exact Sutherland–Hodgman/shoelace clipping | 2.7e-14 |
| sRGB round-trip | 1.1e-16 |
| Coverage sweep: correct / naive / double / premul | 0 / 74 / 105 / 0 per 255 |
| 64-glyph conformance vs independent reference (coverage + compositor) | ≤ 1/255 (naive 74/255) |
| Horizontal-on-centre / in-pixel extremum / coincident endpoints | exact / 2.65e-4 / 9.46e-4 |
Because the embedded markdown code was re-extracted and run standalone, the document is directly usable.
# Evidence - Problem class: js-glyph-coverage-gamma-correct-compositor - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-09-18T10:08:04.588Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Implement an analytic glyph rasterizer: given a quadratic-Bezier outline and a horizontal scanline, compute exact signed area coverage per pixel (true antialiasing, no supersampling), then composite the glyph color onto an arbitrary sRGB background so the result matches a reference renderer within +/-1/255 over a 64-glyph conformance set. The trap is that coverage is a linear-light fraction: blending coverage directly against sRGB-encoded values (or alpha-compositing the already-encoded result twice) passes thin stems but fails at mid-tone coverage, and premultiplication must be handled in linear light before re-encoding. Also handle the degenerate cases a naive scanline integrator drops: horizontal edges exactly on a pixel center, three-point extrema inside one pixel, and closed contours with coincident endpoints.", "environment": "node20", "language": "js", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "js-glyph-coverage-gamma-correct-compositor", "provider": "openrouter", "solved_at": "2026-09-18T10:08:04.588Z", "version": "20"}