mirror of
https://github.com/microsoft/terminal.git
synced 2026-02-04 05:35:20 +00:00
Simplify the handling of alpha values in the color table (#11900)
This PR attempts to minimize the amount of fiddling we do with the alpha color components, by storing all colors with a zero alpha (the default for `COLORREF` values) and then leaving it up to the renderer to adjust the final alpha value as required (which it was already doing anyway). This gets rid of the `argb.h` header file, which was originally being used to produce `COLORREF` values with custom alpha components, and thus is no longer required. Anywhere that was using the `ARGB` macro is now using a standard `RGB` macro with a 0 alpha. The `Utils::SetColorTableAlpha` method has also been removed, since that was only really used to force an alpha of 255 on all the color table entries, which isn't necessary. There were also a number of places where we were using `til::color::with_alpha`, to switch alpha components back and forth between 0 and 255, which have now been removed. Some of these were essentially noops, because the `til::color` class already applied the appropriate alpha changes when converting from or to a `COLORREF`. I've manually run a few attribute rendering tests to check that the colors were still working correctly, and the default background color is appropriately transparent when in acrylic mode. Closes #11885
This commit is contained in:
@@ -81,7 +81,6 @@ namespace SettingsModelLocalTests
|
||||
std::array<COLORREF, COLOR_TABLE_SIZE> expectedCampbellTable;
|
||||
const auto campbellSpan = gsl::make_span(expectedCampbellTable);
|
||||
Utils::InitializeColorTable(campbellSpan);
|
||||
Utils::SetColorTableAlpha(campbellSpan, 0);
|
||||
|
||||
for (size_t i = 0; i < expectedCampbellTable.size(); i++)
|
||||
{
|
||||
|
||||
@@ -732,11 +732,11 @@ namespace SettingsModelLocalTests
|
||||
const auto terminalSettings4 = createTerminalSettings(activeProfiles.GetAt(4), colorSchemes);
|
||||
const auto terminalSettings5 = createTerminalSettings(activeProfiles.GetAt(5), colorSchemes);
|
||||
|
||||
VERIFY_ARE_EQUAL(ARGB(0, 0x12, 0x34, 0x56), terminalSettings0->CursorColor()); // from color scheme
|
||||
VERIFY_ARE_EQUAL(RGB(0x12, 0x34, 0x56), terminalSettings0->CursorColor()); // from color scheme
|
||||
VERIFY_ARE_EQUAL(DEFAULT_CURSOR_COLOR, terminalSettings1->CursorColor()); // default
|
||||
VERIFY_ARE_EQUAL(ARGB(0, 0x23, 0x45, 0x67), terminalSettings2->CursorColor()); // from profile (trumps color scheme)
|
||||
VERIFY_ARE_EQUAL(ARGB(0, 0x34, 0x56, 0x78), terminalSettings3->CursorColor()); // from profile (not set in color scheme)
|
||||
VERIFY_ARE_EQUAL(ARGB(0, 0x45, 0x67, 0x89), terminalSettings4->CursorColor()); // from profile (no color scheme)
|
||||
VERIFY_ARE_EQUAL(RGB(0x23, 0x45, 0x67), terminalSettings2->CursorColor()); // from profile (trumps color scheme)
|
||||
VERIFY_ARE_EQUAL(RGB(0x34, 0x56, 0x78), terminalSettings3->CursorColor()); // from profile (not set in color scheme)
|
||||
VERIFY_ARE_EQUAL(RGB(0x45, 0x67, 0x89), terminalSettings4->CursorColor()); // from profile (no color scheme)
|
||||
VERIFY_ARE_EQUAL(DEFAULT_CURSOR_COLOR, terminalSettings5->CursorColor()); // default
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,6 @@ Author(s):
|
||||
#include "til.h"
|
||||
|
||||
// Common includes for most tests:
|
||||
#include "../../inc/argb.h"
|
||||
#include "../../inc/conattrs.hpp"
|
||||
#include "../../types/inc/utils.hpp"
|
||||
#include "../../inc/DefaultSettings.h"
|
||||
|
||||
@@ -69,7 +69,6 @@ Author(s):
|
||||
#include "til.h"
|
||||
|
||||
// Common includes for most tests:
|
||||
#include "../../inc/argb.h"
|
||||
#include "../../inc/conattrs.hpp"
|
||||
#include "../../types/inc/utils.hpp"
|
||||
#include "../../inc/DefaultSettings.h"
|
||||
|
||||
@@ -1101,7 +1101,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
|
||||
til::color ControlCore::BackgroundColor() const
|
||||
{
|
||||
return til::color{ _terminal->GetColorTableEntry(TextColor::DEFAULT_BACKGROUND) }.with_alpha(0xff);
|
||||
return _terminal->GetColorTableEntry(TextColor::DEFAULT_BACKGROUND);
|
||||
}
|
||||
|
||||
// Method Description:
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "pch.h"
|
||||
#include "ControlInteractivity.h"
|
||||
#include <argb.h>
|
||||
#include <DefaultSettings.h>
|
||||
#include <unicode.hpp>
|
||||
#include <Utf16Parser.hpp>
|
||||
|
||||
@@ -450,7 +450,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
|
||||
void TermControl::_InitializeBackgroundBrush()
|
||||
{
|
||||
auto settings{ _core.Settings() };
|
||||
auto bgColor = til::color{ _core.FocusedAppearance().DefaultBackground() }.with_alpha(0xff);
|
||||
auto bgColor = til::color{ _core.FocusedAppearance().DefaultBackground() };
|
||||
if (settings.UseAcrylic())
|
||||
{
|
||||
// See if we've already got an acrylic background brush
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "../../terminal/parser/OutputStateMachineEngine.hpp"
|
||||
#include "TerminalDispatch.hpp"
|
||||
#include "../../inc/unicode.hpp"
|
||||
#include "../../inc/argb.h"
|
||||
#include "../../types/inc/utils.hpp"
|
||||
#include "../../types/inc/colorTable.hpp"
|
||||
|
||||
@@ -81,7 +80,7 @@ Terminal::Terminal() :
|
||||
_InitializeColorTable();
|
||||
|
||||
_colorTable.at(TextColor::DEFAULT_FOREGROUND) = RGB(255, 255, 255);
|
||||
_colorTable.at(TextColor::DEFAULT_BACKGROUND) = ARGB(0, 0, 0, 0);
|
||||
_colorTable.at(TextColor::DEFAULT_BACKGROUND) = RGB(0, 0, 0);
|
||||
_colorTable.at(TextColor::CURSOR_COLOR) = INVALID_COLOR;
|
||||
}
|
||||
|
||||
@@ -137,12 +136,12 @@ void Terminal::UpdateSettings(ICoreSettings settings)
|
||||
}
|
||||
else
|
||||
{
|
||||
_tabColor = til::color{ settings.TabColor().Value() }.with_alpha(0xff);
|
||||
_tabColor = settings.TabColor().Value();
|
||||
}
|
||||
|
||||
if (!_startingTabColor && settings.StartingTabColor())
|
||||
{
|
||||
_startingTabColor = til::color{ settings.StartingTabColor().Value() }.with_alpha(0xff);
|
||||
_startingTabColor = settings.StartingTabColor().Value();
|
||||
}
|
||||
|
||||
if (_pfnTabColorChanged)
|
||||
@@ -186,7 +185,7 @@ void Terminal::UpdateAppearance(const ICoreAppearance& appearance)
|
||||
// Set the default background as transparent to prevent the
|
||||
// DX layer from overwriting the background image or acrylic effect
|
||||
const til::color newBackgroundColor{ appearance.DefaultBackground() };
|
||||
_colorTable.at(TextColor::DEFAULT_BACKGROUND) = newBackgroundColor.with_alpha(0);
|
||||
_colorTable.at(TextColor::DEFAULT_BACKGROUND) = newBackgroundColor;
|
||||
const til::color newForegroundColor{ appearance.DefaultForeground() };
|
||||
_colorTable.at(TextColor::DEFAULT_FOREGROUND) = newForegroundColor;
|
||||
const til::color newCursorColor{ appearance.CursorColor() };
|
||||
@@ -1226,8 +1225,6 @@ try
|
||||
const gsl::span<COLORREF> tableView = { _colorTable.data(), _colorTable.size() };
|
||||
// First set up the basic 256 colors
|
||||
Utils::InitializeColorTable(tableView);
|
||||
// Then make sure all the values have an alpha of 255
|
||||
Utils::SetColorTableAlpha(tableView, 0xff);
|
||||
}
|
||||
CATCH_LOG()
|
||||
|
||||
@@ -1311,9 +1308,7 @@ Scheme Terminal::GetColorScheme() const noexcept
|
||||
Scheme s;
|
||||
|
||||
s.Foreground = til::color{ _colorTable.at(TextColor::DEFAULT_FOREGROUND) };
|
||||
// Don't leak the implementation detail that our _defaultBg is stored
|
||||
// internally without alpha.
|
||||
s.Background = til::color{ _colorTable.at(TextColor::DEFAULT_BACKGROUND) }.with_alpha(0xff);
|
||||
s.Background = til::color{ _colorTable.at(TextColor::DEFAULT_BACKGROUND) };
|
||||
|
||||
// SelectionBackground is stored in the ControlAppearance
|
||||
s.CursorColor = til::color{ _colorTable.at(TextColor::CURSOR_COLOR) };
|
||||
@@ -1340,10 +1335,7 @@ Scheme Terminal::GetColorScheme() const noexcept
|
||||
void Terminal::ApplyScheme(const Scheme& colorScheme)
|
||||
{
|
||||
_colorTable.at(TextColor::DEFAULT_FOREGROUND) = til::color{ colorScheme.Foreground };
|
||||
// Set the default background as transparent to prevent the
|
||||
// DX layer from overwriting the background image or acrylic effect
|
||||
til::color newBackgroundColor{ colorScheme.Background };
|
||||
_colorTable.at(TextColor::DEFAULT_BACKGROUND) = newBackgroundColor.with_alpha(0);
|
||||
_colorTable.at(TextColor::DEFAULT_BACKGROUND) = til::color{ colorScheme.Background };
|
||||
|
||||
_colorTable[0] = til::color{ colorScheme.Black };
|
||||
_colorTable[1] = til::color{ colorScheme.Red };
|
||||
|
||||
@@ -50,7 +50,6 @@ Licensed under the MIT license.
|
||||
#include "ThrottledFunc.h"
|
||||
|
||||
// Common includes for most tests:
|
||||
#include "../../inc/argb.h"
|
||||
#include "../../inc/conattrs.hpp"
|
||||
#include "../../types/inc/utils.hpp"
|
||||
#include "../../inc/DefaultSettings.h"
|
||||
|
||||
@@ -44,7 +44,6 @@ Licensed under the MIT license.
|
||||
#include "til.h"
|
||||
|
||||
// Common includes for most tests:
|
||||
#include "../../inc/argb.h"
|
||||
#include "../../inc/conattrs.hpp"
|
||||
#include "../../types/inc/utils.hpp"
|
||||
#include "../../inc/DefaultSettings.h"
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "pch.h"
|
||||
#include <WexTestClass.h>
|
||||
|
||||
#include <argb.h>
|
||||
#include <DefaultSettings.h>
|
||||
|
||||
#include "../renderer/inc/DummyRenderTarget.hpp"
|
||||
|
||||
@@ -53,7 +53,6 @@ Author(s):
|
||||
#include "til.h"
|
||||
|
||||
// Common includes for most tests:
|
||||
#include "../../inc/argb.h"
|
||||
#include "../../inc/conattrs.hpp"
|
||||
#include "../../types/inc/utils.hpp"
|
||||
#include "../../inc/DefaultSettings.h"
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
/*++
|
||||
Copyright (c) Microsoft Corporation
|
||||
Licensed under the MIT license.
|
||||
|
||||
Module Name:
|
||||
- argb.h
|
||||
|
||||
Abstract:
|
||||
- Replaces the RGB macro with one that fills the highest order byte with 0xff.
|
||||
We use this for the cascadia project, because it can have colors with an
|
||||
alpha component. For code that is alpha-aware, include this header to make
|
||||
RGB() fill the alpha byte. Otherwise, colors made with RGB will be transparent.
|
||||
Author(s):
|
||||
- Mike Griese (migrie) Feb 2019
|
||||
--*/
|
||||
#pragma once
|
||||
|
||||
constexpr COLORREF ARGB(const BYTE a, const BYTE r, const BYTE g, const BYTE b) noexcept
|
||||
{
|
||||
return (a << 24) | (b << 16) | (g << 8) | (r);
|
||||
}
|
||||
|
||||
#ifdef RGB
|
||||
#undef RGB
|
||||
#define RGB(r, g, b) (ARGB(255, (r), (g), (b)))
|
||||
#endif
|
||||
@@ -348,8 +348,7 @@ try
|
||||
if (!fInvert)
|
||||
{
|
||||
// Make sure to make the cursor opaque
|
||||
RETURN_IF_FAILED(d2dContext->CreateSolidColorBrush(til::color{ OPACITY_OPAQUE | options.cursorColor },
|
||||
&brush));
|
||||
RETURN_IF_FAILED(d2dContext->CreateSolidColorBrush(til::color{ options.cursorColor }, &brush));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -16,20 +16,4 @@ namespace Microsoft::Console::Utils
|
||||
gsl::span<const til::color> CampbellColorTable();
|
||||
|
||||
std::optional<til::color> ColorFromXOrgAppColorName(const std::wstring_view wstr) noexcept;
|
||||
|
||||
// Function Description:
|
||||
// - Fill the alpha byte of the colors in a given color table with the given value.
|
||||
// Arguments:
|
||||
// - table: a color table
|
||||
// - newAlpha: the new value to use as the alpha for all the entries in that table.
|
||||
// Return Value:
|
||||
// - <none>
|
||||
constexpr void SetColorTableAlpha(const gsl::span<COLORREF> table, const BYTE newAlpha) noexcept
|
||||
{
|
||||
const auto shiftedAlpha = newAlpha << 24;
|
||||
for (auto& color : table)
|
||||
{
|
||||
WI_UpdateFlagsInMask(color, 0xff000000, shiftedAlpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user