MCPcopy Create free account
hub / github.com/danihek/hellwal / process_variable_alpha

Function process_variable_alpha

hellwal.c:1827–1852  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1825}
1826
1827char *process_variable_alpha(char *color, char *value, enum COLOR_TYPES type)
1828{
1829 if ((type != HEX_t && type != RGB_t) || !is_between_01_float(value))
1830 return color;
1831
1832 const float alpha_value = strtod(value, NULL);
1833 char *buffer = NULL;
1834
1835 if (type == HEX_t)
1836 {
1837 buffer = malloc(sizeof(color) + 3); // 3 because 2 next hex aplha numbers
1838 // and 1 null termination
1839 int a = (int)(alpha_value * 255);
1840 sprintf(buffer, "%s%02x", color, a);
1841 }
1842 else // we can safely assume it's rgb
1843 {
1844 buffer = malloc(sizeof(color) + sizeof(", "));
1845 sprintf(buffer, "%s, %f", color, alpha_value);
1846 }
1847
1848 if (buffer != NULL)
1849 return buffer;
1850
1851 return color;
1852}
1853
1854/*
1855 * Loads content from file file to buffer,

Callers 1

Calls 1

is_between_01_floatFunction · 0.85

Tested by

no test coverage detected