2 * Copyright (c) 2014 - 2015 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
4 * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
5 * Written by Gaius Mulley <gaius@glam.ac.uk>
7 * This is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2, or (at your option) any later
12 * This is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * You should have received a copy of the GNU General Public License along
18 * with groff; see the file COPYING. If not, write to the Free Software
19 * Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
30 enum color_scheme
{DEFAULT
, CMY
, CMYK
, RGB
, GRAY
};
35 unsigned int components
[4];
37 static color
*free_list
;
39 int read_encoding(const color_scheme
, const char * const,
44 enum {MAX_COLOR_VAL
= 0xffff};
45 color(symbol s
= default_symbol
) : scheme(DEFAULT
), nm(s
) {}
46 color(const color
* const);
48 void *operator new(size_t);
49 void operator delete(void *);
51 int operator==(const color
& c
) const;
52 int operator!=(const color
& c
) const;
54 int is_default() { return scheme
== DEFAULT
; }
56 // set color from given color component values
58 void set_rgb(const unsigned int r
, const unsigned int g
,
59 const unsigned int b
);
60 void set_cmy(const unsigned int c
, const unsigned int m
,
61 const unsigned int y
);
62 void set_cmyk(const unsigned int c
, const unsigned int m
,
63 const unsigned int y
, const unsigned int k
);
64 void set_gray(const unsigned int g
);
66 // set color from a color string
67 int read_rgb(const char * const s
);
68 int read_cmy(const char * const s
);
69 int read_cmyk(const char * const s
);
70 int read_gray(const char * const s
);
72 // Return the actual color scheme and retrieve the color components
73 // into a predefined vector (of length at least 4).
74 color_scheme
get_components(unsigned int *c
) const;
76 // retrieve the components of a color
77 void get_rgb(unsigned int *r
, unsigned int *g
, unsigned int *b
) const;
78 void get_cmy(unsigned int *c
, unsigned int *m
, unsigned int *y
) const;
79 void get_cmyk(unsigned int *c
, unsigned int *m
,
80 unsigned int *y
, unsigned int *k
) const;
81 void get_gray(unsigned int *g
) const;
86 #define Cyan components[0]
87 #define Magenta components[1]
88 #define Yellow components[2]
89 #define Black components[3]
91 #define Red components[0]
92 #define Green components[1]
93 #define Blue components[2]
95 #define Gray components[0]
97 extern color default_color
; /* FIXME class-global static? (access fun?!) */