ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
Colors.c
Go to the documentation of this file.
1/*
2 * ObjectivelyMVC: Object oriented MVC framework for SDL3 and C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 * 1. The origin of this software must not be misrepresented, you must not
11 * claim that you wrote the original software. If you use this software
12 * in a product, an acknowledgment in the product documentation would be
13 * appreciated but is not required.
14 * 2. Altered source versions must be plainly marked as such, and must not be
15 * misrepresented as being the original software.
16 * 3. This notice may not be removed or altered from any source distribution.
17 */
18
19#include <assert.h>
20#include <math.h>
21#include <string.h>
22#include <stdio.h>
23
24#include <SDL3/SDL_endian.h>
25
26#include "Colors.h"
27
28const struct Colors Colors = {
29 .AliceBlue = { 240, 248, 255, 255 },
30 .AntiqueWhite = { 250, 235, 215, 255 },
31 .Aqua = { 0, 255, 255, 255 },
32 .Aquamarine = { 127, 255, 212, 255 },
33 .Azure = { 240, 255, 255, 255 },
34 .Beige = { 245, 245, 220, 255 },
35 .Bisque = { 255, 228, 196, 255 },
36 .Black = { 0, 0, 0, 255 },
37 .BlanchedAlmond = { 255, 235, 205, 255 },
38 .Blue = { 0, 0, 255, 255 },
39 .BlueViolet = { 138, 43, 226, 255 },
40 .Brown = { 165, 42, 42, 255 },
41 .BurlyWood = { 222, 184, 135, 255 },
42 .CadetBlue = { 95, 158, 160, 255 },
43 .Charcoal = { 48, 48, 48, 255 },
44 .Chartreuse = { 127, 255, 0, 255 },
45 .Chocolate = { 210, 105, 30, 255 },
46 .Coral = { 255, 127, 80, 255 },
47 .CornflowerBlue = { 100, 149, 237, 255 },
48 .Cornsilk = { 255, 248, 220, 255 },
49 .Crimson = { 220, 20, 60, 255 },
50 .Cyan = { 0, 255, 255, 255 },
51 .DarkBlue = { 0, 0, 139, 255 },
52 .DarkCyan = { 139, 139, 255, 255 },
53 .DarkGoldenRod = { 184, 134, 11, 255 },
54 .DarkGray = { 169, 169, 169, 255 },
55 .DarkGrey = { 169, 169, 169, 255 },
56 .DarkGreen = { 0, 100, 0, 255 },
57 .DarkKhaki = { 189, 183, 107, 255 },
58 .DarkMagenta = { 139, 0, 139, 255 },
59 .DarkOliveGreen = { 85, 107, 47, 255 },
60 .DarkOrange = { 255, 140, 0, 255 },
61 .DarkOrchid = { 153, 50, 204, 255 },
62 .DarkRed = { 139, 0, 0, 255 },
63 .DarkSalmon = { 233, 150, 122, 255 },
64 .DarkSeaGreen = { 143, 188, 143, 255 },
65 .DarkSlateBlue = { 72, 61, 139, 255 },
66 .DarkSlateGray = { 47, 79, 79, 255 },
67 .DarkSlateGrey = { 47, 79, 79, 255 },
68 .DarkTurquoise = { 206, 209, 255, 255 },
69 .DarkViolet = { 148, 0, 211, 255 },
70 .DeepPink = { 255, 20, 147, 255 },
71 .DeepSkyBlue = { 191, 255, 255, 255 },
72 .DimGray = { 105, 105, 105, 255 },
73 .DimGrey = { 105, 105, 105, 255 },
74 .DodgerBlue = { 30, 144, 255, 255 },
75 .FireBrick = { 178, 34, 34, 255 },
76 .FloralWhite = { 255, 250, 240, 255 },
77 .ForestGreen = { 34, 139, 34, 255 },
78 .Fuchsia = { 255, 0, 255, 255 },
79 .Gainsboro = { 220, 220, 220, 255 },
80 .GhostWhite = { 248, 248, 255, 255 },
81 .Gold = { 255, 215, 0, 255 },
82 .GoldenRod = { 218, 165, 32, 255 },
83 .Gray = { 128, 128, 128, 255 },
84 .Grey = { 128, 128, 128, 255 },
85 .Green = { 0, 128, 0, 255 },
86 .GreenYellow = { 173, 255, 47, 255 },
87 .HoneyDew = { 240, 255, 240, 255 },
88 .HotPink = { 255, 105, 180, 255 },
89 .IndianRed = { 205, 92, 92, 255 },
90 .Indigo = { 75, 0, 130, 255 },
91 .Ivory = { 255, 255, 240, 255 },
92 .Khaki = { 240, 230, 140, 255 },
93 .Lavender = { 230, 230, 250, 255 },
94 .LavenderBlush = { 255, 240, 245, 255 },
95 .LawnGreen = { 124, 252, 0, 255 },
96 .LemonChiffon = { 255, 250, 205, 255 },
97 .LightBlue = { 173, 216, 230, 255 },
98 .LightCoral = { 240, 128, 128, 255 },
99 .LightCyan = { 224, 255, 255, 255 },
100 .LightGoldenRodYellow = { 250, 250, 210, 255 },
101 .LightGray = { 211, 211, 211, 255 },
102 .LightGrey = { 211, 211, 211, 255 },
103 .LightGreen = { 144, 238, 144, 255 },
104 .LightPink = { 255, 182, 193, 255 },
105 .LightSalmon = { 255, 160, 122, 255 },
106 .LightSeaGreen = { 32, 178, 170, 255 },
107 .LightSkyBlue = { 135, 206, 250, 255 },
108 .LightSlateGray = { 119, 136, 153, 255 },
109 .LightSlateGrey = { 119, 136, 153, 255 },
110 .LightSteelBlue = { 176, 196, 222, 255 },
111 .LightYellow = { 255, 255, 224, 255 },
112 .Lime = { 0, 255, 0, 255 },
113 .LimeGreen = { 50, 205, 50, 255 },
114 .Linen = { 250, 240, 230, 255 },
115 .Magenta = { 255, 0, 255, 255 },
116 .Maroon = { 128, 0, 0, 255 },
117 .MediumAquaMarine = { 102, 205, 170, 255 },
118 .MediumBlue = { 0, 0, 205, 255 },
119 .MediumOrchid = { 186, 85, 211, 255 },
120 .MediumPurple = { 147, 112, 219, 255 },
121 .MediumSeaGreen = { 60, 179, 113, 255 },
122 .MediumSlateBlue = { 123, 104, 238, 255 },
123 .MediumSpringGreen = { 250, 154, 255, 255 },
124 .MediumTurquoise = { 72, 209, 204, 255 },
125 .MediumVioletRed = { 199, 21, 133, 255 },
126 .MidnightBlue = { 25, 25, 112, 255 },
127 .MintCream = { 245, 255, 250, 255 },
128 .MistyRose = { 255, 228, 225, 255 },
129 .Moccasin = { 255, 228, 181, 255 },
130 .NavajoWhite = { 255, 222, 173, 255 },
131 .Navy = { 0, 0, 128, 255 },
132 .OldLace = { 253, 245, 230, 255 },
133 .Olive = { 128, 128, 0, 255 },
134 .OliveDrab = { 107, 142, 35, 255 },
135 .Orange = { 255, 165, 0, 255 },
136 .OrangeRed = { 255, 69, 0, 255 },
137 .Orchid = { 218, 112, 214, 255 },
138 .PaleGoldenRod = { 238, 232, 170, 255 },
139 .PaleGreen = { 152, 251, 152, 255 },
140 .PaleTurquoise = { 175, 238, 238, 255 },
141 .PaleVioletRed = { 219, 112, 147, 255 },
142 .PapayaWhip = { 255, 239, 213, 255 },
143 .PeachPuff = { 255, 218, 185, 255 },
144 .Peru = { 205, 133, 63, 255 },
145 .Pink = { 255, 192, 203, 255 },
146 .Plum = { 221, 160, 221, 255 },
147 .PowderBlue = { 176, 224, 230, 255 },
148 .Purple = { 128, 0, 128, 255 },
149 .RebeccaPurple = { 102, 51, 153, 255 },
150 .Red = { 255, 0, 0, 255 },
151 .RosyBrown = { 188, 143, 143, 255 },
152 .RoyalBlue = { 65, 105, 225, 255 },
153 .SaddleBrown = { 139, 69, 19, 255 },
154 .Salmon = { 250, 128, 114, 255 },
155 .SandyBrown = { 244, 164, 96, 255 },
156 .SeaGreen = { 46, 139, 87, 255 },
157 .SeaShell = { 255, 245, 238, 255 },
158 .Sienna = { 160, 82, 45, 255 },
159 .Silver = { 192, 192, 192, 255 },
160 .SkyBlue = { 135, 206, 235, 255 },
161 .SlateBlue = { 106, 90, 205, 255 },
162 .SlateGray = { 112, 128, 144, 255 },
163 .SlateGrey = { 112, 128, 144, 255 },
164 .Snow = { 255, 250, 250, 255 },
165 .SpringGreen = { 0, 255, 127, 255 },
166 .SteelBlue = { 70, 130, 180, 255 },
167 .Tan = { 210, 180, 140, 255 },
168 .Teal = { 0, 128, 128, 255 },
169 .Thistle = { 216, 191, 216, 255 },
170 .Tomato = { 255, 99, 71, 255 },
171 .Transparent = { 255, 255, 255, 0 },
172 .Turquoise = { 64, 224, 208, 255 },
173 .Violet = { 238, 130, 238, 255 },
174 .Wheat = { 245, 222, 179, 255 },
175 .White = { 255, 255, 255, 255 },
176 .WhiteSmoke = { 245, 245, 245, 255 },
177 .Yellow = { 255, 255, 0, 255 },
178 .YellowGreen = { 154, 205, 50, 255 },
179};
180
181SDL_Color MVC_ColorForName(const char *name) {
182
183 if (name) {
184 if (strcasecmp(name, "AliceBlue") == 0) {
185 return Colors.AliceBlue;
186 }
187 if (strcasecmp(name, "AntiqueWhite") == 0) {
188 return Colors.AntiqueWhite;
189 }
190 if (strcasecmp(name, "Aqua") == 0) {
191 return Colors.Aqua;
192 }
193 if (strcasecmp(name, "Aquamarine") == 0) {
194 return Colors.Aquamarine;
195 }
196 if (strcasecmp(name, "Azure") == 0) {
197 return Colors.Azure;
198 }
199 if (strcasecmp(name, "Beige") == 0) {
200 return Colors.Beige;
201 }
202 if (strcasecmp(name, "Bisque") == 0) {
203 return Colors.Bisque;
204 }
205 if (strcasecmp(name, "Black") == 0) {
206 return Colors.Black;
207 }
208 if (strcasecmp(name, "BlanchedAlmond") == 0) {
209 return Colors.BlanchedAlmond;
210 }
211 if (strcasecmp(name, "Blue") == 0) {
212 return Colors.Blue;
213 }
214 if (strcasecmp(name, "BlueViolet") == 0) {
215 return Colors.BlueViolet;
216 }
217 if (strcasecmp(name, "Brown") == 0) {
218 return Colors.Brown;
219 }
220 if (strcasecmp(name, "BurlyWood") == 0) {
221 return Colors.BurlyWood;
222 }
223 if (strcasecmp(name, "CadetBlue") == 0) {
224 return Colors.CadetBlue;
225 }
226 if (strcasecmp(name, "Charcoal") == 0) {
227 return Colors.Charcoal;
228 }
229 if (strcasecmp(name, "Chartreuse") == 0) {
230 return Colors.Chartreuse;
231 }
232 if (strcasecmp(name, "Chocolate") == 0) {
233 return Colors.Chocolate;
234 }
235 if (strcasecmp(name, "Coral") == 0) {
236 return Colors.Coral;
237 }
238 if (strcasecmp(name, "CornflowerBlue") == 0) {
239 return Colors.CornflowerBlue;
240 }
241 if (strcasecmp(name, "Cornsilk") == 0) {
242 return Colors.Cornsilk;
243 }
244 if (strcasecmp(name, "Crimson") == 0) {
245 return Colors.Crimson;
246 }
247 if (strcasecmp(name, "Cyan") == 0) {
248 return Colors.Cyan;
249 }
250 if (strcasecmp(name, "DarkBlue") == 0) {
251 return Colors.DarkBlue;
252 }
253 if (strcasecmp(name, "DarkCyan") == 0) {
254 return Colors.DarkCyan;
255 }
256 if (strcasecmp(name, "DarkGoldenRod") == 0) {
257 return Colors.DarkGoldenRod;
258 }
259 if (strcasecmp(name, "DarkGray") == 0) {
260 return Colors.DarkGray;
261 }
262 if (strcasecmp(name, "DarkGrey") == 0) {
263 return Colors.DarkGrey;
264 }
265 if (strcasecmp(name, "DarkGreen") == 0) {
266 return Colors.DarkGreen;
267 }
268 if (strcasecmp(name, "DarkKhaki") == 0) {
269 return Colors.DarkKhaki;
270 }
271 if (strcasecmp(name, "DarkMagenta") == 0) {
272 return Colors.DarkMagenta;
273 }
274 if (strcasecmp(name, "DarkOliveGreen") == 0) {
275 return Colors.DarkOliveGreen;
276 }
277 if (strcasecmp(name, "DarkOrange") == 0) {
278 return Colors.DarkOrange;
279 }
280 if (strcasecmp(name, "DarkOrchid") == 0) {
281 return Colors.DarkOrchid;
282 }
283 if (strcasecmp(name, "DarkRed") == 0) {
284 return Colors.DarkRed;
285 }
286 if (strcasecmp(name, "DarkSalmon") == 0) {
287 return Colors.DarkSalmon;
288 }
289 if (strcasecmp(name, "DarkSeaGreen") == 0) {
290 return Colors.DarkSeaGreen;
291 }
292 if (strcasecmp(name, "DarkSlateBlue") == 0) {
293 return Colors.DarkSlateBlue;
294 }
295 if (strcasecmp(name, "DarkSlateGray") == 0) {
296 return Colors.DarkSlateGray;
297 }
298 if (strcasecmp(name, "DarkSlateGrey") == 0) {
299 return Colors.DarkSlateGrey;
300 }
301 if (strcasecmp(name, "DarkTurquoise") == 0) {
302 return Colors.DarkTurquoise;
303 }
304 if (strcasecmp(name, "DarkViolet") == 0) {
305 return Colors.DarkViolet;
306 }
307 if (strcasecmp(name, "DeepPink") == 0) {
308 return Colors.DeepPink;
309 }
310 if (strcasecmp(name, "DeepSkyBlue") == 0) {
311 return Colors.DeepSkyBlue;
312 }
313 if (strcasecmp(name, "DimGray") == 0) {
314 return Colors.DimGray;
315 }
316 if (strcasecmp(name, "DimGrey") == 0) {
317 return Colors.DimGrey;
318 }
319 if (strcasecmp(name, "DodgerBlue") == 0) {
320 return Colors.DodgerBlue;
321 }
322 if (strcasecmp(name, "FireBrick") == 0) {
323 return Colors.FireBrick;
324 }
325 if (strcasecmp(name, "FloralWhite") == 0) {
326 return Colors.FloralWhite;
327 }
328 if (strcasecmp(name, "ForestGreen") == 0) {
329 return Colors.ForestGreen;
330 }
331 if (strcasecmp(name, "Fuchsia") == 0) {
332 return Colors.Fuchsia;
333 }
334 if (strcasecmp(name, "Gainsboro") == 0) {
335 return Colors.Gainsboro;
336 }
337 if (strcasecmp(name, "GhostWhite") == 0) {
338 return Colors.GhostWhite;
339 }
340 if (strcasecmp(name, "Gold") == 0) {
341 return Colors.Gold;
342 }
343 if (strcasecmp(name, "GoldenRod") == 0) {
344 return Colors.GoldenRod;
345 }
346 if (strcasecmp(name, "Gray") == 0) {
347 return Colors.Gray;
348 }
349 if (strcasecmp(name, "Grey") == 0) {
350 return Colors.Grey;
351 }
352 if (strcasecmp(name, "Green") == 0) {
353 return Colors.Green;
354 }
355 if (strcasecmp(name, "GreenYellow") == 0) {
356 return Colors.GreenYellow;
357 }
358 if (strcasecmp(name, "HoneyDew") == 0) {
359 return Colors.HoneyDew;
360 }
361 if (strcasecmp(name, "HotPink") == 0) {
362 return Colors.HotPink;
363 }
364 if (strcasecmp(name, "IndianRed") == 0) {
365 return Colors.IndianRed;
366 }
367 if (strcasecmp(name, "Indigo") == 0) {
368 return Colors.Indigo;
369 }
370 if (strcasecmp(name, "Ivory") == 0) {
371 return Colors.Ivory;
372 }
373 if (strcasecmp(name, "Khaki") == 0) {
374 return Colors.Khaki;
375 }
376 if (strcasecmp(name, "Lavender") == 0) {
377 return Colors.Lavender;
378 }
379 if (strcasecmp(name, "LavenderBlush") == 0) {
380 return Colors.LavenderBlush;
381 }
382 if (strcasecmp(name, "LawnGreen") == 0) {
383 return Colors.LawnGreen;
384 }
385 if (strcasecmp(name, "LemonChiffon") == 0) {
386 return Colors.LemonChiffon;
387 }
388 if (strcasecmp(name, "LightBlue") == 0) {
389 return Colors.LightBlue;
390 }
391 if (strcasecmp(name, "LightCoral") == 0) {
392 return Colors.LightCoral;
393 }
394 if (strcasecmp(name, "LightCyan") == 0) {
395 return Colors.LightCyan;
396 }
397 if (strcasecmp(name, "LightGoldenRodYellow") == 0) {
399 }
400 if (strcasecmp(name, "LightGray") == 0) {
401 return Colors.LightGray;
402 }
403 if (strcasecmp(name, "LightGrey") == 0) {
404 return Colors.LightGrey;
405 }
406 if (strcasecmp(name, "LightGreen") == 0) {
407 return Colors.LightGreen;
408 }
409 if (strcasecmp(name, "LightPink") == 0) {
410 return Colors.LightPink;
411 }
412 if (strcasecmp(name, "LightSalmon") == 0) {
413 return Colors.LightSalmon;
414 }
415 if (strcasecmp(name, "LightSeaGreen") == 0) {
416 return Colors.LightSeaGreen;
417 }
418 if (strcasecmp(name, "LightSkyBlue") == 0) {
419 return Colors.LightSkyBlue;
420 }
421 if (strcasecmp(name, "LightSlateGray") == 0) {
422 return Colors.LightSlateGray;
423 }
424 if (strcasecmp(name, "LightSlateGrey") == 0) {
425 return Colors.LightSlateGrey;
426 }
427 if (strcasecmp(name, "LightSteelBlue") == 0) {
428 return Colors.LightSteelBlue;
429 }
430 if (strcasecmp(name, "LightYellow") == 0) {
431 return Colors.LightYellow;
432 }
433 if (strcasecmp(name, "Lime") == 0) {
434 return Colors.Lime;
435 }
436 if (strcasecmp(name, "LimeGreen") == 0) {
437 return Colors.LimeGreen;
438 }
439 if (strcasecmp(name, "Linen") == 0) {
440 return Colors.Linen;
441 }
442 if (strcasecmp(name, "Magenta") == 0) {
443 return Colors.Magenta;
444 }
445 if (strcasecmp(name, "Maroon") == 0) {
446 return Colors.Maroon;
447 }
448 if (strcasecmp(name, "MediumAquaMarine") == 0) {
450 }
451 if (strcasecmp(name, "MediumBlue") == 0) {
452 return Colors.MediumBlue;
453 }
454 if (strcasecmp(name, "MediumOrchid") == 0) {
455 return Colors.MediumOrchid;
456 }
457 if (strcasecmp(name, "MediumPurple") == 0) {
458 return Colors.MediumPurple;
459 }
460 if (strcasecmp(name, "MediumSeaGreen") == 0) {
461 return Colors.MediumSeaGreen;
462 }
463 if (strcasecmp(name, "MediumSlateBlue") == 0) {
464 return Colors.MediumSlateBlue;
465 }
466 if (strcasecmp(name, "MediumSpringGreen") == 0) {
468 }
469 if (strcasecmp(name, "MediumTurquoise") == 0) {
470 return Colors.MediumTurquoise;
471 }
472 if (strcasecmp(name, "MediumVioletRed") == 0) {
473 return Colors.MediumVioletRed;
474 }
475 if (strcasecmp(name, "MidnightBlue") == 0) {
476 return Colors.MidnightBlue;
477 }
478 if (strcasecmp(name, "MintCream") == 0) {
479 return Colors.MintCream;
480 }
481 if (strcasecmp(name, "MistyRose") == 0) {
482 return Colors.MistyRose;
483 }
484 if (strcasecmp(name, "Moccasin") == 0) {
485 return Colors.Moccasin;
486 }
487 if (strcasecmp(name, "NavajoWhite") == 0) {
488 return Colors.NavajoWhite;
489 }
490 if (strcasecmp(name, "Navy") == 0) {
491 return Colors.Navy;
492 }
493 if (strcasecmp(name, "OldLace") == 0) {
494 return Colors.OldLace;
495 }
496 if (strcasecmp(name, "Olive") == 0) {
497 return Colors.Olive;
498 }
499 if (strcasecmp(name, "OliveDrab") == 0) {
500 return Colors.OliveDrab;
501 }
502 if (strcasecmp(name, "Orange") == 0) {
503 return Colors.Orange;
504 }
505 if (strcasecmp(name, "OrangeRed") == 0) {
506 return Colors.OrangeRed;
507 }
508 if (strcasecmp(name, "Orchid") == 0) {
509 return Colors.Orchid;
510 }
511 if (strcasecmp(name, "PaleGoldenRod") == 0) {
512 return Colors.PaleGoldenRod;
513 }
514 if (strcasecmp(name, "PaleGreen") == 0) {
515 return Colors.PaleGreen;
516 }
517 if (strcasecmp(name, "PaleTurquoise") == 0) {
518 return Colors.PaleTurquoise;
519 }
520 if (strcasecmp(name, "PaleVioletRed") == 0) {
521 return Colors.PaleVioletRed;
522 }
523 if (strcasecmp(name, "PapayaWhip") == 0) {
524 return Colors.PapayaWhip;
525 }
526 if (strcasecmp(name, "PeachPuff") == 0) {
527 return Colors.PeachPuff;
528 }
529 if (strcasecmp(name, "Peru") == 0) {
530 return Colors.Peru;
531 }
532 if (strcasecmp(name, "Pink") == 0) {
533 return Colors.Pink;
534 }
535 if (strcasecmp(name, "Plum") == 0) {
536 return Colors.Plum;
537 }
538 if (strcasecmp(name, "PowderBlue") == 0) {
539 return Colors.PowderBlue;
540 }
541 if (strcasecmp(name, "Purple") == 0) {
542 return Colors.Purple;
543 }
544 if (strcasecmp(name, "RebeccaPurple") == 0) {
545 return Colors.RebeccaPurple;
546 }
547 if (strcasecmp(name, "Red") == 0) {
548 return Colors.Red;
549 }
550 if (strcasecmp(name, "RosyBrown") == 0) {
551 return Colors.RosyBrown;
552 }
553 if (strcasecmp(name, "RoyalBlue") == 0) {
554 return Colors.RoyalBlue;
555 }
556 if (strcasecmp(name, "SaddleBrown") == 0) {
557 return Colors.SaddleBrown;
558 }
559 if (strcasecmp(name, "Salmon") == 0) {
560 return Colors.Salmon;
561 }
562 if (strcasecmp(name, "SandyBrown") == 0) {
563 return Colors.SandyBrown;
564 }
565 if (strcasecmp(name, "SeaGreen") == 0) {
566 return Colors.SeaGreen;
567 }
568 if (strcasecmp(name, "SeaShell") == 0) {
569 return Colors.SeaShell;
570 }
571 if (strcasecmp(name, "Sienna") == 0) {
572 return Colors.Sienna;
573 }
574 if (strcasecmp(name, "Silver") == 0) {
575 return Colors.Silver;
576 }
577 if (strcasecmp(name, "SkyBlue") == 0) {
578 return Colors.SkyBlue;
579 }
580 if (strcasecmp(name, "SlateBlue") == 0) {
581 return Colors.SlateBlue;
582 }
583 if (strcasecmp(name, "SlateGray") == 0) {
584 return Colors.SlateGray;
585 }
586 if (strcasecmp(name, "SlateGrey") == 0) {
587 return Colors.SlateGrey;
588 }
589 if (strcasecmp(name, "Snow") == 0) {
590 return Colors.Snow;
591 }
592 if (strcasecmp(name, "SpringGreen") == 0) {
593 return Colors.SpringGreen;
594 }
595 if (strcasecmp(name, "SteelBlue") == 0) {
596 return Colors.SteelBlue;
597 }
598 if (strcasecmp(name, "Tan") == 0) {
599 return Colors.Tan;
600 }
601 if (strcasecmp(name, "Teal") == 0) {
602 return Colors.Teal;
603 }
604 if (strcasecmp(name, "Thistle") == 0) {
605 return Colors.Thistle;
606 }
607 if (strcasecmp(name, "Tomato") == 0) {
608 return Colors.Tomato;
609 }
610 if (strcasecmp(name, "Transparent") == 0) {
611 return Colors.Transparent;
612 }
613 if (strcasecmp(name, "Turquoise") == 0) {
614 return Colors.Turquoise;
615 }
616 if (strcasecmp(name, "Violet") == 0) {
617 return Colors.Violet;
618 }
619 if (strcasecmp(name, "Wheat") == 0) {
620 return Colors.Wheat;
621 }
622 if (strcasecmp(name, "White") == 0) {
623 return Colors.White;
624 }
625 if (strcasecmp(name, "WhiteSmoke") == 0) {
626 return Colors.WhiteSmoke;
627 }
628 if (strcasecmp(name, "Yellow") == 0) {
629 return Colors.Yellow;
630 }
631 if (strcasecmp(name, "YellowGreen") == 0) {
632 return Colors.YellowGreen;
633 }
634 }
635
636 return Colors.Black;
637}
638
639SDL_Color MVC_HexToRGBA(const char *hex) {
640 static char buffer[9];
641
642 union {
643 SDL_Color c;
644 unsigned int u;
645 } color;
646
647 color.u = 0;
648
649 const size_t length = strlen(hex);
650 if (length != 6 && length != 8) {
651 return color.c;
652 }
653
654 strcpy(buffer, hex);
655
656 if (length == 6) {
657 strcat(buffer, "ff");
658 }
659
660 if (sscanf(buffer, "%x", &color.u) != 1) {
661 return color.c;
662 }
663
664#if SDL_BYTEORDER == SDL_LIL_ENDIAN
665 color.u = (((color.u & 0xff000000) >> 24) | ((color.u & 0x00ff0000) >> 8) | ((color.u & 0x0000ff00) << 8) | ((color.u & 0x000000ff) << 24));
666#endif
667
668 return color.c;
669}
670
671char *MVC_RGBToHex(const SDL_Color *color) {
672 return MVC_RGBAToHex(&(const SDL_Color) { .r = color->r, .g = color->g, .b = color->b, .a = 255 });
673}
674
675char *MVC_RGBAToHex(const SDL_Color *color) {
676 static char hex[9];
677
678 assert(color);
679
680 snprintf(hex, sizeof(hex), "%02x%02x%02x%02x", color->r, color->g, color->b, color->a);
681
682 return hex;
683}
684
685SDL_Color MVC_HSVToRGB(double hue, double saturation, double value) {
686
687 SDL_Color color = { .a = 255 };
688
689 const double h = fabs(fmod(hue, 360.0)) / 60.0;
690 const int i = (int) h;
691 const double f = h - i;
692 const double v = value * 255;
693 const double p = v * (1.0 - saturation);
694 const double q = v * (1.0 - (saturation * f));
695 const double t = v * (1.0 - (saturation * (1.0 - f)));
696
697 switch (i) {
698 case 0:
699 color.r = v;
700 color.g = t;
701 color.b = p;
702 break;
703 case 1:
704 color.r = q;
705 color.g = v;
706 color.b = p;
707 break;
708 case 2:
709 color.r = p;
710 color.g = v;
711 color.b = t;
712 break;
713 case 3:
714 color.r = p;
715 color.g = q;
716 color.b = v;
717 break;
718 case 4:
719 color.r = t;
720 color.g = p;
721 color.b = v;
722 break;
723 default:
724 color.r = v;
725 color.g = p;
726 color.b = q;
727 break;
728 }
729
730 return color;
731}
732
733void MVC_RGBToHSV(const SDL_Color *color, double *hue, double *saturation, double *value) {
734
735 assert(color);
736
737 const double r = color->r / 255.0;
738 const double g = color->g / 255.0;
739 const double b = color->b / 255.0;
740
741 const double rgbMax = max(max(r, g), b);
742 const double rgbMin = min(min(r, g), b);
743 const double rgbDelta = rgbMax - rgbMin;
744
745 if (rgbDelta > 0.0) {
746
747 if (hue) {
748 if (rgbMax == r) {
749 *hue = 60.0 * fmod(((g - b) / rgbDelta), 6.0);
750 } else if (rgbMax == g) {
751 *hue = 60.0 * (((b - r) / rgbDelta) + 2.0);
752 } else if (rgbMax == b) {
753 *hue = 60.0 * (((r - g) / rgbDelta) + 4.0);
754 }
755
756 while (*hue < 0.0) {
757 *hue += 360.0;
758 }
759 }
760
761 if (saturation) {
762 if (rgbMax > 0.0) {
763 *saturation = rgbDelta / rgbMax;
764 } else {
765 *saturation = 0.0;
766 }
767 }
768
769 if (value) {
770 *value = rgbMax;
771 }
772
773 } else {
774 if (hue) {
775 *hue = 0.0;
776 }
777
778 if (saturation) {
779 *saturation = 0.0;
780 }
781
782 if (value) {
783 *value = rgbMax;
784 }
785 }
786}
char * MVC_RGBAToHex(const SDL_Color *color)
Definition Colors.c:675
SDL_Color MVC_HSVToRGB(double hue, double saturation, double value)
Definition Colors.c:685
SDL_Color MVC_ColorForName(const char *name)
Definition Colors.c:181
void MVC_RGBToHSV(const SDL_Color *color, double *hue, double *saturation, double *value)
Definition Colors.c:733
char * MVC_RGBToHex(const SDL_Color *color)
Definition Colors.c:671
SDL_Color MVC_HexToRGBA(const char *hex)
Definition Colors.c:639
W3C Color constants.
W3C Color constants.
Definition Colors.h:37
SDL_Color LightGrey
Definition Colors.h:112
SDL_Color WhiteSmoke
Definition Colors.h:186
SDL_Color LightBlue
Definition Colors.h:107
SDL_Color DarkOrange
Definition Colors.h:70
SDL_Color Gold
Definition Colors.h:91
SDL_Color MediumBlue
Definition Colors.h:128
SDL_Color DarkGoldenRod
Definition Colors.h:63
SDL_Color Brown
Definition Colors.h:50
SDL_Color LightSalmon
Definition Colors.h:115
SDL_Color MediumSlateBlue
Definition Colors.h:132
SDL_Color Pink
Definition Colors.h:155
SDL_Color Lime
Definition Colors.h:122
SDL_Color Turquoise
Definition Colors.h:182
SDL_Color DarkTurquoise
Definition Colors.h:78
SDL_Color Thistle
Definition Colors.h:179
SDL_Color SlateGray
Definition Colors.h:172
SDL_Color AliceBlue
Definition Colors.h:39
SDL_Color Magenta
Definition Colors.h:125
SDL_Color Fuchsia
Definition Colors.h:88
SDL_Color SlateBlue
Definition Colors.h:171
SDL_Color Plum
Definition Colors.h:156
SDL_Color LavenderBlush
Definition Colors.h:104
SDL_Color DimGray
Definition Colors.h:82
SDL_Color DarkRed
Definition Colors.h:72
SDL_Color LightSteelBlue
Definition Colors.h:120
SDL_Color FloralWhite
Definition Colors.h:86
SDL_Color SlateGrey
Definition Colors.h:173
SDL_Color MidnightBlue
Definition Colors.h:136
SDL_Color ForestGreen
Definition Colors.h:87
SDL_Color DarkViolet
Definition Colors.h:79
SDL_Color DarkCyan
Definition Colors.h:62
SDL_Color White
Definition Colors.h:185
SDL_Color Crimson
Definition Colors.h:59
SDL_Color Aquamarine
Definition Colors.h:42
SDL_Color PowderBlue
Definition Colors.h:157
SDL_Color SteelBlue
Definition Colors.h:176
SDL_Color BlanchedAlmond
Definition Colors.h:47
SDL_Color Azure
Definition Colors.h:43
SDL_Color Tan
Definition Colors.h:177
SDL_Color Green
Definition Colors.h:95
SDL_Color Wheat
Definition Colors.h:184
SDL_Color Coral
Definition Colors.h:56
SDL_Color Tomato
Definition Colors.h:180
SDL_Color MintCream
Definition Colors.h:137
SDL_Color Navy
Definition Colors.h:141
SDL_Color NavajoWhite
Definition Colors.h:140
SDL_Color LightSlateGray
Definition Colors.h:118
SDL_Color Snow
Definition Colors.h:174
SDL_Color Gainsboro
Definition Colors.h:89
SDL_Color PaleTurquoise
Definition Colors.h:150
SDL_Color Lavender
Definition Colors.h:103
SDL_Color RosyBrown
Definition Colors.h:161
SDL_Color DeepSkyBlue
Definition Colors.h:81
SDL_Color Maroon
Definition Colors.h:126
SDL_Color LightPink
Definition Colors.h:114
SDL_Color CadetBlue
Definition Colors.h:52
SDL_Color RebeccaPurple
Definition Colors.h:159
SDL_Color DarkSeaGreen
Definition Colors.h:74
SDL_Color DarkGray
Definition Colors.h:64
SDL_Color Cornsilk
Definition Colors.h:58
SDL_Color RoyalBlue
Definition Colors.h:162
SDL_Color LightSkyBlue
Definition Colors.h:117
SDL_Color Ivory
Definition Colors.h:101
SDL_Color Cyan
Definition Colors.h:60
SDL_Color DodgerBlue
Definition Colors.h:84
SDL_Color PeachPuff
Definition Colors.h:153
SDL_Color DarkGrey
Definition Colors.h:65
SDL_Color Linen
Definition Colors.h:124
SDL_Color Salmon
Definition Colors.h:164
SDL_Color DarkSlateGray
Definition Colors.h:76
SDL_Color GreenYellow
Definition Colors.h:96
SDL_Color DarkKhaki
Definition Colors.h:67
SDL_Color LightSlateGrey
Definition Colors.h:119
SDL_Color Charcoal
Definition Colors.h:53
SDL_Color Yellow
Definition Colors.h:187
SDL_Color Blue
Definition Colors.h:48
SDL_Color MediumOrchid
Definition Colors.h:129
SDL_Color DimGrey
Definition Colors.h:83
SDL_Color PaleGoldenRod
Definition Colors.h:148
SDL_Color Violet
Definition Colors.h:183
SDL_Color GhostWhite
Definition Colors.h:90
SDL_Color Sienna
Definition Colors.h:168
SDL_Color DarkSlateGrey
Definition Colors.h:77
SDL_Color GoldenRod
Definition Colors.h:92
SDL_Color LightGreen
Definition Colors.h:113
SDL_Color SaddleBrown
Definition Colors.h:163
SDL_Color CornflowerBlue
Definition Colors.h:57
SDL_Color Chartreuse
Definition Colors.h:54
SDL_Color FireBrick
Definition Colors.h:85
SDL_Color Transparent
Definition Colors.h:181
SDL_Color LawnGreen
Definition Colors.h:105
SDL_Color Indigo
Definition Colors.h:100
SDL_Color MediumTurquoise
Definition Colors.h:134
SDL_Color Olive
Definition Colors.h:143
SDL_Color MediumSpringGreen
Definition Colors.h:133
SDL_Color Purple
Definition Colors.h:158
SDL_Color DarkSalmon
Definition Colors.h:73
SDL_Color DeepPink
Definition Colors.h:80
SDL_Color OliveDrab
Definition Colors.h:144
SDL_Color LightCoral
Definition Colors.h:108
SDL_Color LightGray
Definition Colors.h:111
SDL_Color Black
Definition Colors.h:46
SDL_Color Orange
Definition Colors.h:145
SDL_Color SeaShell
Definition Colors.h:167
SDL_Color Peru
Definition Colors.h:154
SDL_Color LightSeaGreen
Definition Colors.h:116
SDL_Color MediumVioletRed
Definition Colors.h:135
SDL_Color SpringGreen
Definition Colors.h:175
SDL_Color PapayaWhip
Definition Colors.h:152
SDL_Color LightGoldenRodYellow
Definition Colors.h:110
SDL_Color Aqua
Definition Colors.h:41
SDL_Color DarkSlateBlue
Definition Colors.h:75
SDL_Color Beige
Definition Colors.h:44
SDL_Color MediumPurple
Definition Colors.h:130
SDL_Color LightYellow
Definition Colors.h:121
SDL_Color DarkOliveGreen
Definition Colors.h:69
SDL_Color HotPink
Definition Colors.h:98
SDL_Color LimeGreen
Definition Colors.h:123
SDL_Color MediumSeaGreen
Definition Colors.h:131
SDL_Color Gray
Definition Colors.h:93
SDL_Color PaleVioletRed
Definition Colors.h:151
SDL_Color SandyBrown
Definition Colors.h:165
SDL_Color DarkOrchid
Definition Colors.h:71
SDL_Color AntiqueWhite
Definition Colors.h:40
SDL_Color Silver
Definition Colors.h:169
SDL_Color Teal
Definition Colors.h:178
SDL_Color DarkGreen
Definition Colors.h:66
SDL_Color BlueViolet
Definition Colors.h:49
SDL_Color OldLace
Definition Colors.h:142
SDL_Color Khaki
Definition Colors.h:102
SDL_Color Chocolate
Definition Colors.h:55
SDL_Color Moccasin
Definition Colors.h:139
SDL_Color IndianRed
Definition Colors.h:99
SDL_Color MediumAquaMarine
Definition Colors.h:127
SDL_Color LemonChiffon
Definition Colors.h:106
SDL_Color HoneyDew
Definition Colors.h:97
SDL_Color Orchid
Definition Colors.h:147
SDL_Color Bisque
Definition Colors.h:45
SDL_Color LightCyan
Definition Colors.h:109
SDL_Color YellowGreen
Definition Colors.h:188
SDL_Color PaleGreen
Definition Colors.h:149
SDL_Color OrangeRed
Definition Colors.h:146
SDL_Color BurlyWood
Definition Colors.h:51
SDL_Color DarkMagenta
Definition Colors.h:68
SDL_Color SeaGreen
Definition Colors.h:166
SDL_Color DarkBlue
Definition Colors.h:61
SDL_Color Grey
Definition Colors.h:94
SDL_Color MistyRose
Definition Colors.h:138
SDL_Color SkyBlue
Definition Colors.h:170
SDL_Color Red
Definition Colors.h:160