Repository navigation
feat(android): decode images at the resolution they are drawn (#428 part 4) - #440
Merged
Merged
Conversation
…Android Canvas backend (#428 part 4) AndroidCanvasBackend gains ScaledImageDecode (off) and ImageSamplesPerPixel (2) for list renders; page renders take RenderOptions.ScaledImageDecode. With it on, an image is converted at DisplayImage.GetReduction for the canvas (the backend's own RGB converter caps the codec reduction), the reduced samples are mapped through a SampleGrid built from the source size and the delivered reduction, and the overhang is clipped to the unit square. A soft mask of the image's size folds only at the same delivered reduction; explicit masks fold only at reduction 0; otherwise each mask is reduced by its own rule (stencils as 8-bit coverage). The converted-image cache is keyed by the delivered reduction, a finer conversion serving a coarser request. The software rasterizer groups and soft masks fall back to gets the same setting. Off, the pixels are unchanged (golden and allocation tests pass as before). The backend's resampling now works in bands of at most 64 sample rows, as Skia's does since #432: same pixels, peak RSS 477 -> 350 MiB for the full-resolution cover. Tests: AndroidScaledImageDecodeTests (21) over figures the device app reports (ScaledImageDecodeRun): catalogue cover at phone widths, corpus DCT pages, the shared large-image pages with masks of another size and a colour key, a curved conversion, 1:1 identical, page renders off by default, k = 1, zoom in/out conversions, zero allocation on a reduced replay. Measurements in docs/benchmarks/native-scaled-image-decode.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # docs/benchmarks/native-scaled-image-decode.md # docs/conformance/iso-32000-2.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # docs/benchmarks/native-scaled-image-decode.md # docs/conformance/iso-32000-2.md
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 #428: the Android Canvas backend decodes images at the resolution they are drawn, as Skia (#429) and WebGL (#435) do.
What changed
AndroidCanvasBackend.ScaledImageDecode(off by default) andImageSamplesPerPixel(2; 1 is faster and coarser; values below 1 throw) for list renders. Page renders (Render(PdfPage, …, RenderOptions)) followRenderOptions.ScaledImageDecode/ImageSamplesPerPixel, off by default and forced off under overprint preview. This is viewer-only: nothing turns it on for print or export. The Android backend has no tile backend, so there is noPrefetchImagesAsyncto implement.r = image.GetReduction(userToPixels, k, converter to RGB), thenGetSamplesAt(r), and those samples are converted withDecodeMapFor(samples). The geometry comes from the source size and the delivered reduction (SampleGrid). The overhang past the unit square is clipped in both the resampling path and the canvas's own sampling.DisplayImage.GetReduction(…, null)for soft masks,DisplayImageMask.GetReductionfor stencil and explicit masks, as 8-bit coverage).GetSamplesAtagain. A new reduction clears the entry's resampling slots.ImageReducernow resamples in bands of at most 64 sample rows, ported from Skia (MAUI/Skia tiles: every pooled tile backend converts the same full-size image (3.7 GB peak on a catalogue page) #432). The pixels are the same. For the full-resolution cover at 1080 px, peak RSS drops from 477 to 350 MiB and the managed heap from 436 to 184 MiB.Tests
AndroidScaledImageDecodeTests(21 tests). The device app (ScaledImageDecodeRun, run with-e scaled 1as an extra phase of the shared instrumentation run) renders each case reduced first, then in full, and reports only the figures, so no large pixel files are pulled back. The cases:ScaledImagePagespage (depths, stencil, soft masks of the image's size and of another size, an explicit mask of another size, a colour key that is never reduced)On the scratch Android 15 arm64 emulator, all 365 tests of
Broadside.Rendering.Android.Testspass (7 skipped, as before). At k = 2 the lowest PSNR is 42.1 dB (explicit mask of another size, 1.5 % of pixels more than 8 levels off); every cover case is at least 46.7 dB.Measurements
On the emulator, with the catalogue cover drawn as 256-px tiles (
docs/benchmarks/native-scaled-image-decode.md):Local gate: the solution builds with 0 warnings (the Android projects build Release with warnings as errors), Core tests pass,
dotnet formatis clean, the conformance check is OK, andcheck-adr-refs.shis OK.Refs #428 (part 4 of 5)
🤖 Generated with Claude Code