webperimental: killstack decides stack protects.
[freeciv.git] / client / gui-stub / colors.c
blob6c6542e6dbcce2800a4757dd8a4e71fa06dfc49a
1 /**********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 /* utility */
19 #include "mem.h"
21 /* common */
22 #include "rgbcolor.h"
24 /* gui main header */
25 #include "gui_stub.h"
27 #include "colors.h"
29 /****************************************************************************
30 Allocate a color (adjusting it for our colormap if necessary on paletted
31 systems) and return a pointer to it.
32 ****************************************************************************/
33 struct color *gui_color_alloc(int r, int g, int b)
35 struct color *color = fc_malloc(sizeof(*color));
37 /* PORTME */
38 color->r = r;
39 color->g = g;
40 color->b = b;
42 return color;
45 /****************************************************************************
46 Free a previously allocated color. See color_alloc.
47 ****************************************************************************/
48 void gui_color_free(struct color *color)
50 /* PORTME */
51 free(color);
54 /****************************************************************************
55 Return a number indicating the perceptual brightness of this color
56 relative to others (larger is brighter).
57 ****************************************************************************/
58 int color_brightness_score(struct color *pcolor)
60 /* PORTME */
61 /* Can use GUI-specific colorspace functions here. This is a fallback
62 * using platform-independent code */
63 struct rgbcolor *prgb = rgbcolor_new(pcolor->r, pcolor->g, pcolor->b);
64 int score = rgbcolor_brightness_score(prgb);
66 rgbcolor_destroy(prgb);
67 return score;