Repository navigation
feat(rendering): row reduction for images the codec cannot reduce (#362 part 4/4) - #412
Merged
Merged
Conversation
…#362) Part 4 of 4 of issue #362: images the codec cannot reduce (Flate, LZW, raw, CCITT, JBIG2, ...) of at least 512 x 512 samples are reduced after decoding, by an exact box average, at the reduction the viewer asks for. - ImageReducer: box average over 2^n x 2^n samples (the last ones fewer), one row at a time with no allocation per row; samples of fewer than 8 bits become 8-bit averages and DisplayImageSamples.DecodeMap carries the widened Decode mapping (Table 88 is linear). - Colour order: a reduction precedes the colour conversion only when the conversion is affine (device spaces); curved conversions (CalRGB, CalGray, Lab, ICC) are capped at 1/2, Indexed is never reduced (ImageReductions). - Stencil masks and explicit masks reduce to 8-bit coverage (DisplayImageMask.GetReduction, MaskSource); soft masks reduce on their own grid and fold into the image at the same reduction. - Reductions are decoded once per image and reduction, cached with the image samples as before. - ScaledScanBenchmarks (8-bit gray photo and 1-bit scan); the image-decode fuzz target checks reductions; ScrollFrameTests records the loading frames (first tile + 4 s). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…te baseline) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eir size (#362) The CI allocation gate still found +24 B per render and +16 B per page: the Decode mapping in every DisplayImageSamples value, a soft-mask reference in the image source and a reduction in the mask source. The mapping now comes from DisplayImage.DecodeMapFor(samples) (the same instance for samples of one depth); the image source remembers whether a soft mask was folded, and the mask source tells a reduction by the size it converted to (two reductions of one size are the same 1 x 1 average). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…heir earlier size (#362) The gate still counted +8 B per render and +16 B per kept-encoded image. The reduction state of an encoded image is back to its earlier fields: the largest reduction comes from the codec header, and the full decode and widened Decode mapping of a large image decoded at build live in a subclass only such images get. The image source takes its size from the samples it remembers, which leaves room for the flag that tells whether a soft mask was folded (needed: a finer soft-mask reduction at hand can change that for the same samples). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
New cases only: ScaledScanBenchmarks.Replay (0 B, scaled or not). No existing case changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 4 of 4 of #362 (closes #362): images the codec cannot reduce are reduced by rows after decoding, and the measured gains of the whole issue.
What changes
ImageReducer): an image decoded at build (Flate, LZW, raw, CCITT, JBIG2, …) of at least 512 × 512 samples is reduced at the reduction the viewer asks for by an exact box average over 2^n × 2^n samples (the last row and column cover fewer), one row at a time, nothing allocated per row. Samples of fewer than 8 bits become 8-bit averages;DisplayImageSamples.DecodeMapcarries the widened Decode mapping (§8.9.5.2 Table 88 is linear, so the mean of raw values maps to the mean of the component values).ImageReductions).DisplayImageMask.GetReduction,MaskSource); a soft mask reduces on its own grid and folds into its image at the same reduction.ScrollFrameTestsrecords the loading frames (first tile + 4 s: max frame, frames over 50 ms).Measured (M4 Max)
ScaledScanBenchmarks(a letter page holding one Flate image, replay at 390 px, viewer vs page render):Whole issue (parts 1 to 4)
Catalogue-class page (2550 × 3150 DCT 4:4:4 photo with an ICC profile,
CatalogueSamples.Cover, generated; never the owner's file):JPX
issue5567.pdfimage: 472.8 ms → 149.6 / 41.0 / 11.1 ms at 1/2, 1/4, 1/8.Blazor viewer (non-AOT, Chrome via Playwright,
ScrollFrameTests; before =spec/33-broadside-v1before part 1):issue5567.pdfScrolling frames stay at 8.4 ms mean either way. Without the render worker the phone cover is unchanged: at DPR 3 the 2550-px cover is drawn at more than half its resolution, which k = 2 does not reduce (k = 1 would).
Allocation gate
No existing case changes; the only baseline change is the new
ScaledScanBenchmarks.Replay(*)cases, 0 B (recorded from this PR's CI run). Getting there: the first version added about 96 B to every software render, reduced or not, and 16 B per kept-encoded image. Fixed by:DisplayImageSamplesno longer carries a Decode mapping (the value grew by 8 B wherever it is stored):DisplayImage.DecodeMapFor(samples)gives it, the same instance for samples of one depth;Reduced-mask coverage counts are 64-bit, so a mask reduced by 2^15 cannot overflow them.
Tests
RowReductionRenderingTests(box-average exactness, the widened Decode map of a 1-bit image, the colour-order caps, small images left alone, gray / 16-bit RGB / 1-bit / stencil / soft masks of both sizes / explicit mask pages within PSNR ≥ 35 dB and ≤ 4 % over 8 levels of a full-resolution render, curved conversions within 45 dB of converting first, zero allocation replaying a reduced list),ScaledImageDecodeTestsupdated; the image-decode fuzz target checks reductions.Conformance: §8.9.5.1, §8.9.5.2, §8.9.6.2, §8.9.6.3, §11.6.5.2 rows updated.
Deferred (follow-ups in the handoff)
Mattesoft masks are not reduced.🤖 Generated with Claude Code