summaryrefslogtreecommitdiff
path: root/src/Color.cpp
blob: b612315084485c7a14402d4986c3c170ad1761c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

#include "Color.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>

unsigned Colors::colors[] = {0x888888, 0xFF0000, 0x0000FF, 0x00FF00,
                             0x660099, 0xFFFF00, 0x00FFFF, 0xFF8800};
char* Colors::color_names[] = {"GA", "RE", "BL", "GE", "PU", "YE", "CY", "OR", NULL};

Color Colors::read_color(char* s)
{
    for (int i = 0; Colors::color_names[i]; i++)
        if (!strcmp(Colors::color_names[i], s))
            return (Color) i;
    fprintf(stderr, "Error - Color not found: %s\n", s);
    exit(1);
}

unsigned Colors::get_color(Color c)
{
    // Color to 0xAABBCC format
    return colors[(int)c];
}

void Colors::to_rgb(Color c, unsigned char* r, unsigned char* g, unsigned char* b)
{
    unsigned c_int = get_color(c);
    *r = c_int >> 16;
    *g = (c_int >> 8) % 256;
    *b = c_int % 256;
}