-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Improve the legacy color conversions #6358
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b405a87
Eliminate unnecessary GetLegacyAttribute calls in the console IME.
j4james 65155b7
Eliminate unnecessary GetLegacyAttribute use in the color selection h…
j4james a18dc5e
Eliminate unnecessary color remapping in the popup windows.
j4james a4d5aea
Why are popup attributes returned as a pointer?
j4james b315b7e
Simplify the null fill hack in ScrollRegion to avoid using GetLegacyA…
j4james 9a2174e
Update ReadOutputAttributes to use the more correct GenerateLegacyAtt…
j4james e1864e8
Reimplement the legacy attribute generation with simple table lookups.
j4james f8b1479
Get rid of unused TextAttribute methods.
j4james dbc66b4
Add RRRGGGBB to spell-check whitelist.
j4james be5fd3f
Update the legacy color feature test to account for the different val…
j4james File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1976,6 +1976,7 @@ robomac | |
roundtrip | ||
ROWSTOSCROLL | ||
RRF | ||
RRRGGGBB | ||
rtcore | ||
RTEXT | ||
rtf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,57 @@ | |
#include "precomp.h" | ||
#include "TextColor.h" | ||
|
||
// clang-format off | ||
|
||
// A table mapping 8-bit RGB colors, in the form RRRGGGBB, | ||
// down to one of the 16 colors in the legacy palette. | ||
constexpr std::array<BYTE, 256> CompressedRgbToIndex16 = { | ||
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 is clever as heck. I love it. |
||
0, 1, 1, 9, 0, 0, 1, 1, 2, 1, 1, 1, 2, 8, 1, 9, | ||
2, 2, 3, 3, 2, 2, 11, 3, 10, 10, 11, 11, 10, 10, 10, 11, | ||
0, 5, 1, 1, 0, 0, 1, 1, 8, 1, 1, 1, 2, 8, 1, 9, | ||
2, 2, 3, 3, 2, 2, 11, 3, 10, 10, 10, 11, 10, 10, 10, 11, | ||
5, 5, 5, 1, 4, 5, 1, 1, 8, 8, 1, 9, 2, 8, 9, 9, | ||
2, 2, 3, 3, 2, 2, 11, 3, 10, 10, 11, 11, 10, 10, 10, 11, | ||
4, 5, 5, 1, 4, 5, 5, 1, 8, 5, 5, 1, 8, 8, 9, 9, | ||
2, 2, 8, 9, 10, 2, 11, 3, 10, 10, 11, 11, 10, 10, 10, 11, | ||
4, 13, 5, 5, 4, 13, 5, 5, 4, 13, 13, 13, 6, 8, 13, 9, | ||
6, 8, 8, 9, 10, 10, 11, 3, 10, 10, 11, 11, 10, 10, 10, 11, | ||
4, 13, 13, 13, 4, 13, 13, 13, 4, 12, 13, 13, 6, 12, 13, 13, | ||
6, 6, 8, 9, 6, 6, 7, 7, 10, 14, 14, 7, 10, 10, 14, 11, | ||
4, 12, 13, 13, 4, 12, 13, 13, 4, 12, 13, 13, 6, 12, 12, 13, | ||
6, 6, 12, 7, 6, 6, 7, 7, 6, 14, 14, 7, 14, 14, 14, 15, | ||
12, 12, 13, 13, 12, 12, 13, 13, 12, 12, 12, 13, 12, 12, 12, 13, | ||
6, 12, 12, 7, 6, 6, 7, 7, 6, 14, 14, 7, 14, 14, 14, 15 | ||
}; | ||
|
||
// A table mapping indexed colors from the 256-color palette, | ||
// down to one of the 16 colors in the legacy palette. | ||
constexpr std::array<BYTE, 256> Index256ToIndex16 = { | ||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, | ||
0, 1, 1, 1, 9, 9, 2, 1, 1, 1, 1, 1, 2, 2, 3, 3, | ||
3, 3, 2, 2, 11, 11, 3, 3, 10, 10, 11, 11, 11, 11, 10, 10, | ||
10, 10, 11, 11, 5, 5, 5, 5, 1, 1, 8, 8, 1, 1, 9, 9, | ||
2, 2, 3, 3, 3, 3, 2, 2, 11, 11, 3, 3, 10, 10, 11, 11, | ||
11, 11, 10, 10, 10, 10, 11, 11, 4, 13, 5, 5, 5, 5, 4, 13, | ||
13, 13, 13, 13, 6, 8, 8, 8, 9, 9, 10, 10, 11, 11, 3, 3, | ||
10, 10, 11, 11, 11, 11, 10, 10, 10, 10, 11, 11, 4, 13, 13, 13, | ||
13, 13, 4, 12, 13, 13, 13, 13, 6, 6, 8, 8, 9, 9, 6, 6, | ||
7, 7, 7, 7, 10, 14, 14, 14, 7, 7, 10, 10, 14, 14, 11, 11, | ||
4, 12, 13, 13, 13, 13, 4, 12, 13, 13, 13, 13, 6, 6, 12, 12, | ||
7, 7, 6, 6, 7, 7, 7, 7, 6, 14, 14, 14, 7, 7, 14, 14, | ||
14, 14, 15, 15, 12, 12, 13, 13, 13, 13, 12, 12, 12, 12, 13, 13, | ||
6, 12, 12, 12, 7, 7, 6, 6, 7, 7, 7, 7, 6, 14, 14, 14, | ||
7, 7, 14, 14, 14, 14, 15, 15, 0, 0, 0, 0, 0, 0, 8, 8, | ||
8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 15, 15 | ||
}; | ||
|
||
// clang-format on | ||
|
||
bool TextColor::IsLegacy() const noexcept | ||
{ | ||
return IsIndex16() || (IsIndex256() && _index < 16); | ||
} | ||
|
||
bool TextColor::IsHighColor() const noexcept | ||
{ | ||
return IsRgb() || (IsIndex256() && _index >= 16); | ||
} | ||
|
||
bool TextColor::IsIndex16() const noexcept | ||
{ | ||
return _meta == ColorType::IsIndex16; | ||
|
@@ -135,6 +176,37 @@ COLORREF TextColor::GetColor(std::basic_string_view<COLORREF> colorTable, | |
} | ||
} | ||
|
||
// Method Description: | ||
// - Return a legacy index value that best approximates this color. | ||
// Arguments: | ||
// - defaultIndex: The index to use for a default color. | ||
// Return Value: | ||
// - an index into the 16-color table | ||
BYTE TextColor::GetLegacyIndex(const BYTE defaultIndex) const noexcept | ||
{ | ||
if (IsDefault()) | ||
{ | ||
return defaultIndex; | ||
} | ||
else if (IsIndex16()) | ||
{ | ||
return GetIndex(); | ||
} | ||
else if (IsIndex256()) | ||
{ | ||
return Index256ToIndex16.at(GetIndex()); | ||
} | ||
else | ||
{ | ||
// We compress the RGB down to an 8-bit value and use that to | ||
// lookup a representative 16-color index from a hard-coded table. | ||
const BYTE compressedRgb = (_red & 0b11100000) + | ||
((_green >> 3) & 0b00011100) + | ||
((_blue >> 6) & 0b00000011); | ||
return CompressedRgbToIndex16.at(compressedRgb); | ||
} | ||
} | ||
|
||
// Method Description: | ||
// - Return a COLORREF containing our stored value. Will return garbage if this | ||
//attribute is not a RGB attribute. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
note to self and future reviewers: we don't have a constant for this, we just use 0x07 everywhere. Not worth making one.
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.
OK.