Skip to content

Inline colors in the drules text dump - #47

Open
biodranik wants to merge 1 commit into
masterfrom
ab/inline-text-colors
Open

biodranik wants to merge 1 commit into
masterfrom
ab/inline-text-colors

Conversation

@biodranik

Copy link
Copy Markdown
Member

The text dumps exist only to review style changes, but they referenced colors by palette index. The palette is numbered by first use, so adding or removing a single color renumbers every later reference: dropping 19 unused named colors in organicmaps/organicmaps#13545 rewrote ~78K lines of the dumps.

Colors are now written by value (one per variant, /-separated, only when the variants differ) and the palette section is gone. The binary output is unchanged.

Measured on the Organic Maps dumps:

  • that 19-color removal becomes 19 changed lines per file;
  • replaying all 7 regenerations since the native format landed: 1391 changed lines in total become 355;
  • the dumps grow ~22% (+3.5% gzipped);
  • a recolor now lists every rule using the color (4 lines -> 202 for the dark wetland/waterway tweak) instead of one anonymous palette line, which shows which types changed.

Tested: python3 -m unittest discover -s tests and ruff check --target-version=py39, plus two new tests (values are inlined; adding a color leaves the other lines untouched).

@biodranik biodranik left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Verified locally against the Organic Maps checkout with this branch in tools/kothic: tools/unix/generate_drules.sh reproduces organicmaps#13549's dumps byte-for-byte (clean git status after a run), the .bin files and colors.txt are untouched, no stale cNNN reference is left, and no dump line carries more than 2 slash-separated values. python3 -m unittest discover -s tests (59 tests) and ruff check --target-version=py39 pass. The #TTRRGGBB header matches mwm_encode_color (libkomwm.py:107, 255 - alpha).

One real finding (shield plate outline hidden in the single-variant dump) plus two optional notes inline.


Generated by Claude Code

Comment thread src/drules.py Outdated
Comment thread src/drules.py Outdated
Comment thread src/drules.py
out = []
out.append("# drules text dump, format 1. Generated by generate_drules.sh - do not edit.")
out.append("# drules text dump, format 2. Generated by generate_drules.sh - do not edit.")
out.append("# Colors are #TTRRGGBB, where TT is 255 - alpha (00 is opaque), as stored in the rules.")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Optional alternative, since the dump is review-only: write opaque colors as plain #RRGGBB and keep the 8-digit form only when TT != 0. 22010 of the 32743 color refs in drules_default.txt (67%) are opaque, so this makes the common case directly greppable against colors.mapcss (@label_halo_light: #FFFFFF ↔ #FFFFFF instead of #00FFFFFF) and cancels a good part of the +22% size growth.

Cons: two forms in one file, and it stops being a literal echo of the stored bytes — which is what this line currently promises. Fine to keep as is; just noting the trade-off was available.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Keeping the 8-digit form for now: the dump stays a literal echo of the stored bytes, with one spelling per value, and mixed widths would make column-wise scanning of a diff harder. The +22% is on a review-only artefact. Happy to switch if you prefer the greppability.

The text dump exists only to review style changes, but it referenced colors
by palette index. The palette is numbered by first use, so adding or removing
a single color renumbered every later reference: removing 19 unused named
colors rewrote ~78K lines of the Organic Maps dumps. Write colors by value
instead, one per variant only if the variants differ.

The binary output is unchanged. The dumps grow by ~22% (+3.5% compressed).

Signed-off-by: Alexander Borsuk <me@alex.bio>
@biodranik
biodranik force-pushed the ab/inline-text-colors branch from aa3c788 to dce9435 Compare September 11, 2026 23:47
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