Skip to content

LibGfx+Tests: Support refining strip-refined symbols with export control#26578

Merged
nico merged 1 commit intoSerenityOS:masterfrom
nico:jbig2-symbol-refine-indices
Jan 27, 2026
Merged

LibGfx+Tests: Support refining strip-refined symbols with export control#26578
nico merged 1 commit intoSerenityOS:masterfrom
nico:jbig2-symbol-refine-indices

Conversation

@nico
Copy link
Contributor

@nico nico commented Jan 27, 2026

When we don't export some symbols, symbol indices are different in different symbol dictionary sections.

For example, in the included test, segment 1 exports 7 symbols, and segment 2 refers to it, but only exports 3 of these 7 symbols, and it only exports 1 of the 4 symbols itself defines. So within segment 2, indices 0-10 are valid. But in segment 3, which refers to segment 2, only indices 0-3 are valid, and they refer to the symbols that have indices 0, 1, 6, and 10 in segment 2.

This is mostly a problem for the writer (see #26510 / d15f574).

When the text region refines its symbol 3, the code used to look up the symbol ids that it referred to. But those indices were in the namespace of segment 2, but we used the symbol list from segment 3.

As a fix, don't store symbol dictionary results as a SymbolDictionarySegmentData::HeightClass::Symbol but just as a BilevelImage. For regular symbols and regular refined symbols, it doesn't make a difference. Strip-refined symbols are converted to bitmaps eagerly instead of only when they are refined, but in return this needs less code, it handles indices correctly, and chains of strip-refined symbols are no longer O(n^2) (...not that these happen in practice).

The new test is the same as bitmap-symbol-symbolrefine-textrefine.json (or bitmap-symbol-symhuffrefine-textrefine.json), but the last symbol_region sets export_flags_for_referred_to_symbols to not export temporary symbols from its referred-to symbol dictionaries, and it sets "exported" to false for its internal symbols (and symbol_ids are adjusted to match).

When we don't export some symbols, symbol indices are different in
different symbol dictionary sections.

For example, in the included test, segment 1 exports 7 symbols, and
segment 2 refers to it, but only exports 3 of these 7 symbols, and it
only exports 1 of the 4 symbols itself defines. So within segment 2,
indices 0-10 are valid.  But in segment 3, which refers to segment 2,
only indices 0-3 are valid, and they refer to the symbols that have
indices 0, 1, 6, and 10 in segment 2.

This is mostly a problem for the writer (see SerenityOS#26510 / d15f574).

When the text region refines its symbol 3, the code used to look up the
symbol ids that it referred to. But those indices were in the namespace
of segment 2, but we used the symbol list from segment 3.

As a fix, don't store symbol dictionary results as a
SymbolDictionarySegmentData::HeightClass::Symbol but just as a
BilevelImage.  For regular symbols and regular refined symbols, it
doesn't make a difference.  Strip-refined symbols are converted to
bitmaps eagerly instead of only when they are refined, but in return
this needs less code, it handles indices correctly, and chains of
strip-refined symbols are no longer O(n^2) (...not that these happen in
practice).

The new test is the same as bitmap-symbol-symbolrefine-textrefine.json
(or bitmap-symbol-symhuffrefine-textrefine.json), but the last
symbol_region sets `export_flags_for_referred_to_symbols` to not export
temporary symbols from its referred-to symbol dictionaries, and it sets
`"exported"` to false for its internal symbols (and symbol_ids are
adjusted to match).
@github-actions github-actions bot added the 👀 pr-needs-review PR needs review from a maintainer or community member label Jan 27, 2026
@nico nico merged commit d861e29 into SerenityOS:master Jan 27, 2026
13 checks passed
@nico nico deleted the jbig2-symbol-refine-indices branch January 27, 2026 14:09
@github-actions github-actions bot removed the 👀 pr-needs-review PR needs review from a maintainer or community member label Jan 27, 2026
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