mirror of
https://github.com/hyprwm/hyprpicker.git
synced 2024-11-17 00:25:57 +01:00
output: colorize BG instead of FG (#70)
This commit is contained in:
parent
be7a0e82c4
commit
e2472f499d
1 changed files with 13 additions and 4 deletions
|
@ -137,6 +137,10 @@ void Events::handlePointerButton(void* data, struct wl_pointer* wl_pointer, uint
|
||||||
auto fmax3 = [](float a, float b, float c) -> float { return (a > b && a > c) ? a : (b > c) ? b : c; };
|
auto fmax3 = [](float a, float b, float c) -> float { return (a > b && a > c) ? a : (b > c) ? b : c; };
|
||||||
auto fmin3 = [](float a, float b, float c) -> float { return (a < b && a < c) ? a : (b < c) ? b : c; };
|
auto fmin3 = [](float a, float b, float c) -> float { return (a < b && a < c) ? a : (b < c) ? b : c; };
|
||||||
|
|
||||||
|
// relative brightness of a color
|
||||||
|
// https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
|
||||||
|
const auto FLUMI = [](const float& c) -> float { return c <= 0.03928 ? c / 12.92 : powf((c + 0.055) / 1.055, 2.4); };
|
||||||
|
|
||||||
// get the px and print it
|
// get the px and print it
|
||||||
const auto SCALE = Vector2D{
|
const auto SCALE = Vector2D{
|
||||||
g_pHyprpicker->m_pLastSurface->screenBuffer.pixelSize.x / (g_pHyprpicker->m_pLastSurface->buffers[0].pixelSize.x / g_pHyprpicker->m_pLastSurface->m_pMonitor->scale),
|
g_pHyprpicker->m_pLastSurface->screenBuffer.pixelSize.x / (g_pHyprpicker->m_pLastSurface->buffers[0].pixelSize.x / g_pHyprpicker->m_pLastSurface->m_pMonitor->scale),
|
||||||
|
@ -146,6 +150,10 @@ void Events::handlePointerButton(void* data, struct wl_pointer* wl_pointer, uint
|
||||||
|
|
||||||
const auto COL = g_pHyprpicker->getColorFromPixel(g_pHyprpicker->m_pLastSurface, CLICKPOS);
|
const auto COL = g_pHyprpicker->getColorFromPixel(g_pHyprpicker->m_pLastSurface, CLICKPOS);
|
||||||
|
|
||||||
|
// threshold: (lumi_white + 0.05) / (x + 0.05) == (x + 0.05) / (lumi_black + 0.05)
|
||||||
|
// https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
|
||||||
|
const uint8_t FG = 0.2126 * FLUMI(COL.r / 255.0f) + 0.7152 * FLUMI(COL.g / 255.0f) + 0.0722 * FLUMI(COL.b / 255.0f) > 0.17913 ? 0 : 255;
|
||||||
|
|
||||||
switch (g_pHyprpicker->m_bSelectedOutputMode) {
|
switch (g_pHyprpicker->m_bSelectedOutputMode) {
|
||||||
case OUTPUT_CMYK: {
|
case OUTPUT_CMYK: {
|
||||||
// http://www.codeproject.com/KB/applications/xcmyk.aspx
|
// http://www.codeproject.com/KB/applications/xcmyk.aspx
|
||||||
|
@ -160,7 +168,7 @@ void Events::handlePointerButton(void* data, struct wl_pointer* wl_pointer, uint
|
||||||
k = std::round(k * 100);
|
k = std::round(k * 100);
|
||||||
|
|
||||||
if (g_pHyprpicker->m_bFancyOutput)
|
if (g_pHyprpicker->m_bFancyOutput)
|
||||||
Debug::log(NONE, "\033[38;2;%i;%i;%im%g%% %g%% %g%% %g%%\033[0m", COL.r, COL.g, COL.b, c, m, y, k);
|
Debug::log(NONE, "\033[38;2;%i;%i;%i;48;2;%i;%i;%im%g%% %g%% %g%% %g%%\033[0m", FG, FG, FG, COL.r, COL.g, COL.b, c, m, y, k);
|
||||||
else
|
else
|
||||||
Debug::log(NONE, "%g%% %g%% %g%% %g%%", c, m, y, k);
|
Debug::log(NONE, "%g%% %g%% %g%% %g%%", c, m, y, k);
|
||||||
|
|
||||||
|
@ -182,7 +190,8 @@ void Events::handlePointerButton(void* data, struct wl_pointer* wl_pointer, uint
|
||||||
};
|
};
|
||||||
|
|
||||||
if (g_pHyprpicker->m_bFancyOutput)
|
if (g_pHyprpicker->m_bFancyOutput)
|
||||||
Debug::log(NONE, "\033[38;2;%i;%i;%im#%s%s%s\033[0m", COL.r, COL.g, COL.b, toHex(COL.r).c_str(), toHex(COL.g).c_str(), toHex(COL.b).c_str());
|
Debug::log(NONE, "\033[38;2;%i;%i;%i;48;2;%i;%i;%im#%s%s%s\033[0m", FG, FG, FG, COL.r, COL.g, COL.b, toHex(COL.r).c_str(), toHex(COL.g).c_str(),
|
||||||
|
toHex(COL.b).c_str());
|
||||||
else
|
else
|
||||||
Debug::log(NONE, "#%s%s%s", toHex(COL.r).c_str(), toHex(COL.g).c_str(), toHex(COL.b).c_str());
|
Debug::log(NONE, "#%s%s%s", toHex(COL.r).c_str(), toHex(COL.g).c_str(), toHex(COL.b).c_str());
|
||||||
|
|
||||||
|
@ -193,7 +202,7 @@ void Events::handlePointerButton(void* data, struct wl_pointer* wl_pointer, uint
|
||||||
}
|
}
|
||||||
case OUTPUT_RGB: {
|
case OUTPUT_RGB: {
|
||||||
if (g_pHyprpicker->m_bFancyOutput)
|
if (g_pHyprpicker->m_bFancyOutput)
|
||||||
Debug::log(NONE, "\033[38;2;%i;%i;%im%i %i %i\033[0m", COL.r, COL.g, COL.b, COL.r, COL.g, COL.b);
|
Debug::log(NONE, "\033[38;2;%i;%i;%i;48;2;%i;%i;%im%i %i %i\033[0m", FG, FG, FG, COL.r, COL.g, COL.b, COL.r, COL.g, COL.b);
|
||||||
else
|
else
|
||||||
Debug::log(NONE, "%i %i %i", COL.r, COL.g, COL.b);
|
Debug::log(NONE, "%i %i %i", COL.r, COL.g, COL.b);
|
||||||
|
|
||||||
|
@ -240,7 +249,7 @@ void Events::handlePointerButton(void* data, struct wl_pointer* wl_pointer, uint
|
||||||
s = std::round(s * 100);
|
s = std::round(s * 100);
|
||||||
|
|
||||||
if (g_pHyprpicker->m_bFancyOutput)
|
if (g_pHyprpicker->m_bFancyOutput)
|
||||||
Debug::log(NONE, "\033[38;2;%i;%i;%im%g %g%% %g%%\033[0m", COL.r, COL.g, COL.b, h, s, l_or_v);
|
Debug::log(NONE, "\033[38;2;%i;%i;%i;48;2;%i;%i;%im%g %g%% %g%%\033[0m", FG, FG, FG, COL.r, COL.g, COL.b, h, s, l_or_v);
|
||||||
else
|
else
|
||||||
Debug::log(NONE, "%g %g%% %g%%", h, s, l_or_v);
|
Debug::log(NONE, "%g %g%% %g%%", h, s, l_or_v);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue