LibGfx/JBIG2+Tests: Add support for refining page contents #26410
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.
Encoding a generic refinement region that refines the page contents
requires that the writer has access to the current page contents. For
some region types (text, halftone), computing the output bitmap isn't
trivial, and handling all the composition operators and so on is also
not trivial.
Reimplementing all this in the writer doesn't seem ideal.
So instead, when encountering a generic refinement region refining the
page contents in the writer, collect the encoded segment data for all
segments for the current page (and for the "global page" 0) that are in
front of the refinement region, and call into the loader to decode the
data so far, and then refine the bitmap returned by the loader.
This requires storing the encoded data for each segment, but we do that
already for implementing writing files in random access organization.
It also requires making the list of segments available on
JBIG2EncodingContext.
This approach is O(n^2) in the number of refinement regions encoding the page, but n is usually 0 or 1, and it's also only writing that hits this code path. It doesn't seem worth adding complexity to add a codepath to incrementally draw the segments that are new since last time, and to only pass those.