Skip to content

Commit

Permalink
works
Browse files Browse the repository at this point in the history
  • Loading branch information
PankajBhojwani committed Aug 31, 2021
1 parent 6373bae commit da2cad8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
50 changes: 25 additions & 25 deletions src/cascadia/TerminalCore/ColorFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
#include <math.h>
#include "ColorFix.hpp"

const double g_min_thrashold = 12.0;
const double g_exp_thrashold = 20.0;
const double g_L_step = 5.0;
const double gMinThreshold = 12.0;
const double gExpThreshold = 20.0;
const double gLStep = 5.0;

// DeltaE 2000
// Source: https://github.com/zschuessler/DeltaE
dE00::dE00(ColorFix ax1, ColorFix ax2, double weight_lightness, double weight_chroma, double weight_hue)
dE00::dE00(ColorFix x1, ColorFix x2, double weightLightness, double weightChroma, double weightHue)
{
_x1 = ax1;
_x2 = ax2;
_x1 = x1;
_x2 = x2;

_kSubL = weight_lightness;
_kSubC = weight_chroma;
_kSubH = weight_hue;
_kSubL = weightLightness;
_kSubC = weightChroma;
_kSubH = weightHue;

// Delta L Prime
_deltaLPrime = _x2.L - _x1.L;

// L Bar
_lBar = (_x1.L + _x2.L) / 2;

// _c1 & _c2
// C1 & C2
_c1 = sqrt(pow(_x1.A, 2) + pow(_x1.B, 2));
_c2 = sqrt(pow(_x2.A, 2) + pow(_x2.B, 2));

Expand Down Expand Up @@ -418,26 +418,26 @@ ColorFix::ColorFix()
B = 0;
}

ColorFix::ColorFix(COLORREF a_rgb)
ColorFix::ColorFix(COLORREF color)
{
rgb = a_rgb;
rgb = color;
ToLab();
}

ColorFix::ColorFix(double a_L, double a_a, double a_b)
ColorFix::ColorFix(double l, double a, double b)
{
L = a_L;
A = a_a;
B = a_b;
L = l;
A = a;
B = b;
ToRGB();
}

ColorFix::ColorFix(const ColorFix& clr)
ColorFix::ColorFix(const ColorFix& color)
{
L = clr.L;
A = clr.A;
B = clr.B;
rgb = clr.rgb;
L = color.L;
A = color.A;
B = color.B;
rgb = color.rgb;
}

void ColorFix::ToLab()
Expand All @@ -455,7 +455,7 @@ double ColorFix::DeltaE(ColorFix color)
return ColorSpace::DeltaE(*this, color);
}

bool ColorFix::PerceivableColor(COLORREF back /*, COLORREF alt*/, ColorFix& pColor, double* oldDE /*= NULL*/, double* newDE /*= NULL*/)
bool ColorFix::PerceivableColor(COLORREF back, ColorFix& pColor, double* oldDE, double* newDE)
{
bool bChanged = false;
ColorFix backLab(back);
Expand All @@ -464,19 +464,19 @@ bool ColorFix::PerceivableColor(COLORREF back /*, COLORREF alt*/, ColorFix& pCol
*oldDE = de1;
if (newDE)
*newDE = de1;
if (de1 < g_min_thrashold)
if (de1 < gMinThreshold)
{
for (int i = 0; i <= 1; i++)
{
double step = (i == 0) ? g_L_step : -g_L_step;
double step = (i == 0) ? gLStep : -gLStep;
pColor.L = L + step;
pColor.A = A;
pColor.B = B;

while (((i == 0) && (pColor.L <= 100)) || ((i == 1) && (pColor.L >= 0)))
{
double de2 = pColor.DeltaE(backLab);
if (de2 >= g_exp_thrashold)
if (de2 >= gExpThreshold)
{
if (newDE)
*newDE = de2;
Expand Down
10 changes: 5 additions & 5 deletions src/cascadia/TerminalCore/ColorFix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
struct ColorFix
{
ColorFix();
ColorFix(COLORREF a_rgb);
ColorFix(double a_L, double a_a, double a_b);
ColorFix(const ColorFix& clr);
ColorFix(COLORREF color);
ColorFix(double l, double a, double b);
ColorFix(const ColorFix& color);

void ToLab();
void ToRGB();

double DeltaE(ColorFix color);

bool PerceivableColor(COLORREF back /*, COLORREF alt*/, ColorFix& pColor, double* oldDE = NULL, double* newDE = NULL);
bool PerceivableColor(COLORREF back, ColorFix& pColor, double* oldDE = NULL, double* newDE = NULL);

// RGB
union
Expand All @@ -40,7 +40,7 @@ struct ColorFix
struct dE00
{
public:
dE00(ColorFix ax1, ColorFix ax2, double weight_lightness = 1, double weight_chroma = 1, double weight_hue = 1);
dE00(ColorFix x1, ColorFix x2, double weightLightness = 1, double weightChroma = 1, double weightHue = 1);
double GetDeltaE();

private:
Expand Down
7 changes: 6 additions & 1 deletion src/cascadia/TerminalCore/terminalrenderdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "pch.h"
#include "Terminal.hpp"
#include <DefaultSettings.h>
#include "ColorFix.hpp"

using namespace Microsoft::Terminal::Core;
using namespace Microsoft::Console::Types;
using namespace Microsoft::Console::Render;
Expand Down Expand Up @@ -59,7 +61,10 @@ std::pair<COLORREF, COLORREF> Terminal::GetAttributeColors(const TextAttribute&
{
colors.second |= 0xff000000;
}
return colors;
ColorFix colorFix{ colors.first };
ColorFix result{};
colorFix.PerceivableColor(colors.second, result);
return std::pair<COLORREF, COLORREF>(result.rgb, colors.second);
}

COORD Terminal::GetCursorPosition() const noexcept
Expand Down

1 comment on commit da2cad8

@github-actions

This comment was marked as outdated.

Please sign in to comment.