mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-27 20:44:56 +00:00
Simplify graph gradient stuff.
This commit is contained in:
parent
d65c33146e
commit
ed5dbc02bb
@ -88,43 +88,51 @@ unsigned int adjust_colours(unsigned int colour)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* this function returns the next colour between two colours for a gradient */
|
/* this function returns the next colour between two colours for a gradient */
|
||||||
unsigned long *do_gradient(float diff, int width, unsigned long first_colour, unsigned long last_colour)
|
unsigned long *do_gradient(int width, unsigned long first_colour, unsigned long last_colour)
|
||||||
{
|
{
|
||||||
int red1, green1, blue1; // first colour
|
int red1, green1, blue1; // first colour
|
||||||
int red2, green2, blue2; // last colour
|
int red2, green2, blue2; // last colour
|
||||||
|
int reddiff, greendiff, bluediff; // difference
|
||||||
short redshift = (2 * colour_depth / 3 + colour_depth % 3);
|
short redshift = (2 * colour_depth / 3 + colour_depth % 3);
|
||||||
short greenshift = (colour_depth / 3);
|
short greenshift = (colour_depth / 3);
|
||||||
unsigned long *colours = malloc(width * sizeof(unsigned long));
|
unsigned long *colours = malloc(width * sizeof(unsigned long));
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (colour_depth == 0) {
|
||||||
|
set_up_gradient();
|
||||||
|
}
|
||||||
red1 = (first_colour & redmask) >> redshift;
|
red1 = (first_colour & redmask) >> redshift;
|
||||||
green1 = (first_colour & greenmask) >> greenshift;
|
green1 = (first_colour & greenmask) >> greenshift;
|
||||||
blue1 = first_colour & bluemask;
|
blue1 = first_colour & bluemask;
|
||||||
red2 = (last_colour & redmask) >> redshift;
|
red2 = (last_colour & redmask) >> redshift;
|
||||||
green2 = (last_colour & greenmask) >> greenshift;
|
green2 = (last_colour & greenmask) >> greenshift;
|
||||||
blue2 = last_colour & bluemask;
|
blue2 = last_colour & bluemask;
|
||||||
|
reddiff = abs(red1 - red2);
|
||||||
|
greendiff = abs(green1 - green2);
|
||||||
|
bluediff = abs(blue1 - blue2);
|
||||||
#ifdef HAVE_OPENMP
|
#ifdef HAVE_OPENMP
|
||||||
#pragma omp parallel for
|
#pragma omp parallel for
|
||||||
#endif /* HAVE_OPENMP */
|
#endif /* HAVE_OPENMP */
|
||||||
for (i = 0; i < width; i++) {
|
for (i = 0; i < width; i++) {
|
||||||
int red3 = 0, green3 = 0, blue3 = 0; // colour components
|
int red3 = 0, green3 = 0, blue3 = 0; // colour components
|
||||||
|
|
||||||
int factor = round_to_int(diff * ((float)i / width));
|
float factor = ((float)(i + 1) / width);
|
||||||
|
|
||||||
if (red1 > red2) {
|
/* the '+ 0.5' bit rounds our floats to ints properly */
|
||||||
red3 = -factor;
|
if (red1 >= red2) {
|
||||||
|
red3 = -(factor * reddiff) - 0.5;
|
||||||
} else if (red1 < red2) {
|
} else if (red1 < red2) {
|
||||||
red3 = factor;
|
red3 = factor * reddiff + 0.5;
|
||||||
}
|
}
|
||||||
if (green1 > green2) {
|
if (green1 >= green2) {
|
||||||
green3 = -factor;
|
green3 = -(factor * greendiff) - 0.5;
|
||||||
} else if (green1 < green2) {
|
} else if (green1 < green2) {
|
||||||
green3 = factor;
|
green3 = factor * greendiff + 0.5;
|
||||||
}
|
}
|
||||||
if (blue1 > blue2) {
|
if (blue1 >= blue2) {
|
||||||
blue3 = -factor;
|
blue3 = -(factor * bluediff) - 0.5;
|
||||||
} else if (blue1 < blue2) {
|
} else if (blue1 < blue2) {
|
||||||
blue3 = factor;
|
blue3 = factor * bluediff + 0.5;
|
||||||
}
|
}
|
||||||
red3 += red1;
|
red3 += red1;
|
||||||
green3 += green1;
|
green3 += green1;
|
||||||
@ -144,47 +152,11 @@ unsigned long *do_gradient(float diff, int width, unsigned long first_colour, un
|
|||||||
if (green3 > bluemask) {
|
if (green3 > bluemask) {
|
||||||
green3 = bluemask;
|
green3 = bluemask;
|
||||||
}
|
}
|
||||||
if (blue1 > bluemask) {
|
if (blue3 > bluemask) {
|
||||||
blue1 = bluemask;
|
blue3 = bluemask;
|
||||||
}
|
}
|
||||||
colours[i] = (red3 << redshift) | (green3 << greenshift) | blue3;
|
colours[i] = (red3 << redshift) | (green3 << greenshift) | blue3;
|
||||||
}
|
}
|
||||||
return colours;
|
return colours;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this function returns the max diff for a gradient */
|
|
||||||
unsigned long gradient_max(unsigned long first_colour,
|
|
||||||
unsigned long last_colour)
|
|
||||||
{
|
|
||||||
int red1, green1, blue1; // first colour
|
|
||||||
int red2, green2, blue2; // second colour
|
|
||||||
int red3 = 0, green3 = 0, blue3 = 0; // difference
|
|
||||||
long redshift, greenshift;
|
|
||||||
int max;
|
|
||||||
|
|
||||||
if (colour_depth == 0) {
|
|
||||||
set_up_gradient();
|
|
||||||
}
|
|
||||||
redshift = (2 * colour_depth / 3 + colour_depth % 3);
|
|
||||||
greenshift = (colour_depth / 3);
|
|
||||||
|
|
||||||
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;
|
|
||||||
red3 = abs(red1 - red2);
|
|
||||||
green3 = abs(green1 - green2);
|
|
||||||
blue3 = abs(blue1 - blue2);
|
|
||||||
max = red3;
|
|
||||||
|
|
||||||
if (green3 > max) {
|
|
||||||
max = green3;
|
|
||||||
}
|
|
||||||
if (blue3 > max) {
|
|
||||||
max = blue3;
|
|
||||||
}
|
|
||||||
return max;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
#define _COLOURS_H
|
#define _COLOURS_H
|
||||||
|
|
||||||
unsigned int adjust_colours(unsigned int);
|
unsigned int adjust_colours(unsigned int);
|
||||||
unsigned long *do_gradient(float, int, unsigned long, unsigned long);
|
unsigned long *do_gradient(int, unsigned long, unsigned long);
|
||||||
unsigned long gradient_max(unsigned long, unsigned long);
|
|
||||||
|
|
||||||
#endif /* _COLOURS_H */
|
#endif /* _COLOURS_H */
|
||||||
|
@ -6095,10 +6095,7 @@ static void draw_line(char *s)
|
|||||||
|
|
||||||
if (specials[special_index].last_colour != 0
|
if (specials[special_index].last_colour != 0
|
||||||
|| specials[special_index].first_colour != 0) {
|
|| specials[special_index].first_colour != 0) {
|
||||||
int gradient_size =
|
tmpcolour = do_gradient(w - 1, specials[special_index].last_colour, specials[special_index].first_colour);
|
||||||
gradient_max(specials[special_index].last_colour,
|
|
||||||
specials[special_index].first_colour);
|
|
||||||
tmpcolour = do_gradient(gradient_size, w - 1, specials[special_index].first_colour, specials[special_index].last_colour);
|
|
||||||
}
|
}
|
||||||
colour_idx = 0;
|
colour_idx = 0;
|
||||||
for (i = w - 2; i > -1; i--) {
|
for (i = w - 2; i > -1; i--) {
|
||||||
|
Loading…
Reference in New Issue
Block a user