Skip to content

harness: compare synthetic pages against a supersampled reference - #78

Merged
timzifer merged 1 commit into
mainfrom
feat/harness-supersampled-ref
Nov 13, 2026
Merged

timzifer merged 1 commit into
mainfrom
feat/harness-supersampled-ref

Conversation

@timzifer

Copy link
Copy Markdown
Owner

Summary

  • New harness engine reference for synthetic scene pages. Each operation is rasterized at 8× resolution through a stilus.Compositor that sums its coverage into the page's pixels. The operation is then composited at page resolution in floating point.
  • New pdfbench run -scene-ref flag (default reference; empty falls back to -ref). Synthetic pages are compared against the reference, and PDFium is measured against it too. The reference renders once and is left out of the speed table.
  • Fix: a row for a document that fails to open no longer reports 0 allocations for engines outside the Go heap (PDFium showed "0" instead of "n/a").

Why not PDFium, and why not a supersampled page

  • PDFium is biased at edges. It over-inks partially covered pixels of diagonal lines by 0.5–0.8 % and loses about 0.9 % of the area of small curves. Exact rasterization therefore missed the target against it on hatch-2000-hairline and glyphs-30000-uncached.
  • Supersampling the whole page would not be fair either. Coverage-based antialiasing (stilus and PDFium alike) composites each operation with its own coverage: 1−(1−a)(1−b) where two shapes share a pixel, versus a+b on a supersampled page. Measured, that is about 19/255 on dense hairlines. Supersampling per operation measures only the coverage.
  • Hairlines: strokes thinner than a pixel are drawn one pixel wide in the reference, as both engines draw them.

Results (150 dpi, 8 scenes)

engine pass mean dev. (median) SSIM (median)
stilus 8 / 8 0.30 0.9999
pdfium 6 / 8 0.66 0.9993

The reference takes a few seconds for all eight scenes.

Test plan

  • New TestReferenceArea: a rectangle with edges between pixels, a rotated square, a quadratic circle with r = 3.07 and a hairline match their exact areas within 0.2 %
  • go vet ./..., go test ./... in harness
  • pdfbench scenes + run on scenes alone and on scenes plus the public corpus; real PDFs still compare against PDFium

🤖 Generated with Claude Code

PDFium is biased at edges: it over-inks partially covered pixels of
diagonal lines by 0.5-0.8 % and loses about 0.9 % of the area of small
curves. An exact rasterizer therefore missed the accuracy target against
it on dense hairlines and glyphs.

New engine `reference` for synthetic scene pages: every operation is
rasterized at 8x the resolution through a stilus.Compositor that sums its
coverage into the page's pixels, then composited at the page's
resolution in floating point. Supersampling the whole page would not be
a fair reference: coverage-based antialiasing composites each operation
with its own coverage (1-(1-a)(1-b) where two shapes share a pixel, a+b
supersampled), about 19/255 on dense hairlines. Strokes thinner than a
pixel are drawn one pixel wide, as stilus and PDFium draw them.
TestReferenceArea checks it against exact areas within 0.2 %.

pdfbench run takes -scene-ref (default `reference`, empty: -ref):
synthetic pages are compared against it, and PDFium is measured against
it too. The reference is rendered once and left out of the speed table.

Also: rows for documents that fail to open no longer count as zero
allocations for engines outside the Go heap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@timzifer
timzifer merged commit e749932 into main Nov 13, 2026
14 checks passed
@timzifer
timzifer deleted the feat/harness-supersampled-ref branch November 13, 2026 14:28
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