Commit dc29be39 authored by Mariusz Glebocki's avatar Mariusz Glebocki Committed by Kurt Hindenburg

Keep perceived contrast in random background color

Summary:
Randomize colors using HSLuv color space instead of HSL. It has
perceptually uniform lightness, which means every color with the same
lightness value is perceived as equally bright by humans. Displays
quality and lack of calibration in most monitors lowers this uniformity,
but even on worst color display it should be better than standard HSL.

More information about HSLuv: http://www.hsluv.org/

Minor changes:

* Random seed takes PID into account to prevent repeated colors in
  separate Konsole processes
* Key names in a config were changed
* Adapted "Black on random light" color scheme

Breeze with random ranges on default bg and fg: hue=360° saturation=100:
{F6754773}

To be done in future:

* Automatically convert color schemes which use old randomization
  method.

Reviewers: #konsole, #vdg

Subscribers: hindenburg, #vdg, #konsole

Tags: #konsole, #vdg

Differential Revision: https://phabricator.kde.org/D20263
parent 74a01214
[Background]
Color=247,247,214
MaxRandomHue=340
RandomHueRange=360
RandomSaturationRange=25
RandomLightnessRange=10
[BackgroundIntense]
Color=255,255,221
RandomHueRange=360
RandomSaturationRange=25
RandomLightnessRange=10
[BackgroundFaint]
Color=247,247,214
RandomHueRange=360
RandomSaturationRange=25
RandomLightnessRange=10
[Color0]
Color=0,0,0
......@@ -92,4 +100,5 @@ Color=0,0,0
[General]
Description=Black on Random Light
ColorRandomization=true
Opacity=1
......@@ -51,6 +51,7 @@ qt5_add_dbus_adaptor(windowadaptors_SRCS
set(konsoleprivate_SRCS ${sessionadaptors_SRCS}
${windowadaptors_SRCS}
hsluv.c
BookmarkHandler.cpp
ColorScheme.cpp
ColorSchemeManager.cpp
......
......@@ -43,6 +43,41 @@ typedef QColor ColorEntry;
#define INTENSITIES 3
#define TABLE_COLORS (INTENSITIES*BASE_COLORS)
enum ColorTableIndex {
ColorFgIndex,
ColorBgIndex,
Color0Index,
Color1Index,
Color2Index,
Color3Index,
Color4Index,
Color5Index,
Color6Index,
Color7Index,
ColorFgIntenseIndex,
ColorBgIntenseIndex,
Color0IntenseIndex,
Color1IntenseIndex,
Color2IntenseIndex,
Color3IntenseIndex,
Color4IntenseIndex,
Color5IntenseIndex,
Color6IntenseIndex,
Color7IntenseIndex,
ColorFgFaintIndex,
ColorBgFaintIndex,
Color0FaintIndex,
Color1FaintIndex,
Color2FaintIndex,
Color3FaintIndex,
Color4FaintIndex,
Color5FaintIndex,
Color6FaintIndex,
Color7FaintIndex,
};
#define DEFAULT_FORE_COLOR 0
#define DEFAULT_BACK_COLOR 1
......
This diff is collapsed.
......@@ -132,8 +132,8 @@ public:
/**
* Returns true if this color scheme has a dark background.
* The background color is said to be dark if it has a value of less than 127
* in the HSV color space.
* The background color is said to be dark if it has a lightness
* of less than 50% in the HSLuv color space.
*/
bool hasDarkBackground() const;
......@@ -169,15 +169,15 @@ public:
ColorSchemeWallpaper::Ptr wallpaper() const;
/**
* Enables randomization of the background color. This will cause
* the palette returned by getColorTable() and colorEntry() to
* be adjusted depending on the value of the random seed argument
* to them.
* Enables colors randomization. This will cause the palette
* returned by getColorTable() and colorEntry() to be adjusted
* depending on the parameters of color randomization and the
* random seed parameter passed to them.
*/
void setRandomizedBackgroundColor(bool randomize);
void setColorRandomization(bool randomize);
/** Returns true if the background color is randomized. */
bool randomizedBackgroundColor() const;
/** Returns true if color randomization is enabled. */
bool isColorRandomizationEnabled() const;
static const ColorEntry defaultTable[]; // table of default color entries
......@@ -189,20 +189,20 @@ private:
class RandomizationRange
{
public:
RandomizationRange() : hue(0),
saturation(0),
value(0)
RandomizationRange() : hue(0.0),
saturation(0.0),
lightness(0.0)
{
}
bool isNull() const
{
return hue == 0 && saturation == 0 && value == 0;
return qFuzzyIsNull(hue) && qFuzzyIsNull(saturation) && qFuzzyIsNull(lightness);
}
quint16 hue;
quint8 saturation;
quint8 value;
double hue;
double saturation;
double lightness;
};
// returns the active color table. if none has been set specifically,
......@@ -218,7 +218,7 @@ private:
// sets the amount of randomization allowed for a particular color
// in the palette. creates the randomization table if
// it does not already exist
void setRandomizationRange(int index, quint16 hue, quint8 saturation, quint8 value);
void setRandomizationRange(int index, double hue, double saturation, double lightness);
QString _description;
QString _name;
......@@ -236,9 +236,9 @@ private:
// enables blur behind the terminal window
bool _blur;
ColorSchemeWallpaper::Ptr _wallpaper;
bool _colorRandomization;
static const quint16 MAX_HUE = 340;
ColorSchemeWallpaper::Ptr _wallpaper;
static const char * const colorNames[TABLE_COLORS];
static const char * const translatedColorNames[TABLE_COLORS];
......
......@@ -258,7 +258,7 @@ void ColorSchemeEditor::setBlur(bool blur)
void ColorSchemeEditor::setRandomizedBackgroundColor(bool randomized)
{
_colors->setRandomizedBackgroundColor(randomized);
_colors->setColorRandomization(randomized);
}
void ColorSchemeEditor::setup(const ColorScheme *scheme, bool isNewScheme)
......@@ -291,7 +291,7 @@ void ColorSchemeEditor::setup(const ColorScheme *scheme, bool isNewScheme)
_ui->blurCheckBox->setChecked(scheme->blur());
// randomized background color checkbox
_ui->randomizedBackgroundCheck->setChecked(scheme->randomizedBackgroundColor());
_ui->randomizedBackgroundCheck->setChecked(scheme->isColorRandomizationEnabled());
// wallpaper stuff
_ui->wallpaperPath->setText(scheme->wallpaper()->path());
......
......@@ -45,8 +45,12 @@
</item>
<item>
<widget class="QCheckBox" name="randomizedBackgroundCheck">
<property name="toolTip">
<string>Hue and saturation values of default foreground and background colors are randomized by default. Some color schemes might use different randomization settings.
To see any effect, set colors with saturation value greater than 0.</string>
</property>
<property name="text">
<string>Vary the background color for each tab</string>
<string>Randomly adjust colors for each session</string>
</property>
</widget>
</item>
......
......@@ -774,9 +774,10 @@ void ViewManager::viewDestroyed(QWidget *view)
TerminalDisplay *ViewManager::createTerminalDisplay(Session *session)
{
auto display = new TerminalDisplay(nullptr);
display->setRandomSeed(session->sessionId() * 31);
display->setRandomSeed(session->sessionId() | (qApp->applicationPid() << 10));
connect(display, &TerminalDisplay::requestToggleExpansion,
_viewContainer, &TabbedViewContainer::toggleMaximizeCurrentTerminal);
return display;
}
......
This diff is collapsed.
/*
* HSLuv-C: Human-friendly HSL
* <http://github.com/hsluv/hsluv-c>
* <http://www.hsluv.org/>
*
* Copyright (c) 2015 Alexei Boronine (original idea, JavaScript implementation)
* Copyright (c) 2015 Roger Tallada (Obj-C implementation)
* Copyright (c) 2017 Martin Mitas (C implementation, based on Obj-C implementation)
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef HSLUV_H
#define HSLUV_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* Convert HSLuv to RGB.
*
* @param h Hue. Between 0.0 and 360.0.
* @param s Saturation. Between 0.0 and 100.0.
* @param l Lightness. Between 0.0 and 100.0.
* @param[out] pr Red component. Between 0.0 and 1.0.
* @param[out] pr Green component. Between 0.0 and 1.0.
* @param[out] pr Blue component. Between 0.0 and 1.0.
*/
void hsluv2rgb(double h, double s, double l, double* pr, double* pg, double* pb);
/**
* Convert RGB to HSLuv.
*
* @param r Red component. Between 0.0 and 1.0.
* @param g Green component. Between 0.0 and 1.0.
* @param b Blue component. Between 0.0 and 1.0.
* @param[out] ph Hue. Between 0.0 and 360.0.
* @param[out] ps Saturation. Between 0.0 and 100.0.
* @param[out] pl Lightness. Between 0.0 and 100.0.
*/
void rgb2hsluv(double r, double g, double b, double* ph, double* ps, double* pl);
/**
* Convert HPLuv to RGB.
*
* @param h Hue. Between 0.0 and 360.0.
* @param s Saturation. Between 0.0 and 100.0.
* @param l Lightness. Between 0.0 and 100.0.
* @param[out] pr Red component. Between 0.0 and 1.0.
* @param[out] pg Green component. Between 0.0 and 1.0.
* @param[out] pb Blue component. Between 0.0 and 1.0.
*/
void hpluv2rgb(double h, double s, double l, double* pr, double* pg, double* pb);
/**
* Convert RGB to HPLuv.
*
* @param r Red component. Between 0.0 and 1.0.
* @param g Green component. Between 0.0 and 1.0.
* @param b Blue component. Between 0.0 and 1.0.
* @param[out] ph Hue. Between 0.0 and 360.0.
* @param[out] ps Saturation. Between 0.0 and 100.0.
* @param[out] pl Lightness. Between 0.0 and 100.0.
*/
void rgb2hpluv(double r, double g, double b, double* ph, double* ps, double* pl);
#ifdef __cplusplus
}
#endif
#endif /* HSLUV_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment