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:
Uli Schlachter 2009-04-17 18:20:06 +02:00 committed by Julien Danjou
parent 19e30e56d0
commit 293f2a312d
2 changed files with 26 additions and 0 deletions

24
color.c
View File

@ -25,6 +25,7 @@
#include <ctype.h> #include <ctype.h>
#define RGB_8TO16(i) (0xffff * ((i) & 0xff) / 0xff) #define RGB_8TO16(i) (0xffff * ((i) & 0xff) / 0xff)
#define RGB_16TO8(i) (0xff * ((i) & 0xffff) / 0xffff)
/** Parse an hexadecimal color string to its component. /** Parse an hexadecimal color string to its component.
* \param colstr The color string. * \param colstr The color string.
@ -255,4 +256,27 @@ xcolor_init_reply(xcolor_init_request_t req)
return false; 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 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -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); xcolor_init_request_t xcolor_init_unchecked(xcolor_t *, const char *, ssize_t);
bool xcolor_init_reply(xcolor_init_request_t); bool xcolor_init_reply(xcolor_init_request_t);
bool xcolor_to_color(const xcolor_t *, color_t *);
#endif #endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80