mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-27 00:58:36 +00:00
refactor gradients to use config value instead of hard-coded option
This commit is contained in:
parent
938526755c
commit
ac7887ad09
@ -433,6 +433,10 @@ values:
|
|||||||
desc: Shows the time range covered by a graph.
|
desc: Shows the time range covered by a graph.
|
||||||
- name: show_graph_scale
|
- name: show_graph_scale
|
||||||
desc: Shows the maximum value in scaled graphs.
|
desc: Shows the maximum value in scaled graphs.
|
||||||
|
- name: graph_gradient_mode
|
||||||
|
desc: |-
|
||||||
|
Changes the color space used for interpolation. Arguments are hcl, hsv,
|
||||||
|
and rgb (default).
|
||||||
- name: stippled_borders
|
- name: stippled_borders
|
||||||
desc: Border stippling (dashing) in pixels.
|
desc: Border stippling (dashing) in pixels.
|
||||||
- name: temperature_unit
|
- name: temperature_unit
|
||||||
|
@ -68,6 +68,8 @@ set(conky_sources
|
|||||||
exec.h
|
exec.h
|
||||||
fs.cc
|
fs.cc
|
||||||
fs.h
|
fs.h
|
||||||
|
gradient.cc
|
||||||
|
gradient.h
|
||||||
mail.cc
|
mail.cc
|
||||||
mail.h
|
mail.h
|
||||||
misc.cc
|
misc.cc
|
||||||
@ -299,14 +301,6 @@ if(BUILD_INTEL_BACKLIGHT)
|
|||||||
set(optional_sources ${optional_sources} ${intel_backlight})
|
set(optional_sources ${optional_sources} ${intel_backlight})
|
||||||
endif(BUILD_INTEL_BACKLIGHT)
|
endif(BUILD_INTEL_BACKLIGHT)
|
||||||
|
|
||||||
if(BUILD_HCL_GRADIENT)
|
|
||||||
set(hcl_gradient hcl_gradient.cc hcl_gradient.h)
|
|
||||||
set(optional_sources ${optional_sources} ${hcl_gradient})
|
|
||||||
elseif(BUILD_HSV_GRADIENT)
|
|
||||||
set(hsv_gradient hsv_gradient.cc hsv_gradient.h)
|
|
||||||
set(optional_sources ${optional_sources} ${hsv_gradient})
|
|
||||||
endif(BUILD_HCL_GRADIENT)
|
|
||||||
|
|
||||||
if(BUILD_TESTS)
|
if(BUILD_TESTS)
|
||||||
# Create a library strictly for testing
|
# Create a library strictly for testing
|
||||||
add_library(conky_core ${conky_sources} ${optional_sources})
|
add_library(conky_core ${conky_sources} ${optional_sources})
|
||||||
|
@ -83,69 +83,6 @@ unsigned int adjust_colours(unsigned int colour) {
|
|||||||
return colour;
|
return colour;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this function returns the next colour between two colours for a gradient */
|
|
||||||
std::unique_ptr<unsigned long[]> do_gradient(int width,
|
|
||||||
unsigned long first_colour,
|
|
||||||
unsigned long last_colour) {
|
|
||||||
int red1, green1, blue1; // first colour
|
|
||||||
int red2, green2, blue2; // last colour
|
|
||||||
int reddiff, greendiff, bluediff; // difference
|
|
||||||
short redshift = (2 * colour_depth / 3 + colour_depth % 3);
|
|
||||||
short greenshift = (colour_depth / 3);
|
|
||||||
|
|
||||||
// Make sure the width is always at least 2
|
|
||||||
width = std::max(2, width);
|
|
||||||
|
|
||||||
std::unique_ptr<unsigned long[]> colours(new unsigned long[width]);
|
|
||||||
|
|
||||||
if (colour_depth == 0) { set_up_gradient(); }
|
|
||||||
red1 = (first_colour & redmask) >> redshift;
|
|
||||||
green1 = (first_colour & greenmask) >> greenshift;
|
|
||||||
blue1 = first_colour & bluemask;
|
|
||||||
red2 = (last_colour & redmask) >> redshift;
|
|
||||||
green2 = (last_colour & greenmask) >> greenshift;
|
|
||||||
blue2 = last_colour & bluemask;
|
|
||||||
reddiff = abs(red1 - red2);
|
|
||||||
greendiff = abs(green1 - green2);
|
|
||||||
bluediff = abs(blue1 - blue2);
|
|
||||||
#ifdef HAVE_OPENMP
|
|
||||||
#pragma omp parallel for schedule(dynamic, 10) shared(colours)
|
|
||||||
#endif /* HAVE_OPENMP */
|
|
||||||
for (int i = 0; i < width; i++) {
|
|
||||||
int red3 = 0, green3 = 0, blue3 = 0; // colour components
|
|
||||||
|
|
||||||
float factor = (static_cast<float>(i) / (width - 1));
|
|
||||||
|
|
||||||
/* the '+ 0.5' bit rounds our floats to ints properly */
|
|
||||||
if (red1 >= red2) {
|
|
||||||
red3 = -(factor * reddiff) - 0.5;
|
|
||||||
} else if (red1 < red2) {
|
|
||||||
red3 = factor * reddiff + 0.5;
|
|
||||||
}
|
|
||||||
if (green1 >= green2) {
|
|
||||||
green3 = -(factor * greendiff) - 0.5;
|
|
||||||
} else if (green1 < green2) {
|
|
||||||
green3 = factor * greendiff + 0.5;
|
|
||||||
}
|
|
||||||
if (blue1 >= blue2) {
|
|
||||||
blue3 = -(factor * bluediff) - 0.5;
|
|
||||||
} else if (blue1 < blue2) {
|
|
||||||
blue3 = factor * bluediff + 0.5;
|
|
||||||
}
|
|
||||||
red3 += red1;
|
|
||||||
green3 += green1;
|
|
||||||
blue3 += blue1;
|
|
||||||
if (red3 < 0) { red3 = 0; }
|
|
||||||
if (green3 < 0) { green3 = 0; }
|
|
||||||
if (blue3 < 0) { blue3 = 0; }
|
|
||||||
if (red3 > bluemask) { red3 = bluemask; }
|
|
||||||
if (green3 > bluemask) { green3 = bluemask; }
|
|
||||||
if (blue3 > bluemask) { blue3 = bluemask; }
|
|
||||||
colours[i] = (red3 << redshift) | (green3 << greenshift) | blue3;
|
|
||||||
}
|
|
||||||
return colours;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef BUILD_X11
|
#ifdef BUILD_X11
|
||||||
long get_x11_color(const char *name) {
|
long get_x11_color(const char *name) {
|
||||||
XColor color;
|
XColor color;
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
unsigned int adjust_colours(unsigned int);
|
unsigned int adjust_colours(unsigned int);
|
||||||
std::unique_ptr<unsigned long[]> do_gradient(int, unsigned long, unsigned long);
|
|
||||||
|
|
||||||
long get_x11_color(const std::string &colour);
|
long get_x11_color(const std::string &colour);
|
||||||
// XXX: when everyone uses C++ strings, remove this C version
|
// XXX: when everyone uses C++ strings, remove this C version
|
||||||
|
44
src/conky.cc
44
src/conky.cc
@ -130,13 +130,7 @@
|
|||||||
#include "openbsd.h"
|
#include "openbsd.h"
|
||||||
#endif /* __OpenBSD__ */
|
#endif /* __OpenBSD__ */
|
||||||
|
|
||||||
#ifdef BUILD_HCL_GRADIENT
|
#include "gradient.h"
|
||||||
#include "hcl_gradient.h"
|
|
||||||
#endif /* BUILD_HCL_GRADIENT */
|
|
||||||
|
|
||||||
#ifdef BUILD_HSV_GRADIENT
|
|
||||||
#include "hsv_gradient.h"
|
|
||||||
#endif /* BUILD_HSV_GRADIENT */
|
|
||||||
|
|
||||||
#ifdef BUILD_OLD_CONFIG
|
#ifdef BUILD_OLD_CONFIG
|
||||||
#include "convertconf.h"
|
#include "convertconf.h"
|
||||||
@ -295,12 +289,19 @@ conky::range_config_setting<int> diskio_avg_samples("diskio_avg_samples", 1, 14,
|
|||||||
2, true);
|
2, true);
|
||||||
|
|
||||||
#ifdef BUILD_GUI
|
#ifdef BUILD_GUI
|
||||||
|
/* graph */
|
||||||
conky::simple_config_setting<bool> show_graph_scale("show_graph_scale", false,
|
conky::simple_config_setting<bool> show_graph_scale("show_graph_scale", false,
|
||||||
false);
|
false);
|
||||||
conky::simple_config_setting<bool> show_graph_range("show_graph_range", false,
|
conky::simple_config_setting<bool> show_graph_range("show_graph_range", false,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
|
enum gradient_state { RGB_GRADIENT = 0, HSV_GRADIENT, HCL_GRADIENT };
|
||||||
|
template <>
|
||||||
|
conky::lua_traits<gradient_state>::Map conky::lua_traits<gradient_state>::map =
|
||||||
|
{{"rgb", RGB_GRADIENT}, {"hsv", HSV_GRADIENT}, {"hcl", HCL_GRADIENT}};
|
||||||
|
static conky::simple_config_setting<gradient_state> graph_gradient_mode(
|
||||||
|
"graph_gradient_mode", RGB_GRADIENT, false);
|
||||||
|
|
||||||
/* Position on the screen */
|
/* Position on the screen */
|
||||||
conky::simple_config_setting<int> gap_x("gap_x", 5, true);
|
conky::simple_config_setting<int> gap_x("gap_x", 5, true);
|
||||||
conky::simple_config_setting<int> gap_y("gap_y", 60, true);
|
conky::simple_config_setting<int> gap_y("gap_y", 60, true);
|
||||||
@ -402,6 +403,20 @@ int dpi_scale(int value) {
|
|||||||
#endif /* BUILD_GUI */
|
#endif /* BUILD_GUI */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conky::gradient_factory *create_gradient_factory(int width,
|
||||||
|
unsigned long first_colour,
|
||||||
|
unsigned long last_colour) {
|
||||||
|
switch (graph_gradient_mode.get(*state)) {
|
||||||
|
case RGB_GRADIENT:
|
||||||
|
return new conky::rgb_gradient_factory(width, first_colour, last_colour);
|
||||||
|
case HSV_GRADIENT:
|
||||||
|
return new conky::hsv_gradient_factory(width, first_colour, last_colour);
|
||||||
|
case HCL_GRADIENT:
|
||||||
|
return new conky::hcl_gradient_factory(width, first_colour, last_colour);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
/* formatted text to render on screen, generated in generate_text(),
|
/* formatted text to render on screen, generated in generate_text(),
|
||||||
* drawn in draw_stuff() */
|
* drawn in draw_stuff() */
|
||||||
|
|
||||||
@ -1295,17 +1310,10 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
|
|||||||
std::unique_ptr<unsigned long[]> tmpcolour;
|
std::unique_ptr<unsigned long[]> tmpcolour;
|
||||||
|
|
||||||
if (current->last_colour != 0 || current->first_colour != 0) {
|
if (current->last_colour != 0 || current->first_colour != 0) {
|
||||||
#ifdef BUILD_HCL_GRADIENT
|
auto factory = create_gradient_factory(w, current->last_colour,
|
||||||
tmpcolour = do_hcl_gradient(w - 1, current->last_colour,
|
|
||||||
current->first_colour);
|
current->first_colour);
|
||||||
#endif /* BUILD_HCL_GRADIENT */
|
tmpcolour = factory->create_gradient();
|
||||||
#ifdef BUILD_HSV_GRADIENT
|
delete factory;
|
||||||
tmpcolour = do_hsv_gradient(w - 1, current->last_colour,
|
|
||||||
current->first_colour);
|
|
||||||
#else /* BUILD_HSV_GRADIENT */
|
|
||||||
tmpcolour = do_gradient(w - 1, current->last_colour,
|
|
||||||
current->first_colour);
|
|
||||||
#endif /* BUILD_HSV_GRADIENT */
|
|
||||||
}
|
}
|
||||||
colour_idx = 0;
|
colour_idx = 0;
|
||||||
for (i = w - 2; i > -1; i--) {
|
for (i = w - 2; i > -1; i--) {
|
||||||
|
330
src/gradient.cc
Normal file
330
src/gradient.cc
Normal file
@ -0,0 +1,330 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Conky, a system monitor, based on torsmo
|
||||||
|
*
|
||||||
|
* Any original torsmo code is licensed under the BSD license
|
||||||
|
*
|
||||||
|
* All code written since the fork of torsmo is licensed under the GPL
|
||||||
|
*
|
||||||
|
* Please see COPYING for details
|
||||||
|
*
|
||||||
|
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
|
||||||
|
* Copyright (c) 2005-2021 Brenden Matthews, Philip Kovacs, et. al.
|
||||||
|
* (see AUTHORS)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "gradient.h"
|
||||||
|
#include "conky.h"
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
|
#ifdef BUILD_X11
|
||||||
|
#include "x11.h"
|
||||||
|
#endif /* BUILD_X11 */
|
||||||
|
|
||||||
|
namespace conky {
|
||||||
|
bool gradient_factory::is_set = false;
|
||||||
|
short gradient_factory::colour_depth = 0;
|
||||||
|
long gradient_factory::mask[3];
|
||||||
|
short gradient_factory::shift[3];
|
||||||
|
|
||||||
|
gradient_factory::gradient_factory(int width, unsigned long first_colour,
|
||||||
|
unsigned long last_colour) {
|
||||||
|
// Make sure the width is always at least 2
|
||||||
|
this->width = std::max(2, width);
|
||||||
|
this->first_colour = first_colour;
|
||||||
|
this->last_colour = last_colour;
|
||||||
|
|
||||||
|
if (!is_set) {
|
||||||
|
setup_colour_depth();
|
||||||
|
setup_masks();
|
||||||
|
setup_shifts();
|
||||||
|
is_set = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void gradient_factory::setup_shifts() {
|
||||||
|
shift[0] = (2 * colour_depth / 3 + colour_depth % 3);
|
||||||
|
shift[1] = (colour_depth / 3);
|
||||||
|
shift[2] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gradient_factory::setup_masks() {
|
||||||
|
mask[0] = mask[1] = mask[2] = 0;
|
||||||
|
|
||||||
|
for (int i = (colour_depth / 3) - 1; i >= 0; i--) {
|
||||||
|
mask[0] |= 1 << i;
|
||||||
|
mask[1] |= 1 << i;
|
||||||
|
mask[2] |= 1 << i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (colour_depth % 3 == 1) { mask[1] |= 1 << (colour_depth / 3); }
|
||||||
|
|
||||||
|
mask[0] = mask[0] << (2 * colour_depth / 3 + colour_depth % 3);
|
||||||
|
mask[1] = mask[1] << (colour_depth / 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gradient_factory::setup_colour_depth() {
|
||||||
|
#ifdef BUILD_X11
|
||||||
|
if (out_to_x.get(*state)) {
|
||||||
|
colour_depth = DisplayPlanes(display, screen);
|
||||||
|
} else
|
||||||
|
#endif /* BUILD_X11 */
|
||||||
|
{
|
||||||
|
colour_depth = 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (colour_depth != 24 && colour_depth != 16) {
|
||||||
|
NORM_ERR(
|
||||||
|
"using non-standard colour depth, "
|
||||||
|
"gradients may look like a lolly-pop");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void gradient_factory::convert_from_rgb(long original, long *array) {
|
||||||
|
long scaled[3];
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
auto value = (original & mask[i]) >> shift[i];
|
||||||
|
scaled[i] = value * SCALE;
|
||||||
|
}
|
||||||
|
convert_from_scaled_rgb(scaled, array);
|
||||||
|
}
|
||||||
|
|
||||||
|
int gradient_factory::convert_to_rgb(long *const array) {
|
||||||
|
long scaled_rgb[3];
|
||||||
|
int rgb = 0;
|
||||||
|
|
||||||
|
convert_to_scaled_rgb(array, scaled_rgb);
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
auto value = scaled_rgb[i] / SCALE;
|
||||||
|
rgb |= value << shift[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
gradient_factory::colour_array gradient_factory::create_gradient() {
|
||||||
|
colour_array colours(new unsigned long[width]);
|
||||||
|
|
||||||
|
long first_converted[3];
|
||||||
|
long last_converted[3];
|
||||||
|
long diff[3], delta[3];
|
||||||
|
|
||||||
|
colours[0] = first_colour;
|
||||||
|
colours[width - 1] = last_colour;
|
||||||
|
|
||||||
|
convert_from_rgb(first_colour, first_converted);
|
||||||
|
convert_from_rgb(last_colour, last_converted);
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
diff[i] = last_converted[i] - first_converted[i];
|
||||||
|
}
|
||||||
|
fix_diff(diff);
|
||||||
|
for (int i = 0; i < 3; i++) { delta[i] = diff[i] / (width - 1); }
|
||||||
|
for (int i = 1; i < width - 1; i++) {
|
||||||
|
for (int k = 0; k < 3; k++) { first_converted[k] += delta[k]; }
|
||||||
|
colours[i] = convert_to_rgb(first_converted);
|
||||||
|
}
|
||||||
|
|
||||||
|
return colours;
|
||||||
|
}
|
||||||
|
|
||||||
|
long gradient_factory::get_hue(long *const rgb, long chroma, long value) {
|
||||||
|
if (chroma == 0) { return 0; }
|
||||||
|
|
||||||
|
long diff, offset;
|
||||||
|
|
||||||
|
if (rgb[0] == value) {
|
||||||
|
diff = rgb[1] - rgb[2];
|
||||||
|
offset = 0;
|
||||||
|
} else if (rgb[1] == value) {
|
||||||
|
diff = rgb[2] - rgb[0];
|
||||||
|
offset = SCALE2;
|
||||||
|
} else {
|
||||||
|
diff = rgb[0] - rgb[1];
|
||||||
|
offset = SCALE4;
|
||||||
|
}
|
||||||
|
long h = (SCALE * diff) / chroma + offset;
|
||||||
|
|
||||||
|
return 60L * ((SCALE6 + h) % SCALE6);
|
||||||
|
}
|
||||||
|
|
||||||
|
long gradient_factory::get_intermediate(long hue, long chroma) {
|
||||||
|
long h = hue / 60L;
|
||||||
|
long multiplier = SCALE - std::abs(h % SCALE2 - SCALE);
|
||||||
|
|
||||||
|
return (chroma * multiplier) / SCALE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* rgb_gradient_factory */
|
||||||
|
void rgb_gradient_factory::convert_from_scaled_rgb(long *const scaled,
|
||||||
|
long *target) {
|
||||||
|
target[0] = scaled[0] * 360L;
|
||||||
|
target[1] = scaled[1] * 360L;
|
||||||
|
target[2] = scaled[2] * 360L;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rgb_gradient_factory::convert_to_scaled_rgb(long *const target,
|
||||||
|
long *scaled) {
|
||||||
|
scaled[0] = target[0] / 360L;
|
||||||
|
scaled[1] = target[1] / 360L;
|
||||||
|
scaled[2] = target[2] / 360L;
|
||||||
|
}
|
||||||
|
/* rgb_gradient_factory */
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
long get_value(long *const rgb) {
|
||||||
|
if (rgb[0] > rgb[1]) { return std::max(rgb[0], rgb[2]); }
|
||||||
|
return std::max(rgb[1], rgb[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
long get_minimum(long *const rgb) {
|
||||||
|
if (rgb[0] < rgb[1]) { return std::min(rgb[0], rgb[2]); }
|
||||||
|
return std::min(rgb[1], rgb[2]);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
/* hsv_gradient_factory */
|
||||||
|
void hsv_gradient_factory::fix_diff(long *diff) {
|
||||||
|
if (diff[0] > SCALE180) {
|
||||||
|
diff[0] -= SCALE360;
|
||||||
|
} else if (diff[0] < -SCALE180) {
|
||||||
|
diff[0] += SCALE360;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void hsv_gradient_factory::convert_from_scaled_rgb(long *const scaled,
|
||||||
|
long *target) {
|
||||||
|
auto value = get_value(scaled);
|
||||||
|
auto minimum = get_minimum(scaled);
|
||||||
|
auto chroma = value - minimum;
|
||||||
|
auto saturation = (SCALE * chroma) / value;
|
||||||
|
|
||||||
|
target[0] = get_hue(scaled, chroma, value);
|
||||||
|
target[1] = saturation * 360L;
|
||||||
|
target[2] = value * 360L;
|
||||||
|
}
|
||||||
|
|
||||||
|
void hsv_gradient_factory::convert_to_scaled_rgb(long *const target,
|
||||||
|
long *scaled) {
|
||||||
|
auto hue = target[0] % SCALE360;
|
||||||
|
auto saturation = target[1] / 360L;
|
||||||
|
auto value = target[2] / 360L;
|
||||||
|
auto chroma = (saturation * value) / SCALE;
|
||||||
|
auto x = get_intermediate(hue, chroma);
|
||||||
|
|
||||||
|
scaled[0] = scaled[1] = scaled[2] = (value - chroma);
|
||||||
|
|
||||||
|
if (hue < SCALE60) {
|
||||||
|
scaled[0] += chroma;
|
||||||
|
scaled[1] += x;
|
||||||
|
} else if (hue < SCALE120) {
|
||||||
|
scaled[0] += x;
|
||||||
|
scaled[1] += chroma;
|
||||||
|
} else if (hue < SCALE180) {
|
||||||
|
scaled[1] += chroma;
|
||||||
|
scaled[2] += x;
|
||||||
|
} else if (hue < SCALE240) {
|
||||||
|
scaled[1] += x;
|
||||||
|
scaled[2] += chroma;
|
||||||
|
} else if (hue < SCALE300) {
|
||||||
|
scaled[2] += chroma;
|
||||||
|
scaled[0] += x;
|
||||||
|
} else {
|
||||||
|
scaled[2] += x;
|
||||||
|
scaled[0] += chroma;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* hsv_gradient_factory */
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// Using Rec.2020 color space
|
||||||
|
// Y' = 0.2627 x R + 0.6780 x G + 0.0593 x B
|
||||||
|
long get_luma(long *const rgb) {
|
||||||
|
return (2627L * rgb[0] + 6780L * rgb[1] + 593L * rgb[2]) / 10000L;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Using Rec.2020 color space
|
||||||
|
// m = Y' - (0.2627 x R + 0.6780 x G + 0.0593 x B)
|
||||||
|
long get_minimum_from_luma(long luma, long r, long g, long b) {
|
||||||
|
return luma - (2627L * r + 6780L * g + 593L * b) / 10000L;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
/* hcl_gradient_factory */
|
||||||
|
void hcl_gradient_factory::fix_diff(long *diff) {
|
||||||
|
if (diff[0] > SCALE180) {
|
||||||
|
diff[0] -= SCALE360;
|
||||||
|
} else if (diff[0] < -SCALE180) {
|
||||||
|
diff[0] += SCALE360;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void hcl_gradient_factory::convert_from_scaled_rgb(long *const scaled,
|
||||||
|
long *target) {
|
||||||
|
auto value = get_value(scaled);
|
||||||
|
auto minimum = get_minimum(scaled);
|
||||||
|
auto luma = get_luma(scaled);
|
||||||
|
auto chroma = value - minimum;
|
||||||
|
|
||||||
|
target[0] = get_hue(scaled, chroma, value);
|
||||||
|
target[1] = chroma * 360L;
|
||||||
|
target[2] = luma * 360L;
|
||||||
|
}
|
||||||
|
|
||||||
|
void hcl_gradient_factory::convert_to_scaled_rgb(long *const target,
|
||||||
|
long *scaled) {
|
||||||
|
auto hue = target[0] % SCALE360;
|
||||||
|
auto chroma = target[1] / 360L;
|
||||||
|
auto luma = target[2] / 360L;
|
||||||
|
|
||||||
|
auto x = get_intermediate(hue, chroma);
|
||||||
|
long m;
|
||||||
|
|
||||||
|
if (hue < SCALE60) {
|
||||||
|
m = get_minimum_from_luma(luma, chroma, x, 0);
|
||||||
|
scaled[0] = scaled[1] = scaled[2] = m;
|
||||||
|
scaled[0] += chroma;
|
||||||
|
scaled[1] += x;
|
||||||
|
} else if (hue < SCALE120) {
|
||||||
|
m = get_minimum_from_luma(luma, x, chroma, 0);
|
||||||
|
scaled[0] = scaled[1] = scaled[2] = m;
|
||||||
|
scaled[0] += x;
|
||||||
|
scaled[1] += chroma;
|
||||||
|
} else if (hue < SCALE180) {
|
||||||
|
m = get_minimum_from_luma(luma, 0, chroma, x);
|
||||||
|
scaled[0] = scaled[1] = scaled[2] = m;
|
||||||
|
scaled[1] += chroma;
|
||||||
|
scaled[2] += x;
|
||||||
|
} else if (hue < SCALE240) {
|
||||||
|
m = get_minimum_from_luma(luma, 0, x, chroma);
|
||||||
|
scaled[0] = scaled[1] = scaled[2] = m;
|
||||||
|
scaled[1] += x;
|
||||||
|
scaled[2] += chroma;
|
||||||
|
} else if (hue < SCALE300) {
|
||||||
|
m = get_minimum_from_luma(luma, x, 0, chroma);
|
||||||
|
scaled[0] = scaled[1] = scaled[2] = m;
|
||||||
|
scaled[2] += chroma;
|
||||||
|
scaled[0] += x;
|
||||||
|
} else {
|
||||||
|
m = get_minimum_from_luma(luma, chroma, 0, x);
|
||||||
|
scaled[0] = scaled[1] = scaled[2] = m;
|
||||||
|
scaled[2] += x;
|
||||||
|
scaled[0] += chroma;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* hcl_gradient_factory */
|
||||||
|
} // namespace conky
|
108
src/gradient.h
Normal file
108
src/gradient.h
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Conky, a system monitor, based on torsmo
|
||||||
|
*
|
||||||
|
* Any original torsmo code is licensed under the BSD license
|
||||||
|
*
|
||||||
|
* All code written since the fork of torsmo is licensed under the GPL
|
||||||
|
*
|
||||||
|
* Please see COPYING for details
|
||||||
|
*
|
||||||
|
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
|
||||||
|
* Copyright (c) 2005-2021 Brenden Matthews, Philip Kovacs, et. al.
|
||||||
|
* (see AUTHORS)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _GRADIENT_H
|
||||||
|
#define _GRADIENT_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace conky {
|
||||||
|
class gradient_factory {
|
||||||
|
public:
|
||||||
|
typedef std::unique_ptr<unsigned long[]> colour_array;
|
||||||
|
static const long SCALE = 512L;
|
||||||
|
static const long SCALE2 = SCALE * 2;
|
||||||
|
static const long SCALE4 = SCALE * 4;
|
||||||
|
static const long SCALE6 = SCALE * 6;
|
||||||
|
static const long SCALE60 = SCALE * 60;
|
||||||
|
static const long SCALE120 = SCALE * 120;
|
||||||
|
static const long SCALE180 = SCALE * 180;
|
||||||
|
static const long SCALE240 = SCALE * 240;
|
||||||
|
static const long SCALE300 = SCALE * 300;
|
||||||
|
static const long SCALE360 = SCALE * 360;
|
||||||
|
|
||||||
|
public:
|
||||||
|
gradient_factory(int width, unsigned long first_colour,
|
||||||
|
unsigned long last_colour);
|
||||||
|
|
||||||
|
colour_array create_gradient();
|
||||||
|
|
||||||
|
virtual void convert_from_scaled_rgb(long *const scaled, long *target) = 0;
|
||||||
|
virtual void convert_to_scaled_rgb(long *const target, long *scaled) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void convert_from_rgb(long original, long *array);
|
||||||
|
int convert_to_rgb(long *const array);
|
||||||
|
long get_hue(long *const scaled, long chroma, long value);
|
||||||
|
long get_intermediate(long hue, long chroma);
|
||||||
|
virtual void fix_diff(long *diff) {}
|
||||||
|
|
||||||
|
static short colour_depth;
|
||||||
|
static long mask[3];
|
||||||
|
static short shift[3];
|
||||||
|
|
||||||
|
private:
|
||||||
|
int width;
|
||||||
|
unsigned long first_colour;
|
||||||
|
unsigned long last_colour;
|
||||||
|
|
||||||
|
static bool is_set;
|
||||||
|
static void setup_colour_depth();
|
||||||
|
static void setup_masks();
|
||||||
|
static void setup_shifts();
|
||||||
|
};
|
||||||
|
|
||||||
|
class rgb_gradient_factory : public gradient_factory {
|
||||||
|
using gradient_factory::gradient_factory;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void convert_from_scaled_rgb(long *const scaled, long *target);
|
||||||
|
void convert_to_scaled_rgb(long *const target, long *scaled);
|
||||||
|
};
|
||||||
|
|
||||||
|
class hsv_gradient_factory : public gradient_factory {
|
||||||
|
using gradient_factory::gradient_factory;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void fix_diff(long *diff);
|
||||||
|
void convert_from_scaled_rgb(long *const scaled, long *target);
|
||||||
|
void convert_to_scaled_rgb(long *const target, long *scaled);
|
||||||
|
};
|
||||||
|
|
||||||
|
class hcl_gradient_factory : public gradient_factory {
|
||||||
|
using gradient_factory::gradient_factory;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void fix_diff(long *diff);
|
||||||
|
void convert_from_scaled_rgb(long *const scaled, long *target);
|
||||||
|
void convert_to_scaled_rgb(long *const target, long *scaled);
|
||||||
|
};
|
||||||
|
} // namespace conky
|
||||||
|
|
||||||
|
#endif /* _GRADIENT_H */
|
@ -1,244 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Conky, a system monitor, based on torsmo
|
|
||||||
*
|
|
||||||
* Any original torsmo code is licensed under the BSD license
|
|
||||||
*
|
|
||||||
* All code written since the fork of torsmo is licensed under the GPL
|
|
||||||
*
|
|
||||||
* Please see COPYING for details
|
|
||||||
*
|
|
||||||
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
|
|
||||||
* Copyright (c) 2005-2021 Brenden Matthews, Philip Kovacs, et. al.
|
|
||||||
* (see AUTHORS)
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#include "hcl_gradient.h"
|
|
||||||
#include "colours.h"
|
|
||||||
#include "conky.h"
|
|
||||||
#include "logging.h"
|
|
||||||
|
|
||||||
#ifdef BUILD_X11
|
|
||||||
#include "x11.h"
|
|
||||||
#endif /* BUILD_X11 */
|
|
||||||
|
|
||||||
#define CONST_SCALE 512L
|
|
||||||
#define CONST_SCALE_HALF (CONST_SCALE / 2)
|
|
||||||
#define CONST_SCALE2 (CONST_SCALE * 2L)
|
|
||||||
#define CONST_SCALE4 (CONST_SCALE * 4L)
|
|
||||||
#define CONST_SCALE6 (CONST_SCALE * 6L)
|
|
||||||
#define CONST_SCALE60 (CONST_SCALE * 60L)
|
|
||||||
#define CONST_SCALE120 (CONST_SCALE * 120L)
|
|
||||||
#define CONST_SCALE180 (CONST_SCALE * 180L)
|
|
||||||
#define CONST_SCALE240 (CONST_SCALE * 240L)
|
|
||||||
#define CONST_SCALE300 (CONST_SCALE * 300L)
|
|
||||||
#define CONST_SCALE360 (CONST_SCALE * 360L)
|
|
||||||
|
|
||||||
long to_decimal_scale(long value, long max_value) {
|
|
||||||
if (value == 0) {
|
|
||||||
return 0;
|
|
||||||
} else if (value > 0) {
|
|
||||||
return (value * CONST_SCALE) / max_value;
|
|
||||||
}
|
|
||||||
return -((std::abs(value) * CONST_SCALE) / max_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
long from_decimal_scale(long value, long max_value) {
|
|
||||||
if (value == 0) {
|
|
||||||
return 0;
|
|
||||||
} else if (value > 0) {
|
|
||||||
return (value * max_value) / CONST_SCALE;
|
|
||||||
}
|
|
||||||
return -((std::abs(value) * max_value) / CONST_SCALE);
|
|
||||||
}
|
|
||||||
|
|
||||||
long cap_scaled_color(long colour) {
|
|
||||||
if (colour < 0) {
|
|
||||||
return 0;
|
|
||||||
} else if (colour > CONST_SCALE) {
|
|
||||||
return CONST_SCALE;
|
|
||||||
}
|
|
||||||
return colour;
|
|
||||||
}
|
|
||||||
|
|
||||||
void scaled_rgb_to_scaled_hcl(long *const rgb, long *hcl) {
|
|
||||||
long value =
|
|
||||||
rgb[0] > rgb[1] ? std::max(rgb[0], rgb[2]) : std::max(rgb[1], rgb[2]);
|
|
||||||
long minimum =
|
|
||||||
rgb[0] < rgb[1] ? std::min(rgb[0], rgb[2]) : std::min(rgb[1], rgb[2]);
|
|
||||||
long chroma = value - minimum;
|
|
||||||
long luma = (2627L * rgb[0] + 6780L * rgb[1] + 593L * rgb[2]) /
|
|
||||||
10000L; // Use Rec.2020 color space
|
|
||||||
long hue;
|
|
||||||
|
|
||||||
if (chroma == 0) {
|
|
||||||
hue = 0;
|
|
||||||
} else {
|
|
||||||
long diff;
|
|
||||||
long offset;
|
|
||||||
|
|
||||||
if (rgb[0] == value) {
|
|
||||||
diff = rgb[1] - rgb[2];
|
|
||||||
offset = 0;
|
|
||||||
} else if (rgb[1] == value) {
|
|
||||||
diff = rgb[2] - rgb[0];
|
|
||||||
offset = CONST_SCALE2;
|
|
||||||
} else {
|
|
||||||
diff = rgb[0] - rgb[1];
|
|
||||||
offset = CONST_SCALE4;
|
|
||||||
}
|
|
||||||
long h = (CONST_SCALE * diff) / chroma + offset;
|
|
||||||
hue = 60L * ((CONST_SCALE6 + h) % CONST_SCALE6);
|
|
||||||
}
|
|
||||||
|
|
||||||
hcl[0] = hue;
|
|
||||||
hcl[1] = chroma * 360L;
|
|
||||||
hcl[2] = luma * 360L;
|
|
||||||
}
|
|
||||||
|
|
||||||
void scaled_hcl_to_scaled_rgb(long *const hcl, long *rgb) {
|
|
||||||
long hue = hcl[0] % CONST_SCALE360;
|
|
||||||
long chroma = hcl[1] / 360L;
|
|
||||||
long luma = hcl[2] / 360L;
|
|
||||||
|
|
||||||
long h = hue / 60L;
|
|
||||||
long x = (chroma * (CONST_SCALE - std::abs(h % CONST_SCALE2 - CONST_SCALE))) /
|
|
||||||
CONST_SCALE;
|
|
||||||
long m;
|
|
||||||
|
|
||||||
// use Rec.2020 color space
|
|
||||||
if (hue < CONST_SCALE60) {
|
|
||||||
m = luma - (2627L * chroma + 6780L * x) / 10000L;
|
|
||||||
rgb[0] = rgb[1] = rgb[2] = m;
|
|
||||||
rgb[0] += chroma;
|
|
||||||
rgb[1] += x;
|
|
||||||
} else if (hue < CONST_SCALE120) {
|
|
||||||
m = luma - (2627L * x + 6780L * chroma) / 10000L;
|
|
||||||
rgb[0] = rgb[1] = rgb[2] = m;
|
|
||||||
rgb[0] += x;
|
|
||||||
rgb[1] += chroma;
|
|
||||||
} else if (hue < CONST_SCALE180) {
|
|
||||||
m = luma - (6780L * chroma + 593L * x) / 10000L;
|
|
||||||
rgb[0] = rgb[1] = rgb[2] = m;
|
|
||||||
rgb[1] += chroma;
|
|
||||||
rgb[2] += x;
|
|
||||||
} else if (hue < CONST_SCALE240) {
|
|
||||||
m = luma - (6780L * x + 593L * chroma) / 10000L;
|
|
||||||
rgb[0] = rgb[1] = rgb[2] = m;
|
|
||||||
rgb[1] += x;
|
|
||||||
rgb[2] += chroma;
|
|
||||||
} else if (hue < CONST_SCALE300) {
|
|
||||||
m = luma - (2627L * x + 593L * chroma) / 10000L;
|
|
||||||
rgb[0] = rgb[1] = rgb[2] = m;
|
|
||||||
rgb[2] += chroma;
|
|
||||||
rgb[0] += x;
|
|
||||||
} else {
|
|
||||||
m = luma - (2627L * chroma + 593L * x) / 10000L;
|
|
||||||
rgb[0] = rgb[1] = rgb[2] = m;
|
|
||||||
rgb[2] += x;
|
|
||||||
rgb[0] += chroma;
|
|
||||||
}
|
|
||||||
|
|
||||||
rgb[0] = cap_scaled_color(rgb[0]);
|
|
||||||
rgb[1] = cap_scaled_color(rgb[1]);
|
|
||||||
rgb[2] = cap_scaled_color(rgb[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void rgb_to_scaled_rgb(unsigned long colour, long *scaled, int redshift,
|
|
||||||
int greenshift) {
|
|
||||||
long red = (colour & redmask) >> redshift;
|
|
||||||
long green = (colour & greenmask) >> greenshift;
|
|
||||||
long blue = colour & bluemask;
|
|
||||||
|
|
||||||
long red_max = redmask >> redshift;
|
|
||||||
long green_max = greenmask >> greenshift;
|
|
||||||
long blue_max = bluemask;
|
|
||||||
|
|
||||||
scaled[0] = to_decimal_scale(red, red_max);
|
|
||||||
scaled[1] = to_decimal_scale(green, green_max);
|
|
||||||
scaled[2] = to_decimal_scale(blue, blue_max);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long scaled_rgb_to_rgb(long *const scaled, int redshift,
|
|
||||||
int greenshift) {
|
|
||||||
long red_max = redmask >> redshift;
|
|
||||||
long green_max = greenmask >> greenshift;
|
|
||||||
|
|
||||||
long red = from_decimal_scale(scaled[0], red_max);
|
|
||||||
long green = from_decimal_scale(scaled[1], green_max);
|
|
||||||
long blue = from_decimal_scale(scaled[2], bluemask);
|
|
||||||
|
|
||||||
return (red << redshift) | (green << greenshift) | blue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* this function returns the next colour between two colours in hcl space for a
|
|
||||||
* gradient */
|
|
||||||
std::unique_ptr<unsigned long[]> do_hcl_gradient(int width,
|
|
||||||
unsigned long first_colour,
|
|
||||||
unsigned long last_colour) {
|
|
||||||
long first_colour_rgb[3];
|
|
||||||
long last_colour_rgb[3];
|
|
||||||
long temp_colour_rgb[3];
|
|
||||||
|
|
||||||
long first_colour_hcl[3];
|
|
||||||
long final_colour_hcl[3];
|
|
||||||
|
|
||||||
long hueDiff, chromaDiff, lumaDiff;
|
|
||||||
|
|
||||||
int redshift = (2 * colour_depth / 3 + colour_depth % 3);
|
|
||||||
int greenshift = (colour_depth / 3);
|
|
||||||
|
|
||||||
// Make sure the width is always at least 2
|
|
||||||
width = std::max(2, width);
|
|
||||||
|
|
||||||
std::unique_ptr<unsigned long[]> colours(new unsigned long[width]);
|
|
||||||
|
|
||||||
if (colour_depth == 0) { set_up_gradient(); }
|
|
||||||
|
|
||||||
rgb_to_scaled_rgb(first_colour, first_colour_rgb, redshift, greenshift);
|
|
||||||
rgb_to_scaled_rgb(last_colour, last_colour_rgb, redshift, greenshift);
|
|
||||||
scaled_rgb_to_scaled_hcl(first_colour_rgb, first_colour_hcl);
|
|
||||||
scaled_rgb_to_scaled_hcl(last_colour_rgb, final_colour_hcl);
|
|
||||||
|
|
||||||
hueDiff = final_colour_hcl[0] - first_colour_hcl[0];
|
|
||||||
chromaDiff = final_colour_hcl[1] - first_colour_hcl[1];
|
|
||||||
lumaDiff = final_colour_hcl[2] - first_colour_hcl[2];
|
|
||||||
|
|
||||||
colours[0] = first_colour;
|
|
||||||
colours[width - 1] = last_colour;
|
|
||||||
|
|
||||||
long divisor = width - 1;
|
|
||||||
long hueDelta = hueDiff / divisor;
|
|
||||||
long chromaDelta = chromaDiff / divisor;
|
|
||||||
long lumaDelta = lumaDiff / divisor;
|
|
||||||
|
|
||||||
for (int i = 1; i < (width - 1); i++) {
|
|
||||||
long h = first_colour_hcl[0] + hueDelta;
|
|
||||||
|
|
||||||
if (h < 0) {
|
|
||||||
first_colour_hcl[0] = CONST_SCALE360 + h;
|
|
||||||
} else {
|
|
||||||
first_colour_hcl[0] = h;
|
|
||||||
}
|
|
||||||
first_colour_hcl[1] += chromaDelta;
|
|
||||||
first_colour_hcl[2] += lumaDelta;
|
|
||||||
|
|
||||||
scaled_hcl_to_scaled_rgb(first_colour_hcl, temp_colour_rgb);
|
|
||||||
colours[i] = scaled_rgb_to_rgb(temp_colour_rgb, redshift, greenshift);
|
|
||||||
}
|
|
||||||
|
|
||||||
return colours;
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Conky, a system monitor, based on torsmo
|
|
||||||
*
|
|
||||||
* Any original torsmo code is licensed under the BSD license
|
|
||||||
*
|
|
||||||
* All code written since the fork of torsmo is licensed under the GPL
|
|
||||||
*
|
|
||||||
* Please see COPYING for details
|
|
||||||
*
|
|
||||||
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
|
|
||||||
* Copyright (c) 2005-2021 Brenden Matthews, Philip Kovacs, et. al.
|
|
||||||
* (see AUTHORS)
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Use Hue-Chroma-Luma to create gradients
|
|
||||||
#ifndef _HCL_GRADIENT_H
|
|
||||||
#define _HCL_GRADIENT_H
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
// needed by hcl_gradient
|
|
||||||
extern short colour_depth;
|
|
||||||
extern long redmask, greenmask, bluemask;
|
|
||||||
extern void set_up_gradient();
|
|
||||||
|
|
||||||
std::unique_ptr<unsigned long[]> do_hcl_gradient(int, unsigned long,
|
|
||||||
unsigned long);
|
|
||||||
|
|
||||||
long to_decimal_scale(long value, long max_value);
|
|
||||||
long from_decimal_scale(long value, long max_value);
|
|
||||||
void scaled_rgb_to_scaled_hcl(long *const rgb, long *hcl);
|
|
||||||
void scaled_hcl_to_scaled_rgb(long *const hcl, long *rgb);
|
|
||||||
|
|
||||||
#endif /* _HCL_GRADIENT_H */
|
|
@ -179,12 +179,6 @@ static void print_version() {
|
|||||||
<< _(" * Own window\n")
|
<< _(" * Own window\n")
|
||||||
#endif
|
#endif
|
||||||
#endif /* BUILD_X11 */
|
#endif /* BUILD_X11 */
|
||||||
#ifdef BUILD_HCL_GRADIENT
|
|
||||||
<< _(" * HCL Gradient\n")
|
|
||||||
#endif /* BUILD_HCL_GRADIENT */
|
|
||||||
#ifdef BUILD_HSV_GRADIENT
|
|
||||||
<< _(" * HSV Gradient\n")
|
|
||||||
#endif /* BUILD_HSV_GRADIENT */
|
|
||||||
#if defined BUILD_AUDACIOUS || defined BUILD_CMUS || defined BUILD_MPD || \
|
#if defined BUILD_AUDACIOUS || defined BUILD_CMUS || defined BUILD_MPD || \
|
||||||
defined BUILD_MOC || defined BUILD_XMMS2
|
defined BUILD_MOC || defined BUILD_XMMS2
|
||||||
<< _("\n Music detection:\n")
|
<< _("\n Music detection:\n")
|
||||||
|
@ -17,11 +17,6 @@ endif()
|
|||||||
set(test_srcs ${test_srcs} test-core.cc)
|
set(test_srcs ${test_srcs} test-core.cc)
|
||||||
set(test_srcs ${test_srcs} test-diskio.cc)
|
set(test_srcs ${test_srcs} test-diskio.cc)
|
||||||
set(test_srcs ${test_srcs} test-fs.cc)
|
set(test_srcs ${test_srcs} test-fs.cc)
|
||||||
if(BUILD_HCL_GRADIENT)
|
|
||||||
set(test_srcs ${test_srcs} test-hcl.cc)
|
|
||||||
elseif(BUILD_HSV_GRADIENT)
|
|
||||||
set(test_srcs ${test_srcs} test-hsv.cc)
|
|
||||||
endif(BUILD_HCL_GRADIENT)
|
|
||||||
|
|
||||||
add_executable(test-conky test-common.cc ${test_srcs})
|
add_executable(test-conky test-common.cc ${test_srcs})
|
||||||
target_link_libraries(test-conky conky_core)
|
target_link_libraries(test-conky conky_core)
|
||||||
|
15702
tests/catch2/catch.hpp
15702
tests/catch2/catch.hpp
File diff suppressed because it is too large
Load Diff
@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Conky, a system monitor, based on torsmo
|
|
||||||
*
|
|
||||||
* Any original torsmo code is licensed under the BSD license
|
|
||||||
*
|
|
||||||
* All code written since the fork of torsmo is licensed under the GPL
|
|
||||||
*
|
|
||||||
* Please see COPYING for details
|
|
||||||
*
|
|
||||||
* Copyright (c) 2005-2021 Brenden Matthews, Philip Kovacs, et. al.
|
|
||||||
* (see AUTHORS)
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "catch2/catch.hpp"
|
|
||||||
|
|
||||||
#include <conky.h>
|
|
||||||
#include <hcl_gradient.h>
|
|
||||||
#include <lua-config.hh>
|
|
||||||
|
|
||||||
int testColor(long *rgb, int scale) {
|
|
||||||
long hcl[3];
|
|
||||||
long rgb1[3];
|
|
||||||
long rgb2[3];
|
|
||||||
long rgb3[3];
|
|
||||||
|
|
||||||
rgb1[0] = to_decimal_scale(rgb[0], scale);
|
|
||||||
rgb1[1] = to_decimal_scale(rgb[1], scale);
|
|
||||||
rgb1[2] = to_decimal_scale(rgb[2], scale);
|
|
||||||
|
|
||||||
scaled_rgb_to_scaled_hcl(rgb1, hcl);
|
|
||||||
scaled_hcl_to_scaled_rgb(hcl, rgb2);
|
|
||||||
|
|
||||||
rgb3[0] = from_decimal_scale(rgb2[0], scale);
|
|
||||||
rgb3[1] = from_decimal_scale(rgb2[1], scale);
|
|
||||||
rgb3[2] = from_decimal_scale(rgb2[2], scale);
|
|
||||||
|
|
||||||
return (rgb[0] != rgb3[0] || rgb[1] != rgb3[1] || rgb[2] != rgb3[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("hcl gradient tests") {
|
|
||||||
SECTION("rgb -> hcl -> rgb should returns original value") {
|
|
||||||
int failedCount = 0;
|
|
||||||
long rgb1[3];
|
|
||||||
|
|
||||||
for (int i = 0; i < 256 && failedCount < 10; i++) {
|
|
||||||
for (int j = 0; j < 256 && failedCount < 10; j++) {
|
|
||||||
for (int k = 0; k < 256 && failedCount < 10; k++) {
|
|
||||||
rgb1[0] = i;
|
|
||||||
rgb1[1] = j;
|
|
||||||
rgb1[2] = k;
|
|
||||||
failedCount += testColor(rgb1, 255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
REQUIRE(failedCount == 0);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Conky, a system monitor, based on torsmo
|
|
||||||
*
|
|
||||||
* Any original torsmo code is licensed under the BSD license
|
|
||||||
*
|
|
||||||
* All code written since the fork of torsmo is licensed under the GPL
|
|
||||||
*
|
|
||||||
* Please see COPYING for details
|
|
||||||
*
|
|
||||||
* Copyright (c) 2005-2021 Brenden Matthews, Philip Kovacs, et. al.
|
|
||||||
* (see AUTHORS)
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "catch2/catch.hpp"
|
|
||||||
|
|
||||||
#include <conky.h>
|
|
||||||
#include <hsv_gradient.h>
|
|
||||||
#include <lua-config.hh>
|
|
||||||
|
|
||||||
int testColor(long *rgb, int scale) {
|
|
||||||
long hsv[3];
|
|
||||||
long rgb1[3];
|
|
||||||
long rgb2[3];
|
|
||||||
long rgb3[3];
|
|
||||||
|
|
||||||
rgb1[0] = to_decimal_scale(rgb[0], scale);
|
|
||||||
rgb1[1] = to_decimal_scale(rgb[1], scale);
|
|
||||||
rgb1[2] = to_decimal_scale(rgb[2], scale);
|
|
||||||
|
|
||||||
scaled_rgb_to_scaled_hsv(rgb1, hsv);
|
|
||||||
scaled_hsv_to_scaled_rgb(hsv, rgb2);
|
|
||||||
|
|
||||||
rgb3[0] = from_decimal_scale(rgb2[0], scale);
|
|
||||||
rgb3[1] = from_decimal_scale(rgb2[1], scale);
|
|
||||||
rgb3[2] = from_decimal_scale(rgb2[2], scale);
|
|
||||||
|
|
||||||
return (rgb[0] != rgb3[0] || rgb[1] != rgb3[1] || rgb[2] != rgb3[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("hsv gradient tests") {
|
|
||||||
SECTION("rgb -> hsv -> rgb should returns original value") {
|
|
||||||
int failedCount = 0;
|
|
||||||
long rgb1[3];
|
|
||||||
|
|
||||||
for (int i = 0; i < 256 && failedCount < 10; i++) {
|
|
||||||
for (int j = 0; j < 256 && failedCount < 10; j++) {
|
|
||||||
for (int k = 0; k < 256 && failedCount < 10; k++) {
|
|
||||||
rgb1[0] = i;
|
|
||||||
rgb1[1] = j;
|
|
||||||
rgb1[2] = k;
|
|
||||||
failedCount += testColor(rgb1, 255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
REQUIRE(failedCount == 0);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user