Add an API for converting a xcolor_t to a color_t
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
19e30e56d0
commit
293f2a312d
24
color.c
24
color.c
|
@ -25,6 +25,7 @@
|
|||
#include <ctype.h>
|
||||
|
||||
#define RGB_8TO16(i) (0xffff * ((i) & 0xff) / 0xff)
|
||||
#define RGB_16TO8(i) (0xff * ((i) & 0xffff) / 0xffff)
|
||||
|
||||
/** Parse an hexadecimal color string to its component.
|
||||
* \param colstr The color string.
|
||||
|
@ -255,4 +256,27 @@ xcolor_init_reply(xcolor_init_request_t req)
|
|||
return false;
|
||||
}
|
||||
|
||||
/** Convert a xcolor struct to a color one.
|
||||
* \param xcol The X color.
|
||||
* \param col The color.
|
||||
* \return True if everything has been converted.
|
||||
*/
|
||||
bool
|
||||
xcolor_to_color(const xcolor_t *xcol, color_t *col)
|
||||
{
|
||||
if (!xcol->initialized)
|
||||
{
|
||||
col->initialized = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
col->initialized = true;
|
||||
col->red = RGB_16TO8(xcol->red);
|
||||
col->green = RGB_16TO8(xcol->green);
|
||||
col->blue = RGB_16TO8(xcol->blue);
|
||||
col->alpha = RGB_16TO8(xcol->alpha);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
2
color.h
2
color.h
|
@ -72,6 +72,8 @@ bool color_init_reply(color_init_cookie_t);
|
|||
xcolor_init_request_t xcolor_init_unchecked(xcolor_t *, const char *, ssize_t);
|
||||
bool xcolor_init_reply(xcolor_init_request_t);
|
||||
|
||||
bool xcolor_to_color(const xcolor_t *, color_t *);
|
||||
|
||||
#endif
|
||||
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
Loading…
Reference in New Issue