mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-29 14:56:21 +00:00
XEP-0392: color: implement color hashing
* add the HSL values of each of the 256 terminal colors * add color_pair_cache_hash_str() * move common code to _color_pair_cache_get() helper func after hashing a string to a color, return the closest matching terminal color using euclidian distance of the HSL diff vector (this method was found empirically and seems to work well enough...)
This commit is contained in:
@@ -38,10 +38,20 @@
|
||||
|
||||
/* to access color names */
|
||||
#define COLOR_NAME_SIZE 256
|
||||
extern const char *color_names[];
|
||||
|
||||
/* to add or clear cache */
|
||||
#include <stdint.h>
|
||||
|
||||
struct color_def {
|
||||
uint16_t h; uint8_t s, l;
|
||||
const char *name;
|
||||
};
|
||||
extern const struct color_def color_names[];
|
||||
|
||||
/* hash string to color pair */
|
||||
int color_pair_cache_hash_str(const char *str);
|
||||
/* parse fg_bg string to color pair */
|
||||
int color_pair_cache_get(const char *pair_name);
|
||||
/* clear cache */
|
||||
void color_pair_cache_reset(void);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user