1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
22 * Copyright (C) 2009-2011 Cyril Hrubis <metan@ucw.cz> *
24 *****************************************************************************/
29 #include "GP_Convert.h"
34 static char *color_names
[] = {
50 static uint8_t rgb888_colors
[][3] = {
51 {0x00, 0x00, 0x00}, /* Black */
52 {0xff, 0x00, 0x00}, /* Red */
53 {0x00, 0xff, 0x00}, /* Green */
54 {0x00, 0x00, 0xff}, /* Blue */
55 {0xff, 0xff, 0x00}, /* Yellow */
56 {0x00, 0xff, 0xff}, /* Cyan */
57 {0xff, 0x00, 0xff}, /* Magenta */
58 {0xa5, 0x2a, 0x2a}, /* Brown */
59 {0xff, 0xa5, 0x00}, /* Orange */
60 {0x7f, 0x7f, 0x7f}, /* DarkGray */
61 {0xbe, 0xbe, 0xbe}, /* LightGray */
62 {0xa0, 0x20, 0xf0}, /* Purple */
63 {0xff, 0xff, 0xff}, /* White */
66 /* 3-2-3 RGB palette */
67 static uint8_t p8_colors
[] = {
83 GP_Pixel
GP_ColorToPixel(GP_Color color
, GP_PixelType pixel_type
)
85 GP_ASSERT(color
< GP_COL_MAX
);
86 GP_ASSERT(color
>= 0);
88 if (pixel_type
== GP_PIXEL_P8
)
89 return p8_colors
[color
];
91 return GP_RGBToPixel(rgb888_colors
[color
][0],
92 rgb888_colors
[color
][1],
93 rgb888_colors
[color
][2],
97 GP_Color
GP_ColorNameToColor(const char *color_name
)
101 for (i
= 0; i
< GP_COL_MAX
; i
++)
102 if (!strcasecmp(color_name
, color_names
[i
]))
108 const char *GP_ColorToColorName(GP_Color color
)
110 if (color
< 0 || color
>= GP_COL_MAX
)
113 return color_names
[color
];
116 bool GP_ColorNameToPixel(const char *color_name
, GP_PixelType pixel_type
,
119 GP_Color color
= GP_ColorNameToColor(color_name
);
121 if (color
== GP_COL_INVALID
)
124 *pixel
= GP_ColorToPixel(color
, pixel_type
);
129 void GP_ColorLoadPixels(GP_Pixel pixels
[], GP_PixelType pixel_type
)
133 for (i
= 0; i
< GP_COL_MAX
; i
++)
134 pixels
[i
] = GP_ColorToPixel(i
, pixel_type
);