示例#1
0
/*
 * Multiplies an RGB color by a scalar value.
 *
 * value: Scalar value by which the color is being multiplied
 * color: Color being multiplied.
 */
Color multiply_color(long double value, Color color)
{
    color.red *= value;
    color.green *= value;
    color.blue *= value;
    // Make overflow validation
    return validate_color(color);
}
示例#2
0
/*
 * Multiplies two RGB colors.
 *
 * color1: Original color.
 * color2. Color by which the original color is being multiplied.
 */
Color multiply_colors(Color color1, Color color2)
{
    color1.red *= color2.red;
    color1.green *= color2.green;
    color1.blue *= color2.blue;
    // Make overflow validation
    return validate_color(color1);
}
示例#3
0
/*
 * Returns an empty color.
 */
Color get_empty_color()
{
    return (Color){ .red = 0.0, .green = 0.0, .blue = 0.0 };
}

/*
 * Returns true if the R, G, and B values of the color are 0.
 *
 * color: Color being evaluated.
 */
int is_color_empty(Color color)
{
    return color.red == 0.0 && color.green == 0.0 && color.blue == 0.0;
}

/*
 * Makes a color overflow validation. If any value of the color surpasses 1,
 * that value is changed to one. It returns the non-overflowing color.
 *
 * color: Color being validated.
 */
Color validate_color(Color color)
{
    // Make overflow validation
    if (color.red > 1.0) color.red = 1.0;
    if (color.green > 1.0) color.green = 1.0;
    if (color.blue > 1.0) color.blue = 1.0;
    return color;
}

/*
 * Adds two RGB colors.
 *
 * color1: Original color.
 * color2. Color that we are adding to the original color.
 */
Color add_colors(Color color1, Color color2)
{
    color1.red += color2.red;
    color1.green += color2.green;
    color1.blue += color2.blue;
    // Make overflow validation
    return validate_color(color1);
}
示例#4
0
文件: config.c 项目: cheukyin699/cava
void validate_config(char supportedInput[255], void* params)
{

struct config_params *p = (struct config_params *)params;

// validate: input method
p->im = 0;
if (strcmp(inputMethod, "alsa") == 0) {
	p->im = 1;
	#ifndef ALSA
	        fprintf(stderr,
                        "cava was built without alsa support, install alsa dev files and run make clean && ./configure && make again\n");
                exit(EXIT_FAILURE);
        #endif
}
if (strcmp(inputMethod, "fifo") == 0) {
	p->im = 2;
}
if (strcmp(inputMethod, "pulse") == 0) {
	p->im = 3;
	#ifndef PULSE
	        fprintf(stderr,
                        "cava was built without pulseaudio support, install pulseaudio dev files and run make clean && ./configure && make again\n");
                exit(EXIT_FAILURE);
        #endif

}
if (p->im == 0) {
	fprintf(stderr,
		"input method '%s' is not supported, supported methods are: %s\n",
					inputMethod, supportedInput);
	exit(EXIT_FAILURE);
}

// validate: output method
p->om = 0;
if (strcmp(outputMethod, "ncurses") == 0) {
	p->om = 1;
	#ifndef NCURSES
		fprintf(stderr,
			"cava was built without ncurses support, install ncursesw dev files and run make clean && ./configure && make again\n");
		exit(EXIT_FAILURE);
	#endif
}
if (strcmp(outputMethod, "circle") == 0) {
	 p->om = 2;
	#ifndef NCURSES
		fprintf(stderr,
			"cava was built without ncurses support, install ncursesw dev files and run make clean && ./configure && make again\n");
		exit(EXIT_FAILURE);
	#endif
}
if (strcmp(outputMethod, "noncurses") == 0) {
	p->om = 3;
	p->bgcol = 0;
}
if (strcmp(outputMethod, "raw") == 0) {//raw:
	p->om = 4;
	p->autosens = 0;
	
	//checking data format
	p->is_bin = -1;
	if (strcmp(data_format, "binary") == 0) {
		p->is_bin = 1;
		//checking bit format:
		if (p->bit_format != 8 && p->bit_format != 16 ) {
		fprintf(stderr,
			"bit format  %d is not supported, supported data formats are: '8' and '16'\n",
						p->bit_format );
		exit(EXIT_FAILURE);
	
		}
	} else if (strcmp(data_format, "ascii") == 0) {
		p->is_bin = 0;
		if (p->ascii_range < 1 ) {
		fprintf(stderr,
			"ascii max value must be a positive integer\n");
		exit(EXIT_FAILURE);
		}
	} else {
	fprintf(stderr,
		"data format %s is not supported, supported data formats are: 'binary' and 'ascii'\n",
					data_format);
	exit(EXIT_FAILURE);
	
	}



}
if (p->om == 0) {
	#ifndef NCURSES
	fprintf(stderr,
		"output method %s is not supported, supported methods are: 'noncurses'\n",
					outputMethod);
	exit(EXIT_FAILURE);
	#endif

	#ifdef NCURSES
        fprintf(stderr,
                "output method %s is not supported, supported methods are: 'ncurses' and 'noncurses'\n",
                                        outputMethod);
        exit(EXIT_FAILURE);
	#endif	
}

// validate: output channels
p->stereo = -1;
if (strcmp(channels, "mono") == 0) p->stereo = 0;
if (strcmp(channels, "stereo") == 0) p->stereo = 1;
if (p->stereo == -1) {
	fprintf(stderr,
		"output channels %s is not supported, supported channelss are: 'mono' and 'stereo'\n",
					channels);
	exit(EXIT_FAILURE);
}




// validate: bars
p->autobars = 1;
if (p->fixedbars > 0) p->autobars = 0;
if (p->fixedbars > 200) p->fixedbars = 200;
if (p->bw > 200) p->bw = 200;
if (p->bw < 1) p->bw = 1;

// validate: framerate
if (p->framerate < 0) {
	fprintf(stderr,
		"framerate can't be negative!\n");
	exit(EXIT_FAILURE);
}

// validate: color
if (!validate_color(p->color, p->om)) {
	fprintf(stderr, "The value for 'foreground' is invalid. It can be either one of the 7 named colors or a HTML color of the form '#xxxxxx'.\n");
	exit(EXIT_FAILURE);
}

// validate: background color
if (!validate_color(p->bcolor, p->om)) {
	fprintf(stderr, "The value for 'background' is invalid. It can be either one of the 7 named colors or a HTML color of the form '#xxxxxx'.\n");
	exit(EXIT_FAILURE);
}

// In case color is not html format set bgcol and col to predefinedint values
p->col = 6;
if (strcmp(p->color, "black") == 0) p->col = 0;
if (strcmp(p->color, "red") == 0) p->col = 1;
if (strcmp(p->color, "green") == 0) p->col = 2;
if (strcmp(p->color, "yellow") == 0) p->col = 3;
if (strcmp(p->color, "blue") == 0) p->col = 4;
if (strcmp(p->color, "magenta") == 0) p->col = 5;
if (strcmp(p->color, "cyan") == 0) p->col = 6;
if (strcmp(p->color, "white") == 0) p->col = 7;
// default if invalid

// validate: background color
p->bgcol = -1;
if (strcmp(p->bcolor, "black") == 0) p->bgcol = 0;
if (strcmp(p->bcolor, "red") == 0) p->bgcol = 1;
if (strcmp(p->bcolor, "green") == 0) p->bgcol = 2;
if (strcmp(p->bcolor, "yellow") == 0) p->bgcol = 3;
if (strcmp(p->bcolor, "blue") == 0) p->bgcol = 4;
if (strcmp(p->bcolor, "magenta") == 0) p->bgcol = 5;
if (strcmp(p->bcolor, "cyan") == 0) p->bgcol = 6;
if (strcmp(p->bcolor, "white") == 0) p->bgcol = 7;
// default if invalid


// validate: gravity
p->gravity = p->gravity / 100;
if (p->gravity < 0) {
	p->gravity = 0;
} 


// validate: integral
p->integral = p->integral / 100;
if (p->integral < 0) {
	p->integral = 0;
} else if (p->integral > 1) {
	p->integral = 1;
}

// validate: cutoff
if (p->lowcf == 0 ) p->lowcf++;
if (p->lowcf > p->highcf) {
	fprintf(stderr,
		"lower cutoff frequency can't be higher than higher cutoff frequency\n");
	exit(EXIT_FAILURE);
}

//setting sens
p->sens = p->sens / 100;


}