Skip to content

feat(coregraphics): decode images at the resolution they are drawn (#428 part 3) - #439

Merged
michaelstonis merged 1 commit into
spec/33-broadside-v1from
428-coregraphics-scaled-decode
Oct 27, 2026
Merged

michaelstonis merged 1 commit into
spec/33-broadside-v1from
428-coregraphics-scaled-decode

Conversation

@michaelstonis

Copy link
Copy Markdown
Owner

Part 3 of #428 (CoreGraphics). Does not close the issue; parts 4 (Android Canvas) and 5 (Direct2D) remain.

What changed

  • CoreGraphicsRenderer.ScaledImageDecode (off by default) and ImageSamplesPerPixel (k, 2 by default; must be a finite number of at least 1) for list renders. Page renders take RenderOptions.ScaledImageDecode / ImageSamplesPerPixel (off by default; overprint preview forces it off).
  • With scaled decode on, an image is converted at r = image.GetReduction(unit square to device pixels, k, converter to RGB) from GetSamplesAt(r) (DecodeMapFor(samples) for the widened Decode map). The grid comes from the source size and the delivered reduction, and the overhang is clipped to the unit square, both in the backend's own resampling and in CoreGraphics' sampling.
  • Masks: a soft mask of the image's size folds only when its samples have the same delivered reduction; explicit masks fold only at r = 0. Otherwise each mask is reduced by its own rule (DisplayImage.GetReduction(..., null) for soft masks; DisplayImageMask.GetReduction for stencils and explicit masks, as 8-bit coverage).
  • The converted-image cache is keyed by the delivered reduction. A finer conversion serves a coarser request without calling GetSamplesAt, and a new reduction forgets the old resampling transforms.
  • The software rasterizer that groups and soft masks fall back to uses the same setting.
  • CoreGraphics has no tile backend, so there is no PrefetchImagesAsync to implement and no pool to share (MAUI/Skia tiles: every pooled tile backend converts the same full-size image (3.7 GB peak on a catalogue page) #432 does not apply).

Tests

CoreGraphicsScaledImageDecodeTests (29 cases), run locally on macOS: the full CoreGraphics suite passes, 262/262.

  • Catalogue cover at 390, 300 and 150 px, corpus DCT pages at 1/4, and all eight ScaledImagePages (depths, stencil, soft masks of the image's size and of another size, an explicit mask of another size, and a colour key that is never reduced). All are within PSNR ≥ 35 dB and ≤ 4% of pixels more than 8 levels off, compared with full conversion.
  • A curved conversion caps the codec reduction at 1/2.
  • Identical pixels at 1:1, and when off.
  • The converted pixels kept are the reduced size.
  • Zooming in converts once for every tile; zooming out converts nothing.
  • k = 1 reduces one step further.
  • A reduced replay allocates nothing.

Byte identity when off: SHA-256 of 116 page renders (the scaled-image pages, the cover and 20 corpus image files, each at 0.125, 0.25, 1 and 2) is the same on this branch and on the integration tip.

Measurements (macOS, M4 Max; docs/benchmarks/native-scaled-image-decode.md)

First render of the cover's list (decode plus conversion):

Page width Reduction Time Kept
590 / 390 px 1/2 249 / 236 → 97 / 95 ms 32 → 9 MB
294 px 1/4 229 → 52 ms 31 → 2.3 MB
150 px 1/8 221 → 36 ms 31 → 0.6 MB

At full width (1180 px) and k = 2 nothing changes (no reduction applies).

Conformance: §8.9.4, §8.9.6.2, §8.9.6.3 and §11.6.5.2 rows list the new tests.

🤖 Generated with Claude Code

)

Part 3 of #428. With CoreGraphicsRenderer.ScaledImageDecode (list renders, off
by default) or RenderOptions.ScaledImageDecode (page renders), an image is
converted at the reduction DisplayImage.GetReduction gives for the device at
ImageSamplesPerPixel (k, 2 by default), masks at their own rule; the converted
image cache is keyed by the delivered reduction, a finer one serving a coarser
request. Off, renders are byte-identical to before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 27, 2026 19:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@michaelstonis
michaelstonis merged commit 50d84ee into spec/33-broadside-v1 Oct 27, 2026
28 checks passed
@michaelstonis
michaelstonis deleted the 428-coregraphics-scaled-decode branch October 27, 2026 20:05
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