JSON protocol: fix field_addr memory leak.
[freeciv.git] / client / gui-qt / colors.cpp
blob16760951be2f3155f599d8bc372a116632f8812b
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 // gui-qt
22 #include "colors.h"
23 #include "qtg_cxxside.h"
25 /****************************************************************************
26 Allocate a color (adjusting it for our colormap if necessary on paletted
27 systems) and return a pointer to it.
28 ****************************************************************************/
29 struct color *qtg_color_alloc(int r, int g, int b)
31 struct color *pcolor = new color;
33 pcolor->qcolor.setRgb(r, g, b);
35 return pcolor;
38 /****************************************************************************
39 Free a previously allocated color. See qtg_color_alloc.
40 ****************************************************************************/
41 void qtg_color_free(struct color *pcolor)
43 delete pcolor;
46 /****************************************************************************
47 Return a number indicating the perceptual brightness of this color
48 relative to others (larger is brighter).
49 ****************************************************************************/
50 int color_brightness_score(struct color *pcolor)
52 /* QColor has color space conversions, but nothing giving a perceptually
53 * even color space */
54 struct rgbcolor *prgb = rgbcolor_new(pcolor->qcolor.red(),
55 pcolor->qcolor.green(),
56 pcolor->qcolor.blue());
57 int score = rgbcolor_brightness_score(prgb);
59 rgbcolor_destroy(prgb);
60 return score;