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)
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 /***********************************************************************
15 colors.c - description
17 begin : Mon Jul 15 2002
18 copyright : (C) 2002 by Rafał Bursig
19 email : Rafał Bursig <bursig@poczta.fm>
20 ***********************************************************************/
23 #include <fc_config.h>
27 #ifdef SDL2_PLAIN_INCLUDE
29 #else /* SDL2_PLAIN_INCLUDE */
31 #endif /* SDL2_PLAIN_INCLUDE */
37 #include "themespec.h"
41 /**************************************************************************
43 **************************************************************************/
44 SDL_Color
*get_theme_color(enum theme_color themecolor
)
46 return theme_get_color(theme
, themecolor
)->color
;
49 /**************************************************************************
50 Get color for some game object instance.
51 **************************************************************************/
52 SDL_Color
*get_game_color(enum color_std stdcolor
)
54 return get_color(tileset
, stdcolor
)->color
;
57 /****************************************************************************
58 Allocate a color with alpha channel and return a pointer to it. Alpha
59 channel is not really used yet.
60 ****************************************************************************/
61 struct color
*color_alloc_rgba(int r
, int g
, int b
, int a
)
63 struct color
*result
= fc_malloc(sizeof(*result
));
64 SDL_Color
*pcolor
= fc_malloc(sizeof(*pcolor
));
71 result
->color
= pcolor
;
76 /****************************************************************************
77 Allocate a solid color and return a pointer to it.
78 ****************************************************************************/
79 struct color
*color_alloc(int r
, int g
, int b
)
81 struct color
*result
= fc_malloc(sizeof(*result
));
82 SDL_Color
*pcolor
= fc_malloc(sizeof(*pcolor
));
89 result
->color
= pcolor
;
94 /****************************************************************************
95 Free resources allocated for color.
96 ****************************************************************************/
97 void color_free(struct color
*pcolor
)
110 /****************************************************************************
111 Return a number indicating the perceptual brightness of this color
112 relative to others (larger is brighter).
113 ****************************************************************************/
114 int color_brightness_score(struct color
*pcolor
)
116 struct rgbcolor
*prgb
= rgbcolor_new(pcolor
->color
->r
,
119 int score
= rgbcolor_brightness_score(prgb
);
121 rgbcolor_destroy(prgb
);