Xonotic
color.qh File Reference
#include "string.qh"
+ Include dependency graph for color.qh:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define colormapPaletteColor(c, isPants)   colormapPaletteColor_(c, isPants, time)
 

Functions

ERASEABLE vector colormapPaletteColor_ (int c, bool isPants, float t)
 
ERASEABLE vector hsl_to_rgb (vector hsl)
 
ERASEABLE vector hsv_to_rgb (vector hsv)
 
ERASEABLE vector hue_mi_ma_to_rgb (float hue, float mi, float ma)
 
ERASEABLE float rgb_mi_ma_to_hue (vector rgb, float mi, float ma)
 
ERASEABLE string rgb_to_hexcolor (vector rgb)
 
ERASEABLE vector rgb_to_hsl (vector rgb)
 
ERASEABLE vector rgb_to_hsv (vector rgb)
 

Macro Definition Documentation

◆ colormapPaletteColor

Function Documentation

◆ colormapPaletteColor_()

ERASEABLE vector colormapPaletteColor_ ( int  c,
bool  isPants,
float  t 
)

Definition at line 7 of file color.qh.

References ERASEABLE, M_E, M_PI, and sin().

8 {
9  // these colors are defined in gfx/colormap_palette.pl
10  // to generate them run: perl gfx/colormap_palette.pl > gfx/colormap_palette.lmp
11  // it will save them to gfx/colormap_palette.lmp (in the lmp format)
12  // and prints the cases of the following switch so they can be copy-pasted here
13 
14  switch (c)
15  {
16  // generated by gfx/colormap_palette.pl
17  case 0: return '1.000000 1.000000 1.000000';
18  case 1: return '1.000000 0.333333 0.000000';
19  case 2: return '0.000000 1.000000 0.501961';
20  case 3: return '0.000000 1.000000 0.000000';
21  case 4: return '1.000000 0.000000 0.000000';
22  case 5: return '0.000000 0.666667 1.000000';
23  case 6: return '0.000000 1.000000 1.000000';
24  case 7: return '0.501961 1.000000 0.000000';
25  case 8: return '0.501961 0.000000 1.000000';
26  case 9: return '1.000000 0.000000 1.000000';
27  case 10: return '1.000000 0.000000 0.501961';
28  case 11: return '0.000000 0.000000 1.000000';
29  case 12: return '1.000000 1.000000 0.000000';
30  case 13: return '0.000000 0.333333 1.000000';
31  case 14: return '1.000000 0.666667 0.000000';
32  case 15:
33  if (isPants)
34  return '1 0 0' * (0.502 + 0.498 * sin(t / M_E + 0))
35  + '0 1 0' * (0.502 + 0.498 * sin(t / M_E + M_PI * 2 / 3))
36  + '0 0 1' * (0.502 + 0.498 * sin(t / M_E + M_PI * 4 / 3));
37  else
38  return '1 0 0' * (0.502 + 0.498 * sin(t / M_PI + M_PI * 5 / 3))
39  + '0 1 0' * (0.502 + 0.498 * sin(t / M_PI + M_PI))
40  + '0 0 1' * (0.502 + 0.498 * sin(t / M_PI + M_PI * 1 / 3));
41  default: return '0.000 0.000 0.000';
42  }
43 }
const float M_PI
Definition: csprogsdefs.qc:269
const float M_E
Definition: mathlib.qh:102
+ Here is the call graph for this function:

◆ hsl_to_rgb()

ERASEABLE vector hsl_to_rgb ( vector  hsl)

Definition at line 167 of file color.qh.

References ERASEABLE, and hue_mi_ma_to_rgb().

Referenced by GenericCommand(), and hslimage_color().

168 {
169  float mi, ma, maminusmi;
170 
171  if (hsl.z <= 0.5) maminusmi = hsl.y * 2 * hsl.z;
172  else maminusmi = hsl.y * (2 - 2 * hsl.z);
173 
174  // hsl_z = 0.5 * mi + 0.5 * ma
175  // maminusmi = - mi + ma
176  mi = hsl.z - 0.5 * maminusmi;
177  ma = hsl.z + 0.5 * maminusmi;
178 
179  return hue_mi_ma_to_rgb(hsl.x, mi, ma);
180 }
ERASEABLE vector hue_mi_ma_to_rgb(float hue, float mi, float ma)
Definition: color.qh:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hsv_to_rgb()

ERASEABLE vector hsv_to_rgb ( vector  hsv)

Definition at line 141 of file color.qh.

References ERASEABLE, and hue_mi_ma_to_rgb().

142 {
143  return hue_mi_ma_to_rgb(hsv.x, hsv.z * (1 - hsv.y), hsv.z);
144 }
ERASEABLE vector hue_mi_ma_to_rgb(float hue, float mi, float ma)
Definition: color.qh:68
+ Here is the call graph for this function:

◆ hue_mi_ma_to_rgb()

ERASEABLE vector hue_mi_ma_to_rgb ( float  hue,
float  mi,
float  ma 
)

Definition at line 68 of file color.qh.

References ERASEABLE, floor(), and vector().

Referenced by hsl_to_rgb(), and hsv_to_rgb().

69 {
70  vector rgb;
71 
72  hue -= 6 * floor(hue / 6);
73 
74  // else if(ma == rgb_x)
75  // hue = 60 * (rgb_y - rgb_z) / (ma - mi);
76  if (hue <= 1)
77  {
78  rgb.x = ma;
79  rgb.y = hue * (ma - mi) + mi;
80  rgb.z = mi;
81  }
82  // else if(ma == rgb_y)
83  // hue = 60 * (rgb_z - rgb_x) / (ma - mi) + 120;
84  else if (hue <= 2)
85  {
86  rgb.x = (2 - hue) * (ma - mi) + mi;
87  rgb.y = ma;
88  rgb.z = mi;
89  }
90  else if (hue <= 3)
91  {
92  rgb.x = mi;
93  rgb.y = ma;
94  rgb.z = (hue - 2) * (ma - mi) + mi;
95  }
96  // else // if(ma == rgb_z)
97  // hue = 60 * (rgb_x - rgb_y) / (ma - mi) + 240;
98  else if (hue <= 4)
99  {
100  rgb.x = mi;
101  rgb.y = (4 - hue) * (ma - mi) + mi;
102  rgb.z = ma;
103  }
104  else if (hue <= 5)
105  {
106  rgb.x = (hue - 4) * (ma - mi) + mi;
107  rgb.y = mi;
108  rgb.z = ma;
109  }
110  // else if(ma == rgb_x)
111  // hue = 60 * (rgb_y - rgb_z) / (ma - mi);
112  else // if(hue <= 6)
113  {
114  rgb.x = ma;
115  rgb.y = mi;
116  rgb.z = (6 - hue) * (ma - mi) + mi;
117  }
118 
119  return rgb;
120 }
vector(float skel, float bonenum) _skel_get_boneabs_hidden
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rgb_mi_ma_to_hue()

ERASEABLE float rgb_mi_ma_to_hue ( vector  rgb,
float  mi,
float  ma 
)

Definition at line 46 of file color.qh.

References ERASEABLE.

Referenced by rgb_to_hsl(), and rgb_to_hsv().

47 {
48  if (mi == ma)
49  {
50  return 0;
51  }
52  else if (ma == rgb.x)
53  {
54  if (rgb.y >= rgb.z) return (rgb.y - rgb.z) / (ma - mi);
55  else return (rgb.y - rgb.z) / (ma - mi) + 6;
56  }
57  else if (ma == rgb.y)
58  {
59  return (rgb.z - rgb.x) / (ma - mi) + 2;
60  }
61  else // if(ma == rgb_z)
62  {
63  return (rgb.x - rgb.y) / (ma - mi) + 4;
64  }
65 }
+ Here is the caller graph for this function:

◆ rgb_to_hexcolor()

ERASEABLE string rgb_to_hexcolor ( vector  rgb)

Definition at line 183 of file color.qh.

References DEC_TO_HEXDIGIT, floor(), and strcat().

Referenced by BUFF_NAME(), GenericCommand(), getDemos_for_ext(), getScreenshots_for_ext(), and XonoticColorpicker_mouseDrag().

184 {
185  return strcat(
186  "^x",
187  DEC_TO_HEXDIGIT(floor(rgb.x * 15 + 0.5)),
188  DEC_TO_HEXDIGIT(floor(rgb.y * 15 + 0.5)),
189  DEC_TO_HEXDIGIT(floor(rgb.z * 15 + 0.5))
190  );
191 }
#define DEC_TO_HEXDIGIT(d)
Definition: string.qh:503
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rgb_to_hsl()

ERASEABLE vector rgb_to_hsl ( vector  rgb)

Definition at line 147 of file color.qh.

References ERASEABLE, max(), min(), rgb_mi_ma_to_hue(), and vector().

Referenced by color_hslimage().

148 {
149  float mi, ma;
150  vector hsl;
151 
152  mi = min(rgb.x, rgb.y, rgb.z);
153  ma = max(rgb.x, rgb.y, rgb.z);
154 
155  hsl.x = rgb_mi_ma_to_hue(rgb, mi, ma);
156 
157  hsl.z = 0.5 * (mi + ma);
158  if (mi == ma) hsl.y = 0;
159  else if (hsl.z <= 0.5) hsl.y = (ma - mi) / (2 * hsl.z);
160  else // if(hsl_z > 0.5)
161  hsl.y = (ma - mi) / (2 - 2 * hsl.z);
162 
163  return hsl;
164 }
vector(float skel, float bonenum) _skel_get_boneabs_hidden
ERASEABLE float rgb_mi_ma_to_hue(vector rgb, float mi, float ma)
Definition: color.qh:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rgb_to_hsv()

ERASEABLE vector rgb_to_hsv ( vector  rgb)

Definition at line 123 of file color.qh.

References ERASEABLE, max(), min(), rgb_mi_ma_to_hue(), and vector().

124 {
125  float mi, ma;
126  vector hsv;
127 
128  mi = min(rgb.x, rgb.y, rgb.z);
129  ma = max(rgb.x, rgb.y, rgb.z);
130 
131  hsv.x = rgb_mi_ma_to_hue(rgb, mi, ma);
132  hsv.z = ma;
133 
134  if (ma == 0) hsv.y = 0;
135  else hsv.y = 1 - mi / ma;
136 
137  return hsv;
138 }
vector(float skel, float bonenum) _skel_get_boneabs_hidden
ERASEABLE float rgb_mi_ma_to_hue(vector rgb, float mi, float ma)
Definition: color.qh:46
+ Here is the call graph for this function: