From 3c43c4c7feba063a31ffc83c0f0f5c5e93c9f2f6 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Wed, 3 Mar 2021 07:38:21 -0600 Subject: [PATCH] Refactor hsv code. --- src/colours.h | 6 ------ src/conky.cc | 4 ++-- src/hsv_gradient.cc | 8 +++++--- src/hsv_gradient.h | 5 +++++ tests/CMakeLists.txt | 4 +++- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/colours.h b/src/colours.h index 66b5f0f2..b1aefb22 100644 --- a/src/colours.h +++ b/src/colours.h @@ -33,15 +33,9 @@ unsigned int adjust_colours(unsigned int); unsigned long *do_gradient(int, unsigned long, unsigned long); -unsigned long *do_hsv_gradient(int, unsigned long, unsigned long); long get_x11_color(const std::string &colour); // XXX: when everyone uses C++ strings, remove this C version long get_x11_color(const char *); -// needed by hsv_gradient -extern short colour_depth; -extern long redmask, greenmask, bluemask; -extern void set_up_gradient(); - #endif /* _COLOURS_H */ diff --git a/src/conky.cc b/src/conky.cc index 5ed02569..ebf722a4 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -1464,10 +1464,10 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) { #ifdef BUILD_HSV_GRADIENT tmpcolour = do_hsv_gradient(w - 1, current->last_colour, current->first_colour); -#else +#else /* BUILD_HSV_GRADIENT */ tmpcolour = do_gradient(w - 1, current->last_colour, current->first_colour); -#endif +#endif /* BUILD_HSV_GRADIENT */ } colour_idx = 0; for (i = w - 2; i > -1; i--) { diff --git a/src/hsv_gradient.cc b/src/hsv_gradient.cc index 68d62377..8eab665f 100644 --- a/src/hsv_gradient.cc +++ b/src/hsv_gradient.cc @@ -26,13 +26,14 @@ * along with this program. If not, see . * */ +#include "hsv_gradient.h" #include "colours.h" #include "conky.h" #include "logging.h" + #ifdef BUILD_X11 #include "x11.h" - -#endif +#endif /* BUILD_X11 */ #define CONST_SCALE 512L #define CONST_SCALE_HALF (CONST_SCALE / 2) @@ -150,7 +151,7 @@ unsigned long *do_hsv_gradient(int width, unsigned long first_colour, int redshift = (2 * colour_depth / 3 + colour_depth % 3); int greenshift = (colour_depth / 3); - auto *colours = + unsigned long *colours = static_cast(malloc(width * sizeof(unsigned long))); int i; @@ -212,5 +213,6 @@ unsigned long *do_hsv_gradient(int width, unsigned long first_colour, colours[i] = (red3 << redshift) | (green3 << greenshift) | blue3; } + return colours; } diff --git a/src/hsv_gradient.h b/src/hsv_gradient.h index 7024ef7b..a2454789 100644 --- a/src/hsv_gradient.h +++ b/src/hsv_gradient.h @@ -29,6 +29,11 @@ #ifndef _HSV_GRADIENT_H #define _HSV_GRADIENT_H +// needed by hsv_gradient +extern short colour_depth; +extern long redmask, greenmask, bluemask; +extern void set_up_gradient(); + unsigned long *do_hsv_gradient(int, unsigned long, unsigned long); long to_decimal_scale(long value, long max_value); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 34804eb7..2db5f75a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,7 +17,9 @@ endif() set(test_srcs ${test_srcs} test-core.cc) set(test_srcs ${test_srcs} test-diskio.cc) set(test_srcs ${test_srcs} test-fs.cc) -set(test_srcs ${test_srcs} test-hsv.cc) +if(BUILD_HSV_GRADIENT) + set(test_srcs ${test_srcs} test-hsv.cc) +endif(BUILD_HSV_GRADIENT) add_executable(test-conky test-common.cc ${test_srcs}) target_link_libraries(test-conky conky_core)