Enabled multicolored gradient

Now, the option to configure gradient with more than 2 colors is
supported. To use this, write the following in your config :
gradient = 1
gradient_count = <num>
gradient_color_1 = <col>
gradient_color_2 = <col>
gradient_color_3 = <col>
.
.
.
gradient_color_<num> = <col>

Replace <num> with the number of colors (2 <= colors <= 8), and replace
 <col>s with your colors of choice. You must explicitly provide all
 colors for the gradient to work, otherwise appropiate errors will be
 shown.
master
Subhranil Mukherjee 8 years ago
parent 8e236dca26
commit 6c4d11e440
No known key found for this signature in database
GPG Key ID: 79079C068D692AD2
  1. 2
      cava.c
  2. 39
      config.c
  3. 3
      example_files/config
  4. 56
      output/terminal_ncurses.c
  5. 2
      output/terminal_ncurses.h

@ -454,7 +454,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
//output: start ncurses mode
if (p.om == 1 || p.om == 2) {
init_terminal_ncurses(p.color, p.bcolor, p.col,
p.bgcol, p.gradient, p.gradient_color_1, p.gradient_color_2,&w, &h);
p.bgcol, p.gradient, p.gradient_count, p.gradient_colors,&w, &h);
//get_terminal_dim_ncurses(&w, &h);
}
#endif

@ -11,13 +11,13 @@ char *inputMethod, *outputMethod, *channels;
struct config_params {
char *color, *bcolor, *raw_target, *audio_source, *gradient_color_1, *gradient_color_2, *data_format;
char *color, *bcolor, *raw_target, *audio_source, /**gradient_color_1, *gradient_color_2,*/ **gradient_colors, *data_format;
char bar_delim, frame_delim ;
double monstercat, integral, gravity, ignore, sens;
unsigned int lowcf, highcf;
double *smooth;
int smcount, customEQ, im, om, col, bgcol, autobars, stereo, is_bin, ascii_range,
bit_format, gradient, fixedbars, framerate, bw, bs, autosens, overshoot, waves;
bit_format, gradient, gradient_count, fixedbars, framerate, bw, bs, autosens, overshoot, waves;
};
@ -214,13 +214,11 @@ if (!validate_color(p->bcolor, p->om)) {
}
if (p->gradient) {
if (!validate_color(p->gradient_color_1, p->om)) {
fprintf(stderr, "The first gradient color is invalid. It must be HTML color of the form '#xxxxxx'.\n");
exit(EXIT_FAILURE);
}
if (!validate_color(p->gradient_color_2, p->om)) {
fprintf(stderr, "The second gradient color is invalid. It must be HTML color of the form '#xxxxxx'.\n");
exit(EXIT_FAILURE);
for(int i = 0;i < p->gradient_count;i++){
if (!validate_color(p->gradient_colors[i], p->om)) {
fprintf(stderr, "The first gradient color is invalid. It must be HTML color of the form '#xxxxxx'.\n");
exit(EXIT_FAILURE);
}
}
}
@ -360,8 +358,27 @@ p->bcolor = (char *)iniparser_getstring(ini, "color:background", "default");
p->gradient = iniparser_getint(ini, "color:gradient", 0);
if (p->gradient) {
p->gradient_color_1 = (char *)iniparser_getstring(ini, "color:gradient_color_1", "#0099ff");
p->gradient_color_2 = (char *)iniparser_getstring(ini, "color:gradient_color_2", "#ff3399");
p->gradient_count = iniparser_getint(ini, "color:gradient_count", 2);
if(p->gradient_count < 2){
printf("\nAtleast two colors must be given as gradient!\n");
exit(EXIT_FAILURE);
}
if(p->gradient_count > 8){
printf("\nMaximum 8 colors can be specified as gradient!\n");
exit(EXIT_FAILURE);
}
p->gradient_colors = (char **)malloc(sizeof(char*) * p->gradient_count);
for(int i = 0;i < p->gradient_count;i++){
char ini_config[23];
sprintf(ini_config, "color:gradient_color_%d", (i + 1));
p->gradient_colors[i] = (char *)iniparser_getstring(ini, ini_config, NULL);
if(p->gradient_colors[i] == NULL){
printf("\nGradient color not specified : gradient_color_%d\n", (i + 1));
exit(EXIT_FAILURE);
}
}
//p->gradient_color_1 = (char *)iniparser_getstring(ini, "color:gradient_color_1", "#0099ff");
//p->gradient_color_2 = (char *)iniparser_getstring(ini, "color:gradient_color_2", "#ff3399");
}
p->fixedbars = iniparser_getint(ini, "general:bars", 0);

@ -102,7 +102,8 @@
# Gradient mode, only hex defined colors are supported, background must also be defined in hex
# or remain commented out. 1 = on, 0 = off. Warning: for certain terminal emulators cava will
# not able to restore color definitions on exit, simply restart your terminal to restore colors.
; gradient = 0
; gradient = 1
; gradient_count = 2
; gradient_color_1 = '#0099ff'
; gradient_color_2 = '#ff3399'

@ -63,7 +63,7 @@ char* const color_string, NCURSES_COLOR_T predef_color) {
void init_terminal_ncurses(char* const fg_color_string,
char* const bg_color_string, int predef_fg_color, int predef_bg_color, int gradient,
char* const gradient_color_1, char* const gradient_color_2, int* width, int* height) {
int gradient_count, char **gradient_colors, int* width, int* height) {
initscr();
curs_set(0);
timeout(0);
@ -87,8 +87,9 @@ char* const bg_color_string, int predef_fg_color, int predef_bg_color, int gradi
init_pair(color_pair_number, fg_color_number, bg_color_number);
} else if (gradient) {
short unsigned int rgb[3][3];
// 0 -> col1, 1-> col1<=>col2, 2 -> col2 and so on
short unsigned int rgb[2 * gradient_count - 1][3];
char next_color[8];
gradient_size = *height;
@ -99,24 +100,49 @@ char* const bg_color_string, int predef_fg_color, int predef_bg_color, int gradi
if (gradient_size > MAX_COLOR_REDEFINITION) gradient_size = MAX_COLOR_REDEFINITION - 1;
sscanf(gradient_color_1 + 1, "%02hx%02hx%02hx", &rgb[0][0], &rgb[0][1], &rgb[0][2]);
sscanf(gradient_color_2 + 1, "%02hx%02hx%02hx", &rgb[1][0], &rgb[1][1], &rgb[1][2]);
for(int i = 0;i < gradient_count;i++){
int col = (i + 1)*2 - 2;
sscanf(gradient_colors[i]+1, "%02hx%02hx%02hx", &rgb[col][0], &rgb[col][1], &rgb[col][2]);
}
for (int n = 0; n < gradient_size; n++) {
//sscanf(gradient_color_1 + 1, "%02hx%02hx%02hx", &rgb[0][0], &rgb[0][1], &rgb[0][2]);
//sscanf(gradient_color_2 + 1, "%02hx%02hx%02hx", &rgb[1][0], &rgb[1][1], &rgb[1][2]);
for(int i = 0; i < 3; i++) {
rgb[2][i] = rgb[0][i] + (rgb[1][i] - rgb[0][i]) * n / (gradient_size * 0.85);
if (rgb[2][i] > 255) rgb[2][i] = 0;
if ( n > gradient_size * 0.85 ) rgb[2][i] = rgb[1][i];
}
sprintf(next_color,"#%02x%02x%02x",rgb[2][0], rgb[2][1], rgb[2][2]);
int individual_size = gradient_size/(gradient_count - 1);
change_color_definition(n + 1, next_color, n + 1);
init_pair(color_pair_number++, n + 1, bg_color_number);
int row = 0;
for(int i = 0;i < gradient_count - 1;i++){
int col = (i + 1)* 2 - 2;
if(i == gradient_count - 1)
col = 2*(gradient_count - 1) - 2;
for(int j = 0; j < individual_size;j++){
for(int k = 0; k < 3; k++) {
rgb[col+1][k] = rgb[col][k] + (rgb[col+2][k] - rgb[col][k]) * (j / (individual_size * 0.85));
if (rgb[col+1][k] > 255) rgb[col][k] = 0;
if ( j > individual_size * 0.85 ) rgb[col+1][k] = rgb[col+2][k];
}
sprintf(next_color,"#%02x%02x%02x",rgb[col+1][0], rgb[col+1][1], rgb[col+1][2]);
change_color_definition(row + 1, next_color, row + 1);
init_pair(color_pair_number++, row + 1, bg_color_number);
row++;
}
}
int left = individual_size * (gradient_count - 1);
int col = 2*(gradient_count) - 2;
while(left < gradient_size){
sprintf(next_color,"#%02x%02x%02x",rgb[col][0], rgb[col][1], rgb[col][2]);
change_color_definition(row + 1, next_color, row + 1);
init_pair(color_pair_number++, row + 1, bg_color_number);
row++;
left++;
}
}
if (bg_color_number != -1)

@ -1,6 +1,6 @@
void init_terminal_ncurses(char* const fg_color_string,
char* const bg_color_string, int predef_fg_color, int predef_bg_color, int gradient,
char* const gradient_color_1, char* const gradient_color_2,int* width, int* height);
int gradient_count, char **gradient_colors,int* width, int* height);
void get_terminal_dim_ncurses(int* width, int* height);
int draw_terminal_ncurses(int is_tty, int terminal_height, int terminal_width,
int bars_count, int bar_width, int bar_spacing, int rest, const int f[200],

Loading…
Cancel
Save