Fix rgbgfx -Z palette overgeneration on merged color sets#1912
Fix rgbgfx -Z palette overgeneration on merged color sets#1912vulcandth wants to merge 3 commits intogbdev:masterfrom
Conversation
| if (*self_item < *other_item) { | ||
| // *self_item is not in other, so self cannot be a strict subset of other | ||
| self_has_unique = true; | ||
| ++self_item; | ||
| } else if (*self_item > *other_item) { | ||
| // *other_item is not in self, so self cannot be a strict superset of other | ||
| other_has_unique = true; | ||
| ++other_item; | ||
| } else { | ||
| // *self_item == *other_item, so continue comparing | ||
| ++self_item; | ||
| ++other_item; |
There was a problem hiding this comment.
Might as well use a spaceship at this point, since we use C++20, huh?
There was a problem hiding this comment.
Some older system doesn't support <=>: #1228 (comment)
There was a problem hiding this comment.
This unfortunately doesn't record which old system that would be. And since two years have passed, we can give it a new try, I think. But I don't care much, anyway.
ISSOtm
left a comment
There was a problem hiding this comment.
The logic added in that third commit looks correct, but I'm feeling wary of it.
| for (size_t i = 0; i + 1 < attrmap.size(); ++i) { | ||
| AttrmapEntry &entry = attrmap[i]; | ||
| if (entry.colorSetID == AttrmapEntry::transparent | ||
| || entry.colorSetID == AttrmapEntry::background) { | ||
| continue; | ||
| } | ||
| if (entry.colorSetID == m) { | ||
| entry.colorSetID = n; | ||
| } else if (entry.colorSetID > m) { | ||
| --entry.colorSetID; | ||
| } | ||
| } |
There was a problem hiding this comment.
I'm a little wary of this attrmap rescanning, as I fear it could blow up in some cases. rsgbgfx handles this image correctly even without this logic, so I feel it's preferable to avoid it if possible.
| for (size_t m = n + 1; m < colorSets.size();) { | ||
| if (colorSet.compare(colorSets[m]) != ColorSet::STRICT_SUPERSET) { | ||
| ++m; | ||
| continue; |
There was a problem hiding this comment.
I'd rather make the rest of the loop a else, for clarity.
| // Remove any other color sets that we are also a strict superset of | ||
| // (example: we have [(0, 1), (0, 2)] and are inserting (0, 1, 2)) |
There was a problem hiding this comment.
This logic is deeply indented and fairly self-contained, so I'd extract it into a static helper function.
| // Override the previous color set that this one is a strict superset of | ||
|
|
||
| if (checkVerbosity(VERB_DEBUG)) { | ||
| fprintf(stderr, "- tile (%" PRIu32 ", %" PRIu32 ") overrides color set #%zu: [", tile.x, tile.y, n); |
There was a problem hiding this comment.
If we're keeping these debug logs, may as well format them more like the rest.
| fprintf(stderr, "- tile (%" PRIu32 ", %" PRIu32 ") overrides color set #%zu: [", tile.x, tile.y, n); | |
| fprintf(stderr, "- Tile (%" PRIu32 ", %" PRIu32 ") overrides color set #%zu: [", tile.x, tile.y, n); |
| } | ||
|
|
||
| if (checkVerbosity(VERB_DEBUG)) { | ||
| fprintf(stderr, "- tile (%" PRIu32 ", %" PRIu32 ") adds color set #%zu: [", tile.x, tile.y, colorSets.size()); |
There was a problem hiding this comment.
| fprintf(stderr, "- tile (%" PRIu32 ", %" PRIu32 ") adds color set #%zu: [", tile.x, tile.y, colorSets.size()); | |
| fprintf(stderr, "- Tile (%" PRIu32 ", %" PRIu32 ") adds color set #%zu: [", tile.x, tile.y, colorSets.size()); |
| @@ -0,0 +1 @@ | |||
| -Z No newline at end of file | |||
There was a problem hiding this comment.
The individual tiles of this could have their pixels scrambled without changing the colors of each tile or the overall size, so we don't have a poketcg image sitting in the repo.
|
|

Fix rgbgfx -Z palette overgeneration on merged color sets
Closes #1887.
Summary
This fixes the RGBGFX bug where automatic palette generation could produce more palettes under
-Zthan without it for the same image.The issue-reproducer Gloom image now generates 3 palettes with and without
-Z, matching the intended behavior.Root Cause
The remaining bug was not in
ColorSet::compare; that part of thecolor-setsbranch was already correct.The problem was in color-set generation after a strict superset was found.
When a tile introduced a color set that was a strict superset of an existing one, RGBGFX only overrode the first matching subset and then stopped. Any other existing strict subsets were left behind as redundant color sets.
That made the final set of color sets depend on tile traversal order. In the Gloom
-Zcase, those redundant subset classes survived long enough to force a fourth palette later in the packing step.Changes
VERB_DEBUGand off stdout, which also fixes the knownwrite_stdoutregression caused by the debug instrumentation.test/gfxregression fixture for the-Zreproduction.Testing
rgbgfx -P -Zon the Gloom fixture now builds 3 color sets and 3 palettes instead of 4 palettes.base_idsgfx case and thewrite_stdoutpath.test/gfxsuite:All 235 tests passed!