-
-
Notifications
You must be signed in to change notification settings - Fork 182
Fix rgbgfx -Z palette overgeneration on merged color sets #1912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1027,29 +1027,75 @@ void process() { | |||||
| // Insert the color set, making sure to avoid overlaps | ||||||
| for (size_t n = 0; n < colorSets.size(); ++n) { | ||||||
| switch (colorSet.compare(colorSets[n])) { | ||||||
| case ColorSet::WE_BIGGER: | ||||||
| colorSets[n] = colorSet; // Override them | ||||||
| // Remove any other color sets that we encompass | ||||||
| // (Example [(0, 1), (0, 2)], inserting (0, 1, 2)) | ||||||
| case ColorSet::STRICT_SUPERSET: | ||||||
| // 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); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're keeping these debug logs, may as well format them more like the rest.
Suggested change
|
||||||
| for (uint16_t color : colorSets[n]) { | ||||||
| fprintf(stderr, "$%04x, ", color); | ||||||
| } | ||||||
| fputs("] becomes [", stderr); | ||||||
| for (uint16_t color : colorSet) { | ||||||
| fprintf(stderr, "$%04x, ", color); | ||||||
| } | ||||||
| fputs("]\n", stderr); | ||||||
| } | ||||||
|
|
||||||
| colorSets[n] = colorSet; | ||||||
| // 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)) | ||||||
|
Comment on lines
+1046
to
+1047
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic is deeply indented and fairly self-contained, so I'd extract it into a |
||||||
| for (size_t m = n + 1; m < colorSets.size();) { | ||||||
| if (colorSet.compare(colorSets[m]) != ColorSet::STRICT_SUPERSET) { | ||||||
| ++m; | ||||||
| continue; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather make the rest of the loop a |
||||||
| } | ||||||
|
|
||||||
| 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; | ||||||
| } | ||||||
| } | ||||||
|
Comment on lines
+1054
to
+1065
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||||||
|
|
||||||
| colorSets.erase(colorSets.begin() + m); | ||||||
| } | ||||||
| [[fallthrough]]; | ||||||
|
|
||||||
| case ColorSet::THEY_BIGGER: | ||||||
| // Do nothing, they already contain us | ||||||
| case ColorSet::SUBSET_OR_EQUAL: | ||||||
| // Use the previous color set that this one is a subset or duplicate of | ||||||
| attrs.colorSetID = n; | ||||||
| goto continue_visiting_tiles; // Can't `continue` from within a nested loop | ||||||
|
|
||||||
| case ColorSet::NEITHER: | ||||||
| break; // Keep going | ||||||
| case ColorSet::INCOMPARABLE: | ||||||
| // This color set is incomparable so far, so keep going | ||||||
| break; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // This color set is incomparable with all previous ones, so add it as a new one | ||||||
| attrs.colorSetID = colorSets.size(); | ||||||
| if (colorSets.size() == AttrmapEntry::background) { // Check for overflow | ||||||
| fatal( | ||||||
| "Reached %zu color sets... sorry, this image is too much for me to handle :(", | ||||||
| AttrmapEntry::transparent | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| if (checkVerbosity(VERB_DEBUG)) { | ||||||
| fprintf(stderr, "- tile (%" PRIu32 ", %" PRIu32 ") adds color set #%zu: [", tile.x, tile.y, colorSets.size()); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| for (uint16_t color : colorSet) { | ||||||
| fprintf(stderr, "$%04x, ", color); | ||||||
| } | ||||||
| fputs("]\n", stderr); | ||||||
| } | ||||||
|
|
||||||
| colorSets.push_back(colorSet); | ||||||
| continue_visiting_tiles:; | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| -Z | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| "XH9g‘bpIH9gS"g |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well use a spaceship at this point, since we use C++20, huh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some older system doesn't support
<=>: #1228 (comment)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.