mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-09-29 21:49:07 +00:00
Replace temporary colour array with smart pointer.
This should fix #1070.
This commit is contained in:
parent
d3527e1ed9
commit
0f3c706336
@ -85,15 +85,15 @@ unsigned int adjust_colours(unsigned int colour) {
|
||||
}
|
||||
|
||||
/* this function returns the next colour between two colours for a gradient */
|
||||
unsigned long *do_gradient(int width, unsigned long first_colour,
|
||||
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);
|
||||
auto *colours =
|
||||
static_cast<unsigned long *>(malloc(width * sizeof(unsigned long)));
|
||||
std::unique_ptr<unsigned long[]> colours(new unsigned long[width]);
|
||||
int i;
|
||||
|
||||
if (colour_depth == 0) { set_up_gradient(); }
|
||||
|
@ -29,10 +29,11 @@
|
||||
#ifndef _COLOURS_H
|
||||
#define _COLOURS_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
unsigned int adjust_colours(unsigned int);
|
||||
unsigned long *do_gradient(int, unsigned long, unsigned long);
|
||||
std::unique_ptr<unsigned long[]> do_gradient(int, unsigned long, unsigned long);
|
||||
|
||||
long get_x11_color(const std::string &colour);
|
||||
// XXX: when everyone uses C++ strings, remove this C version
|
||||
|
@ -1458,7 +1458,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
|
||||
|
||||
/* in case we don't have a graph yet */
|
||||
if (current->graph != nullptr) {
|
||||
unsigned long *tmpcolour = nullptr;
|
||||
std::unique_ptr<unsigned long[]> tmpcolour;
|
||||
|
||||
if (current->last_colour != 0 || current->first_colour != 0) {
|
||||
#ifdef BUILD_HSV_GRADIENT
|
||||
@ -1492,7 +1492,6 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
|
||||
current->scale));
|
||||
++j;
|
||||
}
|
||||
free_and_zero(tmpcolour);
|
||||
}
|
||||
if (h > cur_y_add && h > font_h) { cur_y_add = h; }
|
||||
if (show_graph_range.get(*state)) {
|
||||
|
@ -143,7 +143,8 @@ void scaled_hsv_to_scaled_rgb(long *const hsv, long *rgb) {
|
||||
|
||||
/* this function returns the next colour between two colours in hsv space for a
|
||||
* gradient */
|
||||
unsigned long *do_hsv_gradient(int width, unsigned long first_colour,
|
||||
std::unique_ptr<unsigned long[]> do_hsv_gradient(int width,
|
||||
unsigned long first_colour,
|
||||
unsigned long last_colour) {
|
||||
long rgb1[3], rgb2[3], rgb3[3];
|
||||
long hsv1[3], hsv2[3];
|
||||
@ -151,8 +152,9 @@ 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);
|
||||
unsigned long *colours =
|
||||
static_cast<unsigned long *>(malloc(width * sizeof(unsigned long)));
|
||||
std::unique_ptr<unsigned long[]> colours(new unsigned long[width]);
|
||||
// unsigned long *colours =
|
||||
// static_cast<unsigned long *>(malloc(width * sizeof(unsigned long)));
|
||||
int i;
|
||||
|
||||
if (colour_depth == 0) { set_up_gradient(); }
|
||||
|
@ -29,12 +29,15 @@
|
||||
#ifndef _HSV_GRADIENT_H
|
||||
#define _HSV_GRADIENT_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
// 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);
|
||||
std::unique_ptr<unsigned long[]> do_hsv_gradient(int, unsigned long,
|
||||
unsigned long);
|
||||
|
||||
long to_decimal_scale(long value, long max_value);
|
||||
long from_decimal_scale(long value, long max_value);
|
||||
|
Loading…
Reference in New Issue
Block a user