-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathsh_color.h
87 lines (75 loc) · 2.16 KB
/
sh_color.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef __SH_COLOR_H__
#define __SH_COLOR_H__
/*******************************************************************************
* sh_color *
* Wed Dec 18 CET 2013 *
* Copyright Eduardo San Martin Morote *
* http://posva.net *
******************************************************************************/
#include <stdint.h>
/**
* @defgroup sh_color sh_color
* Manipulation of pixels
* @{
*/
/**
* @brief Structure defining a color in RGB format
*/
typedef struct {
uint8_t r, ///< Red
g, ///< Green
b, ///< Blue
a; ///< Alpha
} color_t;
/**
* @brief Structure defining a color in YUV format
*/
typedef struct {
float y, ///< Y'
u, ///< u
v; ///< v
} color_yuv_t;
#define N_COLORS 247 ///< Number of colors in terminal
//uint32_t color_map[N_COLORS]; ///< palette of the terminal colors in RGB 0x00RRGGBB
// yuv equivalents
//color_yuv_t yuv_color_map[N_COLORS]; ///< palette of the terminal colors in YUV format
/**
* @brief Convert a color from RGB to YUV
*
* @param rgb color in rgb
* @param yuv returned conversion
*/
void rgb2yuv(const color_t *rgb, color_yuv_t *yuv);
/**
* @brief Squared distance between 2 YUV colors
*
* @param a from color
* @param b to color
* @return the distance
*/
float col_yuv_distance(const color_yuv_t *a, const color_yuv_t *b);
/**
* @brief Convert a color to its nearest equivalent in the terminal palette
*
* @param col color to convert
* @param out returned color
*/
void convert_color(color_t *col, color_t *out);
/**
* @brief Copy a color
*
* @param col color to copy
* @param out color where to copy
*/
void col_cpy(const color_t *col, color_t *out);
/**
* @brief Initialize the hastable for the colors
*/
void init_hash_colors();
/**
* @brief Free the hashtables for the colors
*/
void free_hash_colors();
/// @}
#endif