mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-27 04:32:55 +00:00
OMPtimize the gradient stuff.
This commit is contained in:
parent
b0f37a63e8
commit
d65c33146e
113
src/colours.c
113
src/colours.c
@ -68,8 +68,8 @@ static void set_up_gradient(void)
|
||||
greenmask = greenmask << (colour_depth / 3);
|
||||
}
|
||||
|
||||
/* adjust color values depending on color depth */
|
||||
unsigned int adjust_colors(unsigned int color)
|
||||
/* adjust colour values depending on colour depth */
|
||||
unsigned int adjust_colours(unsigned int colour)
|
||||
{
|
||||
double r, g, b;
|
||||
|
||||
@ -77,26 +77,25 @@ unsigned int adjust_colors(unsigned int color)
|
||||
set_up_gradient();
|
||||
}
|
||||
if (colour_depth == 16) {
|
||||
r = (color & 0xff0000) >> 16;
|
||||
g = (color & 0xff00) >> 8;
|
||||
b = color & 0xff;
|
||||
color = (int) (r * CONST_8_TO_5_BITS) << 11;
|
||||
color |= (int) (g * CONST_8_TO_6_BITS) << 5;
|
||||
color |= (int) (b * CONST_8_TO_5_BITS);
|
||||
r = (colour & 0xff0000) >> 16;
|
||||
g = (colour & 0xff00) >> 8;
|
||||
b = colour & 0xff;
|
||||
colour = (int) (r * CONST_8_TO_5_BITS) << 11;
|
||||
colour |= (int) (g * CONST_8_TO_6_BITS) << 5;
|
||||
colour |= (int) (b * CONST_8_TO_5_BITS);
|
||||
}
|
||||
return color;
|
||||
return colour;
|
||||
}
|
||||
|
||||
/* this function returns the next colour between two colours for a gradient */
|
||||
unsigned long do_gradient(const unsigned long first_colour,
|
||||
const unsigned long last_colour)
|
||||
unsigned long *do_gradient(float diff, int width, unsigned long first_colour, unsigned long last_colour)
|
||||
{
|
||||
int tmp_color = 0;
|
||||
int red1, green1, blue1; // first colour
|
||||
int red2, green2, blue2; // second colour
|
||||
int red3 = 0, green3 = 0, blue3 = 0; // difference
|
||||
int red2, green2, blue2; // last colour
|
||||
short redshift = (2 * colour_depth / 3 + colour_depth % 3);
|
||||
short greenshift = (colour_depth / 3);
|
||||
unsigned long *colours = malloc(width * sizeof(unsigned long));
|
||||
int i;
|
||||
|
||||
red1 = (first_colour & redmask) >> redshift;
|
||||
green1 = (first_colour & greenmask) >> greenshift;
|
||||
@ -104,47 +103,53 @@ unsigned long do_gradient(const unsigned long first_colour,
|
||||
red2 = (last_colour & redmask) >> redshift;
|
||||
green2 = (last_colour & greenmask) >> greenshift;
|
||||
blue2 = last_colour & bluemask;
|
||||
if (red1 > red2) {
|
||||
red3 = -1;
|
||||
#ifdef HAVE_OPENMP
|
||||
#pragma omp parallel for
|
||||
#endif /* HAVE_OPENMP */
|
||||
for (i = 0; i < width; i++) {
|
||||
int red3 = 0, green3 = 0, blue3 = 0; // colour components
|
||||
|
||||
int factor = round_to_int(diff * ((float)i / width));
|
||||
|
||||
if (red1 > red2) {
|
||||
red3 = -factor;
|
||||
} else if (red1 < red2) {
|
||||
red3 = factor;
|
||||
}
|
||||
if (green1 > green2) {
|
||||
green3 = -factor;
|
||||
} else if (green1 < green2) {
|
||||
green3 = factor;
|
||||
}
|
||||
if (blue1 > blue2) {
|
||||
blue3 = -factor;
|
||||
} else if (blue1 < blue2) {
|
||||
blue3 = factor;
|
||||
}
|
||||
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 (blue1 > bluemask) {
|
||||
blue1 = bluemask;
|
||||
}
|
||||
colours[i] = (red3 << redshift) | (green3 << greenshift) | blue3;
|
||||
}
|
||||
if (red1 < red2) {
|
||||
red3 = 1;
|
||||
}
|
||||
if (green1 > green2) {
|
||||
green3 = -1;
|
||||
}
|
||||
if (green1 < green2) {
|
||||
green3 = 1;
|
||||
}
|
||||
if (blue1 > blue2) {
|
||||
blue3 = -1;
|
||||
}
|
||||
if (blue1 < blue2) {
|
||||
blue3 = 1;
|
||||
}
|
||||
red1 += red3;
|
||||
green1 += green3;
|
||||
blue1 += blue3;
|
||||
if (red1 < 0) {
|
||||
red1 = 0;
|
||||
}
|
||||
if (green1 < 0) {
|
||||
green1 = 0;
|
||||
}
|
||||
if (blue1 < 0) {
|
||||
blue1 = 0;
|
||||
}
|
||||
if (red1 > bluemask) {
|
||||
red1 = bluemask;
|
||||
}
|
||||
if (green1 > bluemask) {
|
||||
green1 = bluemask;
|
||||
}
|
||||
if (blue1 > bluemask) {
|
||||
blue1 = bluemask;
|
||||
}
|
||||
tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
|
||||
return tmp_color;
|
||||
return colours;
|
||||
}
|
||||
|
||||
/* this function returns the max diff for a gradient */
|
||||
|
@ -27,8 +27,8 @@
|
||||
#ifndef _COLOURS_H
|
||||
#define _COLOURS_H
|
||||
|
||||
unsigned int adjust_colors(unsigned int);
|
||||
unsigned long do_gradient(unsigned long, unsigned long);
|
||||
unsigned int adjust_colours(unsigned int);
|
||||
unsigned long *do_gradient(float, int, unsigned long, unsigned long);
|
||||
unsigned long gradient_max(unsigned long, unsigned long);
|
||||
|
||||
#endif /* _COLOURS_H */
|
||||
|
27
src/conky.c
27
src/conky.c
@ -3894,7 +3894,7 @@ static void generate_text_internal(char *p, int p_max_size,
|
||||
#endif
|
||||
OBJ(execbar) {
|
||||
double barnum;
|
||||
int i;
|
||||
int i = 0, j = 0;
|
||||
|
||||
read_exec(obj->data.s, p, text_buffer_size);
|
||||
barnum = get_barnum(p);
|
||||
@ -3914,10 +3914,12 @@ static void generate_text_internal(char *p, int p_max_size,
|
||||
for(i=0; i<(int)barnum; i++) {
|
||||
*(p+i)='#';
|
||||
}
|
||||
/* gcc seems to think i is not initialized properly :/ */
|
||||
j = i;
|
||||
#ifdef HAVE_OPENMP
|
||||
#pragma omp parallel for
|
||||
#endif /* HAVE_OPENMP */
|
||||
for(i=i /* cheats */; i < obj->a; i++) {
|
||||
for(i = j/* cheats */; i < obj->a; i++) {
|
||||
*(p+i)='_';
|
||||
}
|
||||
*(p+i)=0;
|
||||
@ -6061,7 +6063,7 @@ static void draw_line(char *s)
|
||||
|
||||
case GRAPH:
|
||||
{
|
||||
int h, by, i, j = 0;
|
||||
int h, by, i = 0, j = 0;
|
||||
int colour_idx = 0;
|
||||
unsigned long last_colour = current_color;
|
||||
unsigned long *tmpcolour = 0;
|
||||
@ -6093,23 +6095,10 @@ static void draw_line(char *s)
|
||||
|
||||
if (specials[special_index].last_colour != 0
|
||||
|| specials[special_index].first_colour != 0) {
|
||||
float gradient_factor, gradient_update = 0;
|
||||
int gradient_size =
|
||||
gradient_max(specials[special_index].last_colour,
|
||||
specials[special_index].first_colour);
|
||||
gradient_factor = (float) gradient_size / (w - 1);
|
||||
tmpcolour = malloc((w - 1) * sizeof(unsigned long));
|
||||
tmpcolour[0] = specials[special_index].last_colour;
|
||||
gradient_update += gradient_factor;
|
||||
for (colour_idx = 1; colour_idx < w - 1; colour_idx++) {
|
||||
tmpcolour[colour_idx] = tmpcolour[colour_idx - 1];
|
||||
gradient_update += gradient_factor;
|
||||
while (gradient_update > 0) {
|
||||
tmpcolour[colour_idx] = do_gradient(tmpcolour[colour_idx],
|
||||
specials[special_index].first_colour);
|
||||
gradient_update--;
|
||||
}
|
||||
}
|
||||
tmpcolour = do_gradient(gradient_size, w - 1, specials[special_index].first_colour, specials[special_index].last_colour);
|
||||
}
|
||||
colour_idx = 0;
|
||||
for (i = w - 2; i > -1; i--) {
|
||||
@ -6146,8 +6135,8 @@ static void draw_line(char *s)
|
||||
/* this is mugfugly, but it works */
|
||||
XDrawLine(display, window.drawable, window.gc,
|
||||
cur_x + i + 1, by + h, cur_x + i + 1,
|
||||
by + h - specials[special_index].graph[j] *
|
||||
(h - 1) / specials[special_index].graph_scale);
|
||||
round_to_int((double)by + h - specials[special_index].graph[j] *
|
||||
(h - 1) / specials[special_index].graph_scale));
|
||||
if ((w - i) / ((float) (w - 2) /
|
||||
(specials[special_index].graph_width)) > j
|
||||
&& j < MAX_GRAPH_DEPTH - 3) {
|
||||
|
@ -317,8 +317,8 @@ void new_graph(char *buf, int w, int h, unsigned int first_colour,
|
||||
s->graph_scale = 100;
|
||||
}
|
||||
s->height = h;
|
||||
s->first_colour = adjust_colors(first_colour);
|
||||
s->last_colour = adjust_colors(second_colour);
|
||||
s->first_colour = adjust_colours(first_colour);
|
||||
s->last_colour = adjust_colours(second_colour);
|
||||
if (scale != 0) {
|
||||
s->scaled = 0;
|
||||
s->graph_scale = scale;
|
||||
|
Loading…
Reference in New Issue
Block a user